//index.js //获取应用实例 const app = getApp() import * as API_Order from '../../api/order.js' import * as Common from '../../utils/common.js' import * as API_Logistic from '../../api/logistic' import { $wuxToptips, $wuxToast, $wuxLoading, $wuxDialog } from '../../wux/index.js' Page({ data: { pageParam: { page_size: 10, page_no: 1, order_status: 'WAIT_SHIP' }, finished: false, orderList: [], loading:true, logistics:[], shippingShow:false, shippingModeShow:false, selectLogi:null, ship_no:'', ship_out_sn:'' }, onLoad: function() { const bool_o2o=app.globalData.authorInfo.boolO2o if(bool_o2o===0){ wx.redirectTo({ url:'/pages/noshop/index' }) } this.getLogisticCompany() }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function() { //wx.startPullDownRefresh() wx.showNavigationBarLoading() this.setData({ ['pageParam.page_no']: 1, finished: false, }) this.getOrderData().then(res => { wx.hideNavigationBarLoading() wx.stopPullDownRefresh() }) }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function() { if (!this.data.finished) { this.setData({ ['pageParam.page_no']: this.data.pageParam.page_no + 1 }) this.getOrderData() } }, /** 显示底部导航 */ onShow() { //下拉刷新时,可能用户未登录,再返回此页时顶部会一直显示加载状态,这里首先隐藏加载状态 wx.hideNavigationBarLoading() this.setData({ ['pageParam.page_no']: 1, finished: false }) this.getOrderData() Common.getCurrentShopData().then(res => { this.getTabBar().init() }) }, onChange(event) { this.setData({ activeNames: event.detail }); }, getOrderData() { return new Promise((resolve, reject) => { let that = this const authorInfo=app.globalData.authorInfo if(authorInfo===null||authorInfo===''){ //授权信息不存,不发起请求 return } if (authorInfo.boolO2o===0){ //非o2o店铺 不发起请求 return } $wuxLoading().show({ text: '加载中...', }) API_Order.getOrderList(that.data.pageParam).then(res => { const { data } = res let orders = [] if (that.data.orderList.length === 0 ||that.data.pageParam.page_no===1) { orders = [...data] } else { orders = that.data.orderList orders.push(...data) } if (data.length < 10) { that.setData({ finished: true }) } that.setData({ orderList: orders, loading:false }) $wuxLoading().hide() resolve(res) }).catch(e => { $wuxToptips().error({ icon: 'cancel', hidden: false, text: e?e.error:e.message, duration: 3000 }) that.setData({loading:false}) //reject() }) }) }, delivery(e) { const { sn } = e.currentTarget.dataset const that = this // const order=that.data.orderList.find(p=>p.sn===sn) that.setData({ shippingShow:true, ship_out_sn:sn }) // $wuxDialog().confirm({ // resetOnClose: true, // closable: true, // title: '操作提示', // content: '该订单需线下配送,确认发货?', // onConfirm(e) { // API_Order.deliveryGoods(sn, { // 'ship_no': '线下配送', // 'logi_id': 0, // 'logi_name': '线下配送' // }).then(res => { // if (res === '') { // $wuxToptips().success({ // hidden: false, // text: '发货成功', // duration: 3000, // success: () => { // that.setData({ // ['pageParam.page_no']: 1, // finished: false, // orderList: [] // }) // that.getOrderData() // Common.getCurrentShopData().then(response => { // that.getTabBar().init() // }) // // } // }) // // // } else { // $wuxToptips().error({ // icon: 'cancel', // hidden: false, // text: res.message, // duration: 3000 // }) // } // }).catch(error => { // $wuxToptips().error({ // icon: 'cancel', // hidden: false, // text: error.message, // duration: 3000 // }) // }) // }, // onCancel(e) { // // }, // }) }, shipout(){ let that = this if(!that.data.selectLogi){ $wuxToptips().error({ icon: 'cancel', hidden: false, text: '请选择快递公司', duration: 3000 }) return } const logi =that.data.logistics.find(p=>p.logi_id===that.data.selectLogi) if (logi.name === '无需物流') { that.data.ship_no = logi.name } else { if(!that.data.ship_no.trim()){ $wuxToptips().error({ icon: 'cancel', hidden: false, text: '请填写快递单号', duration: 3000 }) return } } API_Order.deliveryGoods(that.data.ship_out_sn, { 'ship_no': that.data.ship_no, 'logi_id': that.data.selectLogi, 'logi_name': logi.name }).then(res => { if (res === '') { $wuxToptips().success({ hidden: false, text: '发货成功', duration: 3000, success: () => { that.setData({ ['pageParam.page_no']: 1, finished: false, orderList: [], shippingShow:false, shippingModeShow:false }) that.getOrderData() Common.getCurrentShopData().then(response => { that.getTabBar().init() }) } }) } else { $wuxToptips().error({ icon: 'cancel', hidden: false, text: res.message, duration: 3000 }) } }).catch(error => { $wuxToptips().error({ icon: 'cancel', hidden: false, text: error.message, duration: 3000 }) }) }, showShippingMode(){ this.setData({ shippingModeShow:true }) }, getLogisticCompany(){ let that = this API_Logistic.getExpressCompanyList().then(res=>{ that.setData({ logistics:[...res] }) }) }, onClose(){ this.setData({ shippingShow:false }) }, onClose2(){ this.setData({ shippingModeShow:false }) }, /** 物流公司信息开启 /关闭 */ switchLogisState(e){ const {logi_id}=e.currentTarget.dataset let row=this.data.logistics.find(p=>p.logi_id===logi_id) const _tip = (row.shop_id ? '关闭' : '开启')+row.name let that = this wx.showModal({ title: '提示', content: _tip, success (res) { if (res.confirm) { if(row.shop_id){ that.closeLogistics(row.logi_id) }else{ that.openLogistics(row.logi_id) } } else if (res.cancel) { } } }) }, /** 执行关闭 */ closeLogistics(logi_id) { let that = this API_Logistic.closeExpressPower(logi_id, {}).then(response => { wx.showToast({ title: '关闭成功', }) that.getLogisticCompany() }) }, /** 执行开启 */ openLogistics(logi_id) { let that = this API_Logistic.openExpressPower(logi_id, {}).then(response => { wx.showToast({ title: '开启成功', }) that.getLogisticCompany() }) }, radioClick(event){ const { name } = event.currentTarget.dataset; this.setData({ selectLogi: name, }) }, shipNoChange(e){ this.setData({ ship_no:e.detail }) }, scanShipNo(){ let that =this wx.scanCode({ success (res) { that.setData({ ship_no:res.result }) } }) } })