lattice.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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. spoutDeviceId = id
  48. var num = e.currentTarget.dataset.num;
  49. this.gettaskdeatil(id, num);
  50. },
  51. deta: function () {
  52. if (this.data.detashow) {
  53. this.setData({
  54. detashow: false,
  55. });
  56. } else {
  57. this.setData({
  58. detashow: true,
  59. });
  60. }
  61. },
  62. show: function () {
  63. var that = this
  64. that.opentask(function (res) {
  65. if (res) {
  66. if (that.data.status == '空闲')
  67. that.setData({ show: !that.data.show });
  68. else
  69. wx.navigateTo({
  70. url: '/pages/take/opentask/opentask?deviceId=' + deviceId + '&spoutDeviceId=' + spoutDeviceId + '&num=' + that.data.taskdetail.num
  71. })
  72. }
  73. })
  74. },
  75. gettaskList() {
  76. var that = this;
  77. console.log(that.data.deviceId);
  78. app.api.useApi(app.globalData.baseAppUrl + "api/admin/TakeDevices", {
  79. device_no: that.data.deviceId
  80. }, "get").then(function (res) {
  81. console.log(res);
  82. if (res.code != 200) {
  83. wx.showLoading({
  84. title: res.message.msg,
  85. })
  86. setTimeout(function () {
  87. wx.navigateBack({
  88. delta: 1
  89. })
  90. wx.hideLoading();
  91. }, 1000);
  92. } else {
  93. wx.hideLoading();
  94. that.setData({
  95. latticelist: res.message.data.list,
  96. workeinfo: res.message.data
  97. })
  98. }
  99. }).catch(function (err) {
  100. console.log(222);
  101. })
  102. },
  103. gettaskdeatil(id, num) {
  104. var that = this;
  105. if (!id) {
  106. wx.showLoading({
  107. title: '选择失败,请退出重试!',
  108. })
  109. setTimeout(function () {
  110. wx.hideLoading();
  111. }, 1000);
  112. return false;
  113. }
  114. app.api.useApi(app.globalData.baseAppUrl + "api/admin/SelectLattice", {
  115. device_id: "1",
  116. spout_device_id: id,
  117. }, "get").then(function (res) {
  118. console.log(res);
  119. if (res.code != 200) {
  120. wx.showLoading({
  121. title: '数据获取失败',
  122. })
  123. setTimeout(function () {
  124. wx.hideLoading();
  125. }, 1000);
  126. } else {
  127. wx.hideLoading();
  128. res.message.data.num = num
  129. that.setData({
  130. taskdetail: res.message.data
  131. })
  132. }
  133. }).catch(function (err) {
  134. console.log(222);
  135. })
  136. },
  137. //打开柜子
  138. opentask(callback) {
  139. var that = this;
  140. if (isWork)
  141. return;
  142. isWork = true
  143. that.setData({ operateText: '正在开柜...', isWork })
  144. app.api.useApi(app.globalData.baseAppUrl + "api/admin/TakeOpenCupboard", {
  145. device_id: deviceId,
  146. spout_device_id: spoutDeviceId,
  147. }, "post").then(function (res) {
  148. isWork = false
  149. that.setData({ operateText: that.data.status == '空闲' ? '开柜存入' : '开柜取出', isWork })
  150. console.log(res);
  151. if (res.code != 200) {
  152. wx.showLoading({
  153. title: '数据获取失败',
  154. })
  155. setTimeout(function () {
  156. wx.hideLoading();
  157. }, 1000);
  158. callback(false)
  159. } else {
  160. wx.hideLoading();
  161. callback(true)
  162. }
  163. }).catch(function (err) {
  164. callback(false)
  165. console.log(err);
  166. })
  167. },
  168. tel(e) {
  169. wx.makePhoneCall({
  170. phoneNumber: e.currentTarget.dataset.replyPhone //仅为示例,并非真实的电话号码
  171. })
  172. },
  173. copy(e) {
  174. wx.setClipboardData({
  175. data: e.currentTarget.dataset.no,
  176. success(res) {
  177. wx.getClipboardData({
  178. success(res) {
  179. wx.showLoading({
  180. title: '已成功复制',
  181. })
  182. setTimeout(function () {
  183. wx.hideLoading();
  184. }, 1000);
  185. }
  186. })
  187. }
  188. })
  189. },
  190. onClick: function (e) {
  191. var type = e.currentTarget.dataset.type
  192. var that = this
  193. if (type == 1) {
  194. if (that.data.orderSn == '')
  195. return wx.showToast({ title: '物流单号不能为空', icon: 'none' })
  196. app.api.useApi(app.globalData.baseAppUrl + "api/admin/StoreCodeUserInfo", {
  197. order_no: that.data.orderSn
  198. }, "get").then(function (res) {
  199. wx.hideLoading();
  200. if (res.code == 200) {
  201. that.setData({
  202. smallPhone: res.message.data.phone
  203. })
  204. } else
  205. wx.showToast({ title: res.message.msg, icon: 'none' })
  206. }).catch(function (err) {
  207. console.log(222);
  208. })
  209. } else
  210. this.setData({
  211. show: !this.data.show
  212. })
  213. },
  214. scan: function () {
  215. var that = this
  216. wx.scanCode({
  217. onlyFromCamera: true,
  218. success(res) {
  219. that.setData({
  220. orderSn: res.result
  221. })
  222. }
  223. })
  224. },
  225. onSubmit: function (e) {
  226. var that = this
  227. if (that.data.status == '已存')
  228. return;
  229. if (that.data.orderSn == '')
  230. return wx.showToast({ title: '物流单号不能为空', icon: 'none' })
  231. if (deviceId == '')
  232. return wx.showToast({ title: '设备号不能为空', icon: 'none' })
  233. if (spoutDeviceId == '')
  234. return wx.showToast({ title: '柜门号不能为空', icon: 'none' })
  235. app.api.useApi(app.globalData.baseAppUrl + "api/admin/SubmitStore", {
  236. order_no: that.data.orderSn,
  237. device_id: deviceId,
  238. spout_device_id: spoutDeviceId
  239. }, "post").then(function (res) {
  240. wx.hideLoading();
  241. if (res.code == 200) {
  242. that.setData({
  243. operateStatus: res.message.data.status
  244. })
  245. } else
  246. wx.showToast({ title: res.message.msg, icon: 'none' })
  247. }).catch(function (err) {
  248. console.log(222);
  249. })
  250. },
  251. })