index.js 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143
  1. // index.js
  2. // 获取应用实例
  3. //获取应用实例
  4. // const log = require('../../utils/log')
  5. const {
  6. getCache,
  7. setCache,
  8. CacheKeys
  9. } = require('../../utils/cache')
  10. const app = getApp();
  11. var token = my.getStorageSync({
  12. 'key': 'token'
  13. }).data;
  14. const util = require('../../utils/utils.js');
  15. //const { content } = require('/utils/dataTransition.js');
  16. var mytime = null;
  17. let testToken = ''
  18. Page({
  19. data: {
  20. cardBottom: [{
  21. id: 1,
  22. name: '故障上报',
  23. icon: 'icon-banshou',
  24. url: '/pages/breakdown/breakdown'
  25. },
  26. {
  27. id: 2,
  28. name: '输码用车',
  29. icon: 'icon-17-saoma',
  30. url: '/pages/inputcode/inputcode'
  31. },
  32. {
  33. id: 3,
  34. name: '计费规则',
  35. icon: 'icon-wenhao',
  36. url: '/pages/charge_rule/charge_rule'
  37. },
  38. {
  39. id: 4,
  40. name: '个人中心',
  41. icon: 'icon-wode',
  42. url: '/pages/mine/mine'
  43. }
  44. ],
  45. adFrame: false, //首页中间广告弹框
  46. markers: [], //显示单车、停车的P
  47. polygons: [], //区域
  48. longitude: '', //113.786111
  49. latitude: '', //34.78304
  50. height1: '', //兼容自定义导航栏的高度
  51. id: '', //停车区域的ID
  52. stopP: false, //判断是否显示停车区域
  53. polygons1: [], //可骑行区域 先用这个变量代表
  54. controls: [], //地图上当前定位的箭头
  55. background: false, //弹窗的背景颜色
  56. realname: false, //当前是否已经实名
  57. deposit: false, //当前是否交押金
  58. userStatus: '', //用户的一些状态 是否交押金等 0
  59. scanfail: false, //扫码失败弹窗
  60. is_pay_order: false, //检测当前是否有订单未支付
  61. is_ride_order: false, //是否有骑行中订单
  62. is_punishment: false, //有违章订单
  63. code: '', //点击立即用车 把编号赋值给code
  64. over: false, //关闭图标
  65. over1: false, //扫码失败关闭图标
  66. location: '', //是否有位置权限
  67. screenHeight: '', //屏幕可视高度
  68. box_no: '', //中控编号
  69. abnormal: '', //提示账号异常
  70. mid: [], //顶部广告
  71. ads: [], //首页中间广告
  72. currentSwiper: 0,
  73. center_currentSwiper: 0,
  74. bike_no: undefined,
  75. stopShow: false,
  76. stop_info: [],
  77. notice: [], //公告内容
  78. animationData: {},
  79. tabbar_index: 0,
  80. zoom: 12,
  81. versions: false, //版本过低弹窗
  82. chooseSize: false,
  83. animationData1: {},
  84. arrowDown: '',
  85. stop_type: '',
  86. marqueePace: 0.6, //滚动速度
  87. marqueeDistance: 520, //初始滚动距离 用到
  88. size: 26, //通知公告用到
  89. marqueeWidth: 560, //通知公告用到
  90. length: '', //通知公告
  91. swiperCurrent: 0,
  92. midbolear: '',
  93. per_money: '',
  94. img: app.globalData.imgUrl,
  95. new_user_coupons: [],
  96. scanCodeErr: false, //扫码失败弹框
  97. isScan: false,
  98. centerLon: '', //地图中心点经纬度
  99. centerLat: '', //地图中心点经纬度
  100. localSearchStop: app.globalData.localSearchStop, //是否开启使用当前位置查询还车点
  101. bikeMarker: [], //当前车辆位置的mark
  102. mapCtx:''
  103. },
  104. onReady() {
  105. // 使用 my.createMapContext 获取 map 上下文
  106. this.mapCtx = my.createMapContext('map');
  107. },
  108. onLoad: function (query) {
  109. var that = this;
  110. console.log(my.getStorageSync({
  111. 'key': 'token'
  112. }).data, 'yyyyyyyyyyyyyyy')
  113. my.setNavigationBar({
  114. title: app.globalData.title
  115. })
  116. this.setData({
  117. height1: app.globalData.statusBarHeight,
  118. screenHeight: app.globalData.screenHeight
  119. })
  120. // this.reloadMap()
  121. },
  122. onShow: function () {
  123. var that = this;
  124. my.setNavigationBar({
  125. title: app.globalData.title
  126. })
  127. token = my.getStorageSync({
  128. 'key': 'token'
  129. }).data
  130. let home = my.setStorageSync({
  131. 'key': 'home'
  132. }).data
  133. this.setData({
  134. show: false,
  135. midbolear: my.getStorageSync({
  136. 'key': 'midTimes'
  137. }).data,
  138. polygons: [],
  139. zoom: home && home.zoom ? home.zoom : 12
  140. })
  141. if (!this.data.isScan) {
  142. app.login().then(res => {
  143. console.log('YYYYYYYYYYYYY')
  144. that.location()
  145. that.getUser()
  146. that.userState()
  147. })
  148. }
  149. that.setData({
  150. isScan: false
  151. })
  152. },
  153. detail: function () {
  154. var that = this;
  155. if (that.data.mid[0].type == 'url') {
  156. my.navigateTo({
  157. url: '/' + that.data.mid[0].detail
  158. })
  159. }
  160. },
  161. //广告列表
  162. adsList: function (id) {
  163. var that = this;
  164. var area_id = ''
  165. if (id != undefined) {
  166. area_id = id
  167. } else {
  168. area_id = 0
  169. }
  170. console.log(id, 'idididid')
  171. let isCache = getCache('ads:' + id)
  172. if (isCache) {
  173. if (isCache == '') return
  174. if (isCache instanceof Object && isCache.hasOwnProperty('header')) {
  175. that.setData({
  176. ads: isCache.header
  177. })
  178. }
  179. if (isCache instanceof Object && isCache.hasOwnProperty('mid')) {
  180. that.setData({
  181. mid: isCache.mid,
  182. adFrame: true
  183. })
  184. }
  185. return
  186. }
  187. app.request("/ads?area_id=" + area_id + "&position[]=mid&position[]=header&position[]=footer", '', "GET").then(res => {
  188. console.log(res)
  189. if (res.status == 200 && res.data != '') {
  190. setCache('ads:' + id, res.data)
  191. if (res.data.header) {
  192. console.log(res.data, 'ppppppppppppppppppppppppp')
  193. that.setData({
  194. ads: res.data.header
  195. })
  196. }
  197. if (res.data.mid) {
  198. that.setData({
  199. mid: res.data.mid,
  200. adFrame: true
  201. })
  202. }
  203. }
  204. }).catch(err => {
  205. console.log(err)
  206. })
  207. },
  208. reloadMap(classname = 'bottom-bt') {
  209. // let query = my.createSelectorQuery();
  210. // let th = this;
  211. // query.select('.' + classname).boundingClientRect(function (rect) {
  212. // if (rect != null && rect instanceof Object && rect.hasOwnProperty('height')) {
  213. // let height = rect.height;
  214. // th.setData({ mapHeight: 'calc(100vh - ' + height + 'px)' });
  215. // }
  216. // }).exec();
  217. },
  218. //点击广告页
  219. swiper: util.throttle(function (e) {
  220. var type = e.currentTarget.dataset.type;
  221. var index = e.currentTarget.dataset.index;
  222. var name = e.currentTarget.dataset.name;
  223. var detail = e.currentTarget.dataset.detail;
  224. var id = e.currentTarget.dataset.id;
  225. if (type != 'clilk_null') {
  226. if (type == 'wxUrl') {
  227. my.navigateTo({
  228. url: '/' + detail,
  229. })
  230. } else if (type == 'phone') {
  231. my.makePhoneCall({
  232. number: detail,
  233. })
  234. } else if (type == 'toMiniProgram') {
  235. my.navigateToMiniProgram({
  236. appId: detail,
  237. extraData: {
  238. foo: 'bar'
  239. },
  240. // envVersion: 'develop',
  241. success(res) {
  242. // 打开成功
  243. }
  244. })
  245. } else {
  246. my.navigateTo({
  247. url: '../swiper/swiper?type=' + type + '&url=' + id + '&name=' + name + '&detail=' + detail,
  248. })
  249. }
  250. }
  251. }, 1000),
  252. //点击轮播图
  253. swiperChange: function (e) {
  254. if (this.data.currentSwiper == 0 && this.data.swiperCurrent > 1) { //卡死时,重置current为正确索引
  255. this.setData({
  256. currentSwiper: this.data.swiperCurrent
  257. });
  258. } else { //正常轮转时,记录正确页码索引
  259. this.setData({
  260. swiperCurrent: e.detail.current
  261. });
  262. }
  263. },
  264. //通知公告
  265. getNotice(id) {
  266. let data = {
  267. 'area_id': id
  268. }
  269. let isCache = getCache('Notice:' + id)
  270. if (isCache) {
  271. if (isCache instanceof Object && !isCache.hasOwnProperty('id')) return
  272. this.setData({
  273. notice: isCache
  274. })
  275. var length = isCache.description.length * this.data.size; //计算文字的长度
  276. this.setData({
  277. length: length
  278. })
  279. if (this.data.length > this.data.marqueeWidth) {
  280. this.noticeRun();
  281. } else {
  282. this.setData({
  283. marqueeDistance: 0
  284. })
  285. }
  286. return
  287. }
  288. app.request("/index/an", data, "GET").then(res => {
  289. console.log(res)
  290. if (200 == res.status && res.data.id) {
  291. setCache('Notice:' + id, res.data)
  292. this.setData({
  293. notice: res.data
  294. })
  295. var length = res.data.description.length * this.data.size; //计算文字的长度
  296. this.setData({
  297. length: length
  298. })
  299. if (this.data.length > this.data.marqueeWidth) {
  300. this.noticeRun();
  301. } else {
  302. this.setData({
  303. marqueeDistance: 0
  304. })
  305. }
  306. }
  307. }).catch(err => {
  308. console.log(err)
  309. })
  310. },
  311. noticeRun: function () {
  312. var that = this;
  313. mytime = setInterval(function () {
  314. if (-that.data.marqueeDistance < that.data.length) {
  315. that.setData({
  316. marqueeDistance: that.data.marqueeDistance - that.data.marqueePace,
  317. })
  318. } else {
  319. clearInterval(mytime);
  320. that.setData({
  321. marqueeDistance: that.data.marqueeWidth
  322. });
  323. that.noticeRun();
  324. }
  325. }, 10)
  326. },
  327. //定位当前位置
  328. posi: util.throttle(function () {
  329. //点击定位
  330. //这是一段注
  331. var that = this;
  332. my.showLoading({
  333. content: '定位中'
  334. })
  335. my.getLocation({
  336. type: 'gcj02',
  337. success: (res) => {
  338. console.log('经纬度为:+++++++++++++++++++++' + res.latitude + '++++++++' + res.longitude)
  339. my.hideLoading()
  340. that.setData({
  341. centerLon: res.longitude,
  342. centerLat: res.latitude
  343. })
  344. },
  345. fail: function (err) {
  346. console.log(err, '用户授权失败')
  347. if (err.error == 11) {
  348. my.showAuthGuide({
  349. authType: 'LBS',
  350. success: (res) => {
  351. },
  352. fail: (error) => {
  353. my.alert({
  354. content: '获取位置授权失败'
  355. });
  356. },
  357. });
  358. }
  359. my.hideLoading()
  360. my.showToast({
  361. content: '定位失败',
  362. icon: 'none'
  363. })
  364. }
  365. // fail: function (err) {
  366. // my.hideLoading()
  367. // console.log(err, '定位失败打印')
  368. // my.showToast({
  369. // content: '定位失败',
  370. // icon: 'none'
  371. // })
  372. // }
  373. })
  374. }, 1000),
  375. //点击扫描二维码
  376. sweepCode: util.throttle(function () {
  377. this.sweep_code()
  378. // let that = this
  379. // console.log('点击扫码,‘iooooo')
  380. // if (!that.data.latitude && !that.data.longitude) {
  381. // that.setData({
  382. // background: true,
  383. // location: true
  384. // })
  385. // } else {
  386. // that.sweep_code()
  387. // }
  388. }, 1500),
  389. //骑行区禁停区车辆
  390. home: function () {
  391. //请求首页接口和一些设置。
  392. console.log('测试')
  393. var that = this;
  394. if (that.data.longitude != '' && that.data.latitude != '') {
  395. //116.411027
  396. var data = {
  397. 'lat': that.data.latitude,
  398. 'lng': that.data.longitude
  399. }
  400. app.request("/pages/home?include=setting", data, "POST").then(res => {
  401. console.log(res)
  402. if (res.status == 200) {
  403. var data = res.data;
  404. console.log(data, '区域')
  405. let id = data.id
  406. this.getNotice(id)
  407. if (data.points != []) {
  408. that.setData({
  409. id: data.id,
  410. polygons1: that.data.polygons.concat(data),
  411. setting: data.setting,
  412. per_money: Number(data.setting.starting_price),
  413. polygons: that.data.polygons.concat(data),
  414. zoom: data.zoom ? data.zoom : 12
  415. })
  416. if (!data.id) return
  417. that.adsList(data.id)
  418. //原获取全部还车点接口
  419. if (that.data.localSearchStop == false) that.ban_stop(data.id)
  420. //根据位置请求区域
  421. if (that.data.localSearchStop == true) that.searchStopArea(that.data.longitude, that.data.latitude)
  422. }
  423. if (res.status == 423) {
  424. my.getLocation({
  425. success: function (res) {
  426. my.alert({
  427. title: '提示',
  428. content: '您附近暂无运营区域~',
  429. })
  430. var setting = {
  431. is_deposit: 1
  432. }
  433. that.setData({
  434. setting
  435. })
  436. },
  437. fail: function (err) {
  438. that.setData({
  439. location: true
  440. })
  441. }
  442. })
  443. }
  444. my.setStorageSync({
  445. 'key': 'home',
  446. data: data
  447. })
  448. }
  449. if (data) {
  450. my.setStorageSync({
  451. 'key': 'setting',
  452. data: data.setting
  453. })
  454. } else {
  455. my.removeStorageSync({
  456. key: 'setting'
  457. })
  458. my.removeStorageSync({
  459. key: 'home'
  460. })
  461. }
  462. }).catch(err => {
  463. console.log(err, 'lkkkkk')
  464. // if (err.data.message == "该附近暂无运营区域") {
  465. // my.removeStorageSync({ key: 'setting' })
  466. // my.removeStorageSync({ key: 'home' })
  467. // }
  468. my.alert({
  469. title: '提示',
  470. content: err.data.message,
  471. })
  472. })
  473. }
  474. },
  475. regionchange: function (e) {
  476. if (this.data.localSearchStop == false) return
  477. if (e.type == 'end') {
  478. this.searchStopArea(e.longitude, e.latitude)
  479. }
  480. },
  481. //添加定位点,并展示周围还车点
  482. searchStopArea: function (longitude, latitude) {
  483. let home = my.getStorageSync({
  484. 'key': 'home'
  485. }).data
  486. if (!home || !home.id) return
  487. let params = {
  488. 'lat': latitude,
  489. 'lng': longitude,
  490. 'area_id':home.id,
  491. }
  492. console.log(this.data.polygons)
  493. app.request('/parking/nearby-all', params, 'GET').then(res => {
  494. console.log('根据位置获取区域', res)
  495. let arr = [home]
  496. this.setData({
  497. markers: this.data.bikeMarker.concat(res.data.points),
  498. polygons: arr.concat(res.data.polygons),
  499. centerLat:latitude,
  500. centerLon:longitude
  501. })
  502. })
  503. },
  504. //停车区域
  505. ban_stop: function (id) {
  506. var that = this;
  507. var data1 = {
  508. 'area_id': id
  509. }
  510. let isCache = getCache('BAN_STOP:' + id)
  511. if (isCache) {
  512. that.setData({
  513. markers: that.data.markers.concat(isCache.centres),
  514. polygons: that.data.polygons1.concat(isCache.polygons),
  515. })
  516. return
  517. }
  518. app.request('/parking/stop-sites', data1, 'GET').then(res => {
  519. console.log(res)
  520. if (res.status == 200) {
  521. var data = res.data
  522. setCache('BAN_STOP:' + id, data)
  523. that.setData({
  524. polygons2: data.polygons,
  525. markers: that.data.markers.concat(data.centres),
  526. polygons: that.data.polygons1.concat(data.polygons)
  527. })
  528. }
  529. })
  530. },
  531. //附近车辆坐标
  532. nearbyCars: function () {
  533. //附近的车
  534. var that = this;
  535. that.setData({
  536. markers: []
  537. })
  538. var data = {
  539. "lat": that.data.latitude,
  540. "lng": that.data.longitude
  541. }
  542. app.request("/bikes", data, "POST").then(res => {
  543. // console.log(res)
  544. if (res.status == 200) {
  545. var makers = res.data
  546. if (makers == '') {
  547. my.showToast({
  548. content: '附近暂无车辆',
  549. icon: 'none'
  550. })
  551. that.setData({
  552. markers: []
  553. })
  554. } else {
  555. that.setData({
  556. markers: makers
  557. })
  558. }
  559. }
  560. }).catch(err => {
  561. console.log(err)
  562. })
  563. },
  564. //点击刷新
  565. refresh: util.throttle(function () {
  566. var that = this;
  567. that.setData({
  568. polygons: []
  569. })
  570. if (this.data.stopP == true) {
  571. that.stopP(), my.showToast({
  572. content: '刷新成功',
  573. icon: 'none'
  574. })
  575. } else {
  576. this.location(),
  577. my.showToast({
  578. content: '刷新成功',
  579. icon: 'none'
  580. })
  581. }
  582. }, 1500),
  583. // //点击去实名认证
  584. authentication: util.throttle(function () {
  585. var state = my.getStorageSync({
  586. 'key': 'userState'
  587. }).data
  588. if (state.is_bind_mobile == 1) {
  589. my.navigateTo({
  590. url: '/pages/real_name/real_name?state1=1&index=0',
  591. })
  592. } else if (state.is_bind_mobile == 1) {
  593. my.navigateTo({
  594. url: '/pages/real_name/real_name?state2=2&index=1',
  595. })
  596. }
  597. this.setData({
  598. background: false,
  599. realname: false,
  600. over: false
  601. })
  602. }, 1500),
  603. //点击扫码开锁
  604. sweep_code: util.throttle(function () {
  605. var that = this;
  606. console.log('ooooooo')
  607. var userStatus = that.data.userStatus;
  608. var setting = my.getStorageSync({
  609. 'key': 'setting'
  610. }).data
  611. if (!setting) {
  612. my.alert({
  613. title: '提示',
  614. content: '您附近暂无运营区,暂不可用车'
  615. })
  616. } else {
  617. that.jiance('scan');
  618. // if (!userStatus) {
  619. // my.navigateTo({
  620. // url: '/pages/authorization/authorization',
  621. // })
  622. // } else {
  623. // that.jiance('scan');
  624. // }
  625. }
  626. }, 1500),
  627. //扫码用车检测不可用车条件
  628. jiance: function (source) {
  629. var that = this;
  630. var userStatus = that.data.userStatus;
  631. var setting = my.getStorageSync({
  632. 'key': 'setting'
  633. }).data
  634. //未绑定手机号
  635. // if (userStatus.is_bind_mobile == 0) {
  636. // my.navigateTo({
  637. // url: '/pages/authorization/authorization',
  638. // })
  639. // } else
  640. //未实名认证
  641. if (userStatus.is_card_certified == 0 && setting.is_card == 1) {
  642. my.navigateTo({
  643. url: '/pages/real_name/real_name',
  644. })
  645. } else {
  646. //有违章订单
  647. if (userStatus.is_punishment) {
  648. my.showToast({
  649. content: '您当前有违章订单需要处理,请处理后再来用车吧',
  650. icon: 'none'
  651. })
  652. return;
  653. } else if (userStatus.is_ride_order != false && userStatus.is_ride_order != undefined) {
  654. my.showToast({
  655. content: '您有一个正在骑行中的订单',
  656. icon: 'none'
  657. })
  658. return;
  659. } else {
  660. //有待支付骑行订单
  661. if (userStatus.is_pay_order != false && userStatus.is_pay_order != undefined) {
  662. my.showToast({
  663. content: '你有未支付订单,请先支付',
  664. icon: 'none'
  665. })
  666. return;
  667. } else {
  668. //没有押金没有免押券
  669. if (userStatus.is_deposit == 0 && setting.is_deposit != 0 && userStatus.is_coupon_deposit_free == false) {
  670. console.log('没有押金没有免押券')
  671. my.navigateTo({
  672. url: '/pages/ride_zige/ride_zige',
  673. })
  674. // my.navigateTo({
  675. // url: '/pages/inputcode/inputcode',
  676. // })
  677. } else {
  678. that.saoMa()
  679. }
  680. }
  681. }
  682. }
  683. },
  684. //扫码事件
  685. saoMa: function () {
  686. let that = this
  687. this.setData({
  688. scanCodeErr: false
  689. })
  690. my.scan({
  691. onlyFromCamera: true,
  692. success: function (res) {
  693. let scanLength = app.globalData.scanLength
  694. console.log(res, '扫码结果')
  695. var index = res.code.lastIndexOf("\=");
  696. console.log(index, '----------')
  697. var code = res.code.substring(index + 1, res.code.length);
  698. console.log(code)
  699. console.log(app.globalData)
  700. if (code.length == scanLength) {
  701. that.getBikeMessage(code)
  702. // my.navigateTo({
  703. // url: '/pages/use_bike/use_bike?code=' + code,
  704. // })
  705. } else {
  706. console.log(res, '错误码')
  707. // my.showModal({
  708. // title:'提示',
  709. // content:'非法码,请核对车码',
  710. // showCancel:false
  711. // })
  712. that.setData({
  713. scanCodeErr: true
  714. })
  715. }
  716. },
  717. fail: function (err) {
  718. console.log('tuihui')
  719. // that.setData({
  720. // scanCodeErr: true
  721. // })
  722. }
  723. })
  724. },
  725. //获取车辆信息
  726. getBikeMessage: function (code) {
  727. var that = this;
  728. app.request('/bike/' + code, '', 'GET').then(res => {
  729. console.log(res, '车辆信息--------------------')
  730. my.hideLoading()
  731. if (res.status == 200) {
  732. if (res.data.is_link == 0) {
  733. my.alert({
  734. title: '提示',
  735. content: '当前车子已下线请换辆车子骑行吧~',
  736. success: function (res) {
  737. my.reLaunch({
  738. url: '/pages/index/index',
  739. })
  740. }
  741. })
  742. return;
  743. } else if (res.data.put_status == 0) {
  744. my.alert({
  745. title: '提示',
  746. content: '当前车子还未投放请换辆车子骑行吧~',
  747. })
  748. return;
  749. } else if (res.data.is_low_battery_power == 0) {
  750. my.alert({
  751. title: '提示',
  752. content: '当前车子电量过低请换辆车子骑行吧~',
  753. })
  754. return;
  755. } else if (res.data.is_trouble == 1) {
  756. my.alert({
  757. title: '提示',
  758. content: '当前车子出现故障请换辆车子骑行吧~',
  759. })
  760. return;
  761. } else if (res.data.is_riding == 1) {
  762. my.alert({
  763. title: '提示',
  764. content: '当前车子正在骑行请换辆车子骑行吧~',
  765. })
  766. return;
  767. } else {
  768. my.reLaunch({
  769. url: '/pages/use_bike/use_bike?code=' + code,
  770. })
  771. }
  772. } else {
  773. my.alert({
  774. title: '提示',
  775. content: res.data.message,
  776. })
  777. }
  778. })
  779. },
  780. //去支付未支付订单
  781. go_pay: util.throttle(function () {
  782. //点击去支付
  783. this.setData({
  784. is_pay_order: false,
  785. })
  786. var pay_order = ''
  787. if (this.data.userStatus.is_pay_order !== false && this.data.userStatus.is_pay_order !== undefined) {
  788. pay_order = this.data.userStatus.is_pay_order
  789. }
  790. my.navigateTo({
  791. url: '/pages/pay/pay?order=' + pay_order,
  792. })
  793. }, 1500),
  794. //点击查看正在进行中的订单
  795. goUseBike: function () {
  796. console.log(this.data.is_ride_order, 'this.data.is_ride_order')
  797. my.navigateTo({
  798. url: '/pages/use_bike/use_bike?order=' + this.data.is_ride_order,
  799. })
  800. },
  801. //有违章订单
  802. havePunishment: function () {
  803. my.navigateTo({
  804. url: '/pages/weizhang/weizhang',
  805. })
  806. },
  807. //用户状态
  808. userState: function (id) {
  809. var that = this;
  810. app.request("/user/status", "GET").then(res => {
  811. console.log(res)
  812. if (res.status == 200) {
  813. console.log(res, 'XYYING================')
  814. that.setData({
  815. userStatus: res.data,
  816. is_pay_order: res.data.is_pay_order,
  817. is_ride_order: res.data.is_ride_order,
  818. is_punishment: res.data.is_punishment,
  819. }), my.setStorageSync({
  820. 'key': 'userState',
  821. data: res.data
  822. })
  823. }
  824. }).catch(err => {
  825. console.log(err)
  826. })
  827. },
  828. getUser() {
  829. app.request("/me", '', "GET").then(res => {
  830. console.log(res)
  831. 200 == res.status && my.setStorageSync({
  832. 'key': 'userInfo',
  833. data: res.data
  834. })
  835. }).catch(err => {
  836. console.log(err)
  837. })
  838. },
  839. go_setting: util.throttle(function () {
  840. //点击去设置位置权限
  841. this.setData({
  842. background: false,
  843. location: false
  844. })
  845. my.openSetting({
  846. success: function (res) {}
  847. })
  848. }, 1500),
  849. //点击已开启位置权限
  850. open: util.throttle(function () {
  851. this.setData({
  852. background: false,
  853. location: false
  854. })
  855. }, 1500),
  856. location: function () {
  857. //获取当前经纬度 如果未授权让用户去授权
  858. console.log('dingwei')
  859. var that = this;
  860. my.showLoading({
  861. content: '定位中...',
  862. mask: true
  863. })
  864. my.getLocation({
  865. type: 'gcj02',
  866. success: (res) => {
  867. console.log('经纬度为:+++++++++++++++++++++' + res.latitude + '++++++++' + res.longitude)
  868. this.data.longitude =res.longitude
  869. this.data.latitude =res.latitude
  870. that.setData({
  871. centerLon: res.longitude,
  872. centerLat: res.latitude,
  873. show: false
  874. })
  875. console.log(res, 'ppp')
  876. that.home(), that.nearbyCars()
  877. if (that.data.stopP == false) {
  878. console.log('false')
  879. } else {
  880. that.stop()
  881. }
  882. my.hideLoading()
  883. },
  884. fail: function (err) {
  885. console.log(err, '用户授权失败')
  886. if (err.error == 11) {
  887. my.showAuthGuide({
  888. authType: 'LBS',
  889. success: (res) => {
  890. },
  891. fail: (error) => {
  892. my.alert({
  893. content: '获取位置授权失败'
  894. });
  895. },
  896. });
  897. }
  898. my.hideLoading()
  899. my.getSetting({
  900. success: function (res) {
  901. // console.log(res)
  902. var statu = res.authSetting;
  903. if (statu['scope.userLocation'] == false) {
  904. that.setData({
  905. background: true,
  906. location: true
  907. })
  908. }
  909. }
  910. })
  911. }
  912. })
  913. },
  914. //底部跳转页面按钮(用户未授权和未实名认证的时候不可以跳转)
  915. skipPage: function (e) {
  916. let data = e.target.dataset.id
  917. let that = this
  918. console.log(that.data, 'oooooo')
  919. var userStatus = that.data.userStatus;
  920. var setting = my.getStorageSync({
  921. 'key': 'setting'
  922. }).data
  923. if (data.id == 2 && !that.data.latitude && !that.data.longitude) {
  924. that.setData({
  925. background: true,
  926. location: true
  927. })
  928. return
  929. }
  930. if (data.id == 2 && !setting) {
  931. my.alert({
  932. title: '提示',
  933. content: '您附近暂无运营区,暂不可用车'
  934. })
  935. return
  936. }
  937. if (data.id == 2 && setting) {
  938. // if (!userStatus) {
  939. // my.navigateTo({
  940. // url: '/pages/authorization/authorization',
  941. // })
  942. // } else {
  943. // that.jiance1();
  944. // }
  945. that.jiance1();
  946. } else {
  947. my.navigateTo({
  948. url: data.url,
  949. })
  950. }
  951. // if (!that.data.latitude && !that.data.longitude) {
  952. // that.setData({
  953. // background: true,
  954. // location: true
  955. // })
  956. // } else {
  957. // if (data.id == 2) {
  958. // console.log(that.data.userStatus, '')
  959. // if (!setting) {
  960. // my.alert({
  961. // title: '提示',
  962. // content: '您附近暂无运营区,暂不可用车'
  963. // })
  964. // }
  965. // else {
  966. // if (!userStatus) {
  967. // my.navigateTo({
  968. // url: '/pages/authorization/authorization',
  969. // })
  970. // }
  971. // else {
  972. // that.jiance1();
  973. // }
  974. // }
  975. // } else if (data.id == 4) {
  976. // if (userStatus.is_bind_mobile == 0) {
  977. // my.navigateTo({
  978. // url: '/pages/authorization/authorization',
  979. // })
  980. // } else {
  981. // my.navigateTo({
  982. // url: data.url,
  983. // })
  984. // }
  985. // }
  986. // else {
  987. // if (!userStatus) {
  988. // my.navigateTo({
  989. // url: '/pages/authorization/authorization',
  990. // })
  991. // } else {
  992. // my.navigateTo({
  993. // url: data.url,
  994. // })
  995. // }
  996. // }
  997. // }
  998. },
  999. //输码开锁检测
  1000. jiance1: function (source) {
  1001. var that = this;
  1002. let setting = my.getStorageSync({
  1003. 'key': 'setting'
  1004. }).data
  1005. var userStatus = that.data.userStatus;
  1006. //未绑定手机号
  1007. // if (userStatus.is_bind_mobile == 0) {
  1008. // my.navigateTo({
  1009. // url: '/pages/authorization/authorization',
  1010. // })
  1011. // } else
  1012. //未实名认证
  1013. if (userStatus.is_card_certified == 0 && setting.is_card == 1) {
  1014. my.navigateTo({
  1015. url: '/pages/real_name/real_name',
  1016. })
  1017. } else {
  1018. //有违章订单
  1019. if (that.data.userStatus.is_punishment) {
  1020. my.showToast({
  1021. content: '您当前有违章订单需要处理,请处理后再来用车吧',
  1022. icon: 'none'
  1023. })
  1024. return;
  1025. } else if (userStatus.is_ride_order != false && userStatus.is_ride_order != undefined) {
  1026. my.showToast({
  1027. content: '您有一个正在骑行中的订单',
  1028. icon: 'none'
  1029. })
  1030. return;
  1031. } else {
  1032. //有待支付骑行订单
  1033. if (userStatus.is_pay_order != false && userStatus.is_pay_order != undefined) {
  1034. my.showToast({
  1035. content: '你有未支付订单,请先支付',
  1036. icon: 'none'
  1037. })
  1038. return;
  1039. } else {
  1040. //没有押金没有免押券
  1041. if (userStatus.is_deposit == 0 && that.data.setting.is_deposit != 0 && userStatus.is_coupon_deposit_free == false) {
  1042. console.log('没有押金没有免押券')
  1043. my.navigateTo({
  1044. url: '/pages/ride_zige/ride_zige',
  1045. })
  1046. } else {
  1047. my.navigateTo({
  1048. url: '/pages/inputcode/inputcode',
  1049. })
  1050. }
  1051. }
  1052. }
  1053. }
  1054. },
  1055. // // 客服
  1056. kefu: function () {
  1057. let phone = my.getStorageSync({
  1058. 'key': 'home'
  1059. })
  1060. my.makePhoneCall({
  1061. number: phone ? phone.data.customer_service_phone : '13203706613'
  1062. })
  1063. },
  1064. //附近还车点
  1065. findPark: function () {
  1066. my.navigateTo({
  1067. url: '/pages/parking/parking',
  1068. })
  1069. },
  1070. //关闭中间广告弹框
  1071. closeAdframe: function () {
  1072. this.setData({
  1073. adFrame: false
  1074. })
  1075. },
  1076. onHide: function () {
  1077. console.log('onHide')
  1078. this.setData({
  1079. bike_no: undefined,
  1080. background: false,
  1081. bluetooth: false,
  1082. location: false,
  1083. scanfail: false,
  1084. over1: false
  1085. })
  1086. clearInterval(mytime)
  1087. },
  1088. // 去输码弹框
  1089. cancelErrFrame: function () {
  1090. this.setData({
  1091. scanCodeErr: false
  1092. })
  1093. },
  1094. goInputCode: function () {
  1095. my.navigateTo({
  1096. url: '/pages/inputcode/inputcode',
  1097. })
  1098. },
  1099. })