// pages/tabber/news/index.js const app=getApp(); var deviceId='',spoutDeviceId='',num=''; Page({ /** * 页面的初始数据 */ data: { selectInfo: {}, factoryName:[], factoryId:[], index:0, content:[], show:false, orderSn:'', status:'', num:'' }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { //this.gettaskList(); deviceId=options&&options.deviceId?options.deviceId:1 spoutDeviceId=options&&options.spoutDeviceId?options.spoutDeviceId:8 num=options&&options.num?options.num:'' this.getFactory() }, bindput(e){ this.setData({ orderSn:e.detail.value }) }, getFactory:function(){ var that=this app.api.useApi(app.globalData.baseAppUrl + "api/admin/FactoryList", { device_id: deviceId, spout_device_id:spoutDeviceId }, "get").then(function (res) { console.log(res); if (res.code != 200) { wx.showLoading({ title: '数据获取失败', }) setTimeout(function () { wx.hideLoading(); }, 1000); } else { wx.hideLoading(); var FactoryList=res.message.data.list for(var i in FactoryList){ that.data.factoryName.push(FactoryList[i].external_title) that.data.factoryId.push(FactoryList[i].id) } console.log(that.data.factoryName) that.setData({ factoryName:that.data.factoryName, factoryId:that.data.factoryId, num, content:res.message.data.group }) } }).catch(function (err) { console.log(222); }) }, bindPickerChange: function(e) { console.log('picker发送选择改变,携带值为', e.detail.value) this.setData({ index: e.detail.value }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, saoma:function(){ var that=this wx.scanCode({ onlyFromCamera: true, success (res) { that.setData({ orderSn:res.result }) } }) }, onClick:function(e){ var type=e.currentTarget.dataset.type var that=this if(type==1){ if(that.data.orderSn=='') return wx.showToast({title: '封签号不能为空',icon:'none'}) app.api.useApi(app.globalData.baseAppUrl + "api/admin/StoreCodeUserInfo", { seal_no: that.data.orderSn }, "get").then(function (res) { wx.hideLoading(); if (res.code== 200) { that.setData({ status:res.message.data.phone }) } else wx.showToast({title: res.message.msg,icon:'none'}) }).catch(function (err) { console.log(222); }) }else this.setData({ show:!this.data.show }) }, onSubmit:function(e){ var that=this if(that.data.orderSn=='') return wx.showToast({title: '封签号不能为空',icon:'none'}) if(deviceId=='') return wx.showToast({title: '设备号不能为空',icon:'none'}) if(spoutDeviceId=='') return wx.showToast({title: '柜门号不能为空',icon:'none'}) if(that.data.factoryName.length<=0) return wx.showToast({title: '目的地不能为空',icon:'none'}) app.api.useApi(app.globalData.baseAppUrl + "api/admin/BindSeals", { seal_no: that.data.orderSn, device_id:deviceId, spout_device_id:spoutDeviceId, factory_id:that.data.factoryId[that.data.index] }, "post").then(function (res) { wx.hideLoading(); that.setData({status:res.message.msg,result:res.code== 200?true:false}) if (res.code== 200) { res.message.data.id=res.message.data.logistic_group_id that.data.content.unshift(res.message.data) that.setData({ content:that.data.content, }) } }).catch(function (err) { console.log(err); }) }, quitBind:function(e){ var that=this wx.showModal({ title: '提示', content: '确认删除该条封签么?', success(res) { if (res.confirm) { that.remove(e); } else if (res.cancel) { console.log('用户点击取消') } } }) return; }, remove:function(e){ var that=this var logistic_group_id=e.currentTarget.dataset.id; if(logistic_group_id=='') return wx.showToast({title: '封签对象不能为空',icon:'none'}) app.api.useApi(app.globalData.baseAppUrl + "api/admin/UnsealBind", { logistic_group_id }, "post").then(function (res) { wx.hideLoading(); if (res.code== 200) { var info = that.data.content; var info = info.filter(function (item) { return item.id != logistic_group_id; }); that.setData({ content: info }) }else wx.showToast({title: res.message.msg,icon:'none'}) }).catch(function (err) { console.log(222); }) }, confirm:function(){ var that=this; wx.showModal({ title: '提示', content: '请确认是否提交?', success(res) { if (res.confirm) { that.finish(); } else if (res.cancel) { console.log('用户点击取消') } } }) }, finish:function(){ var that=this app.api.useApi(app.globalData.baseAppUrl + "api/admin/SubmitSeals", { device_id:deviceId, spout_device_id:spoutDeviceId, }, "post").then(function (res) { wx.hideLoading(); if (res.code== 200) { wx.showModal({ title: '成功', content: res.message.msg, showCancel:false, success (res) { if (res.confirm) { console.log('用户点击确定') wx.navigateBack() } else if (res.cancel) { console.log('用户点击取消') } } }) }else wx.showToast({title: res.message.msg,icon:'none'}) }).catch(function (err) { console.log(222); }) } })