index.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. import {
  2. BluetoothManager,
  3. BtErrorCode
  4. } from '../../service/BlueMgr'
  5. const bluM = new BluetoothManager
  6. Page({
  7. data: {
  8. message:[],
  9. bike_id:'',
  10. bike_no:'',
  11. tap:false
  12. },
  13. onLoad: function (options) {
  14. var that = this;
  15. console.log(options)
  16. that.setData({
  17. bike_id:options.bike_id,
  18. bike_no: options.bike_no,
  19. })
  20. this.refresh1()
  21. wx.showLoading({
  22. title: '初始化蓝牙中...',
  23. mask:true
  24. })
  25. bluM.connectDeivece(options.bike_no).then(res => {
  26. //蓝牙连接成功 是否用蓝牙
  27. wx.hideLoading()
  28. wx.showToast({
  29. title: '蓝牙初始化成功',
  30. icon:'none',
  31. duration:2000
  32. })
  33. }, rej => {
  34. console.log(rej)
  35. //蓝牙连接异常
  36. wx.hideLoading()
  37. wx.getBluetoothAdapterState({
  38. success(res) {
  39. console.log(res)
  40. if (res.available == false) {
  41. wx.showModal({
  42. title: '提示',
  43. content: '手动开启蓝牙体验快速开锁~',
  44. showCancel: false
  45. })
  46. }else{
  47. wx.showModal({
  48. title: '提示',
  49. content: '蓝牙扫描超时~',
  50. showCancel: false
  51. })
  52. }
  53. }
  54. })
  55. }).catch(err=>{
  56. wx.hideLoading()
  57. wx.showToast({
  58. title: '蓝牙初始化失败',
  59. icon: 'none',
  60. duration: 2000
  61. })
  62. })
  63. },
  64. refresh:function(){
  65. this.setData({tap:true})
  66. this.refresh1()
  67. },
  68. refresh1:function(){
  69. //刷新信息
  70. var that = this;
  71. wx.request({
  72. url: 'https://admin.weilaibike.com/app-api/open/bikeInfo',
  73. method: 'GET',
  74. data: {
  75. box_no: this.data.bike_no,
  76. token:wx.getStorageSync('token')
  77. },
  78. header: {
  79. 'content-type': 'application/x-www-form-urlencoded'
  80. },
  81. success: function (res) {
  82. console.log(res)
  83. if (res.statusCode == 200) {
  84. that.setData({
  85. message:res.data
  86. })
  87. if(that.data.tap==true){
  88. wx.showToast({
  89. title: '成功',
  90. icon: 'none'
  91. })
  92. }
  93. } else if (res.statusCode == 401) {
  94. wx.clearStorageSync('token');
  95. wx.redirectTo({
  96. url: '../login/index',
  97. })
  98. }else {
  99. wx.showToast({
  100. title: res.data.message,
  101. icon: 'none',
  102. duration: 3000
  103. })
  104. }
  105. }
  106. })
  107. },
  108. bikeBell:function(){
  109. //响铃
  110. var that = this;
  111. bluM.connectDeivece(that.data.bike_no).then(res => {
  112. console.log('bellbike ===>')
  113. return bluM.bellBike()
  114. }, rej => {
  115. //抛出异常 当前蓝牙不可用
  116. console.log(rej, 123)
  117. wx.request({
  118. url: 'https://admin.weilaibike.com/app-api/open/bikeBell',
  119. method: 'POST',
  120. data: {
  121. bike_no: that.data.bike_id,
  122. token: wx.getStorageSync('token')
  123. },
  124. header: {
  125. 'content-type': 'application/x-www-form-urlencoded'
  126. },
  127. success: function (res) {
  128. console.log(res)
  129. if (res.statusCode == 200) {
  130. wx.showToast({
  131. title: '找车成功',
  132. icon: 'none'
  133. })
  134. } else if (res.statusCode == 401) {
  135. wx.clearStorageSync('token');
  136. wx.redirectTo({
  137. url: '../login/index',
  138. })
  139. }else {
  140. wx.showToast({
  141. title: res.data.message,
  142. icon: 'none',
  143. duration: 3000
  144. })
  145. }
  146. }
  147. })
  148. }).then(res => {
  149. console.log(res, 1234)
  150. }, rej => {
  151. console.log(rej, 12345)
  152. wx.request({
  153. url: 'https://admin.weilaibike.com/app-api/open/bikeBell',
  154. method: 'POST',
  155. data: {
  156. bike_no: that.data.bike_id,
  157. token: wx.getStorageSync('token')
  158. },
  159. header: {
  160. 'content-type': 'application/x-www-form-urlencoded'
  161. },
  162. success: function (res) {
  163. console.log(res)
  164. if (res.statusCode == 200) {
  165. wx.showToast({
  166. title: '找车成功',
  167. icon: 'none'
  168. })
  169. } else if (res.statusCode == 401) {
  170. wx.clearStorageSync('token');
  171. wx.redirectTo({
  172. url: '../login/index',
  173. })
  174. }else {
  175. wx.showToast({
  176. title: res.data.message,
  177. icon: 'none',
  178. duration: 3000
  179. })
  180. }
  181. }
  182. })
  183. })
  184. },
  185. bikeOpen: function () {
  186. //开锁
  187. var that = this;
  188. wx.request({
  189. url: 'https://admin.weilaibike.com/app-api/open/bikeOpen',
  190. method: 'POST',
  191. data: {
  192. bike_no: this.data.bike_id,
  193. token: wx.getStorageSync('token')
  194. },
  195. header: {
  196. 'content-type': 'application/x-www-form-urlencoded'
  197. },
  198. success: function (res) {
  199. bluM.connectDeivece(that.data.bike_no).then(res => {
  200. console.log('连接成功')
  201. bluM.unlockBike()
  202. })
  203. console.log(res)
  204. if (res.statusCode == 200) {
  205. wx.showToast({
  206. title: '开锁成功',
  207. icon: 'none'
  208. })
  209. } else if (res.statusCode == 401) {
  210. wx.clearStorageSync('token');
  211. wx.redirectTo({
  212. url: '../login/index',
  213. })
  214. }else {
  215. wx.showToast({
  216. title: res.data.message,
  217. icon: 'none',
  218. duration: 3000
  219. })
  220. }
  221. }
  222. })
  223. },
  224. bikeClose: function () {
  225. //关锁
  226. var that = this;
  227. wx.request({
  228. url: 'https://admin.weilaibike.com/app-api/open/bikeClose',
  229. method: 'POST',
  230. data: {
  231. bike_no: this.data.bike_id,
  232. token: wx.getStorageSync('token')
  233. },
  234. header: {
  235. 'content-type': 'application/x-www-form-urlencoded'
  236. },
  237. success: function (res) {
  238. console.log(res)
  239. bluM.connectDeivece(that.data.bike_no).then(res => {
  240. console.log('lockbike')
  241. return bluM.lockBike()
  242. }, reject => { })
  243. if (res.statusCode == 200) {
  244. wx.showToast({
  245. title: '关锁成功',
  246. icon: 'none'
  247. })
  248. } else if (res.statusCode == 401) {
  249. wx.clearStorageSync('token');
  250. wx.redirectTo({
  251. url: '../login/index',
  252. })
  253. }else {
  254. wx.showToast({
  255. title: res.data.message,
  256. icon: 'none',
  257. duration: 3000
  258. })
  259. }
  260. }
  261. })
  262. },
  263. bikeOpenBattery: function () {
  264. //开电池锁
  265. var that = this;
  266. wx.request({
  267. url: 'https://admin.weilaibike.com/app-api/open/bikeOpenBattery',
  268. method: 'POST',
  269. data: {
  270. bike_no: this.data.bike_id,
  271. token: wx.getStorageSync('token')
  272. },
  273. header: {
  274. 'content-type': 'application/x-www-form-urlencoded'
  275. },
  276. success: function (res) {
  277. console.log(res)
  278. bluM.connectDeivece(that.data.bike_no).then(res => {
  279. return bluM.batteryUnlockBike()
  280. })
  281. if (res.statusCode == 200) {
  282. wx.showToast({
  283. title: '开电池锁成功',
  284. icon: 'none'
  285. })
  286. } else if (res.statusCode == 401) {
  287. wx.clearStorageSync('token');
  288. wx.redirectTo({
  289. url: '../login/index',
  290. })
  291. }else {
  292. wx.showToast({
  293. title: res.data.message,
  294. icon: 'none',
  295. duration: 3000
  296. })
  297. }
  298. }
  299. })
  300. },
  301. bikeCloseBattery: function () {
  302. //关电池锁
  303. var that = this;
  304. wx.request({
  305. url: 'https://admin.weilaibike.com/app-api/open/bikeCloseBattery',
  306. method: 'POST',
  307. data: {
  308. bike_no: this.data.bike_id,
  309. token: wx.getStorageSync('token')
  310. },
  311. header: {
  312. 'content-type': 'application/x-www-form-urlencoded'
  313. },
  314. success: function (res) {
  315. bluM.connectDeivece(that.data.bike_no).then(res => {
  316. return bluM.batteryLockBike()
  317. })
  318. console.log(res)
  319. if (res.statusCode == 200) {
  320. wx.showToast({
  321. title: '关电池锁成功',
  322. icon: 'none'
  323. })
  324. } else if (res.statusCode == 401){
  325. wx.clearStorageSync('token');
  326. wx.redirectTo({
  327. url: '../login/index',
  328. })
  329. }else{
  330. wx.showToast({
  331. title: res.data.message,
  332. icon: 'none',
  333. duration: 3000
  334. })
  335. }
  336. }
  337. })
  338. },
  339. bikeBattery:function(){
  340. var that = this;
  341. wx.request({
  342. url: 'https://admin.weilaibike.com/app-api/open/newBikeBatteryMSG',
  343. method: 'POST',
  344. data: {
  345. bike_no: that.data.bike_id,
  346. token: wx.getStorageSync('token')
  347. },
  348. header: {
  349. 'content-type': 'application/x-www-form-urlencoded'
  350. },
  351. success: function (res) {
  352. bluM.connectDeivece(that.data.bike_id).then(res => {
  353. console.log('bellbike ===>')
  354. return bluM.boxReboot()
  355. })
  356. console.log(res)
  357. if (res.statusCode == 200) {
  358. wx.showToast({
  359. title: '刷新电量成功',
  360. icon: 'none'
  361. })
  362. } else if (res.statusCode == 401) {
  363. wx.clearStorageSync('token');
  364. wx.redirectTo({
  365. url: '../login/index',
  366. })
  367. } else {
  368. wx.showToast({
  369. title: res.data.message,
  370. icon: 'none',
  371. duration: 3000
  372. })
  373. }
  374. }
  375. })
  376. },
  377. bikeLocation:function(){
  378. var that = this;
  379. wx.request({
  380. url: 'https://admin.weilaibike.com/app-api/open/newBikeLocation',
  381. method: 'POST',
  382. data: {
  383. bike_no: that.data.bike_id,
  384. token: wx.getStorageSync('token')
  385. },
  386. header: {
  387. 'content-type': 'application/x-www-form-urlencoded'
  388. },
  389. success: function (res) {
  390. bluM.connectDeivece(that.data.bike_id).then(res => {
  391. console.log('bellbike ===>')
  392. return bluM.boxReboot()
  393. })
  394. console.log(res)
  395. if (res.statusCode == 200) {
  396. wx.showToast({
  397. title: '获取位置成功',
  398. icon: 'none'
  399. })
  400. } else if (res.statusCode == 401) {
  401. wx.clearStorageSync('token');
  402. wx.redirectTo({
  403. url: '../login/index',
  404. })
  405. } else {
  406. wx.showToast({
  407. title: res.data.message,
  408. icon: 'none',
  409. duration: 3000
  410. })
  411. }
  412. }
  413. })
  414. },
  415. chongqi:function(){
  416. console.log(this.data.bike_id)
  417. var that = this;
  418. wx.request({
  419. url: 'https://admin.weilaibike.com/app-api/open/rebootBox',
  420. method: 'POST',
  421. data: {
  422. bike_no: that.data.bike_id,
  423. token: wx.getStorageSync('token')
  424. },
  425. header: {
  426. 'content-type': 'application/x-www-form-urlencoded'
  427. },
  428. success: function (res) {
  429. bluM.connectDeivece(that.data.bike_id).then(res => {
  430. console.log('bellbike ===>')
  431. return bluM.boxReboot()
  432. })
  433. console.log(res)
  434. if (res.statusCode == 200) {
  435. wx.showToast({
  436. title: '重启中控成功',
  437. icon: 'none'
  438. })
  439. } else if (res.statusCode == 401) {
  440. wx.clearStorageSync('token');
  441. wx.redirectTo({
  442. url: '../login/index',
  443. })
  444. } else {
  445. wx.showToast({
  446. title: res.data.message,
  447. icon: 'none',
  448. duration: 3000
  449. })
  450. }
  451. }
  452. })
  453. }
  454. })