riding.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868
  1. var app = getApp()
  2. var interval;
  3. var interval1;
  4. var locationTerval;
  5. var bikelocationTerval;
  6. var settime;
  7. var timeing;
  8. var inter1;
  9. var huancheTime;
  10. import {
  11. BluetoothManager,
  12. BtErrorCode,
  13. CMD
  14. } from '../../service/BluWkm'
  15. const bluM = new BluetoothManager;
  16. const util = require('../../utils/utils.js');
  17. Page({
  18. data: {
  19. windowHeight: '',
  20. bolear: 1,
  21. code: '',
  22. longitude: '',
  23. latitude: '',
  24. order: '',
  25. markers: [], //显示单车、停车的P图标
  26. polygons: [], //区域
  27. id: '', //区域的ID
  28. polygons1: [], //可骑行区域 先用这个变量代表
  29. controls: [], //地图上当前定位的箭头
  30. height: '',
  31. times: '0', //当前骑行时间
  32. detail: '', //车辆信息详情
  33. estimate_money: '0.00', //预计金额
  34. minute: '', //骑行总时间秒
  35. data: [],
  36. box_no: '',
  37. screenHeight: '',
  38. change: false,
  39. timing: 5,
  40. isShow: false,
  41. minute1: '',
  42. parke: true,
  43. timeout: 15,
  44. retry: '',
  45. bikePosition: false,
  46. battery_power: '',
  47. huanche_timeout: 0,
  48. img: app.globalData.imgUrl,
  49. title:app.globalData.title,
  50. isHour:false,//及时判断是否含有小时
  51. },
  52. onLoad: function (options) {
  53. var that = this;
  54. wx.showLoading({
  55. title: '加载中...',
  56. mask: true
  57. })
  58. wx.getSystemInfo({
  59. success: function (res) {
  60. // 获取可使用窗口宽度
  61. let clientHeight = res.windowHeight;
  62. // 获取可使用窗口高度
  63. let clientWidth = res.windowWidth;
  64. // 算出比例
  65. let ratio = 750 / clientWidth;
  66. // 算出高度(单位rpx)
  67. let height = clientHeight * ratio;
  68. // 设置高度
  69. console.log(height)
  70. that.setData({
  71. windowHeight: height
  72. });
  73. }
  74. })
  75. console.log(app.globalData.screenHeight)
  76. that.setData({
  77. screenHeight: app.globalData.screenHeight
  78. })
  79. console.log(options)
  80. if (options.order != undefined) {
  81. that.setData({
  82. order: options.order
  83. })
  84. }
  85. if (options.box_no != undefined) {
  86. that.setData({
  87. box_no: options.box_no
  88. })
  89. }
  90. wx.hideLoading()
  91. that.posiLoca()
  92. that.bikePosition()
  93. if (options.time == 'true') {
  94. that.setData({
  95. retry: true
  96. })
  97. that.inter1()
  98. }
  99. },
  100. terval: function () {
  101. var that = this;
  102. clearInterval(interval)
  103. clearInterval(huancheTime)
  104. var times = ''; //秒数
  105. // var minute = 0; //分钟
  106. var minute = Math.round(that.data.minute / 60); //分钟
  107. var minute1 = '0'; //分钟
  108. var hour = 0; //小时
  109. var hour1 = '0'; //小时
  110. var time = that.data.minute //获取当前已骑行的秒数
  111. console.log(time,'ppppp---------')
  112. var setting = wx.getStorageSync('setting');
  113. // var no_money_time = time;
  114. // var close_bike_time = setting.close_bike_time;
  115. // if (no_money_time < close_bike_time) {
  116. // that.setData({
  117. // huanche_timeout: close_bike_time - no_money_time
  118. // })
  119. // huancheTime = setInterval(() => {
  120. // var no_money_time1 = that.data.huanche_timeout - 1
  121. // that.setData({
  122. // huanche_timeout: no_money_time1
  123. // })
  124. // if (no_money_time1 == 0) {
  125. // that.setData({
  126. // huanche_timeout: -1
  127. // })
  128. // clearInterval(huancheTime)
  129. // }
  130. // }, 1000);
  131. // } else {
  132. // that.setData({
  133. // huanche_timeout: -1
  134. // })
  135. // }
  136. if (time > 60) { //秒数大于60 分钟= 秒数/60 秒数= -1*60 40
  137. minute = parseInt(time / 60);
  138. times = time - minute * 60;
  139. //minute代表分钟 times 代表秒数
  140. } else {
  141. minute = parseInt(time / 60);
  142. times = time;
  143. }
  144. interval = setInterval(function () {
  145. //定时器 秒数一秒加1
  146. minute++
  147. // if (times > 59) { //如果秒数大于59 让分钟加1 秒数归0
  148. // minute = minute + 1
  149. // times = 0
  150. // }
  151. // if (times < 10) { //如果秒数小于10 加一个0
  152. // times = '0' + times
  153. // }
  154. if (minute < 10 && hour>0) { //如果分钟小于10 加一个0
  155. minute1 = '0' + minute
  156. } else {
  157. minute1 = minute
  158. }
  159. if (minute > 59) {
  160. //分钟大于59 让小时+1
  161. hour = parseInt(minute / 60)
  162. minute1 = minute - hour * 60;
  163. if (hour < 10) {
  164. hour1 = '0' + hour;
  165. } else {
  166. hour1 = hour
  167. }
  168. }
  169. if (minute1 < 10 && hour > 0) { //如果分钟小于10 加一个0
  170. minute1 = '0' + minute1
  171. } else {
  172. minute1 = minute1
  173. }
  174. if (hour > 0) {
  175. //如果小时大于0 显示 时分
  176. that.setData({
  177. // times: hour1 + ':' + minute1 + ':' + times
  178. times: hour1 + ':' + minute1,
  179. isHour: true
  180. })
  181. } else {
  182. //else 显示 分秒
  183. that.setData({
  184. // times: minute1 + ':' + times
  185. times: minute1,
  186. isHour: false
  187. })
  188. }
  189. // that.setData({ times: minute1 + ':' + times})
  190. //计算钱 分钟除以5*5 判断秒数>30 minute = minute+1
  191. //不满12分钟按12分钟算 并且大于30秒
  192. var per_money = setting.per_money;
  193. var per_minute = setting.per_minute;
  194. // console.log(minute)
  195. // console.log(minute1)
  196. if (setting.starting_price_time > minute) {
  197. that.setData({
  198. estimate_money: setting.starting_price
  199. })
  200. } else {
  201. //起步价+(分钟数-起步时长)/ 一块钱可骑多少分钟 * 钱数
  202. var time = minute - setting.starting_price_time;
  203. // let money = parseInt(time / per_minute) * per_money + parseFloat(setting.starting_price)
  204. let money = Math.ceil(time / per_minute * Number(per_money)) + Number(setting.starting_price)
  205. that.setData({
  206. estimate_money:parseFloat(setting.starting_price)+ money,
  207. })
  208. // let money = Math.ceil(time / per_minute * Number(per_money)) + Number(setting.starting_price) + '.00';
  209. // if (money == NaN) {
  210. // money = Math.ceil(time / per_minute * Number(per_money)) + Number(setting.starting_price) + '.00';
  211. // }
  212. // if (minute > 0) {
  213. // that.setData({
  214. // estimate_money: money
  215. // })
  216. // } else {
  217. // if (times >= 30) {
  218. // that.setData({
  219. // estimate_money: Math.ceil(1 / per_minute * Number(per_money)) + '.00'
  220. // })
  221. // }
  222. // }
  223. }
  224. console.log(time,'ppppp++++++++++++++++++++++++++++++++++++++++++')
  225. }, 60000)
  226. },
  227. onReady: function () {
  228. var that = this;
  229. // wx.getSystemInfo({
  230. // success({
  231. // windowHeight
  232. // }) {
  233. // console.log(windowHeight)
  234. // that.setData({
  235. // windowHeight
  236. // });
  237. // }
  238. // });
  239. this.dialog = this.selectComponent("#dialog");
  240. },
  241. help: util.throttle(function () {
  242. //点击帮助
  243. wx.navigateTo({
  244. url: '../personal/help/help',
  245. })
  246. }, 1000),
  247. posiLoca: function () {
  248. //每5秒刷新当前位置
  249. var that = this;
  250. locationTerval = setInterval(function () {
  251. wx.getLocation({
  252. type: 'gcj02',
  253. success: (res) => {
  254. console.log('经纬度为:+++++++++++++++++++++' + res.latitude + '++++++++' + res.longitude)
  255. var latitude = res.latitude
  256. var longitude = res.longitude
  257. that.setData({
  258. longitude: longitude,
  259. latitude: latitude
  260. })
  261. },
  262. fail: function (err) {
  263. console.log(err)
  264. }
  265. })
  266. }, 5000)
  267. },
  268. bikePosition: function () {
  269. //每5秒刷新当前位置
  270. var that = this;
  271. bikelocationTerval = setInterval(function () {
  272. that.bikeLocation()
  273. }, 50000)
  274. },
  275. posi: util.throttle(function () {
  276. //点击定位
  277. var that = this;
  278. wx.getLocation({
  279. type: 'gcj02',
  280. success: (res) => {
  281. console.log('经纬度为:+++++++++++++++++++++' + res.latitude + '++++++++' + res.longitude)
  282. var latitude = res.latitude
  283. var longitude = res.longitude
  284. that.setData({
  285. longitude: longitude,
  286. latitude: latitude
  287. })
  288. }
  289. })
  290. }, 1000),
  291. search: util.throttle(function () {
  292. wx.navigateTo({
  293. url: '../navigation/navigation',
  294. })
  295. }, 1000),
  296. seek: util.throttle(function () {
  297. //点击响铃
  298. var that = this;
  299. wx.showLoading({
  300. title: '找车中...',
  301. mask: true
  302. })
  303. bluM.connectDeivece(that.data.code, CMD.bell)
  304. app.request('/order/retry-bell-lock?order_no=' + that.data.order + '&bike_no=' + that.data.code, '', 'GET').then(res => {
  305. console.log(res)
  306. if (res.statusCode == 200) {
  307. res.data.is_ok == true && wx.showToast({
  308. title: '找车成功',
  309. icon: 'none',
  310. duration: 2000
  311. })
  312. res.data.is_ok == false && wx.showToast({
  313. title: '找车失败请重试',
  314. icon: 'none',
  315. duration: 2000
  316. })
  317. }
  318. })
  319. }, 1000),
  320. refresh: util.throttle(function () {
  321. //点击刷新
  322. var that = this;
  323. var data = Date.parse(new Date()) / 1000;
  324. that.chushi()
  325. }, 1000),
  326. bikeLocation: function () {
  327. var that = this;
  328. var data = {
  329. bike_no: that.data.code
  330. }
  331. app.request('/order/orderBikePosition', data, 'GET').then(res => {
  332. if (res.statusCode == 200) {
  333. var mark = that.data.markers;
  334. if (that.data.bikePosition) {
  335. mark.pop()
  336. }
  337. that.setData({
  338. markers: mark,
  339. battery_power: res.data.battery_power
  340. })
  341. var array = {}
  342. array.iconPath = 'http://resource.bike.hanyiyun.com/weapp/dianche.png';
  343. array.width = 28;
  344. array.height = 28;
  345. array.zIndex = 1111;
  346. array.id = 12345;
  347. array.latitude = res.data.latitude;
  348. array.longitude = res.data.longitude;
  349. that.setData({
  350. markers: that.data.markers.concat(array)
  351. })
  352. that.setData({
  353. bikePosition: true
  354. })
  355. }
  356. }).catch(err => {
  357. console.log(err)
  358. })
  359. },
  360. chushi: function () {
  361. var that = this;
  362. var date = Date.parse(new Date()) / 1000;
  363. var setting = wx.getStorageSync('setting');
  364. app.request('/pages/ride-order?no=' + that.data.order, '', 'GET').then(res => {
  365. console.log(res)
  366. if (res.statusCode == 200) {
  367. // var start_time = 1578446930
  368. if (date - res.data.start_use_bike_time <= 0) {
  369. that.setData({
  370. minute: 0
  371. })
  372. console.log('ppppopopopp')
  373. } else {
  374. // that.setData({
  375. // minute: date - res.data.start_use_bike_time
  376. // })
  377. let cha = date - res.data.start_use_bike_time
  378. console.log(Math.round(cha / 60), 'ppppp')
  379. var time =parseInt(cha / 60) - setting.starting_price_time;
  380. var per_money = setting.per_money;
  381. var per_minute = setting.per_minute;
  382. // console.log('测试1',times)
  383. //页面进来时初始化金额
  384. // let money = parseFloat(parseFloat(time / per_minute * per_money + parseFloat(setting.starting_price)).toFixed(2));
  385. let money = parseInt(time / per_minute) * per_money + parseFloat(setting.starting_price)
  386. var hour = Math.floor(cha / 3600 % 24);
  387. // 分钟
  388. var minute = Math.floor(cha / 60 % 60);
  389. // let hour = parseInt(cha / 3600)
  390. console.log(hour, 'hour')
  391. console.log(minute, 'hour')
  392. hour=hour<10 ? '0'+ hour : hour
  393. minute=minute<10 && hour>0? '0'+ minute : minute
  394. console.log(money,'-------')
  395. if (hour > 0) {
  396. // let minute=
  397. that.setData({
  398. minute: date - res.data.start_use_bike_time,
  399. times: hour + ":" + minute,
  400. estimate_money: money,
  401. isHour: true
  402. })
  403. } else {
  404. // let minute = parseInt(cha / 60)
  405. that.setData({
  406. minute: date - res.data.start_use_bike_time,
  407. times: minute,
  408. estimate_money: money,
  409. isHour: false
  410. })
  411. }
  412. }
  413. // if (date - start_time <= 0) {
  414. // that.setData({ minute: 0 })
  415. // } else {
  416. // that.setData({ minute: date - start_time })
  417. // }
  418. that.terval()
  419. wx.showToast({
  420. title: '刷新成功',
  421. icon: 'none'
  422. })
  423. that.setData({
  424. data: res.data,
  425. code: res.data.bike_no,
  426. })
  427. app.request('/bike/' + that.data.code, '', 'GET').then(res => {
  428. console.log(res)
  429. 200 == res.statusCode && that.setData({
  430. battery_power: res.data.battery_power,
  431. box_no: res.data.box_no
  432. })
  433. })
  434. if (res.data.status == 0) {
  435. that.setData({
  436. bolear: 0
  437. })
  438. } else if (res.data.status == 1) {
  439. that.setData({
  440. bolear: 1
  441. })
  442. } else if (res.data.status == 2) {
  443. clearInterval(interval),
  444. clearInterval(interval1);
  445. clearInterval(locationTerval);
  446. clearInterval(bikelocationTerval);
  447. wx.reLaunch({
  448. url: '../payment/payment?order=' + res.data.no
  449. })
  450. } else if (res.data.status == 3) {
  451. wx.reLaunch({
  452. url: '../index/index',
  453. })
  454. } else if (res.data.status == 4) {
  455. wx.reLaunch({
  456. url: '../index/index',
  457. })
  458. }
  459. that.bikeLocation();
  460. }
  461. }).catch(err => {
  462. console.log(err)
  463. })
  464. },
  465. location: function () {
  466. //获取当前经纬度 给地图赋值
  467. wx.showNavigationBarLoading()
  468. var that = this
  469. that.setData({
  470. polygons: []
  471. })
  472. wx.getLocation({
  473. type: 'gcj02',
  474. success: (res) => {
  475. console.log('经纬度为:+++++++++++++++++++++' + res.latitude + '++++++++' + res.longitude)
  476. var latitude = res.latitude
  477. var longitude = res.longitude
  478. that.setData({
  479. longitude: longitude,
  480. latitude: latitude
  481. })
  482. var data = {
  483. 'lat': latitude,
  484. 'lng': longitude,
  485. 'bike_no':that.data.code ? that.data.code:''
  486. }
  487. app.request('/pages/home?include=setting', data, 'POST').then(res => {
  488. if (res.statusCode == 200) {
  489. var data = res.data;
  490. var points = data.area_fence;
  491. data.points = points;
  492. data.area_fence = []
  493. data.strokeWidth = 4;
  494. data.strokeColor = '#0000FF';
  495. data.zIndex = 1111;
  496. console.log(data)
  497. that.setData({
  498. polygons: that.data.polygons.concat(data),
  499. id: data.id,
  500. polygons1: that.data.polygons.concat(data)
  501. })
  502. var data1 = {
  503. 'area_id': data.id
  504. }
  505. app.request('/parking/stop-sites', data1, 'GET').then(res => {
  506. // console.log(res)
  507. if (res.statusCode == 200) {
  508. var data = res.data
  509. that.setData({
  510. polygons: that.data.polygons1.concat(data.polygons),
  511. markers: data.centres
  512. })
  513. }
  514. })
  515. }
  516. }).catch(err => {
  517. console.log(err)
  518. })
  519. }
  520. })
  521. },
  522. coundDown: function () {
  523. var that = this;
  524. that.setData({
  525. isShow: true
  526. })
  527. timeing = setInterval(function () {
  528. var timeing1 = that.data.timing;
  529. timeing1--
  530. that.setData({
  531. timing: timeing1
  532. })
  533. if (timeing1 <= 0) {
  534. that.setData({
  535. timing: 5,
  536. isShow: false
  537. })
  538. clearInterval(timeing)
  539. }
  540. }, 1000)
  541. },
  542. bindregionchange: function (e) {
  543. //实现大头针移动选点
  544. var that = this;
  545. if (e.type == 'begin') {
  546. clearTimeout(settime)
  547. clearInterval(locationTerval);
  548. }
  549. if (e.type == 'end') {
  550. settime = setTimeout(function () {
  551. that.posiLoca()
  552. }, 3000)
  553. }
  554. },
  555. onShow: function () {
  556. this.location();
  557. this.chushi();
  558. this.posi()
  559. },
  560. closeLock: function (data) {
  561. var that = this;
  562. bluM.connectDeivece(that.data.box_no, CMD.lock)
  563. app.request('/bike/close-lock', data, 'POST').then(res => {
  564. console.log(res)
  565. if (res.statusCode == 200) {
  566. clearInterval(locationTerval);
  567. clearInterval(interval);
  568. clearInterval(bikelocationTerval);
  569. clearInterval(interval1);
  570. wx.reLaunch({
  571. url: '../payment/payment?order=' + res.data.no
  572. })
  573. } else if (res.statusCode == 450) {
  574. that.coundDown()
  575. }
  576. }).catch(err => {
  577. console.log(err)
  578. })
  579. },
  580. end: util.throttle(function () {
  581. //点击结束骑行 先调接口看看是不是在停车区域 如果是清除定时器 如果不是询问用户用户点继续停车 清除定时器 如果点取消 无反应
  582. // wx.showNavigationBarLoading()
  583. wx.showLoading({
  584. title: '结算中...',
  585. mask: true
  586. })
  587. var that = this;
  588. wx.getLocation({
  589. type: 'gcj02',
  590. success: (res) => {
  591. console.log('经纬度为:+++++++++++++++++++++' + res.latitude + '++++++++' + res.longitude)
  592. var latitude = res.latitude
  593. var longitude = res.longitude
  594. var data = {
  595. bike_no: that.data.code,
  596. order_no: that.data.order,
  597. lat: latitude,
  598. lng: longitude
  599. }
  600. app.request('/bike/check-is-riding-area', data, 'POST').then(res => {
  601. console.log(res)
  602. if (res.statusCode == 200) {
  603. // clearInterval(interval);
  604. // clearInterval(interval1);
  605. clearInterval(locationTerval);
  606. clearInterval(bikelocationTerval);
  607. wx.hideNavigationBarLoading(), wx.hideLoading()
  608. if (res.data.is_close_order == false) {
  609. // that.closeLock(data)
  610. wx.navigateTo({
  611. url: '/pages/confirm_order/confirm_order?bike_no=' + that.data.code + '&order_no=' + that.data.order + '&lat=' + latitude + '&lng=' + longitude + '&order=order',
  612. })
  613. } else {
  614. bluM.connectDeivece(that.data.box_no, CMD.lock)
  615. app.request('/bike/close-lock', data, 'POST').then(res => {
  616. console.log(res)
  617. if (res.statusCode == 200) {
  618. clearInterval(interval);
  619. clearInterval(interval1);
  620. clearInterval(locationTerval);
  621. clearInterval(bikelocationTerval);
  622. wx.hideLoading()
  623. wx.reLaunch({
  624. url: '../payment/payment?order=' + res.data.no
  625. })
  626. } else if (res.statusCode == 450) {
  627. that.coundDown()
  628. }
  629. // wx.hideNavigationBarLoading()
  630. }).catch(err => {
  631. console.log(err)
  632. })
  633. }
  634. } else if (res.statusCode == 450) {
  635. that.coundDown()
  636. wx.hideLoading()
  637. }
  638. }).catch(err => {
  639. console.log(err)
  640. })
  641. }
  642. })
  643. }, 1000),
  644. openBike: function () {
  645. //点击开锁失败重试
  646. var that = this;
  647. clearInterval(inter1)
  648. that.setData({
  649. timeout: 15
  650. })
  651. wx.getBluetoothAdapterState({
  652. success(res) {
  653. console.log(res)
  654. if (res.available == false) {
  655. wx.showModal({
  656. title: '提示',
  657. content: '手动开启蓝牙使用蓝牙开锁',
  658. showCancel: false
  659. })
  660. that.inter1()
  661. } else {
  662. wx.showLoading({
  663. title: '开锁中...',
  664. mask: true
  665. })
  666. wx.getLocation({
  667. type: 'gcj02',
  668. success: function (res) {
  669. console.log(res)
  670. bluM.connectDeivece(that.data.box_no, CMD.unlock)
  671. app.request('/order/retry-open-lock?order_no=' + that.data.order + '&bike_no=' + that.data.code, '', 'GET').then(res => {
  672. console.log(res)
  673. that.inter1()
  674. if (res.statusCode == 200) {
  675. wx.hideLoading()
  676. if (res.data.status == 1) {
  677. wx.showToast({
  678. title: '开锁成功',
  679. icon: 'none'
  680. })
  681. }
  682. }
  683. })
  684. },
  685. })
  686. }
  687. }
  688. })
  689. },
  690. inter1: function () {
  691. //点击临时开车 临时停车后按钮的定时器
  692. var that = this;
  693. var timeout1 = that.data.timeout;
  694. inter1 = setInterval(function () {
  695. timeout1--
  696. that.setData({
  697. timeout: timeout1
  698. })
  699. if (timeout1 <= 0) {
  700. clearInterval(inter1)
  701. that.setData({
  702. parke: true,
  703. timeout: 15,
  704. retry: false
  705. })
  706. } else {
  707. retry: true
  708. }
  709. }, 1000)
  710. },
  711. retry1: function () {
  712. var that = this;
  713. that.setData({
  714. timeout: 15
  715. })
  716. clearInterval(inter1)
  717. wx.getLocation({
  718. type: 'gcj02',
  719. success: (res) => {
  720. console.log('经纬度为:+++++++++++++++++++++' + res.latitude + '++++++++' + res.longitude)
  721. var latitude = res.latitude
  722. var longitude = res.longitude
  723. var data = {
  724. bike_no: that.data.code,
  725. order_no: that.data.order,
  726. lat: latitude,
  727. lng: longitude
  728. }
  729. bluM.connectDeivece(that.data.bike_no, CMD.unlock)
  730. app.request('/bike/temporary-open-lock', data, 'POST').then(res => {
  731. that.inter1()
  732. if (res.statusCode == 200) {
  733. wx.showToast({
  734. title: '开车成功',
  735. icon: 'none'
  736. })
  737. that.setData({
  738. bolear: 1
  739. })
  740. }
  741. })
  742. }
  743. })
  744. },
  745. retry2: function () {
  746. var that = this;
  747. that.setData({
  748. timeout: 15
  749. })
  750. clearInterval(inter1)
  751. wx.getLocation({
  752. type: 'gcj02',
  753. success: (res) => {
  754. console.log('经纬度为:+++++++++++++++++++++' + res.latitude + '++++++++' + res.longitude)
  755. var latitude = res.latitude
  756. var longitude = res.longitude
  757. var data = {
  758. bike_no: that.data.code,
  759. order_no: that.data.order,
  760. lat: latitude,
  761. lng: longitude
  762. }
  763. bluM.connectDeivece(that.data.box_no, CMD.lock)
  764. app.request('/bike/temporary-close-lock', data, 'POST').then(res => {
  765. console.log(res)
  766. that.inter1()
  767. if (res.statusCode == 200) {
  768. wx.showToast({
  769. title: '停车成功',
  770. icon: 'none'
  771. })
  772. that.setData({
  773. bolear: 0
  774. })
  775. } else if (res.statusCode == 450) {
  776. that.coundDown()
  777. }
  778. })
  779. }
  780. })
  781. },
  782. parking: function () {
  783. //点击临时停车
  784. var that = this;
  785. wx.getLocation({
  786. type: 'gcj02',
  787. success: (res) => {
  788. console.log('经纬度为:+++++++++++++++++++++' + res.latitude + '++++++++' + res.longitude)
  789. var latitude = res.latitude
  790. var longitude = res.longitude
  791. var data = {
  792. bike_no: that.data.code,
  793. order_no: that.data.order,
  794. lat: latitude,
  795. lng: longitude
  796. }
  797. clearInterval(inter1)
  798. that.setData({
  799. timeout: 15
  800. })
  801. if (that.data.bolear == 1) {
  802. //代表要临时停车
  803. app.request('/bike/temporary-close-lock', data, 'POST').then(res => {
  804. console.log(res)
  805. that.inter1()
  806. if (res.statusCode == 200) {
  807. wx.showToast({
  808. title: '停车成功',
  809. icon: 'none'
  810. })
  811. bluM.connectDeivece(that.data.box_no, CMD.lock)
  812. that.setData({
  813. bolear: 0,
  814. parke: false
  815. })
  816. } else if (res.statusCode == 450) {
  817. that.coundDown()
  818. }
  819. })
  820. }
  821. if (that.data.bolear == 0) {
  822. //代表要临时开车
  823. app.request('/bike/temporary-open-lock', data, 'POST').then(res => {
  824. that.inter1()
  825. if (res.statusCode == 200) {
  826. wx.showToast({
  827. title: '开车成功',
  828. icon: 'none'
  829. })
  830. bluM.connectDeivece(that.data.box_no, CMD.unlock)
  831. that.setData({
  832. bolear: 1,
  833. parke: false
  834. })
  835. }
  836. })
  837. }
  838. }
  839. })
  840. },
  841. onHide: function () {
  842. clearInterval(locationTerval);
  843. },
  844. onUnload: function () {
  845. clearInterval(locationTerval)
  846. clearInterval(bikelocationTerval)
  847. clearTimeout(settime)
  848. // clearInterval(huancheTime)
  849. },
  850. onPullDownRefresh: function () {
  851. },
  852. onReachBottom: function () {
  853. },
  854. onShareAppMessage: function () {
  855. }
  856. })