deposit.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  1. // pages/order/deposit/deposit.js
  2. const app = getApp();
  3. let timer;
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. orderList: [
  10. ],
  11. logisticsStatus: "",
  12. show: false,
  13. result: false,
  14. result2: false,
  15. countDownNum: 0,
  16. spot_id: 0,
  17. device_no: "",
  18. order_num: "",
  19. is_deposit: 1,
  20. netwrok_id: 0,
  21. order_type: 0,
  22. external_cabinet:0,
  23. },
  24. /**
  25. * 生命周期函数--监听页面加载
  26. */
  27. onLoad: function (options) {
  28. var order_type = options.order_type ? options.order_type : 2
  29. var netwrok_id = options.network_id;
  30. var order_num = options.order_num;
  31. var is_deposit = options.is_deposit;
  32. var device_id = options.device_id?options.device_id:0;
  33. console.log(options);
  34. this.setData({
  35. logisticsStatus: app.globalData.logisticsStatus,
  36. order_num: order_num,
  37. netwrok_id: netwrok_id,
  38. is_deposit: is_deposit,
  39. device_id:device_id,
  40. order_type: order_type
  41. })
  42. this.getorderList(order_type, netwrok_id, device_id);
  43. if (this.data.is_deposit != 1) {
  44. wx.setNavigationBarTitle({
  45. title: '等待取出',
  46. })
  47. }
  48. },
  49. againtakeclothes(){
  50. let that = this
  51. // console.log('type:'+e.currentTarget.dataset.type)
  52. app.api.useApi(app.globalData.baseAppUrl + "api/again_save", {
  53. // status: status,
  54. spot_id: that.data.spot_id,
  55. }, "post").then(function (res) {
  56. console.log(res);
  57. if (res.code != 200) {
  58. that.countDown();
  59. that.setData({
  60. device_no: res.message.data.device_no,
  61. spot_id:res.message.data.spot_id,
  62. })
  63. wx.showToast({
  64. title: res.message.msg,
  65. })
  66. console.log(res.message.msg)
  67. setTimeout(function () {
  68. wx.hideLoading();
  69. that.setData({
  70. show: !that.data.show
  71. })
  72. }, 1000)
  73. } else {
  74. console.log(res);
  75. wx.showToast({
  76. title: res.message.msg,
  77. })
  78. that.countDown();
  79. that.setData({
  80. spot_id: res.message.data.spot_id,
  81. })
  82. // that.takeClothes()
  83. // that.goto()
  84. }
  85. wx.hideLoading();
  86. }).catch(function (err) {
  87. console.log(err.message)
  88. })
  89. },
  90. onClose(e) {
  91. let that = this
  92. console.log('type:'+e.currentTarget.dataset.type)
  93. if(that.data.countDownNum<=0){
  94. var no = e.currentTarget.dataset.no
  95. var type = e.currentTarget.dataset.type
  96. var device_id = e.currentTarget.dataset.device_id
  97. var spout_device_id = e.currentTarget.dataset.spout_device_id
  98. var external_cabinet = e.currentTarget.dataset.external_cabinet
  99. var metoh = e.currentTarget.dataset.metoh
  100. wx.nextTick(() => {
  101. that.setData({
  102. show: !that.data.show
  103. })
  104. })
  105. if (that.data.is_deposit != 1) {
  106. console.log('1')
  107. // 注释掉
  108. // if (that.data.spot_id == 0) {
  109. that.setData({
  110. nonum: no,
  111. spot_id: spout_device_id,
  112. device_no: device_id,
  113. external_cabinet:external_cabinet
  114. });
  115. // }
  116. that.opentask1(no, type, that.data.device_no, that.data.spot_id)
  117. } else {
  118. console.log('2')
  119. that.opentask(no, type,metoh);
  120. }
  121. }else{
  122. wx.showToast({
  123. title: that.data.countDownNum+'秒后可重新开门',
  124. icon: 'none',
  125. duration: 1000
  126. })
  127. }
  128. },
  129. countDown: function () {
  130. let that = this;
  131. that.setData({countDownNum: 15})
  132. timer = setInterval(function () {
  133. that.setData({
  134. countDownNum: that.data.countDownNum - 1
  135. })
  136. if (that.data.countDownNum <= 0) {
  137. clearInterval(timer);
  138. }
  139. }, 1000)
  140. },
  141. takeClothes() {
  142. wx.nextTick(() => {
  143. this.setData({
  144. result: !this.data.result
  145. })
  146. })
  147. },
  148. storeClothes() {
  149. wx.nextTick(() => {
  150. this.setData({
  151. result2: !this.data.result2
  152. })
  153. })
  154. },
  155. getorderList(order_type, network_id, device_id = "") {
  156. var that = this;
  157. // var nid = network_id
  158. var data = {
  159. network_id: that.data.netwrok_id,
  160. order_type: that.data.order_type,
  161. order_num: this.data.order_num,
  162. logistics_status: that.data.is_deposit == 1 ? 1 : 6,
  163. is_deposit: that.data.is_deposit
  164. }
  165. console.log(data);
  166. // api/order/index
  167. // api/UserTakeList
  168. app.api.useApi(app.globalData.baseAppUrl + "api/order/index", data, "get").then(function (res) {
  169. if (res.code != 200) {
  170. console.log(res)
  171. wx.showLoading({
  172. title: '订单加载失败',
  173. })
  174. } else {
  175. that.setData({
  176. orderList: res.message.data.data,
  177. network: res.message.network,
  178. is_something: res.message.is_something
  179. })
  180. }
  181. wx.hideLoading();
  182. }).catch(function (err) {
  183. console.log(err);
  184. })
  185. },
  186. opentask(no = "", type = "",metoh="") {
  187. var that = this;
  188. console.log(type)
  189. if(no){
  190. this.setData({
  191. order_no: no,
  192. order_num: that.data.order_num
  193. })
  194. }else{
  195. no = this.data.order_no;
  196. }
  197. if(type){
  198. this.setData({
  199. type: type,
  200. })
  201. }else{
  202. type = this.data.order_type;
  203. }
  204. console.log(metoh);
  205. app.api.useApi(app.globalData.baseAppUrl + "api/"+metoh, {
  206. // status: status,
  207. order_no: no,
  208. order_num: that.data.device_id,
  209. spot_id:that.data.spot_id,
  210. external_cabinet:that.data.external_cabinet
  211. }, "post").then(function (res) {
  212. console.log(res);
  213. if (res.code != 200) {
  214. that.countDown();
  215. that.setData({
  216. device_no: res.message.data.device_no,
  217. spot_id:res.message.data.spot_id,
  218. })
  219. wx.showToast({
  220. title: res.message.msg,
  221. })
  222. console.log(res.message.msg)
  223. // wx.setTimeout(() => {
  224. // wx.hideLoading();
  225. // }, 1000);
  226. setTimeout(function () {
  227. wx.hideLoading();
  228. that.setData({
  229. show: !that.data.show
  230. })
  231. }, 1000)
  232. } else {
  233. console.log(res);
  234. that.countDown();
  235. that.setData({
  236. show: false,
  237. spot_id: res.message.data.spot_id,
  238. device_no: res.message.data.device_id,
  239. external_cabinet:res.message.data.external_cabinet
  240. })
  241. if (type == 1) {
  242. console.log('1')
  243. that.storeClothes()
  244. } else {
  245. console.log('2')
  246. that.takeClothes()
  247. }
  248. that.goto()
  249. }
  250. wx.hideLoading();
  251. }).catch(function (err) {
  252. console.log(err.message)
  253. })
  254. },
  255. goto() {
  256. var order_no = this.data.order_no;
  257. let that = this
  258. that.setData({
  259. result: false,
  260. result2: false,
  261. show: false
  262. })
  263. if (that.data.is_deposit != 1) {
  264. app.api.useApi(app.globalData.baseAppUrl + "api/UserConfirm", {
  265. // status: status,
  266. device_id: that.data.device_no,
  267. spout_device_id: that.data.spot_id,
  268. }, "post").then(function (res) {
  269. if (res.code != 200) {
  270. wx.showLoading({
  271. title: res.message.msg,
  272. })
  273. wx.setTimeout(() => {
  274. wx.hideLoading();
  275. }, 1000);
  276. } else {
  277. let p = getCurrentPages().pop().options
  278. console.log(p);
  279. that.getorderList(p.order_type, p.network_id);
  280. console.log(res);
  281. if (is_deposit == 1) {
  282. that.storeClothes()
  283. } else {
  284. that.takeClothes()
  285. }
  286. that.setData({
  287. show: !that.data.show
  288. })
  289. that.getorderList()
  290. }
  291. wx.hideLoading();
  292. }).catch(function (err) {
  293. console.log(222);
  294. })
  295. } else {
  296. app.api.useApi(app.globalData.baseAppUrl + "api/saved", {
  297. // status: status,
  298. order_no: order_no,
  299. spot_id: that.data.spot_id,
  300. }, "post").then(function (res) {
  301. if (res.code != 200) {
  302. wx.showLoading({
  303. title: res.message.msg,
  304. })
  305. wx.setTimeout(() => {
  306. wx.hideLoading();
  307. }, 1000);
  308. } else {
  309. wx.showToast({
  310. title: res.message.msg,
  311. icon: 'none',
  312. duration: 1000
  313. })
  314. console.log('-------------j'+that.data.order_type, that.data.netwrok_id)
  315. that.getorderList(that.data.order_type, that.data.netwrok_id);
  316. console.log(res);
  317. if (type == 1) {
  318. that.storeClothes()
  319. } else {
  320. that.takeClothes()
  321. }
  322. that.setData({
  323. show: !that.data.show
  324. })
  325. that.getorderList()
  326. }
  327. wx.hideLoading();
  328. }).catch(function (err) {
  329. console.log(222);
  330. that.getorderList()
  331. })
  332. }
  333. },
  334. /**
  335. * @name 开柜取出
  336. * @param {*} no
  337. * @param {*} type
  338. */
  339. opentask1(no = "", type = "", device_id, spout_device_id) {
  340. var that = this;
  341. if (no && type) {
  342. this.setData({
  343. order_no: no,
  344. type: type,
  345. })
  346. } else {
  347. no = this.data.order_no;
  348. type = this.data.order_type;
  349. }
  350. app.api.useApi(app.globalData.baseAppUrl + "api/UserOpenDevices", {
  351. // status: status,
  352. device_id: that.data.device_no,
  353. spout_device_id: spout_device_id
  354. }, "post").then(function (res) {
  355. if (res.code != 200) {
  356. wx.showLoading({
  357. title: res.message.msg,
  358. })
  359. that.countDown();
  360. that.setData({
  361. device_no: res.message.data.device_no,
  362. })
  363. // wx.setTimeout(() => {
  364. // wx.hideLoading();
  365. // }, 1000);
  366. setTimeout(function () {
  367. wx.hideLoading();
  368. // that.setData({
  369. // show: !that.data.show
  370. // })
  371. }, 3000)
  372. } else {
  373. wx.showToast({
  374. title: res.message.msg,
  375. })
  376. that.countDown();
  377. console.log(res);
  378. if (that.is_deposit == 1) {
  379. that.storeClothes()
  380. } else {
  381. that.takeClothes()
  382. }
  383. that.goto()
  384. }
  385. wx.hideLoading();
  386. }).catch(function (err) {
  387. console.log(err.message)
  388. })
  389. },
  390. nogoto(){
  391. let that = this
  392. app.api.useApi(app.globalData.baseAppUrl + "api/not_saved", {
  393. // status: status,
  394. order_no: that.data.order_no,
  395. spot_id: that.data.spot_id,
  396. }, "post").then(function (res) {
  397. if (res.code != 200) {
  398. wx.showToast({
  399. title: res.message.msg,
  400. icon: 'none',
  401. duration: 1000
  402. })
  403. wx.setTimeout(() => {
  404. wx.hideLoading();
  405. }, 1000);
  406. } else {
  407. wx.showToast({
  408. title: res.message.msg,
  409. icon: 'none',
  410. duration: 1000
  411. })
  412. console.log(res);
  413. setTimeout(() => {
  414. that.getorderList()
  415. that.storeClothes()
  416. }, 500);
  417. }
  418. }).catch(function (err) {
  419. console.log(222);
  420. })
  421. },
  422. nofun(){
  423. },
  424. onPullDownRefresh: function () {
  425. let p = getCurrentPages().pop().options
  426. console.log(p);
  427. this.getorderList(p.order_type, p.network_id);
  428. }
  429. })