var util = require('../../utils/util.js');
|
Page({
|
data: {
|
tabs: ['全部', '待付款', '待配送','待收货','待评价'],
|
currentIndex: 0,
|
orderList:[],
|
limit:8,
|
offset:1,
|
refresh:false,
|
orderShow:false,
|
// hiddenData:true
|
},
|
onUnload: function () {
|
// wx.reLaunch({
|
// url: '../customerCenter/customerCenter'
|
// })
|
},
|
onLoad: function (options) {
|
var status = options.status;
|
if (status!=undefined){
|
this.setData({
|
currentIndex: status
|
})
|
}
|
this.getOrderInfo(this.data.currentIndex);
|
this.goTap();
|
},
|
onShow:function(){
|
if(this.data.refresh){
|
this.getOrderInfo(this.data.currentIndex);
|
}
|
},
|
//获取滚动条当前位置
|
onPageScroll: function (e) {
|
// console.log(e)
|
if (e.scrollTop > 400) {
|
this.setData({
|
floorstatus: true
|
});
|
} else {
|
this.setData({
|
floorstatus: false
|
});
|
}
|
},
|
//一键回到顶部
|
goTap(){
|
util.goTap();
|
},
|
onTabsItemEvent(e){
|
var index = e.currentTarget.dataset.index;
|
|
this.setData({
|
currentIndex:index,
|
offset: 1
|
})
|
this.getOrderInfo(index);
|
},
|
|
// 根据状态获取订单信息
|
getOrderInfo:function(status){
|
var _this = this;
|
var limit = _this.data.limit;
|
var offset = _this.data.offset;
|
util.request({
|
api:"/wxapi/shopOrder/getMyOrderInfo",
|
data: { "limit": limit, "orderStatus": status, "offset": offset},
|
callback: function (data) {
|
console.log("订单信息")
|
console.log(data.rows)
|
_this.setData({
|
orderList: data.rows,
|
currentIndex: status
|
});
|
var orderList = _this.data.orderList;
|
console.log(orderList)
|
if (orderList.length == 0) {
|
_this.setData({
|
orderShow: true,
|
})
|
} else {
|
_this.setData({
|
orderShow: false
|
})
|
}
|
}});
|
},
|
invoice(e){
|
var id = e.currentTarget.dataset.id
|
console.log(id)
|
wx.navigateTo({
|
url: '../applyInvoice/applyInvoice?id='+id,
|
})
|
},
|
// 支付
|
pay(e){
|
var id = e.currentTarget.dataset.id;
|
var status = e.currentTarget.dataset.status;
|
|
var _this = this;
|
var sendData = {
|
|
}
|
util.request({
|
method : "GET",
|
api:"/wxapi/shopOrder/orderSettlement/" + id,
|
data:sendData,
|
callback: function (data) {
|
console.log(data);
|
if (data.status == '700000'){
|
|
wx.showToast({
|
title: data.info,
|
duration: 2000,
|
})
|
return;
|
|
}
|
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=1&&status=' + status,
|
});
|
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',
|
// })
|
}
|
})
|
}});
|
},
|
|
// 评价
|
evaluate(e){
|
var id = e.currentTarget.dataset.id;
|
wx.navigateTo({
|
url: '../productEvaluate/productEvaluate?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') {
|
_this.getOrderInfo(0);
|
}
|
|
}});
|
} else if (sm.cancel) {
|
console.log('用户点击取消')
|
}
|
}
|
})
|
|
|
},
|
|
// 删除订单
|
delOrder(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/delOrder/" + id,callback: function (data) {
|
if (data.status == '200') {
|
_this.getOrderInfo(0);
|
}
|
}});
|
} else if (sm.cancel) {
|
console.log('用户点击取消')
|
}
|
}
|
})
|
|
|
},
|
|
// 确认收货
|
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) {
|
if (data.status == '200') {
|
_this.getOrderInfo(0);
|
|
}
|
}});
|
} else if (sm.cancel) {
|
console.log('用户点击取消')
|
}
|
}
|
})
|
},
|
// 退款
|
refund(e){
|
var _this = this;
|
var id = e.currentTarget.dataset.id;
|
var orderCancel = e.currentTarget.dataset.status;
|
wx.navigateTo({
|
url: '../refund/refund?id=' + id + "&&orderCancel=" + orderCancel,
|
})
|
},
|
|
// 进入详情
|
intoDetail(e){
|
var _this = this;
|
var id = e.currentTarget.dataset.id;
|
wx.navigateTo({
|
url: '../orderDetails/orderDetails?id=' + id,
|
})
|
},
|
|
// 上拉加载
|
onReachBottom: function () {
|
|
var _this = this;
|
var offset = _this.data.offset;
|
var limit = _this.data.limit;
|
var orderList = _this.data.orderList;
|
var status = _this.data.currentIndex;
|
_this.setData({
|
offset: offset + 1
|
});
|
offset = _this.data.offset;
|
|
util.request({api: "/wxapi/shopOrder/getMyOrderInfo",data: { "limit": limit, "orderStatus": status, "offset": offset },
|
callback: function (data) {
|
for (var i = 0; i < data.rows.length; i++) {
|
orderList.push(data.rows[i]);
|
}
|
|
_this.setData({
|
orderList: orderList
|
});
|
}});
|
},
|
|
// 查看物流
|
lookLogistics(e){
|
var _this = this;
|
var id = e.currentTarget.dataset.id;
|
var logistStatus = e.currentTarget.dataset.status;
|
wx.navigateTo({
|
url: '../logistics/logistics?id=' + id + '&&logistStatus=' + logistStatus,
|
})
|
}
|
|
|
|
})
|