index.js 28 KB

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