123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283 |
- 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;
- console.log(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: that.data.deviceId,
- 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
- })
- wx.showToast({ title: res.message.msg, icon: 'none' })
- this.setData({
- show: !this.data.show
- })
- } else
- wx.showToast({ title: res.message.msg, icon: 'none' })
- }).catch(function (err) {
- console.log(222);
- })
- },
- })
|