deposit.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. // pages/order/deposit/deposit.js
  2. const app = getApp();
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. orderList: [
  9. ],
  10. logisticsStatus: "",
  11. show: false,
  12. result: false,
  13. result2: false,
  14. countDownNum: 15,
  15. spot_id: 0,
  16. device_no: "",
  17. order_num: "",
  18. is_deposit: 1,
  19. netwrok_id: 0,
  20. order_type: 0,
  21. external_cabinet:0,
  22. },
  23. /**
  24. * 生命周期函数--监听页面加载
  25. */
  26. onLoad: function (options) {
  27. var order_type = options.order_type ? options.order_type : 2
  28. var netwrok_id = options.network_id;
  29. var order_num = options.order_num;
  30. var is_deposit = options.is_deposit;
  31. var device_id = options.device_id?options.device_id:0;
  32. console.log(options);
  33. this.setData({
  34. logisticsStatus: app.globalData.logisticsStatus,
  35. order_num: order_num,
  36. netwrok_id: netwrok_id,
  37. is_deposit: is_deposit,
  38. device_id:device_id,
  39. order_type: order_type
  40. })
  41. this.getorderList(order_type, netwrok_id, device_id);
  42. if (this.data.is_deposit != 1) {
  43. wx.setNavigationBarTitle({
  44. title: '等待取出',
  45. })
  46. }
  47. },
  48. onClose(e) {
  49. var no = e.currentTarget.dataset.no
  50. var type = e.currentTarget.dataset.type
  51. var device_id = e.currentTarget.dataset.device_id
  52. var spout_device_id = e.currentTarget.dataset.spout_device_id
  53. var external_cabinet = e.currentTarget.dataset.external_cabinet
  54. wx.nextTick(() => {
  55. this.setData({
  56. show: !this.data.show
  57. })
  58. })
  59. if (this.data.is_deposit != 1) {
  60. if (this.data.spot_id == 0) {
  61. this.setData({
  62. spot_id: spout_device_id,
  63. device_no: device_id,
  64. external_cabinet:external_cabinet
  65. });
  66. }
  67. this.opentask1(no, type, this.data.device_no, this.data.spot_id)
  68. } else {
  69. this.opentask(no, type);
  70. }
  71. },
  72. countDown: function () {
  73. let that = this;
  74. let countDownNum = that.data.countDownNum;//获取倒计时初始值
  75. //如果将定时器设置在外面,那么用户就看不到countDownNum的数值动态变化,所以要把定时器存进data里面
  76. that.setData({
  77. timer: setInterval(function () {//这里把setInterval赋值给变量名为timer的变量
  78. //每隔一秒countDownNum就减一,实现同步
  79. countDownNum--;
  80. //然后把countDownNum存进data,好让用户知道时间在倒计着
  81. that.setData({
  82. countDownNum: countDownNum
  83. })
  84. //在倒计时还未到0时,这中间可以做其他的事情,按项目需求来
  85. if (countDownNum == 0) {
  86. //这里特别要注意,计时器是始终一直在走的,如果你的时间为0,那么就要关掉定时器!不然相当耗性能
  87. //因为timer是存在data里面的,所以在关掉时,也要在data里取出后再关闭
  88. clearInterval(that.data.timer);
  89. //关闭定时器之后,可作其他处理codes go here
  90. }
  91. }, 1000)
  92. })
  93. },
  94. takeClothes() {
  95. wx.nextTick(() => {
  96. this.setData({
  97. result: !this.data.result
  98. })
  99. })
  100. },
  101. storeClothes() {
  102. wx.nextTick(() => {
  103. this.setData({
  104. result2: !this.data.result2
  105. })
  106. })
  107. },
  108. getorderList(order_type, network_id, device_id = "") {
  109. var that = this;
  110. var nid = network_id
  111. var data = {
  112. network_id: nid,
  113. order_type: order_type,
  114. order_num: this.data.order_num,
  115. logistics_status: that.data.is_deposit == 1 ? 1 : 6,
  116. is_deposit: that.data.is_deposit
  117. }
  118. console.log(data);
  119. app.api.useApi(app.globalData.baseAppUrl + "api/order/index", data, "get").then(function (res) {
  120. if (res.code != 200) {
  121. console.log(res)
  122. wx.showLoading({
  123. title: '订单加载失败',
  124. })
  125. } else {
  126. that.setData({
  127. orderList: res.message.data.data,
  128. network: res.message.network,
  129. is_something: res.message.is_something
  130. })
  131. }
  132. wx.hideLoading();
  133. }).catch(function (err) {
  134. console.log(err);
  135. })
  136. },
  137. opentask(no = "", type = "") {
  138. var that = this;
  139. if (no && type) {
  140. this.setData({
  141. order_no: no,
  142. type: type,
  143. order_num: that.data.order_num
  144. })
  145. } else {
  146. no = this.data.order_no;
  147. type = this.data.order_type;
  148. }
  149. app.api.useApi(app.globalData.baseAppUrl + "api/save", {
  150. // status: status,
  151. order_no: no,
  152. order_num: that.data.device_id,
  153. }, "post").then(function (res) {
  154. console.log(res);
  155. if (res.code != 200) {
  156. that.countDown();
  157. that.setData({
  158. device_no: res.message.data.device_no,
  159. })
  160. wx.showToast({
  161. title: res.message.msg,
  162. })
  163. console.log(res.message.msg)
  164. // wx.setTimeout(() => {
  165. // wx.hideLoading();
  166. // }, 1000);
  167. setTimeout(function () {
  168. // wx.hideLoading();
  169. that.setData({
  170. show: !that.data.show
  171. })
  172. }, 1000)
  173. } else {
  174. console.log(res);
  175. that.setData({
  176. show: false,
  177. spot_id: res.message.data.spot_id,
  178. device_no: res.message.data.device_id,
  179. external_cabinet:res.message.data.external_cabinet
  180. })
  181. if (type == 1) {
  182. that.storeClothes()
  183. } else {
  184. that.takeClothes()
  185. }
  186. }
  187. // wx.hideLoading();
  188. }).catch(function (err) {
  189. console.log(err.message)
  190. })
  191. },
  192. goto() {
  193. var order_no = this.data.order_no;
  194. this.setData({
  195. result: false,
  196. result2: false,
  197. show: false
  198. })
  199. if (this.data.is_deposit != 1) {
  200. app.api.useApi(app.globalData.baseAppUrl + "api/UserConfirm", {
  201. // status: status,
  202. device_id: this.data.device_no,
  203. spout_device_id: this.data.spot_id,
  204. }, "post").then(function (res) {
  205. if (res.code != 200) {
  206. wx.showLoading({
  207. title: res.message.msg,
  208. })
  209. wx.setTimeout(() => {
  210. wx.hideLoading();
  211. }, 1000);
  212. } else {
  213. let p = getCurrentPages().pop().options
  214. console.log(p);
  215. that.getorderList(p.order_type, p.network_id);
  216. console.log(res);
  217. if (is_deposit == 1) {
  218. that.storeClothes()
  219. } else {
  220. that.takeClothes()
  221. }
  222. that.setData({
  223. show: !this.data.show
  224. })
  225. }
  226. wx.hideLoading();
  227. }).catch(function (err) {
  228. console.log(222);
  229. })
  230. } else {
  231. app.api.useApi(app.globalData.baseAppUrl + "api/saved", {
  232. // status: status,
  233. order_no: order_no,
  234. spot_id: this.data.spot_id,
  235. }, "post").then(function (res) {
  236. if (res.code != 200) {
  237. wx.showLoading({
  238. title: res.message.msg,
  239. })
  240. wx.setTimeout(() => {
  241. wx.hideLoading();
  242. }, 1000);
  243. } else {
  244. that.getorderList(that.data.order_type, that.data.netwrok_id);
  245. console.log(res);
  246. if (type == 1) {
  247. that.storeClothes()
  248. } else {
  249. that.takeClothes()
  250. }
  251. that.setData({
  252. show: !this.data.show
  253. })
  254. }
  255. wx.hideLoading();
  256. }).catch(function (err) {
  257. console.log(222);
  258. })
  259. }
  260. },
  261. /**
  262. * @name 开柜取出
  263. * @param {*} no
  264. * @param {*} type
  265. */
  266. opentask1(no = "", type = "", device_id, spout_device_id) {
  267. var that = this;
  268. if (no && type) {
  269. this.setData({
  270. order_no: no,
  271. type: type,
  272. })
  273. } else {
  274. no = this.data.order_no;
  275. type = this.data.order_type;
  276. }
  277. app.api.useApi(app.globalData.baseAppUrl + "api/UserOpenDevices", {
  278. // status: status,
  279. device_id: device_id,
  280. spout_device_id: spout_device_id
  281. }, "post").then(function (res) {
  282. if (res.code != 200) {
  283. wx.showLoading({
  284. title: res.message.msg,
  285. })
  286. that.countDown();
  287. that.setData({
  288. device_no: res.message.data.device_no,
  289. })
  290. // wx.setTimeout(() => {
  291. // wx.hideLoading();
  292. // }, 1000);
  293. setTimeout(function () {
  294. wx.hideLoading();
  295. that.setData({
  296. show: !that.data.show
  297. })
  298. }, 3000)
  299. } else {
  300. console.log(res);
  301. if (that.is_deposit == 1) {
  302. that.storeClothes()
  303. } else {
  304. that.takeClothes()
  305. }
  306. }
  307. wx.hideLoading();
  308. }).catch(function (err) {
  309. console.log(err.message)
  310. })
  311. },
  312. onPullDownRefresh: function () {
  313. let p = getCurrentPages().pop().options
  314. console.log(p);
  315. this.getorderList(p.order_type, p.network_id);
  316. }
  317. })