dm-wechat-mini/pages/order/detail/index.js
2025-02-23 02:09:33 +08:00

163 lines
3.2 KiB
JavaScript

import userApi from '../../../api/user';
Page({
/**
* 页面的初始数据
*/
data: {
orderId:'',
orderDetail:{},
orderStatusKV:userApi.order.statusKV,
orderStatus:userApi.order.status,
orderDeliverStatusKV:userApi.order.orderDeliverStatusKV,
scrollViewHeight:0,
refresherTriggered:true,
genderKV:userApi.genderKV,
cancelling:false,
isShowCancelView:false
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
const windowInfo = wx.getWindowInfo();
this.setData({
orderId:options.id,
scrollViewHeight:windowInfo.windowHeight - 94
});
this.getOrderDetail();
},
getOrderDetail(){
wx.showNavigationBarLoading();
userApi.order.detail(this.data.orderId).then((data)=>{
wx.hideNavigationBarLoading();
let totalPackage = 0;
data.packages.map((item)=>{
item.pickup_codes = item.pickup_codes.split(',');
totalPackage+=item.pickup_codes.length;
});
data.totalPackage = totalPackage;
this.setData({
orderDetail:data,
refresherTriggered:false
})
})
},
showCancelModal(){
this.setData({
isShowCancelView:true
})
},
cancelOrder(){
this.setData({
cancelling:true
})
userApi.order.cancel(this.data.orderDetail.orderid).then(()=>{
wx.showToast({
title: '取消成功',
})
this.setData({
cancelling:false
});
this.getOrderDetail();
const pages = getCurrentPages();
const prePage = pages[pages.length-2];
prePage.refreshList();
});
},
//订单更改后上一个页面如果是订单列表,就刷新
refreshOrderList(){
const pages = getCurrentPages();
const prePage = pages[pages.length-2];
if(prePage&&prePage.refreshList){
prePage.refreshList();
}
},
pay(){
const merchantPay = this.selectComponent('#merchantOrderComponent');
merchantPay.createPayment(this.data.orderDetail.orderid,true);
},
paySuccess(){
this.refreshOrderList();
this.getOrderDetail();
},
copyOrderId(){
wx.setClipboardData({
data: this.data.orderDetail.orderid,
})
},
handleContact(e){
console.log('handleContact');
console.log(e.detail.path)
console.log(e.detail.query)
},
makePhoneCall(){
wx.makePhoneCall({
phoneNumber: this.data.orderDetail.deliveryman_phone,
})
},
preview(event){
const current = event.currentTarget.dataset.url;
wx.previewImage({
current:current,
urls: this.data.orderDetail.complete_images,
})
},
orderAgain(){
wx.switchTab({
url: '/pages/help/index/index',
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})