You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

657 lines
18 KiB

5 years ago
// pages/order/pay/index.js
import commonApi from "../../../utils/https/common"
import util from "../../../utils/util"
1 year ago
import pwEncode from "../../../utils/passwordEncode"
5 years ago
let timer;
Page({
/**
* 页面的初始数据
*/
data: {
id:null,
info:null,
second:"00",
5 years ago
minute:"00",
4 years ago
payIndex:-1,
3 years ago
numIndex:0,
showNumMask: false,
activePay:false,//是否活动支付
SUBWALLET:false,
wxPay:false,
2 years ago
isBook:false,
ids:[], // 多产品id
1 year ago
status:false,
// 是否新能源汽车专题产品
carCouponTip: 0,
showTipMask:false,
showTipMaskSecond: 3,
MTTip: 0,
1 year ago
1 year ago
SBMask: false, // 数币支付密码弹窗
1 year ago
isFoucs: true,
vcode: '',
1 year ago
haveSBPassword: false, // 是否设置密码
1 year ago
inputData: {
phone: '',
code: '',
password: '',
confirmPassword: '',
},
canSubmit: false,
code:"",
buttonText:"获取验证码",
sendFlag:true,
regToken:null,
codeId:null,
1 year ago
inputAreaHeight: 0,
heightTimer: null,
11 months ago
isPaying: false,
5 years ago
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
11 months ago
// 有token 先更换token
if (options.token) {
wx.setStorageSync("jstrip_token", options.token)
}
5 years ago
this.setData({
id:options.id
})
this.getUserInfo()
5 years ago
},
getUserInfo () {
commonApi.user_post("uservice/user/getMyInfo",{}).then(res => {
if (res && res.data) {
wx.setStorageSync('jstrip_userid', res.data.id)
wx.setStorageSync('jstrip_token', res.data.token)
wx.setStorageSync('jstrip_userInfo', res.data)
}
})
},
5 years ago
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)
},
5 years ago
// 选择支付方式
changePayMethod:function(e){
let index = e.currentTarget.dataset.index;
this.setData({
payIndex:index
})
},
4 years ago
changeNumIndex: function(e){
let index = e.currentTarget.dataset.index;
this.setData({
numIndex:index
})
},
hideNumMask: function() {
this.setData({
showNumMask:false
})
},
5 years ago
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
11 months ago
// 正在支付中不处理
if (this.data.isPaying) return
4 years ago
commonApi.user_post("subwallet.ermb/wallet",{}).then(res=>{
1 year ago
// 给建设银行子钱包做标识
let resData = res.data || []
let JHWallet = resData.find(v=>v.bank_name.indexOf('建设')>=0)
if (JHWallet) {
JHWallet.isJSYH = 1
}
4 years ago
this.setData({
1 year ago
payList:resData
4 years ago
})
})
5 years ago
commonApi.user_post("order/query",{
order_id:this.data.id
}).then(res=>{
1 year ago
// 书券产品
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 ||
res.data.order_product_list[0].product_id == 460429 ){
this.setData({
isBook:true,
payIndex:1
})
}
5 years ago
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()
}
3 years ago
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,
11 months ago
wxPay:res.data.coupon_activity.pay_type.includes('ICBC_WECHAT') || !res.data.coupon_activity.pay_type,
3 years ago
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,
})
3 years ago
console.log(this.data.ERMB);
5 years ago
})
this.checkPay();
this.initTipMask()
5 years ago
},
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'
})
2 years ago
this.setData({
status:true
})
5 years ago
setTimeout(()=>{
wx.reLaunch({
url: '/pages/user/order/list',
})
},1000)
return;
}
})
},
pay:function(){
2 years ago
let arr = []
this.data.info.order_product_list.forEach(item => {
arr.push(item.product_id)
})
this.setData({
ids:arr
})
3 years ago
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
}
}
5 years ago
let _this = this;
4 years ago
if(this.data.payIndex==1) {
this.setData({
showNumMask:true
})
return;
}
5 years ago
commonApi.user_post("order/pay",{
order_id:this.data.id,
// pay_method:"WEIXIN",
// 2024-12-20 换为工行聚合支付
pay_method: "ICBC_WECHAT",
5 years ago
pay_platform:"MINI",
// app_name:"WxXcxConfig"
5 years ago
}).then(res=>{
res.data = JSON.parse(res.data)
console.log(res.data)
11 months ago
_this.data.isPaying = true
5 years ago
wx.requestPayment({
nonceStr: res.data.nonceStr || res.data.noncestr,
5 years ago
package: res.data.package,
paySign: res.data.paySign || res.data.sign,
timeStamp:""+(res.data.timeStamp || res.data.timestamp),
5 years ago
signType:res.data.signType,
success:function(res){
wx.showToast({
title: '支付成功',
icon:'success'
})
setTimeout(()=>{
11 months ago
// 支付成功不还原isPaying redirectTo 会删掉当前页面触发unload
// _this.data.isPaying = false
5 years ago
wx.redirectTo({
2 years ago
url: '../payresult/index?tid='+_this.data.id+'&ids='+_this.data.ids.join(',')
5 years ago
})
},1000)
},
fail:function(err){
11 months ago
_this.data.isPaying = false
5 years ago
console.log(err)
}
})
console.log(res)
})
},
5 years ago
// 电子钱包支付
1 year ago
walletPay:function(otherData){
4 years ago
let item = this.data.payList[this.data.numIndex];
5 years ago
commonApi.user_post("order/pay",{
order_id:this.data.id,
pay_method:"SUBWALLET",
pay_platform:"MINI",
app_name:"WxXcxConfig",
1 year ago
ins_no:item.ins_no,
1 year ago
...otherData
5 years ago
}).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(',')
5 years ago
})
},1000)
}
})
}
else {
wx.showToast({
// title: data.ERRORMSG || "支付失败,请重试",
title: res.msg,
5 years ago
icon:"none"
})
}
})
},
5 years ago
// 临时支付弹窗
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,
})
}
},
1 year ago
// 数币密码确认
1 year ago
showPassword () {
11 months ago
let _this =this
1 year ago
// 请求是否设置密码
commonApi.user_post("pay_password/checkUsedPassword",{}).then(res=>{
11 months ago
if (res.data && (res.data.data || res.data.data===0)) {
11 months ago
let resCode = res.data.data
11 months ago
// 密码未设置
if (resCode === 0) {
11 months ago
let userinfo = wx.getStorageSync('jstrip_userInfo')
let inputData = {phone: '',code: '',password: '',confirmPassword: ''}
if (userinfo && userinfo.mobile) {
inputData.phone = userinfo.mobile
}
this.setData({
SBMask: true,
inputData: inputData,
haveSBPassword: false,
})
11 months ago
} else {
commonApi.user_post("pay_password/checkLocked",{}).then(res=>{
if (res.code!=1) {
return
} else {
if (resCode == 1) {
// 密码正常
this.setData({
SBMask: true,
haveSBPassword: true,
vcode: '',
isFoucs: true
11 months ago
})
11 months ago
} else {
wx.showModal({
title: '您的支付密码已过期',
content: resCode,
cancelText: '修改密码',
confirmText:'忘记密码',
confirmColor:"#0E8790",
success(res){
if (res.confirm) {
console.log('忘记密码')
_this.goReset()
} else if (res.cancel) {
console.log('修改密码')
_this.goEdit()
}
},
})
}
}
11 months ago
})
11 months ago
}
1 year ago
}
})
},
1 year ago
hideSBMask(){
1 year ago
this.setData({
SBMask:false,
})
1 year ago
},
passwordChange: function (e) {
let val = e.detail.value
this.setData({
vcode: val
})
if (val.length==6) {
1 year ago
let password = pwEncode.handleEncrypt(val)
1 year ago
// 验证密码
1 year ago
commonApi.user_post("pay_password/verifyPassword",{password:password}).then(res =>{
1 year ago
// 密码校验成功
if (res.code == 1) {
1 year ago
this.setData({vcode: '',SBMask: false})
commonApi.user_post('pay_password/getNonce',{}).then(nonceRes =>{
if (nonceRes.code == 1) {
let pwSign = pwEncode.getPWSignature(password, nonceRes.data)
pwSign.password = password
pwSign.type = 1
this.walletPay(pwSign)
}
1 year ago
})
} else {
this.setData({
vcode: '',
})
}
})
1 year ago
}
},
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(){
1 year ago
// 如果已经在发送则不能继续发送验证码
if (!this.data.sendFlag){
return false;
}
if(!this.data.inputData.phone){
wx.showToast({
title: '请输入手机号',
icon:"none"
})
return false;
}
if(!util.isTel(this.data.inputData.phone)){
wx.showToast({
title: '请输入正确的手机号码',
icon: "none"
})
return false;
}
// 获取验证码则需要改变按钮的文字
this.setData({
buttonText:"发送中...",
sendFlag:false
})
commonApi.user_post("uservice/user/getMobileCodeForResetPayPass",{mobile:this.data.inputData.phone}).then(res=>{
if(res.code==1){
// 发送成功 即接口调用成功
this.setData({
buttonText: "发送成功",
sendFlag: false,
codeId: res.data.smsCodeId
})
// 获取成功之后需要马上改变成倒计时
let time = 59;
var timer = setInterval(() => {
// 倒计时结束需要重置可发送验证码状态和按钮文字
if (time < 0) {
// 清除定时器
clearInterval(timer)
this.setData({
buttonText: "重新发送",
sendFlag: true
})
return false;
}
this.setData({
buttonText: time + "秒后重新发送"
})
time--;
}, 1000)
}
else {
this.setData({
buttonText: "重新发送",
sendFlag: true
})
}
}).catch(e=>{
this.setData({
buttonText: "重新发送",
sendFlag: true
})
})
1 year ago
},
// 绑定
submit:function(){
1 year ago
if (!this.data.canSubmit) {
return
}
if(!this.data.inputData.code){
wx.showToast({
title: '请输入验证码',
icon: "none"
})
return false;
}
1 year ago
1 year ago
let data={
code:this.data.inputData.code,
mobile:this.data.inputData.phone,
smsCodeId:this.data.codeId,
password: pwEncode.handleEncrypt(this.data.inputData.password),
confirm_password:pwEncode.handleEncrypt(this.data.inputData.confirmPassword)
}
let service = "pay_password/set"
commonApi.user_post(service,data).then(res=>{
if(res.code==1){
wx.showToast({
title: '密码设置成功',
icon: 'none'
})
this.setData({
haveSBPassword: true,
isFoucs: true,
vcode: '',
})
}
})
1 year ago
},
1 year ago
inputfocus: function () {
clearTimeout(this.data.heightTimer)
this.setData({inputAreaHeight: 600})
},
inputblur: function () {
let _this = this
this.data.heightTimer = setTimeout(()=>{
_this.setData({inputAreaHeight: 0})
},300)
},
1 year ago
goReset: function () {
commonApi.user_post("pay_password/checkLocked",{}).then(res=>{
if (res.code!=1) {
return
} else {
wx.navigateTo({
1 year ago
url: '/subPackages/password/setting/setting?type=reset'
1 year ago
})
}
})
},
11 months ago
goEdit: function () {
commonApi.user_post("pay_password/checkLocked",{}).then(res=>{
if (res.code!=1) {
return
} else {
wx.navigateTo({
url: '/subPackages/password/setting/setting?type=edit'
})
}
})
},
1 year ago
5 years ago
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
clearTimeout(timer)
timer = null;
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
11 months ago
if (!this.data.status && !this.data.isPaying) {
2 years ago
wx.reLaunch({
url: '/pages/user/order/list',
})
}
5 years ago
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
}
})