index.js 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426
  1. //获取应用实例
  2. const app = getApp();
  3. var token = wx.getStorageSync('token');
  4. var http = require("../../utils/config.js");
  5. const util = require('../../utils/utils.js');
  6. var mytime = null;
  7. let interstitialAd = null
  8. import {
  9. BluetoothManager,
  10. BtErrorCode
  11. } from '../../service/BlueMgr';
  12. const bluM = new BluetoothManager;
  13. Page({
  14. data: {
  15. markers: [], //显示单车、停车的P
  16. polygons: [], //区域
  17. longitude: '0',
  18. latitude: '0',
  19. height1: '', //兼容自定义导航栏的高度
  20. show: false, //车子详情的布尔值
  21. id: '', //停车区域的ID
  22. stopP: false, //判断是否显示停车区域
  23. polygons1: [], //可骑行区域 先用这个变量代表
  24. controls: [], //地图上当前定位的箭头
  25. background: false, //弹窗的背景颜色
  26. realname: false, //当前是否已经实名
  27. deposit: false, //当前是否交押金
  28. userStatus: '', //用户的一些状态 是否交押金等 0
  29. scanfail: false, //扫码失败弹窗
  30. is_pay_order: '', //检测当前是否有订单未支付
  31. code: '', //点击立即用车 把编号赋值给code
  32. over: false, //关闭图标
  33. over1: false, //扫码失败关闭图标
  34. location: '', //是否有位置权限
  35. screenHeight: '', //屏幕可视高度
  36. bluetooth: false, //是否开启蓝牙 false开始 true未开启
  37. box_no: '', //中控编号
  38. abnormal: '', //提示账号异常
  39. ads: [],
  40. mid: [],
  41. currentSwiper: 0,
  42. center_currentSwiper: 0,
  43. bike_no: undefined,
  44. stopShow: false,
  45. stop_info: [],
  46. notice: [], //公告内容
  47. animationData: {},
  48. tabbar_index: 0,
  49. zoom: 18,
  50. versions: false, //版本过低弹窗
  51. chooseSize: false,
  52. animationData1: {},
  53. arrowDown: '',
  54. stop_type: '',
  55. marqueePace: 0.6, //滚动速度
  56. marqueeDistance: 520, //初始滚动距离 用到
  57. size: 26, //用到
  58. marqueeWidth: 520, //用到
  59. length: '',
  60. swiperCurrent: 0,
  61. midbolear:'',
  62. per_money:'',
  63. site: {
  64. latitude: '0',
  65. longitude: '0'
  66. }
  67. },
  68. chooseSezi: function (e) {
  69. //底部广告动画效果
  70. // 用that取代this,防止不必要的情况发生
  71. var that = this;
  72. // 创建一个动画实例
  73. var animation = wx.createAnimation({
  74. // 动画持续时间
  75. duration: 600,
  76. // 定义动画效果,当前是匀速
  77. timingFunction: 'linear'
  78. })
  79. // 将该变量赋值给当前动画
  80. that.animation = animation
  81. // 先在y轴偏移,然后用step()完成一个动画
  82. animation.translateY(300).step()
  83. // 用setData改变当前动画
  84. that.setData({
  85. // 通过export()方法导出数据
  86. animationData1: animation.export(),
  87. // 改变view里面的Wx:if
  88. chooseSize: true
  89. })
  90. // 设置setTimeout来改变y轴偏移量,实现有感觉的滑动
  91. setTimeout(function () {
  92. animation.translateY(0).step()
  93. that.setData({
  94. animationData1: animation.export()
  95. })
  96. }, 100)
  97. var query = wx.createSelectorQuery();
  98. query.select('.choose').boundingClientRect();
  99. query.exec(function (res) {
  100. console.log(res)
  101. that.setData({
  102. arrowDown: res[0].height + 40
  103. })
  104. })
  105. var query = wx.createSelectorQuery();
  106. query.select('.bottomAd').boundingClientRect();
  107. query.exec(function (res) {
  108. console.log(res)
  109. })
  110. },
  111. hideModal: function (e) {
  112. var that = this;
  113. var animation = wx.createAnimation({
  114. duration: 800,
  115. timingFunction: 'linear'
  116. })
  117. that.animation = animation
  118. animation.translateY(300).step()
  119. that.setData({
  120. animationData1: animation.export()
  121. })
  122. setTimeout(function () {
  123. animation.translateY(0).step()
  124. that.setData({
  125. animationData1: animation.export(),
  126. chooseSize: false
  127. })
  128. }, 700)
  129. },
  130. onLoad: function (query) {
  131. var that = this;
  132. console.log(query)
  133. if (query.q) {
  134. var code1 = decodeURIComponent(query.q)
  135. var index = code1.lastIndexOf("\=");
  136. var code = code1.substring(index + 1, code1.length);
  137. console.log(code)
  138. that.setData({
  139. bike_no: code
  140. })
  141. }
  142. if(query.scene){
  143. app.globalData.id = query.scene
  144. }
  145. // if (token == '' || token == undefined) {
  146. // wx.login({
  147. // success: res => {
  148. // var arr = []
  149. // wx.getSystemInfo({
  150. // success(res) {
  151. // arr = [{
  152. // label: '品牌',
  153. // type: 'brand',
  154. // value: res.brand
  155. // },
  156. // {
  157. // label: '型号',
  158. // type: 'model',
  159. // value: res.model
  160. // },
  161. // {
  162. // label: '系统平台',
  163. // type: 'platform',
  164. // value: res.platform
  165. // },
  166. // {
  167. // label: '系统版本',
  168. // type: 'system',
  169. // value: res.system
  170. // },
  171. // {
  172. // label: '微信版本',
  173. // type: 'version',
  174. // value: res.version
  175. // },
  176. // {
  177. // label: '小程序版本',
  178. // type: 'SDKVersion',
  179. // value: res.SDKVersion
  180. // },
  181. // {
  182. // label: '定位状态',
  183. // type: 'locationEnabled',
  184. // value: res.locationEnabled ? '开' : '关'
  185. // },
  186. // {
  187. // label: '定位授权',
  188. // type: 'locationAuthorized',
  189. // value: res.locationAuthorized ? '已授权' : '未授权'
  190. // }
  191. // ]
  192. // }
  193. // })
  194. // // 发送 res.code 到后台换取 openId, sessionKey, unionId
  195. // wx.request({
  196. // url: http.url + '/auth/weapp-login',
  197. // data: {
  198. // 'code': res.code,
  199. // 'appid': 'wx660b94f751a78b61',
  200. // 'phone_detail': JSON.stringify(arr),
  201. // 'invite_user_id':query.scene ? query.scene : 0
  202. // },
  203. // header: {
  204. // 'content-type': 'application/x-www-form-urlencoded',
  205. // },
  206. // method: 'POST',
  207. // success: function (res) {
  208. // console.log(res);
  209. // if (res.statusCode == 200) {
  210. // // 判断微信版本是否过低
  211. // token = res.data.token;
  212. // // wx.setStorageSync('token', res.data.token)
  213. // // wx.setStorageSync('session_key', res.data.session_key)
  214. // // wx.setStorageSync('token_time', res.data.exp)
  215. // // wx.setStorageSync('user_ID', res.data.user.id);
  216. // that.getUser();
  217. // that.userState();
  218. // }
  219. // }
  220. // })
  221. // }
  222. // })
  223. // }
  224. this.setData({
  225. height1: app.globalData.statusBarHeight,
  226. screenHeight: app.globalData.screenHeight
  227. })
  228. wx.getSystemInfo({
  229. success: (res) => {
  230. this.setData({
  231. controls: [{
  232. id: 1,
  233. iconPath: '/img/map.png', // 大头针图片
  234. position: {
  235. left: res.windowWidth / 2 - 9,
  236. top: res.windowHeight / 2 - 27,
  237. width: 15,
  238. height: 27
  239. },
  240. clickable: true
  241. }]
  242. })
  243. }
  244. })
  245. },
  246. detail: function () {
  247. var that = this;
  248. if (that.data.mid[0].type == 'url') {
  249. wx.navigateTo({
  250. url: '/' + that.data.mid[0].detail
  251. })
  252. }
  253. },
  254. guanbi() {
  255. this.setData({
  256. mid: []
  257. })
  258. var timestamp = Date.parse(new Date())/1000+43200;
  259. // 缓存过期时间
  260. wx.setStorageSync('midTimes', timestamp)
  261. },
  262. tabbar_top: util.throttle(function (e) {
  263. this.setData({
  264. stopP: !this.data.stopP,
  265. tabbar_index: !this.data.stopP ? '1' : '0',
  266. show: false,
  267. stopShow: false
  268. }), this.stop()
  269. var polygons = this.data.polygons;
  270. if (this.data.stopP == true) {
  271. this.setData({
  272. polygons,
  273. zoom: 14
  274. })
  275. } else {
  276. this.setData({
  277. polygons,
  278. zoom: 18
  279. })
  280. }
  281. }, 2000),
  282. stop1: util.throttle(function () {
  283. this.setData({
  284. stopP: !this.data.stopP,
  285. tabbar_index: !this.data.stopP ? '1' : '0',
  286. show: false,
  287. stopShow: false
  288. }), this.stop()
  289. var polygons = this.data.polygons;
  290. if (this.data.stopP == true) {
  291. this.setData({
  292. polygons,
  293. zoom: 14
  294. })
  295. } else {
  296. this.setData({
  297. polygons,
  298. zoom: 18
  299. })
  300. }
  301. }, 2000),
  302. swiper: util.throttle(function (e) {
  303. //点击广告页
  304. // console.log(e)
  305. var type = e.currentTarget.dataset.type;
  306. var index = e.currentTarget.dataset.index;
  307. var name = e.currentTarget.dataset.name;
  308. var detail = e.currentTarget.dataset.detail;
  309. var id = e.currentTarget.dataset.id;
  310. if (type != 'clilk_null') {
  311. if (type == 'wxUrl') {
  312. wx.navigateTo({
  313. url: '/' + detail,
  314. })
  315. } else if (type == 'phone') {
  316. wx.makePhoneCall({
  317. phoneNumber: detail,
  318. })
  319. } else {
  320. wx.navigateTo({
  321. url: '../swiper/swiper?type=' + type + '&url=' + id + '&name=' + name + '&detail=' + detail,
  322. })
  323. }
  324. }
  325. }, 1000),
  326. swiperChange: function (e) {
  327. if (this.data.currentSwiper == 0 && this.data.swiperCurrent > 1) { //卡死时,重置current为正确索引
  328. this.setData({
  329. currentSwiper: this.data.swiperCurrent
  330. });
  331. } else { //正常轮转时,记录正确页码索引
  332. this.setData({
  333. swiperCurrent: e.detail.current
  334. });
  335. }
  336. },
  337. center_swiperChange: function (e) {
  338. this.setData({
  339. center_currentSwiper: e.detail.current
  340. })
  341. },
  342. ads: function (id) {
  343. var that = this;
  344. var area_id = ''
  345. if (id != undefined) {
  346. area_id = id
  347. } else {
  348. area_id = 0
  349. }
  350. app.request("/ads?area_id=" + area_id + "&position[]=mid&position[]=header&position[]=footer", '', "GET").then(res => {
  351. console.log(res)
  352. if (res.statusCode == 200 && res.data!='') {
  353. if (res.data.header != undefined || res.data.header != 'undefined') {
  354. that.setData({
  355. ads: res.data.header
  356. })
  357. }
  358. if (res.data.mid != undefined || res.data.mid != 'undefined') {
  359. that.setData({
  360. mid: res.data.mid
  361. })
  362. }
  363. if (res.data.footer != undefined || res.data.footer != 'undefined') {
  364. that.setData({
  365. footer: res.data.footer
  366. })
  367. }
  368. }
  369. }).catch(err => {
  370. console.log(err)
  371. })
  372. },
  373. run1: function () {
  374. var that = this;
  375. mytime = setInterval(function () {
  376. if (-that.data.marqueeDistance < that.data.length) {
  377. that.setData({
  378. marqueeDistance: that.data.marqueeDistance - that.data.marqueePace,
  379. })
  380. } else {
  381. clearInterval(mytime);
  382. that.setData({
  383. marqueeDistance: that.data.marqueeWidth
  384. });
  385. that.run1();
  386. }
  387. }, 6)
  388. },
  389. notice: function () {
  390. var that = this;
  391. var area_id = ''
  392. if (wx.getStorageSync('home').id != undefined) {
  393. area_id = wx.getStorageSync('home').id
  394. }
  395. var data = {
  396. 'area_id': area_id
  397. }
  398. app.request("/index/an", data, "GET").then(res => {
  399. if (res.statusCode == 200) {
  400. console.log(res);
  401. if (res.data != '') {
  402. that.setData({
  403. notice: res.data
  404. });
  405. var length = res.data.description.length * that.data.size; //计算文字的长度
  406. that.setData({
  407. length: length
  408. })
  409. if (that.data.length > that.data.marqueeWidth) {
  410. that.run1();
  411. } else {
  412. that.setData({
  413. marqueeDistance: 0
  414. })
  415. }
  416. }
  417. }
  418. })
  419. },
  420. tap_notice: util.throttle(function (e) {
  421. // console.log(e)
  422. var id = e.currentTarget.dataset.id;
  423. wx.navigateTo({
  424. url: '../public_details/public_details?id=' + id,
  425. })
  426. }, 1000),
  427. posi: util.throttle(function () {
  428. //点击定位
  429. //这是一段注释
  430. this.map()
  431. var that = this;
  432. console.log('dingei')
  433. wx.getLocation({
  434. type: 'gcj02',
  435. success: (res) => {
  436. console.log('经纬度为:+++++++++++++++++++++' + res.latitude + '++++++++' + res.longitude)
  437. var latitude = res.latitude
  438. var longitude = res.longitude
  439. that.setData({
  440. longitude: longitude,
  441. latitude: latitude
  442. })
  443. },
  444. fail: function (err) {
  445. console.log(err,'dingwei zhibai')
  446. that.setData({
  447. location: true
  448. })
  449. }
  450. })
  451. }, 1500),
  452. search: util.throttle(function () {
  453. //点击首页的搜索框
  454. wx.navigateTo({
  455. url: '../navigation/navigation',
  456. })
  457. }, 1500),
  458. bindregionchange: function (e) {
  459. //实现大头针移动选点
  460. var that = this
  461. // console.log(e)
  462. // if (e.type == "end" && e.causedBy == 'drag') {
  463. // //停止
  464. // console.log('end')
  465. // var mapCtx = wx.createMapContext("map")
  466. // mapCtx.getCenterLocation({
  467. // success: function (res) {
  468. // var latitude = res.latitude
  469. // var longitude = res.longitude
  470. // that.setData({ latitude, longitude })
  471. // if(that.data.stopP==false){
  472. // that.nearbyCars(), that.map()
  473. // }
  474. // }
  475. // })
  476. // }
  477. },
  478. sweepcode: util.throttle(function () {
  479. this.setData({
  480. background: false,
  481. scanfail: false,
  482. over1: false
  483. })
  484. this.sweep_code()
  485. }, 1500),
  486. gocode: util.throttle(function () {
  487. //点击去试试看、使用车牌号开锁
  488. this.setData({
  489. background: false,
  490. scanfail: false,
  491. over1: false
  492. })
  493. wx.navigateTo({
  494. url: '../input_number/input_number',
  495. })
  496. }, 1500),
  497. home: function () {
  498. //请求首页接口和一些设置。
  499. var that = this;
  500. if (that.data.longitude != '' && that.data.latitude != '' && token != '') {
  501. //116.411027
  502. var data = {
  503. 'lat': that.data.latitude,
  504. 'lng': that.data.longitude,
  505. 'bike_no':that.data.code ? that.data.code:''
  506. }
  507. wx.request({
  508. url: http.url + '/pages/home?include=setting',
  509. method: 'POST',
  510. header: {
  511. 'content-type': 'application/x-www-form-urlencoded',
  512. Authorization: token
  513. },
  514. data: data,
  515. success: function (res) {
  516. console.log(res)
  517. if (res.statusCode == 200) {
  518. var data = res.data;
  519. console.log(data)
  520. if (data.points != []) {
  521. that.setData({
  522. id: data.id,
  523. polygons1: that.data.polygons.concat(data),
  524. setting: data.setting,
  525. per_money: Number(data.setting.starting_price),
  526. polygons: []
  527. })
  528. if (!data.id) return
  529. that.ads(data.id),
  530. that.ban_stop(data.id), that.setData({
  531. polygons: that.data.polygons.concat(data)
  532. })
  533. }
  534. clearInterval(mytime)
  535. setTimeout(function () {
  536. that.notice();
  537. }, 500)
  538. if (res.data.status_code == 423) {
  539. wx.getLocation({
  540. success: function (res) {
  541. wx.showModal({
  542. title: '提示',
  543. content: '您附近暂无运营区域~',
  544. showCancel: false
  545. })
  546. },
  547. fail: function (err) {
  548. that.setData({
  549. location: true
  550. })
  551. }
  552. })
  553. }
  554. wx.setStorageSync('setting', data.setting)
  555. wx.setStorageSync('home', data)
  556. }
  557. }
  558. })
  559. }
  560. },
  561. ban_stop: function (id) {
  562. var that = this;
  563. var data1 = {
  564. 'area_id': id
  565. }
  566. app.request('/parking/ban-stop-sites', data1, 'GET').then(res => {
  567. console.log(res)
  568. if (res.statusCode == 200) {
  569. var data = res.data
  570. console.log(data)
  571. that.setData({
  572. polygons2: data.polygons,
  573. markers: that.data.markers.concat(data.centres),
  574. polygons: that.data.polygons1.concat(data.polygons)
  575. })
  576. }
  577. })
  578. },
  579. nearbyCars: function () {
  580. //附近的车
  581. var that = this;
  582. that.setData({
  583. markers: []
  584. })
  585. var data = {
  586. "lat": that.data.latitude,
  587. "lng": that.data.longitude
  588. }
  589. app.request("/bikes", data, "POST").then(res => {
  590. // console.log(res)
  591. if (res.statusCode == 200) {
  592. var makers = res.data
  593. if (makers == '') {
  594. wx.showToast({
  595. title: '附近暂无车辆',
  596. icon: 'none'
  597. })
  598. that.setData({
  599. markers: []
  600. })
  601. } else {
  602. that.setData({
  603. markers: makers
  604. })
  605. }
  606. }
  607. }).catch(err => {
  608. console.log(err)
  609. })
  610. },
  611. use: util.throttle(function () {
  612. //点击车辆详情的立即用车按钮
  613. var that = this;
  614. if(that.data.userStatus.is_punishment){
  615. wx.showModal({
  616. title: '提示',
  617. content:'您当前有违章订单需要处理,请处理后再来用车吧!',
  618. confirmText:'去处理',
  619. success:function(res){
  620. if(res.confirm){
  621. wx.navigateTo({
  622. url: '/pages/fine/fine',
  623. })
  624. }
  625. }
  626. })
  627. return;
  628. }
  629. var userStatus = that.data.userStatus;
  630. if (userStatus.is_pay_order != false && userStatus.is_pay_order != undefined) {
  631. this.setData({
  632. is_pay_order: 1,
  633. background: true
  634. })
  635. return;
  636. } else if (userStatus.is_pay_rent_order != false && userStatus.is_pay_rent_order != undefined) {
  637. this.setData({
  638. is_pay_order: 1,
  639. background: true
  640. })
  641. return;
  642. } else {
  643. if (wx.getStorageSync('userInfo').avatar_url != null && wx.getStorageSync('userInfo') != '') {
  644. if (userStatus.is_card_certified == 0) {
  645. that.setData({
  646. realname: true,
  647. background: true,
  648. over: true
  649. })
  650. return;
  651. } else if (userStatus.is_bind_mobile == 0) {
  652. wx.showModal({
  653. title: '提示',
  654. content: '您还未绑定手机号,去绑定?',
  655. success: function (res) {
  656. if (res.confirm) {
  657. wx.navigateTo({
  658. url: '/pages/real_name/real_name?state1=1&index=0',
  659. })
  660. }
  661. }
  662. })
  663. return;
  664. } else {
  665. if (userStatus.is_deposit == 0) {
  666. that.setData({
  667. deposit: true,
  668. background: true
  669. })
  670. return;
  671. } else {
  672. wx.navigateTo({
  673. url: '../sweep_code/sweep_code?code=' + that.data.code,
  674. })
  675. return;
  676. }
  677. }
  678. } else {
  679. wx.reLaunch({
  680. url: '../authentication/authentication',
  681. })
  682. }
  683. }
  684. }, 1000),
  685. map: function () {
  686. //点击地图使车子变回原来颜色 并且隐藏车子信息
  687. if (this.data.stopP == false) {
  688. var markers = this.data.markers;
  689. for (let item of markers) {
  690. if (item.type == 1) {
  691. item.iconPath = 'http://resource.weilaigo.l4j.cn/ban-stop.png'
  692. } else {
  693. item.iconPath = 'http://resource.weilaigo.l4j.cn/bluebike.png'
  694. }
  695. }
  696. this.setData({
  697. show: false,
  698. markers
  699. })
  700. } else {
  701. var markers = this.data.markers;
  702. for (let item of markers) {
  703. if (item.type == 2) {
  704. item.iconPath = 'http://resource.weilaigo.l4j.cn/stop1.png'
  705. }
  706. if (item.type == 1) {
  707. item.iconPath = 'http://resource.weilaigo.l4j.cn/ban-stop.png'
  708. }
  709. }
  710. this.setData({
  711. stopShow: false,
  712. markers
  713. })
  714. }
  715. },
  716. stop: util.throttle(function () {
  717. //点击P显示停车区域并隐藏所有车子
  718. var that = this;
  719. that.setData({
  720. markers: []
  721. })
  722. that.map()
  723. // console.log(that.data.stopP)
  724. if (that.data.stopP == true) {
  725. that.stopP()
  726. // console.log('显示停车')
  727. } else {
  728. // console.log('隐藏停车')
  729. that.nearbyCars(), that.setData({
  730. polygons: that.data.polygons1
  731. }), that.ban_stop(that.data.id)
  732. }
  733. }, 1500),
  734. marker: function (e) {
  735. //点击地图上每一辆车子 使点击的车子变色并且显示车子详情
  736. var that = this;
  737. var markers = that.data.markers;
  738. var bolear = ''
  739. for (let item of markers) {
  740. if (item.id == e.markerId) {
  741. if (item.type == undefined) {
  742. item.iconPath = 'http://resource.weilaigo.l4j.cn/yellowbike.png';
  743. wx.showLoading({
  744. title: '获取中...',
  745. })
  746. that.setData({
  747. code: e.markerId,
  748. bike: []
  749. })
  750. app.request('/bike/' + e.markerId, '', 'GET').then(res => {
  751. // console.log(res)
  752. wx.hideLoading()
  753. if (res.statusCode == 200) {
  754. that.setData({
  755. bike: res.data,
  756. show: true,
  757. box_no: res.data.box_no
  758. })
  759. }
  760. })
  761. } else {
  762. item.iconPath = 'http://resource.weilaigo.l4j.cn/ban-stop.png';
  763. }
  764. } else {
  765. if (item.type == undefined) {
  766. item.iconPath = 'http://resource.weilaigo.l4j.cn/bluebike.png';
  767. } else {
  768. item.iconPath = 'http://resource.weilaigo.l4j.cn/ban-stop.png';
  769. }
  770. }
  771. }
  772. that.setData({
  773. markers
  774. })
  775. },
  776. mine: function () {
  777. //点击左上角我的图标 跳到我的页面
  778. this.map()
  779. //如果缓存里的avatar_url 不等于空 或者 uese 不等于空
  780. if (wx.getStorageSync('userInfo').avatar_url != null && wx.getStorageSync('userInfo') != '') {
  781. wx.navigateTo({
  782. url: '../personal/mine/mine',
  783. })
  784. } else {
  785. wx.reLaunch({
  786. url: '../authentication/authentication',
  787. })
  788. }
  789. },
  790. stop_marker: function (e) {
  791. console.log(e)
  792. var that = this;
  793. var markers = e.currentTarget.dataset.markers;
  794. var stop_area = this.data.polygons;
  795. for (let item of markers) {
  796. if (item.id == e.markerId) {
  797. if (item.type == 2) {
  798. item.iconPath = 'http://resource.weilaigo.l4j.cn/orange-stop.png'
  799. that.setData({
  800. stop_info: item,
  801. stop_type: 2
  802. })
  803. }
  804. if (item.type == 1) {
  805. item.iconPath = 'http://resource.weilaigo.l4j.cn/ban-stop.png'
  806. that.setData({
  807. stop_info: item,
  808. stop_type: 1
  809. })
  810. }
  811. } else {
  812. if (item.type == 2) {
  813. item.iconPath = 'http://resource.weilaigo.l4j.cn/stop1.png'
  814. }
  815. if (item.type == 1) {
  816. item.iconPath = 'http://resource.weilaigo.l4j.cn/ban-stop.png'
  817. }
  818. }
  819. }
  820. // console.log(markers)
  821. this.setData({
  822. stopShow: true,
  823. markers
  824. })
  825. },
  826. stopP: function () {
  827. var that = this;
  828. var data1 = {
  829. 'area_id': that.data.id
  830. }
  831. that.setData({
  832. markers: []
  833. })
  834. app.request('/parking/stop-sites', data1, 'GET').then(res => {
  835. console.log(res)
  836. if (res.statusCode == 200) {
  837. var data = res.data
  838. that.setData({
  839. polygons: that.data.polygons1.concat(data.polygons),
  840. markers: data.centres
  841. })
  842. }
  843. })
  844. },
  845. refresh: util.throttle(function () {
  846. //点击刷新
  847. var that = this;
  848. that.setData({
  849. polygons: []
  850. })
  851. if (this.data.stopP == true) {
  852. that.stopP(), wx.showToast({
  853. title: '刷新成功',
  854. icon: 'none'
  855. })
  856. } else {
  857. this.location(), wx.showToast({
  858. title: '刷新成功',
  859. icon: 'none'
  860. })
  861. }
  862. }, 1500),
  863. authentication: util.throttle(function () {
  864. //点击去实名认证
  865. var state = wx.getStorageSync('userState')
  866. if (state.is_bind_mobile == 0) {
  867. wx.navigateTo({
  868. url: '/pages/real_name/real_name?state1=1&index=0',
  869. })
  870. } else if (state.is_bind_mobile == 1) {
  871. wx.navigateTo({
  872. url: '/pages/real_name/real_name?state2=2&index=1',
  873. })
  874. }
  875. this.setData({
  876. background: false,
  877. realname: false,
  878. over: false
  879. })
  880. }, 1500),
  881. sweep_code: util.throttle(function () {
  882. //点击扫码开锁
  883. var that = this;
  884. // wx.getLocation({
  885. // success: function (res) {
  886. that.map()
  887. // console.log(that.data.userStatus.is_pay_order)
  888. if (wx.getStorageSync('setting') == '') {
  889. wx.getLocation({
  890. success: function (res) {
  891. wx.showModal({
  892. title: '提示',
  893. content: '您附近暂无运营区域~',
  894. showCancel: false
  895. })
  896. },
  897. fail: function (err) {
  898. that.setData({
  899. location: true
  900. })
  901. }
  902. })
  903. return;
  904. }
  905. if(that.data.userStatus.is_punishment){
  906. wx.showModal({
  907. title: '提示',
  908. content:'您当前有违章订单需要处理,请处理后再来用车吧!',
  909. confirmText:'去处理',
  910. success:function(res){
  911. if(res.confirm){
  912. wx.navigateTo({
  913. url: '/pages/fine/fine',
  914. })
  915. }
  916. }
  917. })
  918. return;
  919. }
  920. if (that.data.userStatus.is_pay_order != false && that.data.userStatus.is_pay_order != undefined) {
  921. that.setData({
  922. is_pay_order: 1,
  923. background: true
  924. })
  925. return;
  926. } else if (that.data.userStatus.is_pay_rent_order != false && that.data.userStatus.is_pay_rent_order != undefined) {
  927. that.setData({
  928. is_pay_order: 1,
  929. background: true
  930. })
  931. return;
  932. } else {
  933. if (wx.getStorageSync('userInfo').avatar_url != null && wx.getStorageSync('userInfo') != '') {
  934. if (that.data.userStatus.is_card_certified == 0) {
  935. that.setData({
  936. realname: true,
  937. background: true,
  938. over: true
  939. })
  940. return;
  941. } else if (that.data.userStatus.is_bind_mobile == 0) {
  942. wx.showModal({
  943. title: '提示',
  944. content: '您还未绑定手机号,去绑定?',
  945. success: function (res) {
  946. if (res.confirm) {
  947. wx.navigateTo({
  948. url: '/pages/real_name/real_name?state1=1&index=0',
  949. })
  950. }
  951. }
  952. })
  953. return;
  954. } else {
  955. if (that.data.userStatus.is_deposit == 0) {
  956. that.setData({
  957. deposit: true,
  958. background: true
  959. })
  960. return;
  961. } else {
  962. wx.scanCode({
  963. onlyFromCamera: true,
  964. success: function (res) {
  965. // console.log(res)
  966. var index = res.result.lastIndexOf("\=");
  967. var code = res.result.substring(index + 1, res.result.length);
  968. console.log(code.length)
  969. if (code.length == 11) {
  970. wx.navigateTo({
  971. url: '../sweep_code/sweep_code?code=' + code,
  972. })
  973. } else {
  974. wx.showToast({
  975. title: '请扫描正确的二维码!',
  976. icon: 'none'
  977. })
  978. }
  979. },
  980. fail: function (err) {
  981. console.log(err)
  982. that.setData({
  983. background: true,
  984. scanfail: true,
  985. over1: true
  986. })
  987. }
  988. })
  989. }
  990. }
  991. } else {
  992. wx.reLaunch({
  993. url: '../authentication/authentication',
  994. })
  995. }
  996. }
  997. // },
  998. // fail: function (err) {
  999. // console.log(err,'Mead')
  1000. // that.setData({
  1001. // location: true
  1002. // })
  1003. // }
  1004. // })
  1005. }, 1500),
  1006. think: util.throttle(function () {
  1007. //点击我再想想 关闭弹窗和背景
  1008. this.setData({
  1009. background: false,
  1010. deposit: false,
  1011. over: false
  1012. })
  1013. }, 1500),
  1014. deposit: util.throttle(function () {
  1015. //点击现在就去 跳到交押金页面
  1016. this.setData({
  1017. background: false,
  1018. deposit: false,
  1019. over: false
  1020. })
  1021. wx.navigateTo({
  1022. url: '/pages/personal/deposit/deposit?home=index',
  1023. })
  1024. }, 1500),
  1025. cancel: util.throttle(function () {
  1026. //点击取消,下次吧
  1027. this.setData({
  1028. is_pay_order: false,
  1029. background: false
  1030. })
  1031. }, 1500),
  1032. go_pay: util.throttle(function () {
  1033. //点击去支付
  1034. this.setData({
  1035. is_pay_order: false,
  1036. background: false
  1037. })
  1038. var pay_order = ''
  1039. var rent = ''
  1040. if (this.data.userStatus.is_pay_order != false && this.data.userStatus.is_pay_order != undefined) {
  1041. pay_order = this.data.userStatus.is_pay_order
  1042. }
  1043. if (this.data.userStatus.is_pay_rent_order != false && this.data.userStatus.is_pay_rent_order != undefined) {
  1044. pay_order = this.data.userStatus.is_pay_rent_order;
  1045. rent = 'rent'
  1046. }
  1047. // console.log(rent)
  1048. wx.navigateTo({
  1049. url: '/pages/payment/payment?order=' + pay_order + '&rent=' + rent,
  1050. })
  1051. }, 1500),
  1052. over: function () {
  1053. //如果当前未实名 弹窗显示后 点击关闭按钮
  1054. this.setData({
  1055. realname: false,
  1056. background: false,
  1057. scanfail: false,
  1058. over1: false,
  1059. over: false,
  1060. })
  1061. },
  1062. onShow: function () {
  1063. wx.startLocationUpdate({
  1064. success: (res) => {
  1065. console.log(res)
  1066. }
  1067. })
  1068. wx.onLocationChange((res)=>{
  1069. this.setData({site:res})
  1070. })
  1071. var that = this;
  1072. token = wx.getStorageSync('token')
  1073. this.setData({
  1074. show: false,
  1075. midbolear: wx.getStorageSync('midTimes'),
  1076. polygons: []
  1077. })
  1078. this.location();
  1079. this.getUser();
  1080. this.userState();
  1081. wx.hideHomeButton();
  1082. },
  1083. onReady: function () {
  1084. },
  1085. kefu: util.throttle(function () {
  1086. wx.makePhoneCall({
  1087. phoneNumber: wx.getStorageSync('home').customer_service_phone,
  1088. })
  1089. }, 1500),
  1090. userState: function () {
  1091. var that = this;
  1092. if (token != '') {
  1093. wx.request({
  1094. url: http.url + '/user/status',
  1095. header: {
  1096. 'content-type': 'application/x-www-form-urlencoded',
  1097. Authorization: token
  1098. },
  1099. method: 'GET',
  1100. success: function (res) {
  1101. // console.log(res)
  1102. if (res.statusCode == 200) {
  1103. that.setData({
  1104. userStatus: res.data,
  1105. is_pay_order: res.data.is_pay_order
  1106. }), wx.setStorageSync('userState', res.data)
  1107. if (res.data.status == 0) {
  1108. that.setData({
  1109. abnormal: true,
  1110. background: true
  1111. })
  1112. return;
  1113. }
  1114. if (that.data.userStatus.is_ride_order != false) {
  1115. wx.reLaunch({
  1116. url: '/pages/riding/riding?order=' + that.data.userStatus.is_ride_order,
  1117. })
  1118. return;
  1119. }
  1120. if (that.data.userStatus.is_rent_order != false) {
  1121. wx.reLaunch({
  1122. url: '/pages/daily_riding/daily_riding?order=' + that.data.userStatus.is_rent_order,
  1123. })
  1124. return;
  1125. }
  1126. if (that.data.userStatus.is_pay_order != false) {
  1127. that.setData({
  1128. background: true,
  1129. is_pay_order: true
  1130. })
  1131. return;
  1132. }
  1133. if (that.data.userStatus.is_pay_rent_order != false) {
  1134. that.setData({
  1135. background: true,
  1136. is_pay_order: true
  1137. })
  1138. return;
  1139. }
  1140. if(that.data.userStatus.is_punishment){
  1141. console.log(that.data.userStatus)
  1142. wx.showModal({
  1143. title: '提示',
  1144. content:'您当前有违章订单需要处理,请处理后再来用车吧!',
  1145. confirmText:'去处理',
  1146. success:function(res){
  1147. if(res.confirm){
  1148. wx.navigateTo({
  1149. url: '/pages/fine/fine',
  1150. })
  1151. }
  1152. }
  1153. })
  1154. return;
  1155. }
  1156. 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) {
  1157. wx.navigateTo({
  1158. url: '../sweep_code/sweep_code?code=' + that.data.bike_no,
  1159. })
  1160. return;
  1161. }
  1162. if (wx.getStorageSync('userInfo').avatar_url != null && wx.getStorageSync('userInfo') != '' && that.data.bike_no != undefined) {
  1163. if (that.data.userStatus.is_card_certified == 0 && that.data.bike_no != undefined) {
  1164. that.setData({
  1165. realname: true,
  1166. background: true,
  1167. over: true
  1168. })
  1169. return;
  1170. } else if (that.data.userStatus.is_bind_mobile == 0 && that.data.bike_no != undefined) {
  1171. wx.showModal({
  1172. title: '提示',
  1173. content: '您还未绑定手机号,去绑定?',
  1174. success: function (res) {
  1175. if (res.confirm) {
  1176. wx.navigateTo({
  1177. url: '/pages/real_name/real_name?state1=1&index=0',
  1178. })
  1179. }
  1180. }
  1181. })
  1182. return;
  1183. } else {
  1184. if (that.data.userStatus.is_deposit == 0 && that.data.bike_no != undefined) {
  1185. that.setData({
  1186. deposit: true,
  1187. background: true
  1188. })
  1189. return;
  1190. }
  1191. }
  1192. } else {
  1193. // wx.redirectTo({
  1194. // url: '../authentication/authentication',
  1195. // })
  1196. }
  1197. }
  1198. },
  1199. fail: function (err) {
  1200. wx.showToast({
  1201. title: err,
  1202. icon: 'none',
  1203. mask: true
  1204. })
  1205. }
  1206. })
  1207. }
  1208. },
  1209. getUser() {
  1210. if (token != '') {
  1211. wx.request({
  1212. url: http.url + '/me',
  1213. header: {
  1214. 'content-type': 'application/x-www-form-urlencoded',
  1215. Authorization: token
  1216. },
  1217. method: 'GET',
  1218. success: function (res) {
  1219. // console.log(res)
  1220. 200 == res.statusCode && wx.setStorageSync("userInfo", res.data)
  1221. }
  1222. })
  1223. } else {
  1224. // wx.navigateTo({
  1225. // url: '/pages/authentication/authentication',
  1226. // })
  1227. }
  1228. },
  1229. lookCar: util.throttle(function (e) {
  1230. // console.log(e)
  1231. wx.showLoading({
  1232. title: '找车中...',
  1233. mask: true
  1234. })
  1235. bluM.connectDeivece(e.currentTarget.dataset.box_no).then(res => {
  1236. // console.log('bellbike ===>')
  1237. return bluM.bellBike()
  1238. }, rej => {
  1239. //抛出异常 当前蓝牙不可用
  1240. // console.log(rej, 123)
  1241. app.request('/bike/find/' + e.currentTarget.dataset.id, '', 'GET').then(res => {
  1242. // console.log(res)
  1243. if (res.statusCode == 200) {
  1244. res.data.is_ok == true && wx.showToast({
  1245. title: '找车成功',
  1246. icon: 'none',
  1247. duration: 2000
  1248. })
  1249. res.data.is_ok == false && wx.showToast({
  1250. title: '找车失败请重试',
  1251. icon: 'none',
  1252. duration: 2000
  1253. })
  1254. } else {
  1255. wx.showToast({
  1256. title: res.data.message,
  1257. icon: 'none',
  1258. duration: 2000,
  1259. mask: true
  1260. })
  1261. }
  1262. })
  1263. }).then(res => {
  1264. // console.log(res, 1234)
  1265. }, rej => {
  1266. // console.log(rej, 12345)
  1267. app.request('/bike/find/' + e.currentTarget.dataset.id, '', 'GET').then(res => {
  1268. // console.log(res)
  1269. if (res.statusCode == 200) {
  1270. res.data.is_ok == true && wx.showToast({
  1271. title: '找车成功',
  1272. icon: 'none',
  1273. duration: 2000
  1274. })
  1275. res.data.is_ok == false && wx.showToast({
  1276. title: '找车失败请重试',
  1277. icon: 'none',
  1278. duration: 2000
  1279. })
  1280. } else {
  1281. wx.showToast({
  1282. title: res.data.message,
  1283. icon: 'none',
  1284. duration: 2000
  1285. })
  1286. }
  1287. })
  1288. })
  1289. }, 1000),
  1290. usage: util.throttle(function () {
  1291. this.map()
  1292. wx.navigateTo({
  1293. url: '/pages/accounting_rules/accounting_rules',
  1294. })
  1295. }, 1500),
  1296. help: util.throttle(function () {
  1297. //点击如何用车 跳到如何用车页面
  1298. this.map()
  1299. wx.navigateTo({
  1300. url: '../personal/help/help',
  1301. })
  1302. }, 1500),
  1303. go_setting: util.throttle(function () {
  1304. //点击去设置位置权限
  1305. this.setData({
  1306. background: false,
  1307. location: false
  1308. })
  1309. wx.openSetting({
  1310. success: function (res) {
  1311. // console.log(res)
  1312. // console.log(res.authSetting)
  1313. }
  1314. })
  1315. }, 1500),
  1316. open: util.throttle(function () {
  1317. //点击已打开
  1318. this.setData({
  1319. background: false,
  1320. location: false
  1321. })
  1322. }, 1500),
  1323. navgiate: util.throttle(function (e) {
  1324. console.log(e)
  1325. if (this.data.stop_type == 1) return;
  1326. var latitude = this.data.stop_info.latitude;
  1327. var longitude = this.data.stop_info.longitude;
  1328. var name = this.data.stop_info.name;
  1329. wx.openLocation({ //​使用微信内置地图查看位置。
  1330. latitude: latitude, //要去的纬度-地址
  1331. longitude: longitude, //要去的经度-地址
  1332. name: name
  1333. })
  1334. }, 1000),
  1335. location: function () {
  1336. //获取当前经纬度 如果未授权让用户去授权
  1337. var that = this;
  1338. wx.showLoading({
  1339. title: '定位中...',
  1340. mask: true
  1341. })
  1342. wx.getLocation({
  1343. type: 'gcj02',
  1344. success: (res) => {
  1345. console.log('经纬度为:+++++++++++++++++++++' + res.latitude + '++++++++' + res.longitude)
  1346. var latitude = res.latitude
  1347. var longitude = res.longitude
  1348. that.setData({
  1349. longitude: longitude,
  1350. latitude: latitude,
  1351. show: false
  1352. })
  1353. if (that.data.stopP == false) {
  1354. console.log('false')
  1355. that.home(), that.nearbyCars()
  1356. }else{
  1357. that.stop()
  1358. }
  1359. wx.hideLoading()
  1360. },
  1361. fail: function () {
  1362. wx.hideLoading()
  1363. wx.getSetting({
  1364. success: function (res) {
  1365. // console.log(res)
  1366. var statu = res.authSetting;
  1367. if (statu['scope.userLocation'] == false) {
  1368. that.setData({
  1369. background: true,
  1370. location: true
  1371. })
  1372. }
  1373. }
  1374. })
  1375. }
  1376. })
  1377. },
  1378. onHide: function () {
  1379. console.log('onHide')
  1380. this.setData({
  1381. bike_no: undefined,
  1382. background: false,
  1383. bluetooth: false,
  1384. location: false,
  1385. scanfail: false,
  1386. over1: false
  1387. })
  1388. wx.offLocationChange()
  1389. wx.stopLocationUpdate({
  1390. success: (res) => {
  1391. console.log(res,"+++>")
  1392. },
  1393. })
  1394. // clearInterval(mytime)
  1395. },
  1396. onUnload: function () {
  1397. console.log('onUnload')
  1398. },
  1399. onShareAppMessage: function () {
  1400. },
  1401. //用户隐私协议
  1402. // 同意
  1403. agree(e) {
  1404. // this.posi()
  1405. var that = this;
  1406. this.location()
  1407. },
  1408. //不同意
  1409. disagree(e) {
  1410. console.log("用户拒绝隐私授权, 未同意过的隐私协议中的接口将不能调用")
  1411. // wx.exitMiniProgram()
  1412. },
  1413. })