|
@ -83,6 +83,7 @@ |
|
|
}, |
|
|
}, |
|
|
data() { |
|
|
data() { |
|
|
return { |
|
|
return { |
|
|
|
|
|
orderId: null, |
|
|
selectedCoupon: [], |
|
|
selectedCoupon: [], |
|
|
num: 1, |
|
|
num: 1, |
|
|
coupon: {}, |
|
|
coupon: {}, |
|
@ -105,8 +106,9 @@ |
|
|
}, |
|
|
}, |
|
|
...mapState(['userInfo', 'payOrderProduct']), |
|
|
...mapState(['userInfo', 'payOrderProduct']), |
|
|
}, |
|
|
}, |
|
|
onLoad(args) { |
|
|
|
|
|
|
|
|
onLoad({ id }) { |
|
|
this.$store.commit('getUserInfo') |
|
|
this.$store.commit('getUserInfo') |
|
|
|
|
|
this.orderId = id |
|
|
}, |
|
|
}, |
|
|
onShow() { |
|
|
onShow() { |
|
|
this.getCouponList() |
|
|
this.getCouponList() |
|
@ -128,11 +130,9 @@ |
|
|
this.selectedCoupon = [1] |
|
|
this.selectedCoupon = [1] |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
async fetchCreateOrder() { |
|
|
|
|
|
|
|
|
async fetchPayOrder() { |
|
|
// todo: check |
|
|
// todo: check |
|
|
let params = { |
|
|
let params = { |
|
|
itemId: this.payOrderProduct[0].id, |
|
|
|
|
|
amount: this.totalPrice, |
|
|
|
|
|
payType : this.payMethod, |
|
|
payType : this.payMethod, |
|
|
|
|
|
|
|
|
// id: this.payOrderProduct[0].id, |
|
|
// id: this.payOrderProduct[0].id, |
|
@ -140,12 +140,17 @@ |
|
|
// memberNum : 1, |
|
|
// memberNum : 1, |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// todo: check |
|
|
|
|
|
// if (this.coupon.id) { |
|
|
|
|
|
// data.couponId = this.coupon.id |
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
let api = 'createOrder' |
|
|
|
|
|
|
|
|
|
|
|
if (this.orderId) { // 支付订单 |
|
|
|
|
|
params.orderId = this.orderId |
|
|
|
|
|
api = 'payOrder' |
|
|
|
|
|
} else { // 创建订单 |
|
|
|
|
|
params.itemId = this.payOrderProduct[0].id |
|
|
|
|
|
params.amount = this.totalPrice |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
const res = await this.$fetch('createOrder', params, false) |
|
|
|
|
|
|
|
|
const res = await this.$fetch(api, params, false) |
|
|
|
|
|
|
|
|
return res |
|
|
return res |
|
|
}, |
|
|
}, |
|
@ -153,7 +158,7 @@ |
|
|
|
|
|
|
|
|
try { |
|
|
try { |
|
|
|
|
|
|
|
|
const res = await this.fetchCreateOrder() |
|
|
|
|
|
|
|
|
const res = await this.fetchPayOrder() |
|
|
|
|
|
|
|
|
if (!res.success) { |
|
|
if (!res.success) { |
|
|
return |
|
|
return |
|
@ -162,6 +167,7 @@ |
|
|
if (this.payMethod == 1) { // 账户余额 |
|
|
if (this.payMethod == 1) { // 账户余额 |
|
|
|
|
|
|
|
|
} else { // 微信支付 |
|
|
} else { // 微信支付 |
|
|
|
|
|
console.log('--发起支付接口回调', res) |
|
|
await uni.requestPaymentWxPay(res) |
|
|
await uni.requestPaymentWxPay(res) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -174,59 +180,7 @@ |
|
|
url: '/pages/index/order' |
|
|
url: '/pages/index/order' |
|
|
}) |
|
|
}) |
|
|
} catch (err) { |
|
|
} catch (err) { |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
|
|
|
|
let data = { |
|
|
|
|
|
'massageItem.id': this.payOrderProduct[0].id, |
|
|
|
|
|
// todo: check |
|
|
|
|
|
amount: this.totalPrice, |
|
|
|
|
|
|
|
|
|
|
|
// num: this.payOrderProduct[0].num, |
|
|
|
|
|
// id: this.payOrderProduct[0].id, |
|
|
|
|
|
// payType : this.payMethod, |
|
|
|
|
|
// memberNum : 1, |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// todo: check |
|
|
|
|
|
// if (this.coupon.id) { |
|
|
|
|
|
// data.couponId = this.coupon.id |
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
this.$api('createOrder', data, res => { |
|
|
|
|
|
if (res.code == 200) { |
|
|
|
|
|
|
|
|
|
|
|
if(this.payMethod == 1){ |
|
|
|
|
|
uni.showToast({ |
|
|
|
|
|
title: '下单成功', |
|
|
|
|
|
icon: 'none' |
|
|
|
|
|
}) |
|
|
|
|
|
this.paySuccess(res) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
uni.requestPaymentWxPay(res).then(e => { |
|
|
|
|
|
uni.showToast({ |
|
|
|
|
|
title: '下单成功', |
|
|
|
|
|
icon: 'none' |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
this.paySuccess(res) |
|
|
|
|
|
}).catch(n => { |
|
|
|
|
|
setTimeout(uni.redirectTo, 700, { |
|
|
|
|
|
url: '/pages/index/order' |
|
|
|
|
|
}) |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
}) |
|
|
|
|
|
}, |
|
|
|
|
|
paySuccess(res){ |
|
|
|
|
|
setTimeout(uni.redirectTo, 700, { |
|
|
|
|
|
url: '/pages/index/order' |
|
|
|
|
|
}) |
|
|
|
|
|
}, |
|
|
}, |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|