index.js 37 KB

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