index.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745
  1. //获取应用实例
  2. const app = getApp();
  3. var token = wx.getStorageSync('token');
  4. const util = require('../../../utils/utils.js');
  5. var mytime = null;
  6. Page({
  7. data: {
  8. showOnlinePhone: wx.getStorageSync('home').setting,
  9. markers: [], //显示单车、停车的P
  10. longitude: '0',
  11. latitude: '0',
  12. height1: '', //兼容自定义导航栏的高度
  13. show: false, //车子详情的布尔值
  14. id: '', //停车区域的ID
  15. background: false, //弹窗的背景颜色
  16. realname: false, //当前是否已经实名
  17. deposit: false, //当前是否交押金
  18. userStatus: '', //用户的一些状态 是否交押金等 0
  19. scanfail: false, //扫码失败弹窗
  20. is_pay_order: '', //检测当前是否有订单未支付
  21. code: '', //点击立即用车 把编号赋值给code
  22. over: false, //关闭图标
  23. over1: false, //扫码失败关闭图标
  24. location: '', //是否有位置权限
  25. screenHeight: '', //屏幕可视高度
  26. bluetooth: false, //是否开启蓝牙 false开始 true未开启
  27. box_no: '', //中控编号
  28. abnormal: '', //提示账号异常
  29. ads: [],
  30. mid: [],
  31. currentSwiper: 0,
  32. center_currentSwiper: 0,
  33. bike_no: undefined,
  34. stop_info: [],
  35. notice: [], //公告内容
  36. animationData: {},
  37. tabbar_index: 0,
  38. zoom: 18,
  39. versions: false, //版本过低弹窗
  40. chooseSize: false,
  41. animationData1: {},
  42. arrowDown: '',
  43. stop_type: '',
  44. marqueePace: 0.6, //滚动速度
  45. marqueeDistance: 520, //初始滚动距离 用到
  46. size: 26, //用到
  47. marqueeWidth: 520, //用到
  48. length: '',
  49. swiperCurrent: 0,
  50. midbolear:'',
  51. per_money:'',
  52. time:'',
  53. img:app.globalData.imgUrl,
  54. title:app.globalData.title
  55. },
  56. onLoad: function (query) {
  57. var that = this;
  58. console.log(query)
  59. wx.setNavigationBarTitle({
  60. title: app.globalData.title
  61. })
  62. if (query.q) {
  63. var code1 = decodeURIComponent(query.q)
  64. var index = code1.lastIndexOf("\=");
  65. var code = code1.substring(index + 1, code1.length);
  66. console.log(code)
  67. that.setData({
  68. bike_no: code
  69. })
  70. }
  71. if(query.scene){
  72. app.globalData.id = query.scene
  73. }
  74. this.setData({
  75. height1: app.globalData.statusBarHeight,
  76. screenHeight: app.globalData.screenHeight
  77. })
  78. this.getUser();
  79. this.userState();
  80. this.location()
  81. },
  82. guanbi() {
  83. this.setData({
  84. mid: []
  85. })
  86. var timestamp = Date.parse(new Date())/1000+43200;
  87. // 缓存过期时间
  88. wx.setStorageSync('midTimes', timestamp)
  89. },
  90. swiper: util.throttle(function (e) {
  91. //点击广告页
  92. // console.log(e)
  93. var type = e.currentTarget.dataset.type;
  94. var name = e.currentTarget.dataset.name;
  95. var detail = e.currentTarget.dataset.detail;
  96. var id = e.currentTarget.dataset.id;
  97. if (type != 'clilk_null') {
  98. if (type == 'wxUrl') {
  99. wx.navigateTo({
  100. url: '/' + detail,
  101. })
  102. } else if (type == 'phone') {
  103. wx.makePhoneCall({
  104. phoneNumber: detail,
  105. })
  106. } else {
  107. wx.navigateTo({
  108. url: '/pages/swiper/swiper?type=' + type + '&url=' + id + '&name=' + name + '&detail=' + detail,
  109. })
  110. }
  111. }
  112. }, 1000),
  113. swiperChange: function (e) {
  114. if (this.data.currentSwiper == 0 && this.data.swiperCurrent > 1) { //卡死时,重置current为正确索引
  115. this.setData({
  116. currentSwiper: this.data.swiperCurrent
  117. });
  118. } else { //正常轮转时,记录正确页码索引
  119. this.setData({
  120. swiperCurrent: e.detail.current
  121. });
  122. }
  123. },
  124. center_swiperChange: function (e) {
  125. this.setData({
  126. center_currentSwiper: e.detail.current
  127. })
  128. },
  129. ads: function (id) {
  130. var that = this;
  131. var area_id = ''
  132. if (id != undefined) {
  133. area_id = id
  134. } else {
  135. area_id = 0
  136. }
  137. app.request("/ads?area_id=" + area_id + "&position[]=mid&position[]=header&position[]=footer", '', "GET").then(res => {
  138. console.log(res)
  139. if (res.statusCode == 200 && res.data!='') {
  140. if (res.data.header != undefined || res.data.header != 'undefined') {
  141. that.setData({
  142. ads: res.data.header
  143. })
  144. }
  145. if (res.data.mid != undefined || res.data.mid != 'undefined') {
  146. that.setData({
  147. mid: res.data.mid
  148. })
  149. }
  150. }
  151. }).catch(err => {
  152. console.log(err)
  153. })
  154. },
  155. run1: function () {
  156. var that = this;
  157. mytime = setInterval(function () {
  158. if (-that.data.marqueeDistance < that.data.length) {
  159. that.setData({
  160. marqueeDistance: that.data.marqueeDistance - that.data.marqueePace,
  161. })
  162. } else {
  163. clearInterval(mytime);
  164. that.setData({
  165. marqueeDistance: that.data.marqueeWidth
  166. });
  167. that.run1();
  168. }
  169. }, 6)
  170. },
  171. notice: function () {
  172. var that = this;
  173. var area_id = ''
  174. if (wx.getStorageSync('home').id != undefined) {
  175. area_id = wx.getStorageSync('home').id
  176. }
  177. var data = {
  178. 'area_id': area_id
  179. }
  180. app.request("/index/an", data, "GET").then(res => {
  181. if (res.statusCode == 200) {
  182. console.log(res);
  183. if (res.data != '') {
  184. that.setData({
  185. notice: res.data
  186. });
  187. var length = res.data.description.length * that.data.size; //计算文字的长度
  188. that.setData({
  189. length: length
  190. })
  191. if (that.data.length > that.data.marqueeWidth) {
  192. that.run1();
  193. } else {
  194. that.setData({
  195. marqueeDistance: 0
  196. })
  197. }
  198. }
  199. }
  200. })
  201. },
  202. tap_notice: util.throttle(function (e) {
  203. // console.log(e)
  204. var id = e.currentTarget.dataset.id;
  205. wx.navigateTo({
  206. url: '/pages/public_details/public_details?id=' + id,
  207. })
  208. }, 1000),
  209. search: util.throttle(function () {
  210. //点击首页的搜索框
  211. wx.navigateTo({
  212. url: '/pages/navigation/navigation',
  213. })
  214. }, 1500),
  215. sweepcode: util.throttle(function () {
  216. this.setData({
  217. background: false,
  218. scanfail: false,
  219. over1: false
  220. })
  221. this.sweep_code()
  222. }, 1500),
  223. gocode: util.throttle(function () {
  224. //点击去试试看、使用车牌号开锁
  225. this.setData({
  226. background: false,
  227. scanfail: false,
  228. over1: false
  229. })
  230. wx.navigateTo({
  231. url: '/pages/input_number/input_number',
  232. })
  233. }, 1500),
  234. home: function () {
  235. //请求首页接口和一些设置。
  236. var that = this;
  237. if (that.data.longitude != '' && that.data.latitude != '' && token != '') {
  238. //116.411027
  239. var data = {
  240. 'lat': that.data.latitude,
  241. 'lng': that.data.longitude
  242. }
  243. app.request('/pages/home?include=setting',data,'POST').then(res=>{
  244. if (res.statusCode == 200) {
  245. var data = res.data;
  246. console.log(data)
  247. if (data.points != []) {
  248. that.setData({
  249. id: data.id,
  250. setting: data.setting,
  251. per_money: Number(data.setting.starting_price),
  252. })
  253. if (!data.id) return
  254. that.ads(data.id)
  255. }
  256. clearInterval(mytime)
  257. setTimeout(function () {
  258. that.notice();
  259. }, 500)
  260. if (res.data.status_code == 423) {
  261. wx.getLocation({
  262. success: function (res) {
  263. wx.showModal({
  264. title: '提示',
  265. content: '您附近暂无运营区域~',
  266. showCancel: false
  267. })
  268. },
  269. fail: function (err) {
  270. that.setData({
  271. location: true
  272. })
  273. }
  274. })
  275. }
  276. wx.setStorageSync('setting', data.setting)
  277. wx.setStorageSync('home', data)
  278. }
  279. })
  280. }
  281. },
  282. html5(e){
  283. wx.navigateTo({
  284. url: '/pages/compatible/html5/html5',
  285. })
  286. },
  287. mine: function () {
  288. //点击左上角我的图标 跳到我的页面
  289. //如果缓存里的avatar_url 不等于空 或者 uese 不等于空
  290. if (wx.getStorageSync('userInfo').avatar_url != null && wx.getStorageSync('userInfo') != '') {
  291. wx.navigateTo({
  292. url: '/pages/personal/mine/mine',
  293. })
  294. } else {
  295. wx.reLaunch({
  296. url: '/pages/authentication/authentication',
  297. })
  298. }
  299. },
  300. qixingCare(){
  301. wx.navigateTo({
  302. url: '/pages/recharge/recharge',
  303. })
  304. },
  305. yajinCare(){
  306. wx.navigateTo({
  307. url: '/pages/personal/deposit/deposit',
  308. })
  309. },
  310. authentication: util.throttle(function () {
  311. //点击去实名认证
  312. var state = wx.getStorageSync('userState')
  313. if (state.is_bind_mobile == 0) {
  314. wx.navigateTo({
  315. url: '/pages/real_name/real_name?state1=1&index=0',
  316. })
  317. } else if (state.is_bind_mobile == 1) {
  318. wx.navigateTo({
  319. url: '/pages/real_name/real_name?state2=2&index=1',
  320. })
  321. }
  322. this.setData({
  323. background: false,
  324. realname: false,
  325. over: false
  326. })
  327. }, 1500),
  328. sweep_code: util.throttle(function () {
  329. //点击扫码开锁
  330. var that = this;
  331. wx.getLocation({
  332. success: function (res) {
  333. // console.log(that.data.userStatus.is_pay_order)
  334. if (wx.getStorageSync('setting') == '') {
  335. wx.getLocation({
  336. success: function (res) {
  337. wx.showModal({
  338. title: '提示',
  339. content: '您附近暂无运营区域~',
  340. showCancel: false
  341. })
  342. },
  343. fail: function (err) {
  344. that.setData({
  345. location: true
  346. })
  347. }
  348. })
  349. return;
  350. }
  351. if(that.data.userStatus.is_punishment){
  352. wx.showModal({
  353. title: '提示',
  354. content:'您当前有违章订单需要处理,请处理后再来用车吧!',
  355. confirmText:'去处理',
  356. success:function(res){
  357. if(res.confirm){
  358. wx.navigateTo({
  359. url: '/pages/fine/fine',
  360. })
  361. }
  362. }
  363. })
  364. return;
  365. }
  366. if (that.data.userStatus.is_pay_order != false && that.data.userStatus.is_pay_order != undefined) {
  367. that.setData({
  368. is_pay_order: 1,
  369. background: true
  370. })
  371. return;
  372. } else if (that.data.userStatus.is_pay_rent_order != false && that.data.userStatus.is_pay_rent_order != undefined) {
  373. that.setData({
  374. is_pay_order: 1,
  375. background: true
  376. })
  377. return;
  378. } else {
  379. if (wx.getStorageSync('userInfo').avatar_url != null && wx.getStorageSync('userInfo') != '') {
  380. if (that.data.userStatus.is_card_certified == 0) {
  381. that.setData({
  382. realname: true,
  383. background: true,
  384. over: true
  385. })
  386. return;
  387. } else if (that.data.userStatus.is_bind_mobile == 0) {
  388. wx.showModal({
  389. title: '提示',
  390. content: '您还未绑定手机号,去绑定?',
  391. success: function (res) {
  392. if (res.confirm) {
  393. wx.navigateTo({
  394. url: '/pages/real_name/real_name?state1=1&index=0',
  395. })
  396. }
  397. }
  398. })
  399. return;
  400. } else {
  401. if (that.data.userStatus.is_deposit == 0) {
  402. that.setData({
  403. deposit: true,
  404. background: true
  405. })
  406. return;
  407. } else {
  408. wx.scanCode({
  409. onlyFromCamera: true,
  410. success: function (res) {
  411. // console.log(res)
  412. var index = res.result.lastIndexOf("\=");
  413. var code = res.result.substring(index + 1, res.result.length);
  414. console.log(code.length)
  415. if (code.length == 11) {
  416. wx.navigateTo({
  417. url: '/pages/sweep_code/sweep_code?code=' + code,
  418. })
  419. } else {
  420. wx.showToast({
  421. title: '请扫描正确的二维码!',
  422. icon: 'none'
  423. })
  424. }
  425. },
  426. fail: function (err) {
  427. console.log(err)
  428. that.setData({
  429. background: true,
  430. scanfail: true,
  431. over1: true
  432. })
  433. }
  434. })
  435. }
  436. }
  437. } else {
  438. wx.reLaunch({
  439. url: '/pages/authentication/authentication',
  440. })
  441. }
  442. }
  443. },
  444. fail: function (err) {
  445. that.setData({
  446. location: true
  447. })
  448. }
  449. })
  450. }, 1500),
  451. think: util.throttle(function () {
  452. //点击我再想想 关闭弹窗和背景
  453. this.setData({
  454. background: false,
  455. deposit: false,
  456. over: false
  457. })
  458. }, 1500),
  459. deposit: util.throttle(function () {
  460. //点击现在就去 跳到交押金页面
  461. this.setData({
  462. background: false,
  463. deposit: false,
  464. over: false
  465. })
  466. wx.navigateTo({
  467. url: '/pages/personal/deposit/deposit?home=index',
  468. })
  469. }, 1500),
  470. cancel: util.throttle(function () {
  471. //点击取消,下次吧
  472. this.setData({
  473. is_pay_order: false,
  474. background: false
  475. })
  476. }, 1500),
  477. go_pay: util.throttle(function () {
  478. //点击去支付
  479. this.setData({
  480. is_pay_order: false,
  481. background: false
  482. })
  483. var pay_order = ''
  484. var rent = ''
  485. if (this.data.userStatus.is_pay_order != false && this.data.userStatus.is_pay_order != undefined) {
  486. pay_order = this.data.userStatus.is_pay_order
  487. }
  488. if (this.data.userStatus.is_pay_rent_order != false && this.data.userStatus.is_pay_rent_order != undefined) {
  489. pay_order = this.data.userStatus.is_pay_rent_order;
  490. rent = 'rent'
  491. }
  492. // console.log(rent)
  493. wx.navigateTo({
  494. url: '/pages/payment/payment?order=' + pay_order + '&rent=' + rent,
  495. })
  496. }, 1500),
  497. over: function () {
  498. //如果当前未实名 弹窗显示后 点击关闭按钮
  499. this.setData({
  500. realname: false,
  501. background: false,
  502. scanfail: false,
  503. over1: false,
  504. over: false,
  505. })
  506. },
  507. location: function () {
  508. //获取当前经纬度 如果未授权让用户去授权
  509. var that = this;
  510. wx.showLoading({
  511. title: '定位中...',
  512. mask: true
  513. })
  514. wx.getLocation({
  515. type: 'gcj02',
  516. success: (res) => {
  517. console.log('经纬度为:+++++++++++++++++++++' + res.latitude + '++++++++' + res.longitude)
  518. var latitude = res.latitude
  519. var longitude = res.longitude
  520. that.setData({
  521. longitude: longitude,
  522. latitude: latitude,
  523. show: false
  524. })
  525. that.home()
  526. wx.hideLoading()
  527. },
  528. fail: function () {
  529. wx.hideLoading()
  530. wx.getSetting({
  531. success: function (res) {
  532. // console.log(res)
  533. var statu = res.authSetting;
  534. if (statu['scope.userLocation'] == false) {
  535. that.setData({
  536. background: true,
  537. location: true
  538. })
  539. }
  540. }
  541. })
  542. }
  543. })
  544. },
  545. onShow: function () {
  546. var that = this;
  547. token = wx.getStorageSync('token')
  548. this.setData({
  549. show: false,
  550. midbolear: wx.getStorageSync('midTimes'),
  551. time: wx.getStorageSync('home').customer_service_time
  552. })
  553. wx.hideHomeButton();
  554. },
  555. onReady: function () {
  556. },
  557. kefu: util.throttle(function () {
  558. wx.makePhoneCall({
  559. phoneNumber: wx.getStorageSync('home').customer_service_phone,
  560. })
  561. }, 1500),
  562. userState: function () {
  563. var that = this;
  564. if (token != '') {
  565. app.request('/user/status','','GET').then(res=>{
  566. console.log(res)
  567. if (res.statusCode == 200) {
  568. that.setData({
  569. userStatus: res.data,
  570. is_pay_order: res.data.is_pay_order
  571. }), wx.setStorageSync('userState', res.data)
  572. if (res.data.status == 0) {
  573. that.setData({
  574. abnormal: true,
  575. background: true
  576. })
  577. return;
  578. }
  579. if (that.data.userStatus.is_ride_order != false) {
  580. wx.reLaunch({
  581. url: '/pages/riding/riding?order=' + that.data.userStatus.is_ride_order,
  582. })
  583. return;
  584. }
  585. if (that.data.userStatus.is_rent_order != false) {
  586. wx.reLaunch({
  587. url: '/pages/daily_riding/daily_riding?order=' + that.data.userStatus.is_rent_order,
  588. })
  589. return;
  590. }
  591. if (that.data.userStatus.is_pay_order != false) {
  592. that.setData({
  593. background: true,
  594. is_pay_order: true
  595. })
  596. return;
  597. }
  598. if (that.data.userStatus.is_pay_rent_order != false) {
  599. that.setData({
  600. background: true,
  601. is_pay_order: true
  602. })
  603. return;
  604. }
  605. if(that.data.userStatus.is_punishment){
  606. console.log(that.data.userStatus)
  607. wx.showModal({
  608. title: '提示',
  609. content:'您当前有违章订单需要处理,请处理后再来用车吧!',
  610. confirmText:'去处理',
  611. success:function(res){
  612. if(res.confirm){
  613. wx.navigateTo({
  614. url: '/pages/fine/fine',
  615. })
  616. }
  617. }
  618. })
  619. return;
  620. }
  621. if (wx.getStorageSync('userInfo') && res.data.is_card_certified == 1 && res.data.is_deposit == 1 && res.data.is_ride_order == false && res.data.is_pay_order == false && that.data.bike_no != undefined && res.data.is_pay_rent_order == false) {
  622. wx.navigateTo({
  623. url: '/pages/sweep_code/sweep_code?code=' + that.data.bike_no,
  624. })
  625. return;
  626. }
  627. if (wx.getStorageSync('userInfo').avatar_url != null && wx.getStorageSync('userInfo') != '' && that.data.bike_no != undefined) {
  628. if (that.data.userStatus.is_card_certified == 0 && that.data.bike_no != undefined) {
  629. that.setData({
  630. realname: true,
  631. background: true,
  632. over: true
  633. })
  634. return;
  635. } else if (that.data.userStatus.is_bind_mobile == 0 && that.data.bike_no != undefined) {
  636. wx.showModal({
  637. title: '提示',
  638. content: '您还未绑定手机号,去绑定?',
  639. success: function (res) {
  640. if (res.confirm) {
  641. wx.navigateTo({
  642. url: '/pages/real_name/real_name?state1=1&index=0',
  643. })
  644. }
  645. }
  646. })
  647. return;
  648. } else {
  649. if (that.data.userStatus.is_deposit == 0 && that.data.bike_no != undefined) {
  650. that.setData({
  651. deposit: true,
  652. background: true
  653. })
  654. return;
  655. }
  656. }
  657. } else {
  658. // wx.redirectTo({
  659. // url: '../authentication/authentication',
  660. // })
  661. }
  662. }
  663. })
  664. }
  665. },
  666. getUser() {
  667. if (token != '') {
  668. app.request('/me','','GET').then(res=>{
  669. 200 == res.statusCode && wx.setStorageSync("userInfo", res.data)
  670. })
  671. }
  672. },
  673. usage: util.throttle(function () {
  674. wx.navigateTo({
  675. url: '/pages/accounting_rules/accounting_rules',
  676. })
  677. }, 1500),
  678. help: util.throttle(function () {
  679. //点击如何用车 跳到如何用车页面
  680. wx.navigateTo({
  681. url: '/pages/personal/help/help',
  682. })
  683. }, 1500),
  684. go_setting: util.throttle(function () {
  685. //点击去设置位置权限
  686. this.setData({
  687. background: false,
  688. location: false
  689. })
  690. wx.openSetting({
  691. success: function (res) {
  692. // console.log(res)
  693. // console.log(res.authSetting)
  694. }
  695. })
  696. }, 1500),
  697. open: util.throttle(function () {
  698. //点击已打开
  699. this.setData({
  700. background: false,
  701. location: false
  702. })
  703. }, 1500),
  704. navgiate: util.throttle(function (e) {
  705. console.log(e)
  706. if (this.data.stop_type == 1) return;
  707. var latitude = this.data.stop_info.latitude;
  708. var longitude = this.data.stop_info.longitude;
  709. var name = this.data.stop_info.name;
  710. wx.openLocation({ //​使用微信内置地图查看位置。
  711. latitude: latitude, //要去的纬度-地址
  712. longitude: longitude, //要去的经度-地址
  713. name: name
  714. })
  715. }, 1000),
  716. onHide: function () {
  717. console.log('onHide')
  718. this.setData({
  719. bike_no: undefined,
  720. background: false,
  721. bluetooth: false,
  722. location: false,
  723. scanfail: false,
  724. over1: false
  725. })
  726. // clearInterval(mytime)
  727. },
  728. service(){
  729. this.setData({kefu:true})
  730. },
  731. hidden(){
  732. this.setData({kefu:false})
  733. },
  734. onUnload: function () {
  735. console.log('onUnload')
  736. },
  737. onShareAppMessage: function () {
  738. }
  739. })