lattice.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. const app = getApp();
  2. var deviceId = '', spoutDeviceId = '';
  3. var isWork = false
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. selectInfo: {},
  10. latticelist: [],
  11. state: -1,
  12. detashow: true,
  13. show: true,
  14. workeinfo: "",
  15. taskdetail: "",
  16. orderSn: '',
  17. smallPhone: '',
  18. deviceId:"",
  19. status: '',//当前选中的状态
  20. operateStatus: ''//操作后的状态
  21. },
  22. /**
  23. * 生命周期函数--监听页面加载
  24. */
  25. onLoad: function (options) {
  26. deviceId = options.deviceId
  27. this.setData({deviceId:deviceId})
  28. },
  29. onPullDownRefresh: function () {
  30. this.gettaskList();
  31. },
  32. onShow() {
  33. this.gettaskList();
  34. },
  35. /**
  36. * 生命周期函数--监听页面初次渲染完成
  37. */
  38. onReady: function () {
  39. },
  40. //点击变色 显示按钮
  41. seled: function (e) {
  42. this.setData({
  43. state: e.currentTarget.dataset.key,
  44. status: e.currentTarget.dataset.status
  45. });
  46. var id = e.currentTarget.dataset.id;
  47. console.log(id);
  48. spoutDeviceId = id
  49. var num = e.currentTarget.dataset.num;
  50. this.gettaskdeatil(id, num);
  51. },
  52. deta: function () {
  53. if (this.data.detashow) {
  54. this.setData({
  55. detashow: false,
  56. });
  57. } else {
  58. this.setData({
  59. detashow: true,
  60. });
  61. }
  62. },
  63. show: function () {
  64. var that = this
  65. that.opentask(function (res) {
  66. if (res) {
  67. if (that.data.status == '空闲')
  68. that.setData({ show: !that.data.show });
  69. else
  70. wx.navigateTo({
  71. url: '/pages/take/opentask/opentask?deviceId=' + deviceId + '&spoutDeviceId=' + spoutDeviceId + '&num=' + that.data.taskdetail.num
  72. })
  73. }
  74. })
  75. },
  76. gettaskList() {
  77. var that = this;
  78. console.log(that.data.deviceId);
  79. app.api.useApi(app.globalData.baseAppUrl + "api/admin/TakeDevices", {
  80. device_no: that.data.deviceId
  81. }, "get").then(function (res) {
  82. console.log(res);
  83. if (res.code != 200) {
  84. wx.showLoading({
  85. title: res.message.msg,
  86. })
  87. setTimeout(function () {
  88. wx.navigateBack({
  89. delta: 1
  90. })
  91. wx.hideLoading();
  92. }, 1000);
  93. } else {
  94. wx.hideLoading();
  95. that.setData({
  96. latticelist: res.message.data.list,
  97. workeinfo: res.message.data
  98. })
  99. }
  100. }).catch(function (err) {
  101. console.log(222);
  102. })
  103. },
  104. gettaskdeatil(id, num) {
  105. var that = this;
  106. if (!id) {
  107. wx.showLoading({
  108. title: '选择失败,请退出重试!',
  109. })
  110. setTimeout(function () {
  111. wx.hideLoading();
  112. }, 1000);
  113. return false;
  114. }
  115. app.api.useApi(app.globalData.baseAppUrl + "api/admin/SelectLattice", {
  116. device_id: that.data.deviceId,
  117. spout_device_id: id,
  118. }, "get").then(function (res) {
  119. console.log(res);
  120. if (res.code != 200) {
  121. wx.showLoading({
  122. title: '数据获取失败',
  123. })
  124. setTimeout(function () {
  125. wx.hideLoading();
  126. }, 1000);
  127. } else {
  128. wx.hideLoading();
  129. res.message.data.num = num
  130. that.setData({
  131. taskdetail: res.message.data
  132. })
  133. }
  134. }).catch(function (err) {
  135. console.log(222);
  136. })
  137. },
  138. //打开柜子
  139. opentask(callback) {
  140. var that = this;
  141. if (isWork)
  142. return;
  143. isWork = true
  144. that.setData({ operateText: '正在开柜...', isWork })
  145. app.api.useApi(app.globalData.baseAppUrl + "api/admin/TakeOpenCupboard", {
  146. device_id: deviceId,
  147. spout_device_id: spoutDeviceId,
  148. }, "post").then(function (res) {
  149. isWork = false
  150. that.setData({ operateText: that.data.status == '空闲' ? '开柜存入' : '开柜取出', isWork })
  151. console.log(res);
  152. if (res.code != 200) {
  153. wx.showLoading({
  154. title: '数据获取失败',
  155. })
  156. setTimeout(function () {
  157. wx.hideLoading();
  158. }, 1000);
  159. callback(false)
  160. } else {
  161. wx.hideLoading();
  162. callback(true)
  163. }
  164. }).catch(function (err) {
  165. callback(false)
  166. console.log(err);
  167. })
  168. },
  169. tel(e) {
  170. wx.makePhoneCall({
  171. phoneNumber: e.currentTarget.dataset.replyPhone //仅为示例,并非真实的电话号码
  172. })
  173. },
  174. copy(e) {
  175. wx.setClipboardData({
  176. data: e.currentTarget.dataset.no,
  177. success(res) {
  178. wx.getClipboardData({
  179. success(res) {
  180. wx.showLoading({
  181. title: '已成功复制',
  182. })
  183. setTimeout(function () {
  184. wx.hideLoading();
  185. }, 1000);
  186. }
  187. })
  188. }
  189. })
  190. },
  191. onClick: function (e) {
  192. var type = e.currentTarget.dataset.type
  193. var that = this
  194. if (type == 1) {
  195. if (that.data.orderSn == '')
  196. return wx.showToast({ title: '物流单号不能为空', icon: 'none' })
  197. app.api.useApi(app.globalData.baseAppUrl + "api/admin/StoreCodeUserInfo", {
  198. order_no: that.data.orderSn
  199. }, "get").then(function (res) {
  200. wx.hideLoading();
  201. if (res.code == 200) {
  202. that.setData({
  203. smallPhone: res.message.data.phone
  204. })
  205. } else
  206. wx.showToast({ title: res.message.msg, icon: 'none' })
  207. }).catch(function (err) {
  208. console.log(222);
  209. })
  210. } else
  211. this.setData({
  212. show: !this.data.show
  213. })
  214. },
  215. scan: function () {
  216. var that = this
  217. wx.scanCode({
  218. onlyFromCamera: true,
  219. success(res) {
  220. that.setData({
  221. orderSn: res.result
  222. })
  223. }
  224. })
  225. },
  226. onSubmit: function (e) {
  227. var that = this
  228. if (that.data.status == '已存')
  229. return;
  230. if (that.data.orderSn == '')
  231. return wx.showToast({ title: '物流单号不能为空', icon: 'none' })
  232. if (deviceId == '')
  233. return wx.showToast({ title: '设备号不能为空', icon: 'none' })
  234. if (spoutDeviceId == '')
  235. return wx.showToast({ title: '柜门号不能为空', icon: 'none' })
  236. app.api.useApi(app.globalData.baseAppUrl + "api/admin/SubmitStore", {
  237. order_no: that.data.orderSn,
  238. device_id: deviceId,
  239. spout_device_id: spoutDeviceId
  240. }, "post").then(function (res) {
  241. wx.hideLoading();
  242. if (res.code == 200) {
  243. that.setData({
  244. operateStatus: res.message.data.status
  245. })
  246. wx.showToast({ title: res.message.msg, icon: 'none' })
  247. this.setData({
  248. show: !this.data.show
  249. })
  250. } else
  251. wx.showToast({ title: res.message.msg, icon: 'none' })
  252. }).catch(function (err) {
  253. console.log(222);
  254. })
  255. },
  256. })