deposit.js 10 KB

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