var util = require('../../../utils/util.js'); var api = require('../../../config/api.js'); import play from '../../../utils/pay.js' Page({ data:{ orderList: [], page: 1, size: 10, loadmoreText: '正在加载更多数据', nomoreText: '全部加载完成', nomore: false, totalPages: 1, activeIdx:-1, header:[ { icon: 'ct1', name: '全部订单', id: -1 }, { icon: 'ct2', name: '待付款', id: 0 }, { icon: 'ct3', name: '待发货', id: 201 }, { icon: 'ct4', name: '待收货', id: 300 }, { icon: 'ct5', name: '已完成', id: 301 } ] }, async quita(ev) { if (this.quiting) return; let text = ['预订中', '预订审核', '预订成功', '预订失败', '取消预订', '已用餐', '支付超时', '已失效'] this.quiting = true let data = ev.target.dataset.itemdata if (data.status === 3 || data.status === 4 || data.status === 5 || data.status === 6 || data.status === 7) { this.quiting = false return wx.navigateTo({ url: '/pages/scene/scene?scene='+data.canteen.sceneNum+'&id='+data.canteen.id+'&deskId='+data.deskId, }) } else if (data.status === 0) { try { await play(data.id) let res1 = await util.request(api.OrderQuery, { orderId: data.id}) wx.showToast({ icon: 'success', title: res1.errmsg }) this.refresh() getApp().callOrderBuyCbs({deskId: data.deskId}) } catch (e) { wx.showToast({ icon: 'none', title: '付款失败', }) } this.quiting = false return } let that = this wx.showActionSheet({ alertText: '是否取消预订座位', itemColor: '#FA5151', itemList: ['确定'], success (res) { util.request(api.OrderCancel, {orderId: ev.target.dataset.orderid}) .then(res => { if (res.code === 0) { util.request(api.refundQuery, {orderId: ev.target.dataset.orderid}) .then(res => { if (res.code === 0) { wx.showToast({ title: '取消预订成功', icon: 'none', duration: 2000 }) that.setData({ orderList: [], page: 1 }) that.getOrderList(); } else { wx.showToast({ icon: 'none', title: res.msg, }) } this.quiting = false }) } else { wx.showToast({ icon: 'none', title: res.msg, }) this.quiting = false } }) }, fail (res) { this.quiting = false console.log(res.errMsg) } }) }, onLoad:function(options){ getApp().checkNetStatu(); let {id} = options this.setData({ activeIdx: -1 }) // 页面初始化 options为页面跳转所带来的参数 // 页面显示 }, refresh: function(){ wx.showLoading({ title: '加载中...', success: function () { } }); this.setData({ orderList: [], page: 1 }) this.getOrderList(); }, onPullDownRefresh() { this.refresh() getApp().onPullDownRefresh() }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { this.getOrderList() }, tabHeader:function(e){ let {id} = e.currentTarget.dataset this.setData({ activeIdx: id }) this.refresh() }, getOrderList(id){ let that = this; this.setData({loadding: true}) util.request(api.OrderList, { pageNum: that.data.page, pageSize: that.data.size}, 'GET').then(function (res) { let text = ['预订中', '预订审核', '预订成功', '预订失败', '取消预订', '已用餐', '支付超时', '已失效'] if (res.code === 0) { let list = res.data.list.map(item => { let order = item.order order.reserveTime = order.reserveTime.substr(0,16) order.canteen = item.canteen order.order_status_text = text[Number(order.status)] order.reserveUserPhone = order.reserveUserPhone.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2') return order }) that.setData({ orderList: that.data.orderList.concat(list), page: res.data.curPage + 1, totalPages: res.data.totalPageNum }); that.setData({loadding: false}) wx.hideLoading(); if (res.data.list.length <= 0) { that.setData({ nomore: true }) return; } } }); }, gotoLogti: function(e){ let {no,id} = e.currentTarget.dataset wx.navigateTo({ url: '/pages/logistics/index?no=' + no + '&id=' + id }) }, payOrder(event){ let that = this; let orderIndex = event.currentTarget.dataset.orderIndex; let order = that.data.orderList[orderIndex]; wx.redirectTo({ url: '/pages/pay/pay?orderId=' + order.id + '&actualPrice=' + order.actual_price, }) }, onReady:function(){ // 页面渲染完成 }, onShow:function(){ this.refresh() }, onHide:function(){ // 页面隐藏 }, onUnload:function(){ // 页面关闭 } })