access.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. // pages/order/access/access.js
  2. const app=getApp();
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. orders:"",
  9. network_id:0,
  10. orde_num:0,
  11. iswhite: true
  12. },
  13. /**
  14. * 生命周期函数--监听页面加载
  15. */
  16. onLoad: function (options) {
  17. console.log(options.q);
  18. var network_id=options.network_id;
  19. if(options.q){
  20. var url=decodeURIComponent(options.q)
  21. var order_num=app.getQueryVariable(url,"orde_num");
  22. var network_id=wx.getStorageSync('nid');
  23. }
  24. this.setData({
  25. network_id:network_id,
  26. orde_num:order_num?order_num:0
  27. })
  28. },
  29. scan(){
  30. wx.scanCode({
  31. onlyFromCamera: true,
  32. success: (result) => {
  33. var url=result.result;
  34. var network_id=this.data.network_id;
  35. var order_num=app.getQueryVariable(url,"orde_num");
  36. wx.navigateTo({
  37. url: '/pages/order/deposit/deposit?network_id='+network_id+"&device_id="+order_num+"&order_num="+order_num+"&is_deposit=1"
  38. })
  39. console.log(result)
  40. },
  41. fail: (res) => {},
  42. complete: (res) => {},
  43. })
  44. },
  45. /**
  46. * 取件
  47. */
  48. receive(){
  49. wx.scanCode({
  50. onlyFromCamera: true,
  51. success: (result) => {
  52. var url=result.result;
  53. var network_id=this.data.network_id?this.data.network_id:app.getQueryVariable(url,"network_id");
  54. var order_num=app.getQueryVariable(url,"orde_num");
  55. wx.navigateTo({
  56. url: '/pages/order/deposit/deposit?network_id='+network_id+"&order_num="+order_num+"&is_deposit=0",
  57. })
  58. console.log(result)
  59. },
  60. fail: (res) => {},
  61. complete: (res) => {},
  62. })
  63. },
  64. /**
  65. * 生命周期函数--监听页面初次渲染完成
  66. */
  67. onReady: function () {
  68. },
  69. /**
  70. * 生命周期函数--监听页面显示
  71. */
  72. onShow: function () {
  73. var that=this;
  74. var token =wx.getStorageSync('token');
  75. that.setData({iswhite: true})
  76. if(!token){
  77. app.login().then(res => {
  78. console.log(res)
  79. that.setData({
  80. token: res.message.token,
  81. })
  82. that.getDeviceinfo(that.data.orde_num);
  83. })
  84. }else{
  85. that.getDeviceinfo(that.data.orde_num);
  86. }
  87. },
  88. /**
  89. * @name 获取当前网点存取单
  90. * @param int network_id 网点id
  91. */
  92. getDeviceinfo:function(order_num){
  93. var that=this;
  94. wx.showLoading({
  95. title: '加载中...',
  96. })
  97. app.api.useApi(app.globalData.baseAppUrl+"api/order/getDeviceinfo",{
  98. order_num:order_num,
  99. network_id:this.data.network_id
  100. }).then((res)=>{
  101. if(res.code!=200){
  102. setTimeout(() => {
  103. that.getDeviceinfo(order_num)
  104. }, 1000);
  105. // wx.showToast({
  106. // title: res.message.msg,
  107. // icon:"none",
  108. // success:function(){
  109. // setTimeout(() => {
  110. // wx.hideLoading({
  111. // success: (res) => {},
  112. // })
  113. // }, 2000);
  114. // }
  115. // })
  116. }else{
  117. wx.hideLoading()
  118. var orders=res.message.data;
  119. that.setData({
  120. orders:orders
  121. })
  122. if(orders.send_count<1 && orders.receive_count <1 && orders.network.id>0){
  123. wx.navigateTo({
  124. url: "/pages/order/placeOrder/placeOrder?network_id="+orders.network.id
  125. })
  126. }else{
  127. that.setData({iswhite: false})
  128. }
  129. }
  130. }).catch((err)=>{
  131. console.log(err);
  132. })
  133. }
  134. })