control.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. // pages/guanlian/guanlian.js.
  2. var app = getApp();
  3. Page({
  4. data: {
  5. erweima: '',
  6. value: '',
  7. index: 0
  8. },
  9. onLoad: function (options) {
  10. },
  11. onShow: function () {
  12. wx.hideHomeButton()
  13. },
  14. tap: function (e) {
  15. this.setData({
  16. index: e.currentTarget.dataset.index,
  17. erweima: '',
  18. value: ''
  19. })
  20. },
  21. input2: function (e) {
  22. this.setData({
  23. value: e.detail.value
  24. })
  25. },
  26. input1: function (e) {
  27. this.setData({
  28. erweima: e.detail.value
  29. })
  30. },
  31. relieve: function () {
  32. //解除绑定
  33. var that = this;
  34. if (that.data.value == '') {
  35. wx.showModal({
  36. title: '提示',
  37. content: '请完善中控设备号',
  38. showCancel: false
  39. })
  40. } else {
  41. wx.showLoading({
  42. title: '解绑中...',
  43. })
  44. let data = {
  45. box_no: that.data.value
  46. }
  47. app.request('control/unbindingBike', data, 'POST').then(res => {
  48. wx.hideLoading();
  49. if (res.statusCode == 200) {
  50. wx.showToast({
  51. title: '解除成功',
  52. icon: 'none'
  53. })
  54. that.setData({
  55. value: ''
  56. })
  57. }
  58. })
  59. }
  60. },
  61. qued: function () {
  62. //点击立即绑定
  63. var that = this;
  64. if (that.data.erweima == '' || that.data.value == '') {
  65. wx.showModal({
  66. title: '提示',
  67. content: '请完善设备码或车辆编号',
  68. showCancel: false
  69. })
  70. } else {
  71. wx.showLoading({
  72. title: '绑定中...',
  73. })
  74. let data = {
  75. bike_no: that.data.erweima,
  76. box_no: that.data.value
  77. }
  78. app.request('control/addBike', data, 'POST').then(res => {
  79. wx.hideLoading();
  80. if (res.statusCode == 200) {
  81. wx.showToast({
  82. title: '绑定成功',
  83. icon: 'none'
  84. })
  85. that.setData({
  86. erweima: '',
  87. value: ''
  88. })
  89. }
  90. })
  91. }
  92. },
  93. tiaoxing: function () {
  94. //点击扫描条形码
  95. var that = this;
  96. wx.scanCode({
  97. success: function (res) {
  98. console.log(typeof (res.result))
  99. if (typeof (res.result) == 'string') {
  100. console.log(res.result)
  101. if (res.result.length == 9) {
  102. that.setData({
  103. value: res.result
  104. })
  105. } else {
  106. wx.showToast({
  107. title: '扫错了~',
  108. icon: 'none'
  109. })
  110. }
  111. }
  112. },
  113. fail: function () {
  114. wx.showToast({
  115. title: '扫码失败',
  116. icon: 'none'
  117. })
  118. }
  119. })
  120. },
  121. erwei: function () {
  122. //点击扫描二维码
  123. var that = this;
  124. wx.scanCode({
  125. success: function (res) {
  126. console.log(res)
  127. var code = decodeURIComponent(res.result);
  128. var code1 = code.lastIndexOf("\=");
  129. var source = code.substring(code1 + 1, code.length);
  130. that.setData({
  131. erweima: source
  132. })
  133. },
  134. fail: function () {
  135. wx.showToast({
  136. title: '扫码失败',
  137. icon: 'none'
  138. })
  139. }
  140. })
  141. },
  142. // scanCode:function(){
  143. // wx.scanCode({
  144. // success: function (res) {
  145. // console.log(res)
  146. // var code = decodeURIComponent(res.result);
  147. // var code1 = code.lastIndexOf("\=");
  148. // var source = code.substring(code1 + 1, code.length);
  149. // wx.request({
  150. // url: 'https://admin.weilaibike.com/app-api/open/bikeInfoByBikeNo?bike_no=' + source+'&token='+wx.getStorageSync('token'),
  151. // method: 'GET',
  152. // header: {
  153. // 'content-type': 'application/x-www-form-urlencoded'
  154. // },
  155. // success: function (res) {
  156. // console.log(res)
  157. // if (res.statusCode == 200) {
  158. // wx.navigateTo({
  159. // url: '../index/index?bike_id=' + res.data.bike_no + '&bike_no=' + res.data.box_no,
  160. // })
  161. // } else if (res.statusCode == 401) {
  162. // wx.clearStorageSync('token');
  163. // wx.redirectTo({
  164. // url: '../login/index',
  165. // })
  166. // }else {
  167. // wx.showToast({
  168. // title: res.data.message,
  169. // icon: 'none',
  170. // duration: 3000
  171. // })
  172. // }
  173. // }
  174. // })
  175. // },
  176. // fail: function () {
  177. // wx.showToast({
  178. // title: '扫码失败',
  179. // icon: 'none'
  180. // })
  181. // }
  182. // })
  183. // }
  184. })