use_bike.js 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699
  1. // const log = require('../../utils/log')
  2. const {
  3. getCache,
  4. setCache,
  5. CacheKeys
  6. } = require('../../utils/cache')
  7. var app = getApp()
  8. var interval;
  9. // var inter1;
  10. var locationTerval;
  11. var huancheTime;
  12. // var coundDown; //运动中不可锁车倒计时
  13. var linshiStop; //临时停车倒计时
  14. const util = require('../../utils/utils.js');
  15. var interval;
  16. //蓝牙操作方法
  17. var BluetoothOperate = require('../../service/bluetooth.js');
  18. //const { content } = require('../../service/dataTransition.js');
  19. let bluetoothOperate = new BluetoothOperate();
  20. let machineNO = "" //设备编号
  21. let key = "" //蓝牙密钥
  22. let operateType = '' //'open'开锁 'close'上锁 'bell'寻铃 'temporaryClose'临时锁车 'temporaryOpen'临时锁车开车
  23. var mytime = null;
  24. Page({
  25. data: {
  26. marqueeDistance: 520, //初始滚动距离 用到
  27. marqueeWidth: 560, //通知公告用到
  28. marqueePace: 0.6, //滚动速度
  29. length: '', //通知公告
  30. size: 26, //通知公告用到
  31. notice: '', //通知公告
  32. currentSwiper: 0,
  33. nowBikeStatus: '', //当前车辆的状态
  34. money: {
  35. time_money: 0,
  36. dispatch_money: 0,
  37. total_money: 0
  38. }, //骑行费用
  39. steps: 1, //开锁步骤
  40. parkStatus: 0, //骑行中:0,临时停车:1,点击结束用车:2
  41. frame: false, //车辆未开锁弹框
  42. code: '', //车辆编码
  43. bikeMessage: '', //车辆信息
  44. times: '0', //当前骑行时间
  45. estimate_money: '0', //预计金额
  46. minute: '', //骑行总时间秒
  47. data: [],
  48. box_no: '',
  49. screenHeight: '',
  50. change: false,
  51. timing: 5,
  52. isShow: false,
  53. minute1: '',
  54. parke: true,
  55. timeout: 15,
  56. retry: '',
  57. bikePosition: false,
  58. battery_power: '--',
  59. huanche_timeout: 0,
  60. img: app.globalData.imgUrl,
  61. title: app.globalData.title,
  62. stopmMinute: 30, //临时停车时间
  63. stopMiao: 0,
  64. chaButton: 0, //0 不显示 1显示
  65. markers: [],
  66. polygons: [],
  67. polygons1: [],
  68. zoom: 12,
  69. temporaryTime: '', //临时锁车时间
  70. background: false, //位置权限弹框
  71. location: false, //位置权限弹框
  72. coundDownTime: 5, //运动中不可锁车倒计时
  73. countTimeShow: false,
  74. dispatch_money: 0, //调度费
  75. area_id: '', //区域id
  76. mapHeight: 'calc(100vh - 300px)',
  77. isHour: false, //及时判断是否含有小时
  78. popShow: false,
  79. centerLon: '', //地图中心点经纬度
  80. centerLat: '', //地图中心点经纬度
  81. is_out_area: false, //当前用户是否超出区域
  82. load_num: 0, //超出区域弹窗提示弹出次数控制控制弹窗弹出次数
  83. isUseTK: app.globalData.isUseTK, //是否使用头盔
  84. ifKnowUseTK: true, //是否已点击使用头盔
  85. is_dev: true, //是否为开发环境是的话隐藏购卡充值
  86. localSearchStop: app.globalData.localSearchStop, //是否开启使用当前位置查询还车点
  87. bikeMarker: [], //当前车辆位置的mark
  88. isUseLinTing: app.globalData.isUseLinTing, //是否使用临时停车
  89. TKfuwei: true, //头盔是否复位
  90. TKtipsProp: false, //头盔是否在位提示框
  91. start_use_bike_time: 0, //开始用车的时间
  92. noShowRefOpenLock: false,//隐藏为开锁按钮,false不隐藏
  93. },
  94. onShow: function () {
  95. let isLearn = my.getStorageSync({
  96. 'key': 'videoLearn'
  97. }).data
  98. let is_dev = my.getStorageSync({
  99. 'key': 'userInfo'
  100. }).data
  101. let home = my.setStorageSync({
  102. 'key': 'home'
  103. }).data
  104. let that = this
  105. that.setData({
  106. polygons1: [],
  107. polygons: [],
  108. is_dev: is_dev ? is_dev.is_dev : true,
  109. markers: [],
  110. zoom: home &&home.zoom ? home.zoom : 12
  111. })
  112. my.setNavigationBar({
  113. title: app.globalData.title
  114. })
  115. clearInterval(locationTerval);
  116. if (isLearn == false || !isLearn) {
  117. my.navigateTo({
  118. url: '/pages/video/video?code=' + this.data.code,
  119. })
  120. }
  121. app.login().then(res => {
  122. that.userState()
  123. that.posiLoca()
  124. that.chushiPosiloc()
  125. if (that.data.code) {
  126. that.getBikeMessage()
  127. }
  128. })
  129. if (that.data.order != undefined) {
  130. console.log(that.data.order, 'that.data.orderthat.data.orderthat.data.order')
  131. that.chushi()
  132. }
  133. // that.reloadMap()
  134. },
  135. //初始化位之信息并获取区域
  136. chushiPosiloc: function () {
  137. let that = this
  138. my.showLoading({
  139. content: '正在定位...',
  140. })
  141. my.getLocation({
  142. type: 'gcj02',
  143. success: (res) => {
  144. console.log('经纬度为:+++++++++++2323++++++++++' + res.latitude + '++++++++' + res.longitude)
  145. var latitude = res.latitude
  146. var longitude = res.longitude
  147. my.hideLoading()
  148. that.setData({
  149. longitude: longitude,
  150. latitude: latitude,
  151. })
  152. that.home()
  153. },
  154. fail: function (err) {
  155. console.log(err)
  156. my.hideLoading()
  157. if (err.error == 11) {
  158. my.showAuthGuide({
  159. authType: 'LBS',
  160. success: (res) => {
  161. },
  162. fail: (error) => {
  163. my.alert({
  164. content: '获取位置授权失败'
  165. });
  166. },
  167. })
  168. }
  169. my.getSetting({
  170. success: function (res) {
  171. // console.log(res)
  172. var statu = res.authSetting;
  173. if (statu['scope.userLocation'] == false) {
  174. that.setData({
  175. background: true,
  176. location: true
  177. })
  178. }
  179. }
  180. })
  181. }
  182. })
  183. },
  184. onLoad: function (options) {
  185. let that = this
  186. console.log(options!=={},!app.globalData.scanCode)
  187. if(options.code){
  188. that.setData({
  189. code: options.code
  190. })
  191. }else if (app.globalData.scanCode) {
  192. that.setData({
  193. code: app.globalData.scanCode
  194. })
  195. } else if (options.order != undefined) {
  196. that.setData({
  197. order: options.order,
  198. })
  199. }else if(options!=={} && !app.globalData.scanCode){
  200. my.reLaunch({
  201. url:'/pages/index/index'
  202. })
  203. }
  204. },
  205. getNotice(id) {
  206. let data = {
  207. 'area_id': id
  208. }
  209. let isCache = getCache('Notice:' + id)
  210. console.log(isCache, 'isCache')
  211. if (isCache) {
  212. if (isCache != null && isCache instanceof Object && !isCache.hasOwnProperty('id')) return
  213. this.setData({
  214. notice: isCache
  215. })
  216. var length = isCache.description.length * this.data.size; //计算文字的长度
  217. this.setData({
  218. length: length
  219. })
  220. if (this.data.length > this.data.marqueeWidth) {
  221. this.noticeRun();
  222. } else {
  223. this.setData({
  224. marqueeDistance: 0
  225. })
  226. }
  227. return
  228. }
  229. app.request("/index/an", data, "GET").then(res => {
  230. if (200 == res.status) {
  231. setCache('Notice:' + id, res.data)
  232. if (res.data != null && res.data instanceof Object && !res.data.hasOwnProperty('id')) return
  233. this.setData({
  234. notice: res.data
  235. })
  236. var length = res.data.description.length * this.data.size; //计算文字的长度
  237. this.setData({
  238. length: length
  239. })
  240. if (this.data.length > this.data.marqueeWidth) {
  241. this.noticeRun();
  242. } else {
  243. this.setData({
  244. marqueeDistance: 0
  245. })
  246. }
  247. }
  248. }).catch(err => {
  249. // console.log(err)
  250. })
  251. },
  252. noticeRun: function () {
  253. var that = this;
  254. clearInterval(mytime);
  255. mytime = setInterval(function () {
  256. if (-that.data.marqueeDistance < that.data.length) {
  257. that.setData({
  258. marqueeDistance: that.data.marqueeDistance - that.data.marqueePace,
  259. })
  260. } else {
  261. clearInterval(mytime);
  262. that.setData({
  263. marqueeDistance: that.data.marqueeWidth
  264. });
  265. that.noticeRun();
  266. }
  267. }, 10)
  268. },
  269. //广告列表
  270. adsList: function (id) {
  271. var that = this;
  272. var area_id = ''
  273. if (id != undefined) {
  274. area_id = id
  275. } else {
  276. area_id = 0
  277. }
  278. let isCache = getCache('ads:' + id)
  279. if (isCache) {
  280. if (isCache == '') return
  281. if (isCache != null && isCache instanceof Object && isCache.hasOwnProperty('header')) {
  282. that.setData({
  283. ads: isCache.header
  284. })
  285. }
  286. if (isCache != null && isCache instanceof Object && isCache.hasOwnProperty('mid')) {
  287. that.setData({
  288. mid: isCache.mid,
  289. adFrame: true
  290. })
  291. }
  292. return
  293. }
  294. app.request("/ads?area_id=" + area_id + "&position[]=mid&position[]=header&position[]=footer", '', "GET").then(res => {
  295. if (res.status == 200) {
  296. setCache('ads:' + id, res.data)
  297. if (res.data == '') return
  298. if (res.data.header) {
  299. that.setData({
  300. ads: res.data.header
  301. })
  302. }
  303. if (res.data.mid) {
  304. that.setData({
  305. mid: res.data.mid,
  306. adFrame: true
  307. })
  308. }
  309. }
  310. }).catch(err => {
  311. // console.log(err)
  312. })
  313. },
  314. //点击广告页
  315. swiper: util.throttle(function (e) {
  316. var type = e.currentTarget.dataset.type;
  317. var index = e.currentTarget.dataset.index;
  318. var name = e.currentTarget.dataset.name;
  319. var detail = e.currentTarget.dataset.detail;
  320. var id = e.currentTarget.dataset.id;
  321. if (type != 'clilk_null') {
  322. if (type == 'wxUrl') {
  323. console.log(e, 'pppp')
  324. my.navigateTo({
  325. url: '/' + detail,
  326. })
  327. } else if (type == 'phone') {
  328. my.makePhoneCall({
  329. number: detail,
  330. })
  331. } else if (type == 'toMiniProgram') {
  332. my.navigateToMiniProgram({
  333. appId: detail,
  334. extraData: {
  335. foo: 'bar'
  336. },
  337. // envVersion: 'develop',
  338. success(res) {
  339. // 打开成功
  340. }
  341. })
  342. } else {
  343. my.navigateTo({
  344. url: '../swiper/swiper?type=' + type + '&url=' + id + '&name=' + name + '&detail=' + detail,
  345. })
  346. }
  347. }
  348. }, 1000),
  349. //点击轮播图
  350. swiperChange: function (e) {
  351. if (this.data.currentSwiper == 0 && this.data.swiperCurrent > 1) { //卡死时,重置current为正确索引
  352. this.setData({
  353. currentSwiper: this.data.swiperCurrent
  354. });
  355. } else { //正常轮转时,记录正确页码索引
  356. this.setData({
  357. swiperCurrent: e.detail.current
  358. });
  359. }
  360. },
  361. //用户状态
  362. userState: function (area_id) {
  363. var that = this;
  364. app.request("/user/status", "GET").then(res => {
  365. console.log(res, 'zhuangtai')
  366. if (res.status == 200) {
  367. my.setStorageSync({
  368. 'key': 'userState',
  369. data: res.data
  370. });
  371. if (res.data.is_ride_order) {
  372. that.setData({
  373. order: res.data.is_ride_order,
  374. })
  375. that.chushi()
  376. }
  377. /**
  378. * 未支付直接调转支付
  379. * mead
  380. */
  381. if (res.data.is_pay_order) {
  382. my.navigateTo({
  383. url: '/pages/pay/pay?order=' + res.data.is_pay_order,
  384. })
  385. }
  386. } else {
  387. if (this.data.bikeInfo.is_link == 0) {
  388. my.alert({
  389. title: '提示',
  390. content: '当前车子已下线请换辆车子骑行吧~',
  391. success: function (res) {
  392. my.reLaunch({
  393. url: '/pages/index/index',
  394. })
  395. }
  396. })
  397. return;
  398. } else if (this.data.bikeMessage.put_status == 0) {
  399. my.alert({
  400. title: '提示',
  401. content: '当前车子还未投放请换辆车子骑行吧~',
  402. success: function (res) {
  403. my.reLaunch({
  404. url: '/pages/index/index',
  405. })
  406. }
  407. })
  408. return;
  409. } else if (this.data.bikeMessage.is_low_battery_power == 0) {
  410. my.alertal({
  411. title: '提示',
  412. content: '当前车子电量过低请换辆车子骑行吧~',
  413. success: function (res) {
  414. my.reLaunch({
  415. url: '/pages/index/index',
  416. })
  417. }
  418. })
  419. return;
  420. } else if (this.data.bikeMessage.is_trouble == 1) {
  421. my.alert({
  422. title: '提示',
  423. content: '当前车子出现故障请换辆车子骑行吧~',
  424. success: function (res) {
  425. my.reLaunch({
  426. url: '/pages/index/index',
  427. })
  428. }
  429. })
  430. return;
  431. } else if (this.data.bikeMessage.is_riding == 1) {
  432. my.alert({
  433. title: '提示',
  434. content: '当前车子正在骑行请换辆车子骑行吧~',
  435. success: function (res) {
  436. my.reLaunch({
  437. url: '/pages/index/index',
  438. })
  439. }
  440. })
  441. return;
  442. }
  443. }
  444. }).catch(err => {
  445. console.log(err)
  446. })
  447. },
  448. //骑行区禁停区车辆
  449. home: function () {
  450. //请求首页接口和一些设置。
  451. var that = this;
  452. if (that.data.longitude != '' && that.data.latitude != '') {
  453. //116.411027
  454. var data = {
  455. 'lat': that.data.latitude,
  456. 'lng': that.data.longitude,
  457. 'bike_no': that.data.code
  458. }
  459. app.request("/pages/home?include=setting", data, "POST").then(res => {
  460. console.log(res, '骑行区域')
  461. if (res.status == 200) {
  462. var data = res.data;
  463. that.setData({
  464. area_id: res.data.id,
  465. zoom: data.zoom ? data.zoom : 12,
  466. polygons: that.data.polygons.concat(data),
  467. })
  468. my.setStorageSync({
  469. 'key': 'home',
  470. data: data
  471. });
  472. let area_id = res.data.id
  473. //原获取全部还车点接口
  474. if (that.data.localSearchStop == false) that.ban_stop(area_id)
  475. //根据位置请求区域
  476. if (that.data.localSearchStop == true) that.searchStopArea(that.data.longitude, that.data.latitude)
  477. that.getNotice(area_id)
  478. that.adsList(area_id)
  479. console.log(data, '区域')
  480. }
  481. console.log(data, 'tdada')
  482. if (data) {
  483. my.setStorageSync({
  484. 'key': 'setting',
  485. data: data.setting
  486. });
  487. } else {
  488. my.removeStorageSync({
  489. key: 'setting'
  490. })
  491. }
  492. }).catch(err => {
  493. console.log(err)
  494. my.alert({
  495. title: '提示',
  496. content: err.data.message,
  497. })
  498. })
  499. }
  500. },
  501. regionchange: function (e) {
  502. if (this.data.localSearchStop == false) return
  503. if (e.type == 'end') {
  504. this.searchStopArea(e.longitude, e.latitude)
  505. }
  506. },
  507. //添加定位点,并展示周围还车点
  508. searchStopArea: function (longitude, latitude) {
  509. let home = my.getStorageSync({
  510. 'key': 'home'
  511. }).data
  512. if (!home || !home.id) return
  513. let params = {
  514. 'lat': latitude,
  515. 'lng': longitude,
  516. 'area_id':home.id,
  517. }
  518. console.log(this.data.polygons)
  519. app.request('/parking/nearby-all', params, 'GET').then(res => {
  520. console.log('根据位置获取区域', res)
  521. let arr = [home]
  522. this.setData({
  523. markers: this.data.bikeMarker.concat(res.data.points),
  524. polygons: arr.concat(res.data.polygons),
  525. centerLat:latitude,
  526. centerLon:longitude
  527. })
  528. })
  529. },
  530. //停车区域
  531. ban_stop: function (area_id) {
  532. var that = this;
  533. let home = my.getStorageSync({
  534. 'key': 'home'
  535. }).data
  536. that.setData({
  537. polygons1: that.data.polygons1.concat(home)
  538. })
  539. let isCache = getCache('BAN_STOP:' + area_id)
  540. if (isCache) {
  541. that.setData({
  542. markers: that.data.markers.concat(isCache.centres),
  543. polygons: that.data.polygons1.concat(isCache.polygons),
  544. })
  545. return
  546. }
  547. var data1 = {
  548. 'area_id': area_id
  549. }
  550. app.request('/parking/stop-sites', data1, 'GET').then(res => {
  551. console.log(res)
  552. if (res.status == 200) {
  553. var data = res.data
  554. console.log(data)
  555. that.setData({
  556. markers: that.data.markers.concat(data.centres),
  557. polygons: that.data.polygons1.concat(data.polygons),
  558. })
  559. }
  560. })
  561. },
  562. //初始化信息
  563. chushi: function () {
  564. my.showLoading()
  565. var that = this;
  566. var date = Date.parse(new Date()) / 1000;
  567. app.request('/pages/ride-order?no=' + that.data.order, '', 'GET').then(res => {
  568. console.log(res, ',---------')
  569. let setting = my.getStorageSync({
  570. 'key': 'setting'
  571. }).data;
  572. if (res.status == 200) {
  573. my.hideLoading()
  574. my.setStorageSync({
  575. 'key': 'bike_status',
  576. data: res.data.status
  577. })
  578. if (res.data.is_out_area == true) {
  579. that.setData({
  580. load_num: that.data.load_num + 1
  581. })
  582. }
  583. this.data.start_use_bike_time = res.data.start_use_bike_time
  584. if (res.data.is_out_area == true && that.data.load_num == 1) {
  585. my.showModal({
  586. title: '提示',
  587. content: '您当前已超出骑行区域,车辆已经断电,请将车辆骑回运营区,或联系客服进行车辆回电',
  588. cancelText: '联系客服',
  589. confirmText: '我知道了',
  590. complete: (res) => {
  591. if (res.cancel) {
  592. my.makePhoneCall({
  593. number: my.getStorageSync({
  594. 'key': 'home'
  595. }).data.customer_service_phone,
  596. })
  597. that.setData({
  598. load_num: 0
  599. })
  600. }
  601. if (res.confirm) {
  602. that.setData({
  603. load_num: 0
  604. })
  605. }
  606. }
  607. })
  608. }
  609. if (res.data.start_use_bike_time <= 0) {
  610. that.setData({
  611. minute: 0
  612. })
  613. } else {
  614. that.countBikeMoney()
  615. }
  616. that.terval()
  617. my.showToast({
  618. content: '刷新成功',
  619. icon: 'none'
  620. })
  621. that.setData({
  622. data: res.data,
  623. code: res.data.bike_no,
  624. temporaryTime: res.data.pause_bike_time
  625. })
  626. let userStatus = my.getStorageSync({
  627. 'key': 'userState'
  628. }).data;
  629. let setting = my.getStorageSync({
  630. 'key': 'setting'
  631. }).data;
  632. let bike_status = my.getStorageSync({
  633. 'key': 'bike_status'
  634. }).data;
  635. console.log('pppppppp---------------------vyvyvyvy')
  636. //有正在骑行中的订单的订单
  637. if (userStatus.is_ride_order != false && bike_status == 1) {
  638. //骑行中
  639. console.log('ppppp')
  640. that.setData({
  641. steps: 3
  642. })
  643. my.setStorageSync({
  644. 'key': 'nowBikeStatus',
  645. data: 0
  646. })
  647. // that.reloadMap()
  648. } else if (bike_status == 0 && userStatus.is_ride_order != false) {
  649. // 临时停车
  650. that.setData({
  651. parkStatus: 1,
  652. steps: 3
  653. })
  654. my.setStorageSync({
  655. 'key': 'nowBikeStatus',
  656. data: 1
  657. })
  658. // that.reloadMap()
  659. that.stopDownTime()
  660. }
  661. app.request('/bike/' + that.data.code, '', 'GET').then(res => {
  662. console.log(res)
  663. 200 == res.status && that.setData({
  664. battery_power: res.data.battery_power,
  665. box_no: res.data.box_no,
  666. bikeMessage: res.data,
  667. })
  668. })
  669. if (res.data.status == 0) {
  670. that.setData({
  671. bolear: 0
  672. })
  673. } else if (res.data.status == 1) {
  674. that.setData({
  675. bolear: 1
  676. })
  677. } else if (res.data.status == 2) {
  678. clearInterval(interval),
  679. // clearInterval(interval1);
  680. clearInterval(locationTerval);
  681. my.reLaunch({
  682. url: '../payment/payment?order=' + res.data.no
  683. })
  684. } else {
  685. my.reLaunch({
  686. url: '../index/index',
  687. })
  688. }
  689. that.bikeLocation();
  690. }
  691. }).catch(err => {
  692. console.log(err)
  693. })
  694. },
  695. //获取车辆位置信息
  696. bikeLocation: function (type) {
  697. var that = this;
  698. var data = {
  699. bike_no: that.data.code
  700. }
  701. app.request('/order/orderBikePosition', data, 'GET').then(res => {
  702. if (res.statusCode == 200) {
  703. if (type == 'getPosition') {
  704. this.data.markers.map((item, index) => {
  705. if (item.id == 12345) {
  706. this.setData({
  707. ['markers[' + index + '].longitude']: res.data.lng,
  708. ['markers[' + index + '].latitude']: res.data.lat
  709. })
  710. this.data.bikeMarker[0].latitude = res.data.lat
  711. this.data.bikeMarker[0].longitude = res.data.lng
  712. }
  713. })
  714. } else {
  715. var array = {}
  716. array.iconPath = '/img/dianche.png';
  717. array.width = 28;
  718. array.height = 28;
  719. array.zIndex = 1111;
  720. array.id = 12345;
  721. array.latitude = res.data.lat;
  722. array.longitude = res.data.lng;
  723. this.setData({
  724. markers:this.data.markers.concat(array)
  725. })
  726. this.data.bikeMarker = [array]
  727. }
  728. }
  729. }).catch(err => {
  730. console.log(err)
  731. })
  732. },
  733. //获取当前位置
  734. posiLoca: function () {
  735. var that = this;
  736. my.showLoading({
  737. content: '正在定位...',
  738. icon: 'none'
  739. })
  740. // locationTerval = setInterval(function () {
  741. my.getLocation({
  742. type: 'gcj02',
  743. success: (res) => {
  744. var latitude = res.latitude
  745. var longitude = res.longitude
  746. my.hideLoading()
  747. that.setData({
  748. longitude: longitude,
  749. latitude: latitude,
  750. })
  751. if (!that.data.centerLon) {
  752. //第一次进入当前页面时为为中心点坐标赋值
  753. that.setData({
  754. centerLon: res.longitude,
  755. centerLat: res.latitude,
  756. })
  757. }
  758. that.home()
  759. },
  760. fail: function (err) {
  761. my.hideLoading()
  762. if (err.error == 11) {
  763. my.showAuthGuide({
  764. authType: 'LBS',
  765. success: (res) => {
  766. },
  767. fail: (error) => {
  768. my.alert({
  769. content: '获取位置授权失败'
  770. });
  771. },
  772. })
  773. }
  774. my.getSetting({
  775. success: function (res) {
  776. // console.log(res)
  777. var statu = res.authSetting;
  778. if (statu['scope.userLocation'] == false) {
  779. that.setData({
  780. background: true,
  781. location: true
  782. })
  783. }
  784. }
  785. })
  786. }
  787. })
  788. },
  789. //获取蓝牙秘钥
  790. getSecretKey(box_no) {
  791. //     if (!box_no) box_no = this._bikeMainId
  792. //     let that = this;
  793. //     if(box_no== my.getStorageSync('box_no')) return;
  794. return new Promise(function (res, rej) {
  795. let param = {
  796. box_no: box_no, //我公司是通过设备编号获取的密钥
  797. };
  798. app.request('/blu/get-key', param, 'GET').then(resp => {
  799. key = resp.data.key
  800. res(resp.data.key);
  801. my.setStorageSync({
  802. 'key': 'box_no',
  803. data: box_no
  804. })
  805. })
  806. });
  807. },
  808. //行车时间计时
  809. terval: function () {
  810. var that = this;
  811. clearInterval(interval)
  812. clearInterval(huancheTime)
  813. interval = setInterval(function () {
  814. that.countBikeMoney()
  815. }, 5000)
  816. },
  817. //计算骑行费用
  818. countBikeMoney: function () {
  819. var that = this
  820. var setting = my.getStorageSync({
  821. 'key': 'setting'
  822. }).data;
  823. var total_minute = this.data.minute
  824. console.log("this.data.start_use_bike_time",this.data.start_use_bike_time)
  825. let cha = (new Date()).getTime() / 1000 - this.data.start_use_bike_time
  826. var time = 0
  827. var _minute = Math.ceil(cha / 60); //分钟
  828. console.log('骑行总时长分钟', _minute, cha, total_minute, setting.starting_price_time)
  829. if (_minute == total_minute) return 0; //分钟相等
  830. if (_minute === 0) {
  831. time = _minute + 1 - setting.starting_price_time;
  832. } else {
  833. time = _minute - setting.starting_price_time;
  834. }
  835. var per_money = setting.per_money;
  836. var per_minute = setting.per_minute;
  837. // 向上取整
  838. let money = 0
  839. if (time <= 0) {
  840. money = parseFloat(setting.starting_price)
  841. } else {
  842. money = Math.ceil(time / per_minute) * per_money + parseFloat(setting.starting_price)
  843. }
  844. //将全部分钟分开为小时+分钟用于显示时间
  845. var hour = Math.floor(_minute / 60);
  846. var minute = Math.floor(_minute % 60);
  847. money = money.toFixed(2)
  848. hour = hour < 10 ? '0' + hour : hour
  849. minute = minute < 10 && hour > 0 ? '0' + minute : minute
  850. if (app.globalData.noShowRefOpenLock == true && that.data.noShowRefOpenLock == false && minute >= 3) {
  851. that.setData({
  852. noShowRefOpenLock: true
  853. })
  854. }
  855. if (hour > 0) {
  856. that.setData({
  857. minute: _minute, // 骑行总分钟
  858. times: hour + ":" + minute,
  859. estimate_money: money,
  860. isHour: true
  861. })
  862. } else {
  863. that.setData({
  864. minute: _minute,
  865. times: minute,
  866. estimate_money: money,
  867. isHour: false
  868. })
  869. }
  870. },
  871. //获取车辆信息
  872. getBikeMessage: function () {
  873. my.showLoading()
  874. var that = this;
  875. app.request('/bike/' + that.data.code, '', 'GET').then(res => {
  876. machineNO = res.data.box_no
  877. my.hideLoading()
  878. if (res.status == 200) {
  879. that.setData({
  880. bikeMessage: res.data,
  881. battery_power: res.data.battery_power,
  882. steps: 1
  883. }),
  884. key = res.data.key
  885. } else {
  886. setTimeout(function () {
  887. my.reLaunch({
  888. url: '/pages/index/index',
  889. })
  890. }, 2000)
  891. }
  892. })
  893. },
  894. //检测用户是否完成实名认证,是否有待支付订单违章记录等
  895. jiance: function () {
  896. let that = this
  897. var userStatus = my.getStorageSync({
  898. 'key': 'userState'
  899. }).data;
  900. var setting = my.getStorageSync({
  901. 'key': 'setting'
  902. }).data;
  903. console.log(userStatus, '旭颖')
  904. console.log(setting, '旭颖')
  905. if (userStatus.is_bind_mobile == 0) {
  906. my.navigateTo({
  907. url: '/pages/authorization/authorization',
  908. })
  909. //未实名认证
  910. } else
  911. if (userStatus.is_card_certified == 0 && setting.is_card == 1) {
  912. my.navigateTo({
  913. url: '/pages/real_name/real_name',
  914. })
  915. } //是否缴纳押金
  916. else if (userStatus.is_deposit == 0 && setting.is_deposit != 0 && userStatus.is_coupon_deposit_free == false) {
  917. my.navigateTo({
  918. url: '/pages/ride_zige/ride_zige',
  919. })
  920. } else if (userStatus.is_ride_order != false) {
  921. my.alert({
  922. title: '提示',
  923. content: '您有一个正在骑行中的订单',
  924. success: function (res) {
  925. my.reLaunch({
  926. url: '/pages/index/index',
  927. })
  928. }
  929. })
  930. } else if (userStatus.is_pay_order != false && userStatus.is_pay_order != undefined) {
  931. my.alert({
  932. title: '提示',
  933. content: '您有一个待支付订单,请先支付',
  934. success: function (res) {
  935. my.reLaunch({
  936. url: '/pages/index/index',
  937. })
  938. }
  939. })
  940. } else {
  941. that.setData({
  942. steps: 2
  943. })
  944. // this.reloadMap()
  945. }
  946. },
  947. reloadMap(classname = 'use-bike-bottom') {
  948. let query = my.createSelectorQuery();
  949. let th = this;
  950. query.select('.' + classname).boundingClientRect(function (rect) {
  951. if (rect != null && rect instanceof Object && rect.hasOwnProperty('height')) {
  952. let height = rect.height || 300;
  953. th.setData({
  954. mapHeight: 'calc(100vh - ' + (height) + 'px)'
  955. });
  956. } else {
  957. let height = 300;
  958. th.setData({
  959. mapHeight: 'calc(100vh - ' + height + 'px)'
  960. });
  961. }
  962. }).exec();
  963. },
  964. //倒计时
  965. //临时停车倒计时
  966. stopDownTime() {
  967. // let that = this
  968. // let endTime = Date.parse(new Date()); //date日期类型
  969. // let startTime
  970. // if (!that.data.temporaryTime || that.data.temporaryTime == null) {
  971. // startTime = endTime
  972. // } else {
  973. // let data1 = that.data.temporaryTime
  974. // let data2 = data1.replace(/-/g, '/')
  975. // let data3 = new Date(data2)
  976. // startTime = data3.getTime()
  977. // }
  978. // let totleTime = 1800
  979. // clearInterval(linshiStop)
  980. // console.log(endTime, 'endTime')
  981. // console.log(startTime, 'startTime')
  982. // let date3 = endTime - startTime;
  983. // console.log(date3, 'date3')
  984. // //计算出相差天数
  985. // var days = Math.floor(date3 / (24 * 3600 * 1000));
  986. // //计算出小时数
  987. // var leave1 = date3 % (24 * 3600 * 1000); //计算天数后剩余的毫秒数
  988. // var hours = Math.floor(leave1 / (3600 * 1000));
  989. // //计算相差分钟数
  990. // var leave2 = leave1 % (3600 * 1000); //计算小时数后剩余的毫秒数
  991. // var minutes = Math.floor(leave2 / (60 * 1000));
  992. // //计算相差秒数
  993. // var leave3 = leave2 % (60 * 1000); //计算分钟数后剩余的毫秒数
  994. // var seconds = Math.round(leave3 / 1000);
  995. // console.log(minutes, 'minutes')
  996. // let chaTime = totleTime - minutes * 60
  997. // console.log(chaTime, 'chaTime')
  998. // linshiStop = setInterval(function () {
  999. // let test = 30 * 60 * 1000
  1000. // console.log(test, 'test')
  1001. // if (date3 > test) {
  1002. // that.setData({
  1003. // stopMiao: 0,
  1004. // stopmMinute: 0
  1005. // })
  1006. // clearInterval(linshiStop)
  1007. // } else if (chaTime <= 0) {
  1008. // that.setData({
  1009. // stopMiao: 0,
  1010. // stopmMinute: 0
  1011. // })
  1012. // clearInterval(linshiStop)
  1013. // } else {
  1014. // console.log(minutes, 'pppp')
  1015. // chaTime--
  1016. // let fen = parseInt(chaTime / 60);
  1017. // let miao = parseInt(chaTime % 60);
  1018. // that.setData({
  1019. // stopMiao: miao,
  1020. // stopmMinute: fen
  1021. // })
  1022. // }
  1023. // }, 1000)
  1024. },
  1025. //开锁方法
  1026. openBike() {
  1027. var that = this;
  1028. var setting = my.getStorageSync({
  1029. 'key': 'setting'
  1030. }).data;
  1031. my.showLoading({
  1032. content: '开锁中...',
  1033. mask: true
  1034. })
  1035. var data = {
  1036. bike_no: that.data.code,
  1037. lat: that.data.latitude,
  1038. lng: that.data.longitude,
  1039. area_id: my.getStorageSync({
  1040. 'key': 'home'
  1041. }).data.id,
  1042. }
  1043. app.request('/bike/open-lock', data, 'POST').then(res => {
  1044. console.log(res)
  1045. if (res.status == 200) {
  1046. that.setData({
  1047. steps: 3,
  1048. order: res.data.no,
  1049. ifKnowUseTK: false,
  1050. estimate_money: parseFloat(setting.starting_price),
  1051. start_use_bike_time: res.data.start_use_bike_timestamp
  1052. })
  1053. that.terval()
  1054. //蓝牙开锁
  1055. operateType = 'open'
  1056. bluetoothOperate.start(operateType, machineNO, key, (flag) => {
  1057. bluetoothOperate.end((flag) => {});
  1058. });
  1059. my.hideLoading()
  1060. } else {
  1061. // that.setData({
  1062. // steps: 3
  1063. // })
  1064. // that.terval()
  1065. }
  1066. })
  1067. },
  1068. //开锁失败重试开锁
  1069. retryOpenBike: function () {
  1070. var that = this;
  1071. console.log('重试开锁')
  1072. //蓝牙重试开锁
  1073. my.showLoading({
  1074. content: '开锁中...',
  1075. mask: true
  1076. })
  1077. let data = {
  1078. order_no: that.data.order,
  1079. bike_no: that.data.code
  1080. }
  1081. app.request('/order/retry-open-lock', data, 'GET').then(res => {
  1082. console.log(res)
  1083. if (res.status == 200) {
  1084. my.hideLoading()
  1085. if (res.data.status == 1) {
  1086. that.setData({
  1087. frame: false
  1088. })
  1089. my.hideLoading()
  1090. operateType = 'open'
  1091. bluetoothOperate.start(operateType, machineNO, key, (flag) => {
  1092. bluetoothOperate.end((flag) => {});
  1093. });
  1094. my.showToast({
  1095. content: '开锁成功',
  1096. icon: 'none'
  1097. })
  1098. }
  1099. }
  1100. })
  1101. },
  1102. openBikeClick: function () {
  1103. let that = this
  1104. if (this.data.bikeMessage.is_link == 0) {
  1105. my.alert({
  1106. title: '提示',
  1107. content: '当前车子已下线请换辆车子骑行吧~',
  1108. success: function (res) {
  1109. my.reLaunch({
  1110. url: '/pages/index/index',
  1111. })
  1112. }
  1113. })
  1114. return;
  1115. } else if (this.data.bikeMessage.put_status == 0) {
  1116. my.alert({
  1117. title: '提示',
  1118. content: '当前车子还未投放请换辆车子骑行吧~',
  1119. success: function (res) {
  1120. my.reLaunch({
  1121. url: '/pages/index/index',
  1122. })
  1123. }
  1124. })
  1125. return;
  1126. } else if (this.data.bikeMessage.is_low_battery_power == 0) {
  1127. my.alert({
  1128. title: '提示',
  1129. content: '当前车子电量过低请换辆车子骑行吧~',
  1130. success: function (res) {
  1131. my.reLaunch({
  1132. url: '/pages/index/index',
  1133. })
  1134. }
  1135. })
  1136. return;
  1137. } else if (this.data.bikeMessage.is_trouble == 1) {
  1138. my.alert({
  1139. title: '提示',
  1140. content: '当前车子出现故障请换辆车子骑行吧~',
  1141. success: function (res) {
  1142. my.reLaunch({
  1143. url: '/pages/index/index',
  1144. })
  1145. }
  1146. })
  1147. return;
  1148. } else if (this.data.bikeMessage.is_riding == 1) {
  1149. my.alert({
  1150. title: '提示',
  1151. content: '当前车子正在骑行请换辆车子骑行吧~',
  1152. success: function (res) {
  1153. my.reLaunch({
  1154. url: '/pages/index/index',
  1155. })
  1156. }
  1157. })
  1158. return;
  1159. }
  1160. that.jiance()
  1161. },
  1162. go_setting: util.throttle(function () {
  1163. //点击去设置位置权限
  1164. this.setData({
  1165. background: false,
  1166. location: false
  1167. })
  1168. my.openSetting({
  1169. success: function (res) {}
  1170. })
  1171. }, 1500),
  1172. //点击已开启位置权限
  1173. open: util.throttle(function () {
  1174. this.setData({
  1175. background: false,
  1176. location: false
  1177. })
  1178. }, 1500),
  1179. //寻铃
  1180. clickBell: util.throttle(function (e) {
  1181. //点击响铃
  1182. var that = this;
  1183. my.showLoading({
  1184. content: '找车中...',
  1185. mask: true
  1186. })
  1187. app.request('/order/retry-bell-lock?order_no=' + that.data.order + '&bike_no=' + that.data.code, '', 'GET').then(res => {
  1188. console.log(res)
  1189. if (res.status == 200) {
  1190. //蓝牙寻铃找车
  1191. operateType = 'bell'
  1192. bluetoothOperate.start(operateType, machineNO, key, (flag) => {
  1193. //flag == true 操作成功
  1194. //flag == false 操作失败
  1195. //end
  1196. bluetoothOperate.end((flag) => {});
  1197. });
  1198. res.data.is_ok == true && my.showToast({
  1199. content: '找车成功',
  1200. icon: 'none',
  1201. duration: 2000
  1202. })
  1203. res.data.is_ok == false && my.showToast({
  1204. content: '找车失败请重试',
  1205. icon: 'none',
  1206. duration: 2000
  1207. })
  1208. }
  1209. })
  1210. }, 1000),
  1211. //立即开锁
  1212. konwOpenBike: util.throttle(function () {
  1213. var that = this;
  1214. // that.jiance()
  1215. if (that.data.deposit == true) return;
  1216. that.openBike()
  1217. }, 1000),
  1218. //临时锁车
  1219. parkBike: function () {
  1220. let that = this
  1221. my.showLoading({
  1222. content: '正在临时锁车',
  1223. })
  1224. var data = {
  1225. bike_no: that.data.code,
  1226. order_no: that.data.order,
  1227. lat: that.data.latitude,
  1228. lng: that.data.longitude
  1229. }
  1230. //代表要临时停车
  1231. app.request('/bike/temporary-close-lock', data, 'POST').then(res => {
  1232. console.log(res)
  1233. if (res.status == 200) {
  1234. my.hideLoading()
  1235. //蓝牙临时锁车
  1236. operateType = 'temporaryClose'
  1237. bluetoothOperate.start(operateType, machineNO, key, (flag) => {
  1238. //flag == true 操作成功
  1239. //flag == false 操作失败
  1240. //end
  1241. bluetoothOperate.end((flag) => {});
  1242. });
  1243. my.showToast({
  1244. content: '停车成功',
  1245. icon: 'none'
  1246. })
  1247. that.setData({
  1248. parkStatus: 1,
  1249. // nowBikeStatus:1
  1250. })
  1251. my.setStorageSync({
  1252. 'key': 'nowBikeStatus',
  1253. data: 1
  1254. })
  1255. that.stopDownTime()
  1256. // that.getBikeMessage()
  1257. } else if (res.status == 450) {
  1258. my.showToast({
  1259. content: '运动中不能关锁,请稍后重试',
  1260. icon: 'none',
  1261. duration: 5000,
  1262. mask: true
  1263. })
  1264. my.hideLoading()
  1265. }
  1266. })
  1267. },
  1268. //结束临时锁车
  1269. openPark: function () {
  1270. let that = this
  1271. my.showLoading({
  1272. content: '解锁中',
  1273. })
  1274. var data = {
  1275. bike_no: that.data.code,
  1276. order_no: that.data.order,
  1277. lat: that.data.latitude,
  1278. lng: that.data.longitude
  1279. }
  1280. // clearInterval(inter1)
  1281. app.request('/bike/temporary-open-lock', data, 'POST').then(res => {
  1282. // that.inter1()
  1283. if (res.status == 200) {
  1284. my.hideLoading()
  1285. // 蓝牙临时开车
  1286. operateType = 'temporaryOpen'
  1287. bluetoothOperate.start(operateType, machineNO, key, (flag) => {
  1288. //flag == true 操作成功
  1289. //flag == false 操作失败
  1290. //end
  1291. bluetoothOperate.end((flag) => {});
  1292. });
  1293. my.showToast({
  1294. content: '开车成功',
  1295. icon: 'none'
  1296. })
  1297. clearInterval(linshiStop)
  1298. my.setStorageSync({
  1299. 'key': 'stopMiao',
  1300. data: 0
  1301. })
  1302. my.setStorageSync({
  1303. 'key': 'stopmMinute',
  1304. data: 30
  1305. })
  1306. that.setData({
  1307. stopMiao: 0,
  1308. stopmMinute: 30,
  1309. parkStatus: 0,
  1310. nowBikeStatus: 0
  1311. })
  1312. my.setStorageSync({
  1313. 'key': 'nowBikeStatus',
  1314. data: 0
  1315. })
  1316. }
  1317. })
  1318. },
  1319. endUseBike: function () {
  1320. let that = this
  1321. this.data.TKfuwei = true
  1322. my.showLoading({
  1323. content: '加载中...'
  1324. })
  1325. var data = {
  1326. bike_no: that.data.code,
  1327. order_no: that.data.order,
  1328. lat: that.data.latitude,
  1329. lng: that.data.longitude
  1330. }
  1331. app.request('/order/expect-order-money', data, 'POST').then(res => {
  1332. console.log(res)
  1333. if (res.status == 200) {
  1334. my.hideLoading()
  1335. let data = res.data.dispatch_money
  1336. res.data.time_money = parseFloat(res.data.time_money)
  1337. let data1 = parseFloat(data)
  1338. if (res.data.is_app_check_helmet_status == true && res.data.helmet_status == 1) {
  1339. this.setData({
  1340. TKtipsProp: true,
  1341. dispatch_money: data1,
  1342. money: res.data,
  1343. })
  1344. } else {
  1345. that.setData({
  1346. dispatch_money: data1,
  1347. money: res.data,
  1348. chaButton: 1,
  1349. parkStatus: 2
  1350. })
  1351. }
  1352. }else{
  1353. my.hideLoading()
  1354. }
  1355. }).catch(res => {
  1356. my.hideLoading()
  1357. })
  1358. },
  1359. //继续还车
  1360. continueHuanche: function () {
  1361. this.data.TKfuwei = false
  1362. this.setData({
  1363. chaButton: 1,
  1364. parkStatus: 2,
  1365. TKtipsProp: false,
  1366. })
  1367. },
  1368. //我知道了
  1369. tkKnow: function () {
  1370. this.setData({
  1371. TKtipsProp: false,
  1372. })
  1373. },
  1374. //确定结束用车
  1375. sureEndUseBike: util.throttle(function () {
  1376. if (this.data.dispatch_money != 0) {
  1377. this.setData({
  1378. popShow: true
  1379. })
  1380. } else {
  1381. this.huanche()
  1382. }
  1383. }, 1000),
  1384. huanche() {
  1385. //还车接口
  1386. my.showLoading({
  1387. content: '结算中...',
  1388. mask: true
  1389. })
  1390. var that = this;
  1391. var data = {
  1392. bike_no: that.data.code,
  1393. order_no: that.data.order,
  1394. lat: that.data.latitude,
  1395. lng: that.data.longitude
  1396. }
  1397. if (this.data.TKfuwei == false) data.forceCloseBike = true
  1398. app.request('/bike/close-lock', data, 'POST').then(res => {
  1399. console.log(res)
  1400. my.hideLoading()
  1401. if (res.status == 200) {
  1402. console.log(res, '结束用车')
  1403. clearInterval(linshiStop);
  1404. clearInterval(interval);
  1405. my.setStorageSync({
  1406. 'key': 'stopMiao',
  1407. data: 0
  1408. })
  1409. my.setStorageSync({
  1410. 'key': 'stopmMinute',
  1411. data: 30
  1412. })
  1413. my.hideNavigationBarLoading(), my.hideLoading()
  1414. my.reLaunch({
  1415. url: '../pay/pay?order=' + res.data.no
  1416. })
  1417. //蓝牙锁车操作 确定结束用车
  1418. if (machineNO && key) {
  1419. operateType = 'close'
  1420. bluetoothOperate.start(operateType, machineNO, key, (flag) => {
  1421. //flag == true 操作成功
  1422. //flag == false 操作失败
  1423. //end
  1424. //订单结束关闭蓝牙
  1425. bluetoothOperate.end((flag) => {});
  1426. });
  1427. }
  1428. } else if (res.status == 450) {
  1429. my.showToast({
  1430. content: '运动中不能关锁,请稍后重试',
  1431. icon: 'none',
  1432. duration: 5000,
  1433. mask: true
  1434. })
  1435. }
  1436. }).catch(err => {
  1437. my.showToast({
  1438. content: '关锁失败,请重试。',
  1439. icon: 'none',
  1440. duration: 5000,
  1441. })
  1442. my.hideLoading()
  1443. })
  1444. },
  1445. //开关头盔锁
  1446. controlToukui: util.throttle(function () {
  1447. var that = this;
  1448. my.showLoading({
  1449. title: '开锁中...',
  1450. mask: true
  1451. })
  1452. let data = {
  1453. order_no: that.data.order,
  1454. bike_no: that.data.code
  1455. }
  1456. // if (app.globalData.req) {
  1457. app.request('/order/retry-open-helmet-lock', data, 'GET', app.globalData.req).then(res => {
  1458. if (res.status == 200) {
  1459. my.hideLoading()
  1460. if (res.data.status == 1) {
  1461. //that.reloadMap()
  1462. my.hideLoading()
  1463. my.showToast({
  1464. content: '头盔锁已开启',
  1465. type: 'none'
  1466. })
  1467. }
  1468. } else {
  1469. // log.warn('重试开锁失败(order/retry-open-lock)' + '用户id' + '--' + wx.getStorageSync('user_ID'))
  1470. my.hideLoading()
  1471. }
  1472. })
  1473. }, 1000),
  1474. //取消锁车
  1475. cancelEndBike: function () {
  1476. let that = this
  1477. that.setData({
  1478. chaButton: 0,
  1479. dispatch_money: 0,
  1480. parkStatus: my.getStorageSync({
  1481. 'key': 'nowBikeStatus'
  1482. }).data
  1483. })
  1484. // that.reloadMap()
  1485. },
  1486. //计价规则
  1487. chargeRule: function () {
  1488. my.navigateTo({
  1489. url: '/pages/charge_rule/charge_rule',
  1490. })
  1491. },
  1492. //骑行须知
  1493. bikeKnow: function () {
  1494. my.navigateTo({
  1495. url: '/pages/ride_rule/ride_rule',
  1496. })
  1497. },
  1498. popHide() {
  1499. //取消继续还车
  1500. this.setData({
  1501. popShow: false
  1502. })
  1503. },
  1504. //骑行优惠券
  1505. bikeCoupon: function () {
  1506. my.navigateTo({
  1507. url: '/pages/buy-card/buy-card',
  1508. })
  1509. },
  1510. //客服
  1511. keFu: function () {
  1512. let phone = my.getStorageSync({
  1513. 'key': 'home'
  1514. })
  1515. my.makePhoneCall({
  1516. number: phone.data.customer_service_phone || '13203706613'
  1517. })
  1518. },
  1519. //车辆为未开锁弹框
  1520. //打开
  1521. frameClose: function () {
  1522. let that = this
  1523. that.setData({
  1524. frame: false
  1525. })
  1526. // that.reloadMap()
  1527. },
  1528. //关闭弹框
  1529. frameShow: function () {
  1530. let that = this
  1531. that.setData({
  1532. frame: true
  1533. })
  1534. that.reloadMap('frame')
  1535. },
  1536. //故障上报
  1537. guzhang: function () {
  1538. this.setData({
  1539. frame: false,
  1540. })
  1541. // this.reloadMap()
  1542. my.navigateTo({
  1543. url: '/pages/breakdown/breakdown',
  1544. })
  1545. },
  1546. //附近还车点
  1547. findPark: function () {
  1548. my.navigateTo({
  1549. url: '/pages/parking/parking',
  1550. })
  1551. },
  1552. onHide: function () {
  1553. console.log('onHide5555')
  1554. // clearInterval(testToken
  1555. clearInterval(mytime)
  1556. clearInterval(interval)
  1557. bluetoothOperate.end((flag) => {});
  1558. },
  1559. onUnload: function () {
  1560. clearInterval(locationTerval)
  1561. bluetoothOperate.end((flag) => {});
  1562. // 停止位置跟踪
  1563. // my.stopLocationUpdate({
  1564. // success: (res) => {
  1565. // console.log("onUnload stopLocationUpdate success", res)
  1566. // },
  1567. // fail: (err) => {
  1568. // console.log("onUnload stopLocationUpdate fail", err)
  1569. // }
  1570. // })
  1571. },
  1572. //返回首页
  1573. backHome() {
  1574. my.reLaunch({
  1575. url: '/pages/index/index',
  1576. })
  1577. },
  1578. //关闭中间广告弹框
  1579. closeAdframe: function () {
  1580. this.setData({
  1581. adFrame: false
  1582. })
  1583. },
  1584. //佩戴头盔提示
  1585. knowToukui() {
  1586. this.setData({
  1587. ifKnowUseTK: true
  1588. })
  1589. },
  1590. //将地图将当前位置展示在屏幕中央,防止用户滑动查看停车区时频繁定位中心点
  1591. // getPosition: function () {
  1592. // this.setData({
  1593. // centerLon: this.data.longitude,
  1594. // centerLat: this.data.latitude,
  1595. // })
  1596. // this.mapCtx.moveToLocation();
  1597. // this.bikeLocation('getPosition');
  1598. // },
  1599. getPosition:util.throttle(function () {
  1600. //点击定位
  1601. //这是一段注
  1602. var that = this;
  1603. my.showLoading({
  1604. content: '定位中'
  1605. })
  1606. my.getLocation({
  1607. type: 'gcj02',
  1608. success: (res) => {
  1609. console.log('经纬度为:+++++++++++++++++++++' + res.latitude + '++++++++' + res.longitude)
  1610. my.hideLoading()
  1611. that.setData({
  1612. centerLon: res.longitude,
  1613. centerLat: res.latitude
  1614. })
  1615. this.bikeLocation('getPosition');
  1616. },
  1617. fail: function (err) {
  1618. console.log(err, '用户授权失败')
  1619. if (err.error == 11) {
  1620. my.showAuthGuide({
  1621. authType: 'LBS',
  1622. success: (res) => {
  1623. },
  1624. fail: (error) => {
  1625. my.alert({
  1626. content: '获取位置授权失败'
  1627. });
  1628. },
  1629. });
  1630. }
  1631. my.hideLoading()
  1632. my.showToast({
  1633. content: '定位失败',
  1634. icon: 'none'
  1635. })
  1636. }
  1637. })
  1638. }, 1000),
  1639. })