Pārlūkot izejas kodu

移动积分去支付

kk.shi 3 gadi atpakaļ
vecāks
revīzija
46d52b7c12
3 mainītis faili ar 463 papildinājumiem un 28 dzēšanām
  1. 28 0
      api/integralinfo.js
  2. 395 24
      pages/integral/integral.js
  3. 40 4
      pages/integral/integral.wxml

+ 28 - 0
api/integralinfo.js

@@ -80,6 +80,34 @@ class Integralinfo extends request {
     return this.postRequest(`${this.INT_URL}app/cmcc/balance`, params);
   }
 
+   /**
+   * 下单
+   */
+  static getOrder(params) {
+    return this.postRequest(`${this.INT_URL}/app/order/order`, params);
+  }
+
+  /**
+   * 一次验证码的支付
+   */
+  static getPayOnce(params) {
+    return this.postRequest(`${this.INT_URL}/app/order/payOnce`, params);
+  }
+
+   /**
+   * 支付短信验证码
+   */
+  static getPaySend(params) {
+    return this.postRequest(`${this.INT_URL}/app/order/paySend`, params);
+  }
+
+   /**
+   * 重新下发移动短信
+   */
+  static getSendCmccSms(params) {
+    return this.postRequest(`${this.INT_URL}/app/order/sendCmccSms`, params);
+  }
+
        /**
    * 创建订单
    */

+ 395 - 24
pages/integral/integral.js

@@ -50,7 +50,21 @@ Page({
         icon: '',
         title: '',
         status: false
-    }
+    },
+    stepList:[
+        {
+          name:"下单时间",
+          status:"0"
+        },
+        {
+          name:"支付时间",
+          status:"0"
+        },
+        {
+          name:"降锁时间",
+          status:"1"//status步骤条状态。=1表示最后一条渲染不同样式
+        }
+      ]
   },
 
   /**
@@ -62,7 +76,9 @@ Page({
         isLogin: getMobileCache() != '',
         phone: getMobileCache() == ''?'********':getMobileCache().replace(reg, "$1****$2"),
         setPhone: getMobileCache(),
+        mobile: getMobileCache(),
     })
+    this.step = this.selectComponent("#step");
   },
 
   /**
@@ -78,6 +94,9 @@ Page({
   onShow: function () {
     this.getBannerList()
     this.getCouponList()
+    if(getMobileCache() != ''){
+        this.getphoneClick()
+    }
   },
 
   /**
@@ -158,7 +177,10 @@ couponListView: function(data) {
             data[i].quantity = parseInt(num / data[i].integral)
             if (data[i].quantity > 0) {
                 num -= (data[i].quantity * data[i].price) * data[i].ratio
-                this.total += (data[i].quantity * data[i].price) * data[i].ratio
+                this.data.total += (data[i].quantity * data[i].price) * data[i].ratio
+                this.setData({
+                    total:this.data.total
+                })
                 arr.push(data[i])
                 data.splice(i, 1)
                 i--
@@ -249,14 +271,14 @@ getPhoneNumber(e) {
         var reg = /^(\d{3})\d{4}(\d{4})$/;
         this.setData({
             isLogin: true,
-            setPhone: getMobileCache(),
-            mobile: getMobileCache(),
-            phone: getMobileCache().replace(reg, "$1****$2")
+            setPhone: '13816922995',
+            mobile:  '13816922995',
+            phone: '13816922995'.replace(reg, "$1****$2")
         })     
         // console.log(this.data.setPhone)
         // console.log(this.data.mobile)
         // console.log(this.data.phone)
-        // this.getphoneClick()
+        this.getphoneClick()
     }
          
     })
@@ -284,7 +306,7 @@ getphoneClick() {
         //     title: '加载中'
         // });
         Integralinfo.getBalance({
-            mobile: this.data.setPhone, 
+            mobile: '13816922995', 
             callbackUrl: '../integral/integral.wxml',
             fingerprint: '',
             sessionid: '',
@@ -294,15 +316,21 @@ getphoneClick() {
             console.log(arr)
             wx.hideLoading();
             if (arr.code === '0000') {
-                this.data.integralNum = arr.data
                 var reg = /^(\d{3})\d{4}(\d{4})$/;
-                this.data.mobile = this.data.setPhone
-                this.data.setPhone = this.data.setPhone.replace(reg, "$1****$2");
+                this.setData({
+                   integralNum: arr.data,
+                   setPhone:  '13816922995',
+                   phone: this.data.setPhone.replace(reg, "$1****$2"),
+                })
+                // this.data.integralNum = arr.data
+                // var reg = /^(\d{3})\d{4}(\d{4})$/;
+                // this.data.mobile = this.data.setPhone
+                // this.data.setPhone = this.data.setPhone.replace(reg, "$1****$2");
                 let response = {
                     points: arr.data,
                     outTokenId: this.data.setPhone + '_out'
                 }
-                App.globalData.AppShow = response
+                // App.globalData.AppShow = response
                 this.hideModal()
                 this.getCouponList()
                 wx.pageScrollTo({
@@ -315,16 +343,19 @@ getphoneClick() {
                         const data = JSON.parse(wx.getStorageSync('orderDetails'))
                         if (dateNum - data.date < 60) {
                             let time = dateNum - data.date
-                            this.codeName = 60 - time + 's后重新获取'
+                            this.data.codeName = 60 - time + 's后重新获取'
                             this.codeSetInterval(60 - time)
                         } else {
-                            this.codeName = '重新获取验证码'
+                            this.data.codeName = '重新获取验证码'
                         }
-                        this.data.paymentStatus = true
-                        this.data.paymentBgStatus = true
-                        this.data.active1code = ''
-                        this.data.active2code = ''
-                        this.data.active1obj = data
+                        this.setData({
+                            paymentStatus: true,
+                            paymentBgStatus: true,
+                            active1code: '',
+                            active2code: '',
+                            active1obj: data,
+                        })
+                       
                         if (data.step === 1) {
                             this.data.activeNum = 1
                         } else if (data.step === 2) {
@@ -333,8 +364,11 @@ getphoneClick() {
                     }
                 }
             } else {
-                this.data.loading = true
-                this.data.bgStatus = true
+                this.setData({
+                    loading: true,
+                    bgStatus: true
+                })
+                
                 setTimeout(() => {
                     // #ifdef H5
                     window.location.href = arr.message;
@@ -382,6 +416,10 @@ reduceClick(e) {
     let index = e.currentTarget.dataset.index
     this.data.couponList[index].quantity--
     this.data.total -= parseInt(this.data.couponList[index].integral)
+    this.setData({
+        total: this.data.total,
+        couponList: this.data.couponList
+    })
 },
 // 商品数量添加按钮
 addClick(e) {
@@ -396,6 +434,10 @@ addClick(e) {
         } else if ((this.data.integralNum - this.data.total) >= this.data.couponList[index].integral) {
             this.data.couponList[index].quantity++
             this.data.total += parseInt(this.data.couponList[index].integral)
+            this.setData({
+                total: this.data.total,
+                couponList:this.data.couponList
+            })
         } else {
             wx.showToast({
                 title: '积分不足',
@@ -418,7 +460,7 @@ addClick(e) {
 /** 刷新 */
 shuaxinClick() {
     Integralinfo.getBalance({
-        mobile: this.data.setPhone, 
+        mobile:  '13816922995', 
         callbackUrl: '../integral/integral.wxml',
         fingerprint: '',
         sessionid: '',
@@ -432,12 +474,341 @@ shuaxinClick() {
                 icon: 'success',
                 duration: 1000
             });
-            this.data.integralNum = arr.data
+            
             var reg = /^(\d{3})\d{4}(\d{4})$/;
-            this.data.setPhone = this.data.mobile
-            this.data.phone = this.data.setPhone.replace(reg, "$1****$2");
+            this.setData({
+               integralNum: arr.data,
+               setPhone:  '13816922995',
+               phone: this.data.setPhone.replace(reg, "$1****$2"),
+            })
+           
         }
     })
 },
+
+// 支付按钮
+paymentClick() {
+    console.log(this.data.mobile)
+    if (this.data.mobile === '********') {
+        setTimeout(() => {
+            this.scoreClick()
+        }, 1000)
+        wx.showToast({
+            title: '先查询移动积分',
+            icon: 'error',
+            duration: 1000
+        });
+    } else if (this.data.total === 0) {
+        wx.showToast({
+            title: '请选择商品数量',
+            icon: 'error',
+            duration: 2000
+        });
+    } else {
+        const data = []
+        this.data.couponList.forEach(v => {
+            if (v.quantity > 0) {
+                data.push({
+                    couponid: v.id,
+                    num: v.quantity,
+                })
+            }
+        })
+
+        // let fingerprint = ''
+        // let sessionid = ''
+
+        // // #ifndef MP-WEIXIN
+        // fingerprint = window.fmOpt
+        // sessionid = window.sessionId
+        // // #endif
+
+        Integralinfo.getOrder({
+            fingerprint:'',
+            list: data,
+            mobile: this.data.setPhone, 
+            tgid: this.data.tgid,
+            sessionid:'',
+            shopid: this.data.shopid
+        }).then(res => {
+                if (res.code === '0000') {
+                    this.codeSetInterval(60)
+                    this.setData({
+                        codeName: '60s后重新获取',
+                        paymentStatus: true,
+                        paymentBgStatus: true,
+                        active1code: '',
+                        active2code: '',
+                        active1obj:{
+                            orderId: res.data.orderId,
+                            order_no: res.data.order_no,
+                            step: res.data.step,
+                            date: Math.round(new Date().getTime() / 1000).toString(),
+                            mobile: this.data.mobile
+                        },
+                    })
+                    wx.setStorageSync('orderDetails', JSON.stringify(this.data.active1obj))
+                    if (res.data.step === 1) {
+                        this.setData({
+                            activeNum: 1,
+                        })
+                    } else if (res.data.step === 2) {
+                        this.setData({
+                            activeNum: 0,
+                        })
+                    }
+                } else {
+                    console.log(res.data.message)
+                    console.log(this.data.integralNum,this.data.mobile,JSON.stringify(data))
+                    // log.error(`${res.data.message}`)
+                    // log.error(`${this.data.integralNum},${this.data.mobile},${JSON.stringify(data)}`)
+                    this.setData({
+                        showToastObj: {
+                            icon: 'iconSueecss',
+                            title: res.data.message,
+                            status: true
+                        }
+                    })
+                    setTimeout(() => {
+                        this.setData({
+                            showToastObj: {
+                                icon: 'iconSueecss',
+                                title: res.data.message,
+                                status: false
+                            }
+                        })
+                    }, 2500)
+                }
+
+            })
+        }
+    },
+    // 步骤按钮
+    nextCodeClick() {
+        console.log(this.data.activeNum,this.data.active2code)
+        if (this.data.activeNum === 1 && this.data.active2code !== '') {
+            uni.showLoading({
+                title: '兑换中'
+            });
+            // let fingerprint = ''
+            // let sessionid = ''
+
+            // // #ifndef MP-WEIXIN
+            // fingerprint = window.fmOpt
+            // sessionid = window.sessionId
+            // #endif
+            Integralinfo.getPayOnce({
+                fingerprint: '',
+                mobile: this.data.mobile,
+                optCode: this.data.active2code,
+                order_no: this.active1obj.order_no,
+                orderId: this.active1obj.orderId,
+                sessionid: '',
+                shopid: this.shopid
+            }).then(res => {
+                    if (res.code === '0000') {
+                        const obj = {
+                            mobile: this.data.mobile,
+                            channelid: this.data.channelid,
+                            shopid: this.data.shopid,
+                            storeid: this.data.storeid
+                        }
+                        this.data.integralNum -= this.data.total
+                        this.setData({
+                            integralNum: this.data.integralNum,
+                            total: 0,
+                            listStatus: false,
+                            listTrue: [],
+                        })
+                        this.data.couponList.forEach((v)=>{
+                            v.quantity = 0
+                        })
+                        this.paymentStatus = false
+                        this.paymentBgStatus = false
+                        wx.setStorageSync('orderDetails', null)
+                        wx.hideLoading();
+                        wx.navigateTo({
+                            url: '../success/success?row=' + JSON.stringify(obj)
+                        })
+                    } else {
+                        wx.hideLoading();
+                        this.setData({
+                            showToastObj: {
+                                icon: 'iconSueecss',
+                                title: res.message,
+                                status: true
+                            }
+                        })
+                        setTimeout(() => {
+                            this.setData({
+                                showToastObj: {
+                                    icon: 'iconSueecss',
+                                    title: res.message,
+                                    status: false
+                                }
+                            })
+                        }, 2500)
+                    }
+            });
+        } else if (this.data.activeNum === 0 && this.data.active1code !== '') {
+            Integralinfo.getPayOnce({
+                fingerprint: '',
+                mobile: this.data.mobile,
+                optCode: this.data.active1code,
+                orderId: this.data.active1obj.orderId,
+                order_no: this.data.active1obj.order_no,
+                sessionid: '',
+                shopid: this.data.shopid
+            }).then(res => {
+                if (res.code === '0000') {
+                    clearInterval(this.data.codeTime)
+                    this.setData({
+                        active2code: '',
+                        activeNum: this.activeNum++,
+                        codeName: '60s后重新获取',
+                    })
+                    this.codeSetInterval(60)
+                } else {
+                    this.setData({
+                        showToastObj: {
+                            icon: 'iconSueecss',
+                            title: res.message,
+                            status: true
+                        }
+                    })
+                    setTimeout(() => {
+                        this.setData({
+                            showToastObj: {
+                                icon: 'iconSueecss',
+                                title: res.message,
+                                status: false
+                            }
+                        })
+                    }, 2500)
+                }
+            })
+        } else {
+            wx.showToast({
+                icon: 'error',
+                title: '请填写验证码'
+            })
+        }
+    },
+    // 短信定时器
+    codeSetInterval(num) {
+        console.log(num)
+        let time = num
+        this.data.codeTime = setInterval(() => {
+            if (time <= 1) {
+                this.setData({
+                    codeName: '重新获取验证码',
+                })
+                clearInterval(this.data.codeTime)
+            } else {
+                time--
+                this.setData({
+                    codeName:`${time}s后重新获取`
+                })
+            }
+        }, 1000)
+    },
+
+    // 重新获取短信
+    getCodeClick() {
+        if ((this.data.activeNum === 1 && this.data.codeName === '重新获取验证码') && this.data.active1obj.step === 1) {
+            Integralinfo.getSendCmccSms({
+                orderId: this.data.active1obj.orderId,
+                mobile: this.data.mobile,
+                shopid: this.data.shopid
+            }).then(res => {
+                    if (res.code === '0000') {
+                        this.setData({
+                            codeName: '60s后重新获取',
+                        })
+                        this.codeSetInterval(60)
+                        const obj = this.active1obj
+                        obj.date = Math.round(new Date().getTime() / 1000).toString()
+                        wx.setStorageSync('orderDetails', JSON.stringify(obj))
+                    } else {
+                        this.setData({
+                            showToastObj: {
+                                icon: 'iconSueecss',
+                                title: res.message,
+                                status: true
+                            }
+                        })
+                        setTimeout(() => {
+                            this.setData({
+                                showToastObj: {
+                                    icon: 'iconSueecss',
+                                    title: res.message,
+                                    status: false
+                                }
+                            })
+                        }, 2500)
+                    }
+            });
+        } else {
+            if (this.data.activeNum === 0 && this.data.codeName === '重新获取验证码') {
+                Integralinfo.getSendCmccSms({
+                    orderId: this.data.active1obj.orderId,
+                    mobile: this.data.mobile,
+                    shopid: this.data.shopid
+                }).then(res => {
+                        if (res.code === '0000') {
+                            this.codeName = '60s后重新获取'
+                            this.codeSetInterval(60)
+                        } else {
+                            this.setData({
+                                showToastObj: {
+                                    icon: 'iconSueecss',
+                                    title: res.message,
+                                    status: true
+                                }
+                            })
+                            setTimeout(() => {
+                                this.setData({
+                                    showToastObj: {
+                                        icon: 'iconSueecss',
+                                        title: res.message,
+                                        status: false
+                                    }
+                                })
+                            }, 2500)
+                        }
+                });
+            } else if (this.data.activeNum === 1 && this.data.codeName === '重新获取验证码') {
+                Integralinfo.getPaySend({
+                    order_no: this.data.active1obj.order_no,
+                    mobile: this.data.mobile,
+                    shopid: this.data.shopid,
+                }).then(res => {
+                        if (res.code === '0000') {
+                            this.setData({
+                                codeName: '60s后重新获取',
+                            })
+                            this.codeSetInterval(60)
+                        } else {
+                            this.setData({
+                                showToastObj: {
+                                    icon: 'iconSueecss',
+                                    title: res.message,
+                                    status: true
+                                }
+                            })
+                            setTimeout(() => {
+                                this.setData({
+                                    showToastObj: {
+                                        icon: 'iconSueecss',
+                                        title: res.message,
+                                        status: false
+                                    }
+                                })
+                            }, 2500)
+                        }
+                });
+            }
+        }
+    },
        
 })

+ 40 - 4
pages/integral/integral.wxml

@@ -13,7 +13,7 @@
         <view class="query-avatar-info" :style="{{phone !== '********'}} ? 'padding-top: 0upx;' : 'padding-top: 28upx;'">
           <view class="query-phone-hide">
             {{phone}}
-            <text style="font-size: 14px;margin-left: 8px;">换号</text>
+            <!-- <text style="font-size: 14px;margin-left: 8px;">换号</text> -->
           </view>
         </view>
         <view class="query-click-column">
@@ -56,11 +56,11 @@
       </view>
     </view>
     <view class="receive-style flex-row" wx:if="{{phone !== '********'}}">
-      <view class="num-reduce flex-colum" catchtap="reduceClick" data-index="{{idx}}" hidden="{{item.quantity <= 0}}">-</view>
+      <view class="num-reduce" catchtap="reduceClick" data-index="{{idx}}" hidden="{{item.quantity <= 0}}">-</view>
       <view class="num-displayNumn">
         <view hidden="{{item.quantity <= 0}}">{{item.quantity}}</view>
       </view>
-      <view class="num-add flex-column" catchtap="addClick" data-index="{{idx}}">+</view>
+      <view class="num-add" catchtap="addClick" data-index="{{idx}}">+</view>
     </view>
     <view class="receive-style" wx:if="{{phone === '********'}}">
       <button class="receive-button" type="default" open-type="getPhoneNumber" bindgetphonenumber="getPhoneNumber">立即领取</button>
@@ -76,7 +76,8 @@
     <text>积分</text>
   </view>
   <view class="receive-info">
-    <button v-if="phone === '********'" type="default" hover-class="navigator-hover" class="receive-btn" open-type="getPhoneNumber" bindgetphonenumber="getPhoneNumber">立即领取</button>
+    <button wx:if="{{phone === '********'}}" type="default" hover-class="navigator-hover" class="receive-btn" open-type="getPhoneNumber" bindgetphonenumber="getPhoneNumber">立即领取</button>
+    <button wx:if="{{phone !== '********'}}" type="default" hover-class="navigator-hover" class="receive-btn" catchtap="paymentClick">立即免费兑换</button>
   </view>
 </view>
 
@@ -151,4 +152,39 @@
   <view class="loading">
     <image class="loading-image" src="../../images/logo.png" mode=""></image>
   </view>
+</view>
+
+<!-- 支付弹出框 -->
+<view class="payment" wx:if="{{paymentStatus}}">
+  <uni-steps active-color="rgb(250, 114, 0)" options="[{title: '移动积分兑换'}, {title: '输入验证码'}, {title: '兑换成功'}]" active="{{activeNum}}"></uni-steps>
+  <view class="payment-move" style="text-align: center;">
+    <view class="payment-code">
+      <view class="payment-code2">验证码已发送到</view>
+      <view class="payment-code3"><text class="payment-iconfont payment-iconphone payment-code3-text"></text>{{mobile}}</view>
+    </view>
+    <view class="payment-code-input" wx:if="{{activeNum === 0}}">
+      <text class="payment-iconfont payment-iconyanzhengma payment-code-input-text"></text>
+      <input type="payment-number" model="active1code" focus="true" maxlength="6" placeholder="输入6位数验证码" />
+    </view>
+    <view class="payment-code-input" wx:if="{{activeNum === 1}}">
+      <text class="payment-iconfont payment-iconyanzhengma payment-code-input-text"></text>
+      <input type="payment-number" model="active2code" focus="true" maxlength="6" placeholder="输入6位数验证码" />
+    </view>
+    <view class="payment-code-btn">
+      <button class="payment-button" type="payment-default" hover-class="navigator-hover" catchtap="nextCodeClick">确
+        定</button>
+    </view>
+    <view class="payment-refresh">
+      <text catchtap="getCodeClick">{{codeName}}</text>
+    </view>
+  </view>
+</view>
+
+<view class="showToast" wx:if="{{showToastObj.status}}">
+  <view class="showToast-icon">
+    <text class="showToast-iconfont" class="showToastObj.icon"></text>
+  </view>
+  <view class="showToast-title">
+    <text>{{showToastObj.title}}</text>
+  </view>
 </view>