deposit.js 10.0 KB

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