// pages/my/my_order/my_order.js var app = getApp(); Page({ /** * 页面的初始数据 */ data: { bgImg: app.globalData.bgImg, statusBarHeight: app.globalData.statusBarHeight, type: 1, typeXz: 142.5, page: 1, num: 10, orderList: [] }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { // 登录 wx.getStorage({ key: 'user', success: data => { this.setData({ userData: data.data, login: true, }) console.log('身份', this.data.userData) }, }) if (options.state) { console.log(options.state) var type = options.state var typeXz = 142.5 + parseInt(type) * 375 this.setData({ type: type, typeXz: typeXz, }) } }, //返回 back() { wx.navigateBack() }, /** * 生命周期函数--监听页面显示 */ onShow: function () { wx.getStorage({ key: 'user', success: user => { this.setData({ storesId: user.data.wisdStores.id, page: 1, orderList: [] }) this.orderList(); }, fail: e => { } }) }, //订单数据 orderList: function () { console.log(11111) wx.showLoading({ title: '加载中..', }) wx.request({ url: app.globalData.ip + '/wisdommining/api/user/getMerchantsStores', method: 'GET', header: { "content-type": "application/x-www-form-urlencoded", }, data: { userId: app.globalData.userId, storesId: this.data.storesId, type: this.data.type, page: this.data.page, num: this.data.num }, success: res => { console.log(res) wx.hideLoading() if (res.data.code == 1) { if (res.data.value.records.length > 0) { var orderList = this.data.orderList; for (var i = 0; i < res.data.value.records.length; i++) { orderList.push(res.data.value.records[i]) } this.setData({ orderList: orderList, page: this.data.page + 1 }) } else { if (this.data.page != 1) { wx.showToast({ title: '暂无更多~', icon: 'none' }) } } } else { wx.showModal({ title: '提示!', content: res.data.message, showCancel: false, }) } } }) }, //type type: function (e) { var type = e.currentTarget.dataset.type; var typeXz = 142.5 + (parseInt(type) - 1) * 375 this.setData({ type: type, typeXz: typeXz, page: 1, orderList: [] }) this.orderList(); }, //确认收货 confirm: function (e) { wx.showModal({ title: '提示!', content: '确认客户已提货吗?', success: s => { if (s.confirm) { wx.showLoading({ title: '加载中..', }) wx.request({ url: app.globalData.ip + '/wisdommining/api/order/confirmOrder', method: 'POST', header: { "content-type": "application/x-www-form-urlencoded", }, data: { orderId: e.currentTarget.dataset.id }, success: res => { console.log(res) wx.hideLoading() if (res.data.code == 1) { wx.showToast({ title: '操作成功~', icon: 'none', success: ss => { setTimeout(() => { this.setData({ page: 1, orderList: [], }) this.orderList(); }, 1000); } }) } else { wx.showModal({ title: '确认失败!', content: res.data.message, showCancel: false, }) } } }) } } }) }, //订单详情 toOrderDetail(e) { wx.navigateTo({ url: '/pages/order_details/order_details?orderNumber=' + e.currentTarget.dataset.num + '&shops=true', }) }, //二维码扫描 scancode: function () { // 允许从相机和相册扫码 wx.scanCode({ success(res) { console.log(res); let scene = res.result.split(',') console.log(scene) if (scene[0] === 'sjfhjsafsjab&*#$.!') { wx.navigateTo({ url: '/pages/order_detailsCode/order_details?id=' + scene[2] + '&orderNumber=' + scene[1], }) } else { wx.showToast({ title: '请扫描正确核销码~', icon: 'none' }) } }, fail: (res) => { console.log(res); wx.showToast({ title: '失败', icon: 'none' }) } }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { this.orderList() }, })