access.js 3.9 KB

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