const app = getApp(); var deviceId = '', spoutDeviceId = ''; var isWork = false Page({ /** * 页面的初始数据 */ data: { selectInfo: {}, latticelist: [], state: -1, detashow: true, show: true, workeinfo: "", taskdetail: "", orderSn: '', smallPhone: '', deviceId:"", status: '',//当前选中的状态 operateStatus: ''//操作后的状态 }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { deviceId = options.deviceId this.setData({deviceId:deviceId}) }, onPullDownRefresh: function () { this.gettaskList(); }, onShow() { this.gettaskList(); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, //点击变色 显示按钮 seled: function (e) { this.setData({ state: e.currentTarget.dataset.key, status: e.currentTarget.dataset.status }); var id = e.currentTarget.dataset.id; spoutDeviceId = id var num = e.currentTarget.dataset.num; this.gettaskdeatil(id, num); }, deta: function () { if (this.data.detashow) { this.setData({ detashow: false, }); } else { this.setData({ detashow: true, }); } }, show: function () { var that = this that.opentask(function (res) { if (res) { if (that.data.status == '空闲') that.setData({ show: !that.data.show }); else wx.navigateTo({ url: '/pages/take/opentask/opentask?deviceId=' + deviceId + '&spoutDeviceId=' + spoutDeviceId + '&num=' + that.data.taskdetail.num }) } }) }, gettaskList() { var that = this; console.log(that.data.deviceId); app.api.useApi(app.globalData.baseAppUrl + "api/admin/TakeDevices", { device_no: that.data.deviceId }, "get").then(function (res) { console.log(res); if (res.code != 200) { wx.showLoading({ title: res.message.msg, }) setTimeout(function () { wx.navigateBack({ delta: 1 }) wx.hideLoading(); }, 1000); } else { wx.hideLoading(); that.setData({ latticelist: res.message.data.list, workeinfo: res.message.data }) } }).catch(function (err) { console.log(222); }) }, gettaskdeatil(id, num) { var that = this; if (!id) { wx.showLoading({ title: '选择失败,请退出重试!', }) setTimeout(function () { wx.hideLoading(); }, 1000); return false; } app.api.useApi(app.globalData.baseAppUrl + "api/admin/SelectLattice", { device_id: "1", spout_device_id: id, }, "get").then(function (res) { console.log(res); if (res.code != 200) { wx.showLoading({ title: '数据获取失败', }) setTimeout(function () { wx.hideLoading(); }, 1000); } else { wx.hideLoading(); res.message.data.num = num that.setData({ taskdetail: res.message.data }) } }).catch(function (err) { console.log(222); }) }, //打开柜子 opentask(callback) { var that = this; if (isWork) return; isWork = true that.setData({ operateText: '正在开柜...', isWork }) app.api.useApi(app.globalData.baseAppUrl + "api/admin/TakeOpenCupboard", { device_id: deviceId, spout_device_id: spoutDeviceId, }, "post").then(function (res) { isWork = false that.setData({ operateText: that.data.status == '空闲' ? '开柜存入' : '开柜取出', isWork }) console.log(res); if (res.code != 200) { wx.showLoading({ title: '数据获取失败', }) setTimeout(function () { wx.hideLoading(); }, 1000); callback(false) } else { wx.hideLoading(); callback(true) } }).catch(function (err) { callback(false) console.log(err); }) }, tel(e) { wx.makePhoneCall({ phoneNumber: e.currentTarget.dataset.replyPhone //仅为示例,并非真实的电话号码 }) }, copy(e) { wx.setClipboardData({ data: e.currentTarget.dataset.no, success(res) { wx.getClipboardData({ success(res) { wx.showLoading({ title: '已成功复制', }) setTimeout(function () { wx.hideLoading(); }, 1000); } }) } }) }, 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", { order_no: that.data.orderSn }, "get").then(function (res) { wx.hideLoading(); if (res.code == 200) { that.setData({ smallPhone: 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 }) }, scan: function () { var that = this wx.scanCode({ onlyFromCamera: true, success(res) { that.setData({ orderSn: res.result }) } }) }, onSubmit: function (e) { var that = this if (that.data.status == '已存') return; 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' }) app.api.useApi(app.globalData.baseAppUrl + "api/admin/SubmitStore", { order_no: that.data.orderSn, device_id: deviceId, spout_device_id: spoutDeviceId }, "post").then(function (res) { wx.hideLoading(); if (res.code == 200) { that.setData({ operateStatus: res.message.data.status }) } else wx.showToast({ title: res.message.msg, icon: 'none' }) }).catch(function (err) { console.log(222); }) }, })