index.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. import {
  2. BluetoothManager,
  3. BtErrorCode,
  4. CMD
  5. } from '../../service/BluWkm'
  6. var app = getApp();
  7. const bluM = new BluetoothManager
  8. Page({
  9. data: {
  10. message: [],
  11. bike_id: '',
  12. bike_no: '',
  13. tap: false,
  14. switch1Checked:false
  15. },
  16. onLoad: function (options) {
  17. var that = this;
  18. that.setData({
  19. bike_id: options.bike_id,
  20. bike_no: options.bike_no,
  21. })
  22. this.refresh1()
  23. },
  24. switch1Change: function (e) {
  25. console.log(e)
  26. var that = this;
  27. wx.openBluetoothAdapter({
  28. success(res) {
  29. console.log(res)
  30. that.setData({
  31. switch1Checked: e.detail.value
  32. })
  33. },
  34. fail(err) {
  35. console.log(err)
  36. wx.showModal({
  37. title: '提示',
  38. content: '请开启蓝牙',
  39. showCancel: false
  40. })
  41. that.setData({
  42. switch1Checked: false
  43. })
  44. }
  45. })
  46. },
  47. refresh: function () {
  48. this.setData({
  49. tap: true
  50. })
  51. this.refresh1()
  52. },
  53. refresh1: function () {
  54. //刷新信息
  55. var that = this;
  56. var data= {
  57. box_no: this.data.bike_no
  58. };
  59. app.request('open/bikeInfo',data,'GET').then(res=>{
  60. console.log(res)
  61. if (res.statusCode == 200) {
  62. that.setData({
  63. message: res.data,
  64. })
  65. if(res.data.is_link==0){
  66. that.setData({switch1Checked:true})
  67. }else{
  68. that.setData({switch1Checked:false})
  69. }
  70. if (that.data.tap == true) {
  71. wx.showToast({
  72. title: '成功',
  73. icon: 'none'
  74. })
  75. }
  76. }
  77. })
  78. },
  79. bikeBell: function () {
  80. //响铃
  81. var that = this;
  82. if(that.data.switch1Checked){
  83. wx.showLoading({
  84. title: '连接蓝牙中...',
  85. mask:true
  86. })
  87. bluM.connectDeivece(that.data.bike_no, CMD.bell)
  88. }else{
  89. wx.showLoading({
  90. title: '找车中...',
  91. })
  92. var data = {
  93. bike_no: that.data.bike_id
  94. }
  95. app.request('open/bikeBell',data,'POST').then(res=>{
  96. console.log(res)
  97. if (res.statusCode == 200) {
  98. wx.showToast({
  99. title: '找车成功',
  100. icon: 'none'
  101. })
  102. }
  103. })
  104. }
  105. },
  106. bikeOpen: function () {
  107. //开锁
  108. var that = this;
  109. if(that.data.switch1Checked){
  110. wx.showLoading({
  111. title: '连接蓝牙中...',
  112. mask:true
  113. })
  114. bluM.connectDeivece(that.data.bike_no,CMD.unlock);
  115. }else{
  116. wx.showLoading({
  117. title: '开锁中...',
  118. })
  119. var data={
  120. bike_no: this.data.bike_id
  121. }
  122. app.request('open/bikeOpen',data,'POST').then(res=>{
  123. console.log(res)
  124. if (res.statusCode == 200) {
  125. wx.showToast({
  126. title: '开锁成功',
  127. icon: 'none'
  128. })
  129. }
  130. })
  131. }
  132. },
  133. bikeClose: function () {
  134. //关锁
  135. var that = this;
  136. if(that.data.switch1Checked){
  137. wx.showLoading({
  138. title: '连接蓝牙中...',
  139. mask:true
  140. })
  141. bluM.connectDeivece(that.data.bike_no,CMD.lock)
  142. }else{
  143. wx.showLoading({
  144. title: '关锁中...',
  145. })
  146. var data= {
  147. bike_no: this.data.bike_id
  148. }
  149. app.request('open/bikeClose',data,'POST').then(res=>{
  150. console.log(res)
  151. if (res.statusCode == 200) {
  152. wx.showToast({
  153. title: '关锁成功',
  154. icon: 'none'
  155. })
  156. }
  157. })
  158. }
  159. },
  160. bikeOpenBattery: function () {
  161. //开电池锁
  162. var that = this;
  163. if(that.data.switch1Checked){
  164. wx.showLoading({
  165. title: '连接蓝牙中...',
  166. mask:true
  167. })
  168. bluM.connectDeivece(that.data.bike_no,CMD.batteryUnlock);
  169. }else{
  170. wx.showLoading({
  171. title: '开电池锁中...',
  172. })
  173. var data= {
  174. bike_no: this.data.bike_id
  175. }
  176. app.request('open/bikeOpenBattery',data,'POST').then(res=>{
  177. console.log(res)
  178. if (res.statusCode == 200) {
  179. wx.showToast({
  180. title: '开电池锁成功',
  181. icon: 'none'
  182. })
  183. }
  184. })
  185. }
  186. },
  187. bikeCloseBattery: function () {
  188. //关电池锁
  189. var that = this;
  190. if(that.data.switch1Checked){
  191. wx.showLoading({
  192. title: '连接蓝牙中...',
  193. mask:true
  194. })
  195. bluM.connectDeivece(that.data.bike_no,CMD.batteryUnlock);
  196. }else{
  197. var data= {
  198. bike_no: this.data.bike_id
  199. }
  200. app.request('open/bikeCloseBattery',data,'POST').then(res=>{
  201. console.log(res)
  202. if (res.statusCode == 200) {
  203. wx.showToast({
  204. title: '关电池锁成功',
  205. icon: 'none'
  206. })
  207. }
  208. })
  209. }
  210. },
  211. bikeBattery: function () {
  212. var that = this;
  213. var data= {
  214. bike_no: this.data.bike_id
  215. }
  216. app.request('open/newBikeBatteryMSG',data,'POST').then(res=>{
  217. console.log(res)
  218. if (res.statusCode == 200) {
  219. wx.showToast({
  220. title: '刷新电量成功',
  221. icon: 'none'
  222. })
  223. }
  224. })
  225. },
  226. bikeLocation: function () {
  227. var that = this;
  228. var data= {
  229. bike_no: this.data.bike_id
  230. }
  231. app.request('open/newBikeLocation',data,'POST').then(res=>{
  232. console.log(res)
  233. if (res.statusCode == 200) {
  234. wx.showToast({
  235. title: '获取位置成功',
  236. icon: 'none'
  237. })
  238. }
  239. })
  240. },
  241. chongqi: function () {
  242. console.log(this.data.bike_id)
  243. var that = this;
  244. var data= {
  245. bike_no: this.data.bike_id
  246. }
  247. app.request('open/rebootBox',data,'POST').then(res=>{
  248. console.log(res)
  249. if (res.statusCode == 200) {
  250. wx.showToast({
  251. title: '重启中控成功',
  252. icon: 'none'
  253. })
  254. }
  255. })
  256. }
  257. })