const app = getApp(); Page({ /** * 页面的初始数据 */ data: { status: 0, pageNumber: 1, pageSize: 20, list: [], state: false }, /** * 生命周期函数--监听页面加载 */ onLoad: function(options) { this.setData({color:app.globalData.color}) }, // onShow: function(options) { // this.cy_getProgramOrderList(); }, /** * 订单列表 */ cy_getProgramOrderList() { var that = this; var status = this.data.status; var pageNumber = this.data.pageNumber; var pageSize = this.data.pageSize; var params = { method: "program.order.list", programId: app.globalData.programId, openId: app.openId, status: status, pageNumber: pageNumber, pageSize: pageSize, } console.log(params); var ignores = ["programId", "openId", "status", "pageNumber", "pageSize"]; app.jsapi.api(app.globalData.appKey, app.globalData.appSecret, app.globalData.serverUrl).ajax(params, ignores, function(json) { wx.stopPullDownRefresh(); console.log(json); var data = json.data; if (data.status) { var list = that.data.list; if (pageNumber == 1) { list = []; } for (var item of data.list) { if (item.status == -1) { item.statusDes = "待支付"; } if (item.status == 0) { item.statusDes = "待接单"; } if (item.status == 1) { item.statusDes = "已接单"; } if (item.status == 2) { item.statusDes = "已配送"; } if (item.status == 3) { item.statusDes = "已取消"; } if (item.status == 4) { item.statusDes = "已完成"; } if (item.refundStatus == 1) { item.statusDes = "申请退款中"; } if (item.refundStatus == 2) { item.statusDes = "商家拒绝退款"; } if (item.refundStatus == 3) { item.statusDes = "已退款"; } for (var product of item.orderProduct) { product.makeInfo = []; product.makeDes = ""; for (var make of item.makeInfo) { if (product.clientId == make.orderItemId) { product.makeInfo.push(make); if (product.makeDes != "") { product.makeDes = product.makeDes + "、"; } product.makeDes = product.makeDes + make.makeName; } } } item.receivable= (parseFloat(item.receivable) + parseFloat(item.packageFee)+parseFloat(item.deliverFee)).toFixed(2), list.push(item); } that.setData({ list: list }); var month = new Date().getMonth() + 1 < 10 ? '0' + new Date().getMonth() + 1 : new Date().getMonth() + 1 var date = new Date().getDate() < 10 ? '0' + new Date().getDate() : new Date().getDate() var str = month + '-' + date for(var [index, item] of list.entries()) { let string = item.saleDate.substr(5, 5) if (item.status == -1) { item.statusDes = "待支付"; } if(item.status == -1 && string == str) { var timer = setInterval(function(){ if(that.state) { clearInterval(timer) } that.cy_getOrderDetail(item, index, list) }, 60 * 1000) } } if (list.length == 0) { wx.showToast({ title: '暂无数据', icon: "none" }) } } else { } }, function(err) { console.log(err); }); }, /** * */ cy_getOrderDetail: function(val, index, list) { let that = this var params = { method: "program.order.getOrderDetail", storeId: val.storeId, programId: app.globalData.programId, tradeNo: val.no } var ignores = ["tradeNo"]; app.jsapi.api(app.globalData.appKey, app.globalData.appSecret, app.globalData.serverUrl).ajax(params, ignores, function(json) { if(json.data.status == 99){ list[index].statusDes = "支付中" } if(json.data.status == 4) { that.data.state = true } that.setData({ list: list }); }, function(err) { console.log(err); }); }, /** * */ cy_orderDetail: function(e) { console.log(e); var no = e.currentTarget.dataset.no; var busmode = e.currentTarget.dataset.busmode; var status = e.currentTarget.dataset.status; if (status == -1) { return; } if (busmode == 0 || busmode == 1) { wx.navigateTo({ url: "../order/balance/paySuccess?once=申请退款&init=true&no=" + no, }) } if (busmode == 3) { wx.navigateTo({ url: "../order/balance/payOrderSuccess?once=申请退款&init=true&no=" + no, }) } }, /** * 去支付 */ cy_tapPay: function(e) { var status = e.currentTarget.dataset.status; var index = e.currentTarget.dataset.index; if (status == -1) { console.log("去付款"); var product = this.data.list[index]; console.log(product); wx.navigateTo({ url: 'myOrderDetail?tradeNo=' + product.no, }) } if (status == 4) { console.log("去评价"); } }, /** * */ cy_selectTypeCoupon: function(e) { console.log(e); var status = e.currentTarget.dataset.status; console.log(status); this.setData({ pageNumber: 1, status: status }); this.cy_getProgramOrderList(); }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function() { console.log("下拉刷新"); this.data.pageNumber = 1; this.cy_getProgramOrderList(); }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function() { console.log("加载更多"); this.data.pageNumber++; this.cy_getProgramOrderList(); }, /** * 用户点击右上角分享 */ onShareAppMessage: function() { } })