141 lines
3.6 KiB
JavaScript
141 lines
3.6 KiB
JavaScript
|
|
import C from '../../utils/constant';
|
||
|
|
import * as F from '../../utils/func';
|
||
|
|
import R from '../../utils/request';
|
||
|
|
Page({
|
||
|
|
data: {
|
||
|
|
expireDate: '',
|
||
|
|
price: '',
|
||
|
|
shareId: '',
|
||
|
|
isPay: false,
|
||
|
|
orderNo: '',
|
||
|
|
phone: '',
|
||
|
|
username: '',
|
||
|
|
tip_before_pay: '',
|
||
|
|
tip_after_pay: '',
|
||
|
|
buy_type: '',
|
||
|
|
},
|
||
|
|
onLoad(options) {
|
||
|
|
const { id, orderNo } = options;
|
||
|
|
if (orderNo) {
|
||
|
|
this.setData({
|
||
|
|
isPay: true,
|
||
|
|
orderNo,
|
||
|
|
})
|
||
|
|
this.fetchOrder(orderNo);
|
||
|
|
} else {
|
||
|
|
R.get('/index.php/api/v1/get_share', { id }).then(({ model }) => {
|
||
|
|
this.setData({
|
||
|
|
shareId: id,
|
||
|
|
price: F.formatePrice(model.price),
|
||
|
|
expireDate: model.expire_time,
|
||
|
|
tip_before_pay: model.tip_before_pay || '',
|
||
|
|
tip_after_pay: model.tip_after_pay || '',
|
||
|
|
buy_type: model.buy_type,
|
||
|
|
});
|
||
|
|
}).catch((e)=>{
|
||
|
|
console.log('xxx',e);
|
||
|
|
})
|
||
|
|
R.get('/index.php/api/v1/view_share', { id });
|
||
|
|
}
|
||
|
|
},
|
||
|
|
refresh() {
|
||
|
|
if (this.data.orderNo) {
|
||
|
|
this.fetchOrder(this.data.orderNo);
|
||
|
|
}
|
||
|
|
},
|
||
|
|
fetchOrder(orderNo) {
|
||
|
|
const that = this;
|
||
|
|
return R.get('/index.php/api/v1/fetch_order_pay', { order_no: orderNo }).then(({ model }) => {
|
||
|
|
console.log('payed', model);
|
||
|
|
if (model.status === 'payed') {
|
||
|
|
clearInterval(that.data.timer);
|
||
|
|
wx.hideLoading();
|
||
|
|
this.setData({
|
||
|
|
isPay: true,
|
||
|
|
orderNo,
|
||
|
|
price: F.formatePrice(model.price),
|
||
|
|
buy_type: model.buy_type,
|
||
|
|
});
|
||
|
|
}
|
||
|
|
});
|
||
|
|
},
|
||
|
|
checkOrderStatus(orderNo) {
|
||
|
|
wx.showLoading({
|
||
|
|
title: '确认支付中...',
|
||
|
|
})
|
||
|
|
this.data.timer = setInterval(() => {
|
||
|
|
this.fetchOrder(orderNo).catch(() => {
|
||
|
|
clearInterval(this.data.timer);
|
||
|
|
});
|
||
|
|
}, 1000);
|
||
|
|
},
|
||
|
|
goPay() {
|
||
|
|
const that = this;
|
||
|
|
if (this.data.shareId) {
|
||
|
|
R.post('/index.php/api/v1/make_order', { share_id: this.data.shareId }).then(({ model: { order_no } }) => {
|
||
|
|
that.data.orderNo = order_no;
|
||
|
|
R.post('/index.php/api/v1/pay_order', { order_no }).then(({ model }) => {
|
||
|
|
wx.requestPayment({
|
||
|
|
...model,
|
||
|
|
success(res) {
|
||
|
|
wx.showToast({
|
||
|
|
title: '支付成功',
|
||
|
|
icon: 'success',
|
||
|
|
duration: 2000,
|
||
|
|
success() {
|
||
|
|
that.checkOrderStatus(order_no);
|
||
|
|
// this.setData({
|
||
|
|
// isPay: true,
|
||
|
|
// })
|
||
|
|
}
|
||
|
|
})
|
||
|
|
},
|
||
|
|
fail(res) {
|
||
|
|
wx.showToast({
|
||
|
|
title: '您已取消支付',
|
||
|
|
icon: 'none',
|
||
|
|
duration: 2000
|
||
|
|
})
|
||
|
|
// wx.redirectTo({
|
||
|
|
// url: '/pages/shop/shop?path=user',
|
||
|
|
// });
|
||
|
|
}
|
||
|
|
})
|
||
|
|
})
|
||
|
|
})
|
||
|
|
}
|
||
|
|
},
|
||
|
|
onShareAppMessage() {
|
||
|
|
|
||
|
|
},
|
||
|
|
validate() {
|
||
|
|
const { username, phone, orderNo, } = this.data;
|
||
|
|
if (!username) {
|
||
|
|
wx.showToast({ title: '请输入姓名', icon: 'none' });
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
if (!/^1\d{10}$/.test(phone)) {
|
||
|
|
wx.showToast({ title: '请输入正确的手机号', icon: 'none' });
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
return true;
|
||
|
|
},
|
||
|
|
submit() {
|
||
|
|
if (!this.validate()) return;
|
||
|
|
const {
|
||
|
|
username, phone, orderNo,
|
||
|
|
} = this.data
|
||
|
|
R.post('/index.php/api/v1/mark_order_info', { name: username, phone, order_no: orderNo, }).then(({ model }) => {
|
||
|
|
wx.showToast({
|
||
|
|
title: '提交成功',
|
||
|
|
icon: 'success',
|
||
|
|
duration: 2000,
|
||
|
|
success() {
|
||
|
|
wx.redirectTo({
|
||
|
|
url: '/pages/paylist/paylist?from=sharebuy',
|
||
|
|
})
|
||
|
|
}
|
||
|
|
});
|
||
|
|
});
|
||
|
|
},
|
||
|
|
})
|