199 lines
4.4 KiB
JavaScript
199 lines
4.4 KiB
JavaScript
import userApi from '../../../api/user';
|
|
import shopApi from '../../../api/shop';
|
|
const app = getApp();
|
|
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
orderId:'',
|
|
orderDetail:{},
|
|
qrcodeUrl:'',
|
|
lng:0,
|
|
lat:0,
|
|
merchantOrderStatus:shopApi.merchantOrderStatus,
|
|
merchantOrderStatusKV:shopApi.merchantOrderStatusKV,
|
|
|
|
genderKV:userApi.genderKV,
|
|
|
|
refunding:false,
|
|
|
|
scrollViewHeight:0,
|
|
refresherTriggered:true
|
|
},
|
|
|
|
goToSuccess(){
|
|
wx.navigateTo({
|
|
url: `/pages/order/success/index?name=${this.data.orderDetail.product_name}&price=${this.data.orderDetail.order_amount}`,
|
|
})
|
|
},
|
|
makePhoneCall(){
|
|
wx.makePhoneCall({
|
|
phoneNumber: this.data.orderDetail.merchant_phone,
|
|
})
|
|
},
|
|
copyOrderId(){
|
|
wx.setClipboardData({
|
|
data: this.data.orderDetail.order_id,
|
|
})
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad(options) {
|
|
this.data.orderId = options.id;
|
|
this.setScrollViewHieght();
|
|
app.getLocation().then((data)=>{
|
|
this.setData({
|
|
lng:data.longitude,
|
|
lat:data.latitude,
|
|
});
|
|
this.getOrderDetail();
|
|
}).catch(()=>{
|
|
this.getOrderDetail();
|
|
});
|
|
},
|
|
setScrollViewHieght(){
|
|
const windowInfo = wx.getWindowInfo();
|
|
let height = windowInfo.windowHeight;
|
|
console.log(this.data.orderDetail.status==this.data.merchantOrderStatus.created,
|
|
this.data.orderDetail.status==this.data.merchantOrderStatus.unverified);
|
|
if(this.data.orderDetail&&this.data.orderDetail.id){
|
|
if(this.data.orderDetail.status==this.data.merchantOrderStatus.created||
|
|
this.data.orderDetail.status==this.data.merchantOrderStatus.unverified){
|
|
height = height - 94;
|
|
}
|
|
}
|
|
this.setData({
|
|
scrollViewHeight:height
|
|
});
|
|
},
|
|
getQRCode(){
|
|
userApi.order.orderQRCode(this.data.orderId).then((data)=>{
|
|
this.setData({
|
|
qrcodeUrl:data.qrcode_url
|
|
})
|
|
});
|
|
},
|
|
getOrderDetail(){
|
|
wx.showNavigationBarLoading();
|
|
userApi.order.merchantDetail(this.data.orderId,this.data.lng,this.data.lat).then((data)=>{
|
|
wx.hideNavigationBarLoading();
|
|
if(data.distance){
|
|
if(data.distance>=1000){
|
|
data.distance = parseFloat(data.distance/1000).toFixed(1)+'km';
|
|
}else{
|
|
data.distance+='m';
|
|
}
|
|
}
|
|
if(data.product_tags){
|
|
data.product_tags = data.product_tags.split(',');
|
|
}
|
|
this.setData({
|
|
orderDetail:data,
|
|
refresherTriggered:false
|
|
});
|
|
if(data.status==this.data.merchantOrderStatus.unverified){
|
|
this.getQRCode();
|
|
}else{
|
|
this.setData({
|
|
qrcodeUrl:''
|
|
})
|
|
}
|
|
this.setScrollViewHieght();
|
|
});
|
|
},
|
|
refund(){
|
|
if(this.data.refunding)return;
|
|
this.setData({
|
|
refunding:true
|
|
});
|
|
wx.showModal({
|
|
title: '是否确认申请退款',
|
|
content: '',
|
|
complete: (res) => {
|
|
if (res.confirm) {
|
|
userApi.order.merchantRefund(this.data.orderDetail.order_id).then(()=>{
|
|
this.getOrderDetail();
|
|
this.setData({
|
|
refunding:false
|
|
});
|
|
wx.showToast({
|
|
icon:'success',
|
|
title: '申请成功',
|
|
});
|
|
this.refreshOrderList();
|
|
});
|
|
}
|
|
}
|
|
})
|
|
},
|
|
//状态更改后上一个页面如果是订单列表,就刷新
|
|
refreshOrderList(){
|
|
const pages = getCurrentPages();
|
|
const prePage = pages[pages.length-2];
|
|
console.log(prePage,prePage.refreshList);
|
|
if(prePage&&prePage.refreshList){
|
|
prePage.refreshList();
|
|
}
|
|
},
|
|
pay(){
|
|
const merchantPay = this.selectComponent('#merchantOrderComponent');
|
|
merchantPay.createPayment(this.data.orderDetail.order_id,true);
|
|
},
|
|
paySuccess(){
|
|
this.getOrderDetail();
|
|
this.refreshOrderList();
|
|
},
|
|
/**
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
*/
|
|
onReady() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
onShow() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面隐藏
|
|
*/
|
|
onHide() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面卸载
|
|
*/
|
|
onUnload() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
*/
|
|
onPullDownRefresh() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面上拉触底事件的处理函数
|
|
*/
|
|
onReachBottom() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 用户点击右上角分享
|
|
*/
|
|
onShareAppMessage() {
|
|
|
|
}
|
|
}) |