// pages/order/pay/index.js import commonApi from "../../../utils/https/common" import util from "../../../utils/util" let timer; Page({ /** * 页面的初始数据 */ data: { id:null, info:null, second:"00", minute:"00", payIndex:-1, numIndex:0, showNumMask: false, activePay:false,//是否活动支付 SUBWALLET:false, wxPay:false, isBook:false, ids:[], // 多产品id status:false, // 是否新能源汽车专题产品 carCouponTip: 0, showTipMask:false, showTipMaskSecond: 3, MTTip: 0, SBMask: true, // 数币支付密码弹窗 isFoucs: true, vcode: '', haveSBPassword: false, inputData: { phone: '', code: '', password: '', confirmPassword: '', }, canSubmit: false, code:"", buttonText:"获取验证码", sendFlag:true, regToken:null, codeId:null, }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.setData({ id:options.id }) }, daojishi:function(time){ let now = new Date().getTime(); if(now>time){ clearTimeout(timer); timer = null; util.back(); return; } let times = time - now,minute = Math.floor(times / (60 * 1000)),second = Math.round((times - minute * 60 * 1000) / 1000); this.setData({ minute:util.formatNumber(minute), second:util.formatNumber(second) }) timer = setTimeout(()=>{ this.daojishi(time); },1000) }, // 选择支付方式 changePayMethod:function(e){ let index = e.currentTarget.dataset.index; this.setData({ payIndex:index }) }, changeNumIndex: function(e){ let index = e.currentTarget.dataset.index; this.setData({ numIndex:index }) }, hideNumMask: function() { this.setData({ showNumMask:false }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { commonApi.user_post("subwallet.ermb/wallet",{}).then(res=>{ // 给建设银行子钱包做标识 let resData = res.data || [] let JHWallet = resData.find(v=>v.bank_name.indexOf('建设')>=0) if (JHWallet) { JHWallet.isJSYH = 1 } this.setData({ payList:resData }) }) commonApi.user_post("order/query",{ order_id:this.data.id }).then(res=>{ // 书券产品 if(res.data.order_product_list[0].product_id == 75012 || res.data.order_product_list[0].product_id == 75013 || res.data.order_product_list[0].product_id == 420265|| res.data.order_product_list[0].product_id == 421929 || res.data.order_product_list[0].product_id == 437166 || res.data.order_product_list[0].product_id == 437248){ this.setData({ isBook:true, payIndex:1 }) } if(res.data.create_time && res.data.auto_close_time && res.data.state=='UNPAID'){ let time = (new Date(res.data.create_time.replace(/-/g,'/')).getTime() + Number(res.data.auto_close_time) * 1000); this.daojishi(time); } else { util.back() } if (Object.keys(res.data.coupon_activity).length != 0) { this.setData({ info:res.data, activePay: Object.keys(res.data.coupon_activity).length === 0 ?false:true, SUBWALLET:res.data.coupon_activity.pay_type.includes('SUBWALLET') || !res.data.coupon_activity.pay_type, wxPay:res.data.coupon_activity.pay_type.includes('WEIXIN') || !res.data.coupon_activity.pay_type, payIndex:Object.keys(res.data.coupon_activity).length === 0 ?-1:0, }) console.log(this.data.wxPay); }else{ this.setData({ info:res.data, }) } //判断是否存在新能源汽车专题产品 let carCouponTip = (res.data.order_product_list || []).some(v=>(v.tag_ids||[]).includes(390) || (v.tag_ids||[]).includes(391)) if (carCouponTip) { res.data.order_product_list.forEach(v=>{ v.needTip = (v.tag_ids||[]).includes(390) || (v.tag_ids||[]).includes(391) }) } // 判断是否存在美团酒店 let MTTip = (res.data.order_product_list || []).some(v=>(v.hotel_type=='mt')) if (MTTip) { res.data.order_product_list.forEach(v=>{ v.needTip = v.hotel_type=='mt' }) } this.setData({ carCouponTip:carCouponTip, info: res.data, MTTip: MTTip, }) console.log(this.data.ERMB); }) this.checkPay(); this.initTipMask() }, checkPay:function(){ commonApi.user_post("order/query_pay_result",{ order_id:this.data.id }).then(res=>{ if(res.data.code==1){ wx.showToast({ title: '订单已支付', icon:'success' }) this.setData({ status:true }) setTimeout(()=>{ wx.reLaunch({ url: '/pages/user/order/list', }) },1000) return; } }) }, pay:function(){ let arr = [] this.data.info.order_product_list.forEach(item => { arr.push(item.product_id) }) this.setData({ ids:arr }) if (this.data.activePay) { let flag = false if (this.data.payList.length!=0 && !this.data.info.coupon_activity.pay_type.includes('SUBWALLET')) { flag = true } if (this.data.activePay && flag && !this.data.wxPay) { wx.showToast({ title: '暂无支付方式请前往其它端付款', icon:'none' }) return } console.log(this.data.payIndex); if (this.data.payIndex===0) { wx.showToast({ title: '请选择支付方式', icon:'none' }) return } } let _this = this; if(this.data.payIndex==1) { this.setData({ showNumMask:true }) return; } commonApi.user_post("order/pay",{ order_id:this.data.id, // pay_method:"WEIXIN", // 2024-12-20 换为工行聚合支付 pay_method: "ICBC_WECHAT", pay_platform:"MINI", // app_name:"WxXcxConfig" }).then(res=>{ res.data = JSON.parse(res.data) console.log(res.data) wx.requestPayment({ nonceStr: res.data.nonceStr || res.data.noncestr, package: res.data.package, paySign: res.data.paySign || res.data.sign, timeStamp:""+(res.data.timeStamp || res.data.timestamp), signType:res.data.signType, success:function(res){ wx.showToast({ title: '支付成功', icon:'success' }) setTimeout(()=>{ wx.redirectTo({ url: '../payresult/index?tid='+_this.data.id+'&ids='+_this.data.ids.join(',') }) },1000) }, fail:function(err){ console.log(err) } }) console.log(res) }) }, // 电子钱包支付 walletPay:function(){ let item = this.data.payList[this.data.numIndex]; commonApi.user_post("order/pay",{ order_id:this.data.id, pay_method:"SUBWALLET", pay_platform:"MINI", app_name:"WxXcxConfig", ins_no:item.ins_no }).then(res=>{ let data = res.data?JSON.parse(res.data):{}; if(data && data.RESULT && data.RESULT=='Y'){ commonApi.user_post("order/query_pay_result",{ order_id:this.data.id }).then(res=>{ if(res.data.code==1){ wx.showToast({ title: '支付成功', icon:"success" }) setTimeout(()=>{ wx.redirectTo({ url: '../payresult/index?tid='+this.data.id+'&ids='+this.data.ids.join(',') }) },1000) } }) } else { wx.showToast({ // title: data.ERRORMSG || "支付失败,请重试", title: res.msg, icon:"none" }) } }) }, // 临时支付弹窗 initTipMask () { if (new Date().getTime()>=new Date('2025-02-01 00:00:00')) { return } this.setData({ showTipMask:true, showTipMaskSecond: 3, }) let second = this.data.showTipMaskSecond let timer = setInterval(()=>{ if(second<0) { clearInterval(timer) } second-- this.setData({showTipMaskSecond: second}) },1000) }, closeTipMask () { if (this.data.showTipMaskSecond<=0) { this.setData({ showTipMask:false, }) } }, // 数币密码确认 hideSBMask(){ this.setData({SBMask:false}) }, passwordChange: function (e) { let val = e.detail.value this.setData({ vcode: val }) if (val.length==6) { // 验证密码 } }, handleFoucs() { this.setData({ isFoucs: true }) }, inputChange:function(e){ let inputData = this.data.inputData let keyname =e.currentTarget.dataset.keyname; inputData[keyname] = e.detail.value this.setData({ inputData: inputData }) let canSubmit = false if (inputData.phone && inputData.code && inputData.password && inputData.confirmPassword) { canSubmit = true } this.setData({canSubmit: canSubmit}) }, // 获取验证码 getCode:function(){ }, // 绑定 submit:function(){ }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { clearTimeout(timer) timer = null; }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { if (!this.data.status) { wx.reLaunch({ url: '/pages/user/order/list', }) } }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { } })