index.js 28 KB

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