var _request = require('../../../../utils/request.js') var rid Page({ data: { tabLeft: '0%', type: '', page: 1, per_page: 10, list: [], more: true, tabChange: false }, onLoad: function (options) { rid = options.type if (rid) { if (rid === 'unpay') { this.tabUnpay() } else if (rid === 'processing') { this.tabProcessing() } else if (rid === 'dispatch') { this.tabDispatch() } else if (rid === 'complete') { this.tabComplete() } else { this.getOrderList() } } else { this.getOrderList() } }, onShow () { if (getApp().globalData.order) { this.typeList() getApp().globalData.order = false } }, tabAll: function () { if (this.data.type !== '') { this.setData({ tabLeft: '0%', type: '', more: true, page: 1, tabChange: true }) this.getOrderList() } else { } }, tabUnpay: function () { if (this.data.type !== 'unpay') { this.setData({ tabLeft: '20%', type: 'unpay', more: true, page: 1, tabChange: true }) this.getOrderList() } }, tabProcessing: function () { if (this.data.type !== 'processing') { this.setData({ tabLeft: '40%', type: 'processing', more: true, page: 1, tabChange: true }) this.getOrderList() } }, tabDispatch: function () { if (this.data.type !== 'dispatch') { this.setData({ tabLeft: '60%', type: 'dispatch', more: true, page: 1, tabChange: true }) this.getOrderList() } }, tabComplete: function () { if (this.data.type !== 'complete') { this.setData({ tabLeft: '80%', type: 'complete', more: true, page: 1, tabChange: true }) this.getOrderList() } }, confirmPopup (val) { var that = this var id = val.currentTarget.dataset.val wx.showModal({ title: '提示', content: '是否确认收货?', success: function(res) { if (res.confirm) { that.confirmOrder(id) } else if (res.cancel) { } } }) }, CancelPopup (val) { var that = this var id = val.currentTarget.dataset.val wx.showModal({ title: '提示', content: '确定取消该订单?', success: function(res) { if (res.confirm) { that.CancelOrder(id) } else if (res.cancel) { } } }) }, confirmOrder: function (val) { var id = val var that = this var url = 'v1/order/' + id + '/confirm' var params = { } var success = function (res) { that.typeList() wx.showToast({ title: '确认收货成功', icon: 'none', duration: 2000 }) } _request.$put(url, params, success) }, CancelOrder: function (val) { var id = val var that = this var url = 'v1/order/' + id + '/cancel' var params = { } var success = function (res) { that.typeList() wx.showToast({ title: '取消订单成功', icon: 'none', duration: 2000 }) } _request.$put(url, params, success) }, getOrderList () { var that = this var url = 'v1/orders' var params = { status: this.data.type, page: this.data.page, per_page: this.data.per_page } var success = function (res) { if (that.data.tabChange) { that.setData({ list: [], tabChange: false }) } var result = that.data.list.concat(res.data.list || []) that.setData({ list: result }) var listMore = res.data.list_count > that.data.list.length that.setData({ more: listMore }) } _request.$get(url, params, success) }, onReachBottom: function () { if (this.data.more) { var page = this.data.page + 1 this.setData({ page: page }) this.getOrderList() } }, typeList: function () { this.setData({ more: true, page: 1, tabChange: true }) this.getOrderList() }, onShareAppMessage: function (val) { return _request.share({ sc: 'xcx_user_orders' }) } })