var util = require('../../utils/util.js');
|
var api = require('../../utils/service-api.js');
|
Page({
|
data: {
|
order:[],
|
logisticsInfo:{},
|
remarks:"",
|
inform: true
|
},
|
onShow: function () {
|
var _this = this;
|
|
},
|
onLoad: function (options) {
|
this.getOrderInfo(options.id)
|
this.getLogisticsInfo(options.id)
|
// 判断是否从通知跳进来
|
if (options.inform == '1') {
|
|
this.setData({
|
inform: false
|
})
|
}
|
},
|
//获取根据id获取订单信息
|
getOrderInfo:function(id){
|
var _this = this;
|
util.request({
|
method:"GET",
|
api:"/wxapi/shopOrder/getOrderInfoById/" + id,
|
callback: function (data) {
|
console.log(data);
|
|
var createTime = new Date(data.rows[0].createTime);
|
|
console.log("createTime", createTime);
|
console.log(createTime.toString());
|
console.log(JSON.stringify(createTime));
|
|
data.rows[0].createTime = util.dateFtt(createTime)
|
|
if (data.rows[0].deliveryInfo !=null && data.rows[0].deliveryInfo.deliveryTime != null){
|
var deliveryTime = new Date(data.rows[0].deliveryInfo.deliveryTime);
|
data.rows[0].deliveryInfo.deliveryTime = util.dateFtt(deliveryTime)
|
}
|
var discountExplain = JSON.parse(data.rows[0].discountExplain);
|
_this.setData({
|
order: data.rows[0],
|
activity: discountExplain.activity,
|
coupon: discountExplain.coupon
|
})
|
|
_this.setData({
|
order:data.rows[0],
|
})
|
|
}});
|
},
|
|
// 支付
|
pay(e) {
|
var id = e.currentTarget.dataset.id;
|
console.log("支付");
|
var _this = this;
|
var sendData = {
|
|
}
|
util.request({
|
method: "GET",
|
api:"/wxapi/shopOrder/orderSettlement/" + id,
|
data:sendData,
|
callback:function (data) {
|
console.log(data);
|
wx.requestPayment({
|
'timeStamp': data.rows[0].timeStamp,
|
'nonceStr': data.rows[0].nonceStr,
|
'package': data.rows[0].prepay_id,
|
'signType': 'MD5',
|
'paySign': data.rows[0].paySign,
|
'success': function (res) {
|
console.log(res.errMsg)
|
if (res.errMsg == 'requestPayment:ok') {
|
console.log(data.mapInfo.orderId);
|
//成功后的回调;
|
util.request({
|
method:"GET",
|
api: '/wxapi/shopOrder/findOrderPayStatus/' + data.mapInfo.orderId,
|
callback: function (payRes) {
|
console.log("查询支付结果", payRes);
|
if (payRes.mapInfo.status == 'success') {
|
wx.navigateTo({
|
url: '../payOrder/paySuccess?getBack=2',
|
});
|
wx.showToast({
|
title: payRes.mapInfo.msg,
|
icon: 'success'
|
})
|
} else {
|
wx.showToast({
|
title: payRes.mapInfo.msg,
|
duration: 2000,
|
image: "/image/fail.png"
|
})
|
wx.navigateTo({
|
url: '../payOrder/payError',
|
})
|
}
|
}});
|
} else {
|
console.log("支付失败");
|
wx.navigateTo({
|
url: '../order/order',
|
})
|
}
|
//{errMsg: "requestPayment:ok"}
|
},
|
'fail': function (res) {
|
wx.navigateTo({
|
url: '../order/order?status=1',
|
})
|
}
|
})
|
}});
|
},
|
|
// 退款
|
refund(e) {
|
var _this = this;
|
var id = e.currentTarget.dataset.id;
|
wx.navigateTo({
|
url: '../refund/refund?id=' + id+'&&getBack=1',
|
})
|
},
|
|
// 确认收货
|
confirmReceipt(e) {
|
var _this = this;
|
var id = e.currentTarget.dataset.id;
|
var index = e.currentTarget.dataset.index;
|
wx.showModal({
|
title: '提示',
|
content: '确认收货吗?',
|
success: function (sm) {
|
if (sm.confirm) {
|
util.request({
|
method:"GET",
|
api: "/wxapi/shopOrder/confirmPackageById/" + id,
|
callback: function (data) {
|
let pages = getCurrentPages();//当前页面
|
let prevPage = pages[pages.length - 2];//上一页面
|
prevPage.setData({//直接给上移页面赋值
|
refresh: true
|
});
|
wx.navigateBack({
|
delta: 1
|
})
|
}});
|
} else if (sm.cancel) {
|
console.log('用户点击取消')
|
}
|
}
|
})
|
},
|
// 开票
|
invoice(e) {
|
var id = e.currentTarget.dataset.id
|
wx.navigateTo({
|
url: '../applyInvoice/applyInvoice?id=' + id + '&&getBack=1',
|
})
|
},
|
// 评价
|
evaluate(e) {
|
var id = e.currentTarget.dataset.id;
|
wx.navigateTo({
|
url: '../productEvaluate/productEvaluate?id=' + id + '&&getBack=1',
|
})
|
},
|
|
// 获取物流信息
|
getLogisticsInfo:function(id){
|
var _this = this;
|
util.request({
|
method:"GET",
|
api: "/wxapi/ShopLogisticsQuery/getLogisticsByOrderId/"+id,callback: function (data) {
|
console.log(data.mapInfo.logisticsInfo);
|
console.log(data.mapInfo.logisticsInfo.isShipments)
|
if (data.status == 200) {
|
_this.setData({
|
logisticsInfo: data.mapInfo.logisticsInfo
|
})
|
}
|
|
}});
|
},
|
|
// 进入物流页面
|
intoLogistics(e){
|
var id = e.currentTarget.dataset.id;
|
wx.navigateTo({
|
url: '../logistics/logistics?id=' + id,
|
})
|
},
|
|
// 取消订单
|
cancelOrder(e) {
|
var _this = this;
|
var id = e.currentTarget.dataset.id;
|
var index = e.currentTarget.dataset.index;
|
wx.showModal({
|
title: '提示',
|
content: '确定取消订单吗?',
|
success: function (sm) {
|
if (sm.confirm) {
|
util.request({
|
method:"GET",
|
api: "/wxapi/shopOrder/cancelOrderWhenWaitPay/" + id,
|
callback: function (data) {
|
if (data.status == '200') {
|
wx.redirectTo({
|
url: '../orderDetails/orderDetails?id=' + id,
|
})
|
}
|
|
}});
|
} else if (sm.cancel) {
|
console.log('用户点击取消')
|
}
|
}
|
})
|
|
|
},
|
// 跳转至商品页
|
goGoods(e) {
|
var id = e.currentTarget.dataset.id;
|
var status = e.currentTarget.dataset.status;
|
var delflag = e.currentTarget.dataset.delflag;
|
|
if (status == 2 || delflag == 1){
|
wx.showToast({
|
title: "商品已失效",
|
icon: "none"
|
});
|
} else {
|
wx.navigateTo({
|
url: '../details/details?id=' + id, //把id传到product页面
|
})
|
}
|
|
},
|
|
// 回到首页
|
goBack() {
|
wx.switchTab({
|
url: '../index/index'
|
})
|
},
|
})
|