sweep_code.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  1. var app = getApp()
  2. import {
  3. BluetoothManager,
  4. CMD
  5. } from '../../service/BluWkm'
  6. const bluM = new BluetoothManager;
  7. const util = require('../../utils/utils.js');
  8. var interval;
  9. Page({
  10. data: {
  11. useBikeTip: true,
  12. code: '',
  13. arr: [],
  14. screenHeight: '',
  15. show: false,
  16. popShow: false, //用车提醒
  17. time: 5,
  18. tapShow: false,
  19. setting: wx.getStorageSync('setting'),
  20. footer: [],
  21. chooseSize: false,
  22. mid: [],
  23. animationData: {},
  24. chooseSize: false,
  25. animationData1: {},
  26. arrowDown: '',
  27. midbolear: '',
  28. img:app.globalData.imgUrl,
  29. deposit:false,
  30. realname:false,
  31. background:false,
  32. over:false,
  33. userStatus:''
  34. },
  35. authentication: util.throttle(function () {
  36. //点击去实名认证
  37. var state = wx.getStorageSync('userState')
  38. if (state.is_bind_mobile == 0) {
  39. wx.navigateTo({
  40. url: '/pages/real_name/real_name?state1=1&index=0',
  41. })
  42. } else if (state.is_bind_mobile == 1) {
  43. wx.navigateTo({
  44. url: '/pages/real_name/real_name?state2=2&index=1',
  45. })
  46. }
  47. this.setData({
  48. background: false,
  49. realname: false,
  50. over: false
  51. })
  52. }, 1500),
  53. deposit: util.throttle(function () {
  54. //点击现在就去 跳到交押金页面
  55. this.setData({
  56. background: false,
  57. deposit: false,
  58. over: false
  59. })
  60. wx.navigateTo({
  61. url: '/pages/personal/deposit/deposit?home=index',
  62. })
  63. }, 1500),
  64. chooseSezi: function (e) {
  65. // 用that取代this,防止不必要的情况发生
  66. var that = this;
  67. // 创建一个动画实例
  68. var animation = wx.createAnimation({
  69. // 动画持续时间
  70. duration: 600,
  71. // 定义动画效果,当前是匀速
  72. timingFunction: 'linear'
  73. })
  74. // 将该变量赋值给当前动画
  75. that.animation = animation
  76. // 先在y轴偏移,然后用step()完成一个动画
  77. animation.translateY(300).step()
  78. // 用setData改变当前动画
  79. that.setData({
  80. // 通过export()方法导出数据
  81. animationData1: animation.export(),
  82. // 改变view里面的Wx:if
  83. chooseSize: true
  84. })
  85. // 设置setTimeout来改变y轴偏移量,实现有感觉的滑动
  86. setTimeout(function () {
  87. animation.translateY(0).step()
  88. that.setData({
  89. animationData1: animation.export()
  90. })
  91. }, 100)
  92. var query = wx.createSelectorQuery();
  93. query.select('.choose').boundingClientRect();
  94. query.exec(function (res) {
  95. console.log(res)
  96. that.setData({
  97. arrowDown: res[0].height + 15
  98. })
  99. })
  100. },
  101. hideModal: function (e) {
  102. var that = this;
  103. var animation = wx.createAnimation({
  104. duration: 800,
  105. timingFunction: 'linear'
  106. })
  107. that.animation = animation
  108. animation.translateY(300).step()
  109. that.setData({
  110. animationData1: animation.export()
  111. })
  112. setTimeout(function () {
  113. animation.translateY(0).step()
  114. that.setData({
  115. animationData1: animation.export(),
  116. chooseSize: false
  117. })
  118. }, 700)
  119. },
  120. ads: function () {
  121. var that = this;
  122. var area_id = ''
  123. if (wx.getStorageSync('home').id != undefined) {
  124. area_id = wx.getStorageSync('home').id
  125. } else {
  126. area_id = 0
  127. }
  128. // var data = {
  129. // 'position': "['header','mid']",
  130. // 'area_id': area_id
  131. // }
  132. app.request("/ads?area_id=" + area_id + "&position[]=mid&position[]=header&position[]=footer", '', "GET").then(res => {
  133. // console.log(res)
  134. if (res.statusCode == 200) {
  135. that.setData({
  136. ads: res.data.header
  137. })
  138. if (res.data.mid == undefined || res.data.mid == 'undefined') {
  139. } else {
  140. that.setData({
  141. mid: res.data.mid
  142. })
  143. }
  144. if (res.data.footer == undefined || res.data.footer == 'undefined') {
  145. } else {
  146. that.setData({
  147. footer: res.data.footer
  148. })
  149. }
  150. }
  151. }).catch(err => {
  152. console.log(err)
  153. })
  154. },
  155. onLoad: function (options) {
  156. console.log(options)
  157. var that = this;
  158. var state = wx.getStorageSync('userState')
  159. if(state.is_new_user==1){
  160. that.setData({
  161. useBikeTip:false
  162. })
  163. console.log(that.data.useBikeTip)
  164. }else{
  165. that.setData({
  166. useBikeTip:true
  167. })
  168. }
  169. wx.showLoading({
  170. title: '加载中...',
  171. mask: true
  172. })
  173. if (wx.getStorageSync('popShow') != true) {
  174. that.setData({
  175. popShow: true
  176. })
  177. } else {
  178. that.setData({
  179. popShow: false
  180. })
  181. }
  182. interval = setInterval(function () {
  183. var time = that.data.time - 1;
  184. that.setData({
  185. time
  186. })
  187. if (time <= 0) {
  188. clearInterval(interval)
  189. that.setData({
  190. tapShow: true
  191. })
  192. }
  193. }, 1000)
  194. this.setData({
  195. screenHeight: app.globalData.screenHeight
  196. })
  197. app.request('/bike/' + options.code, '', 'GET').then(res => {
  198. console.log(res)
  199. 200 == res.statusCode && that.setData({
  200. arr: res.data
  201. }), wx.hideLoading()
  202. if (res.statusCode == 200) {
  203. if (res.data.is_link == 0) {
  204. wx.showModal({
  205. title: '提示',
  206. content: '当前车子已下线请换辆车子骑行吧~',
  207. showCancel: false,
  208. success: function (res) {
  209. if (res.confirm) {
  210. wx.navigateBack()
  211. }
  212. }
  213. })
  214. return;
  215. } else if (res.data.put_status == 0) {
  216. wx.showModal({
  217. title: '提示',
  218. content: '当前车子还未投放请换辆车子骑行吧~',
  219. showCancel: false,
  220. success: function (res) {
  221. if (res.confirm) {
  222. wx.navigateBack()
  223. }
  224. }
  225. })
  226. return;
  227. } else if (res.data.is_low_battery_power == 0) {
  228. wx.showModal({
  229. title: '提示',
  230. content: '当前车子电量过低请换辆车子骑行吧~',
  231. showCancel: false,
  232. success: function (res) {
  233. if (res.confirm) {
  234. wx.navigateBack()
  235. }
  236. }
  237. })
  238. return;
  239. } else if (res.data.is_trouble == 1) {
  240. wx.showModal({
  241. title: '提示',
  242. content: '当前车子出现故障请换辆车子骑行吧~',
  243. showCancel: false,
  244. success: function (res) {
  245. if (res.confirm) {
  246. wx.navigateBack()
  247. }
  248. }
  249. })
  250. return;
  251. } else if (res.data.is_riding == 1) {
  252. wx.showModal({
  253. title: '提示',
  254. content: '当前车子正在骑行请换辆车子骑行吧~',
  255. showCancel: false,
  256. success: function (res) {
  257. if (res.confirm) {
  258. wx.navigateBack()
  259. }
  260. }
  261. })
  262. return;
  263. } else {
  264. // bluM.connectDeivece(res.data.box_no, CMD.bell)
  265. // wx.getBluetoothAdapterState({
  266. // success(res) {
  267. // console.log(res)
  268. // if (res.available == false) {
  269. // wx.showModal({
  270. // title: '提示',
  271. // content: '手动开启蓝牙体验快速开锁~',
  272. // showCancel: false
  273. // })
  274. // }
  275. // }
  276. // })
  277. }
  278. }
  279. })
  280. that.setData({
  281. code: options.code
  282. })
  283. setTimeout(() => {
  284. that.ads();
  285. }, 500);
  286. },
  287. rules: function () {
  288. wx.navigateTo({
  289. url: "/pages/accounting_rules/accounting_rules",
  290. })
  291. },
  292. view_area: function () {
  293. wx.navigateTo({
  294. url: '/pages/navigation/navigation',
  295. })
  296. },
  297. closePop() {
  298. this.setData({
  299. popShow: false,
  300. })
  301. wx.setStorageSync('popShow', true)
  302. },
  303. repair: util.throttle(function () {
  304. wx.navigateTo({
  305. url: '../repair/repair?bike_id=' + this.data.code
  306. })
  307. }, 1000),
  308. openBike() {
  309. var that = this;
  310. wx.showLoading({
  311. title: '开锁中...',
  312. mask: true
  313. })
  314. wx.getLocation({
  315. type: 'gcj02',
  316. success: function (res) {
  317. console.log(res)
  318. var data = {
  319. bike_no: that.data.code,
  320. lat: res.latitude,
  321. lng: res.longitude,
  322. area_id: wx.getStorageSync('home').id,
  323. }
  324. bluM.connectDeivece(that.data.arr.box_no, CMD.unlock)
  325. app.request('/bike/open-lock', data, 'POST', app.globalData.req).then(res => {
  326. console.log(res)
  327. if (res.statusCode == 200) {
  328. wx.reLaunch({
  329. url: '../riding/riding?order=' + res.data.no + '&code=' + that.data.code + '&box_no=' + that.data.arr.box_no + '&time=true',
  330. })
  331. wx.hideLoading()
  332. }
  333. })
  334. },
  335. })
  336. },
  337. think:function () {
  338. //点击我再想想 关闭弹窗和背景
  339. this.setData({
  340. background: false,
  341. deposit: false,
  342. over: false
  343. })
  344. },
  345. start: util.throttle(function () {
  346. var that = this;
  347. that.jiance()
  348. if(that.data.deposit==true) return;
  349. wx.getLocation({
  350. success: function (res) {
  351. wx.requestSubscribeMessage({
  352. tmplIds: ['CBp8jWZHVOQBIB7_n4EHuDv3ik12gOvlaXsOG2U0dPc', 'rV85SkGp7Q508xXz45ycQw8nTN_2VEB7m_GhR-WrCDY'],
  353. success(res) {
  354. console.log(res)
  355. },
  356. fail: function (err) {
  357. console.log(err)
  358. },
  359. complete: function () {
  360. }
  361. })
  362. },
  363. fail: function (err) {
  364. wx.showModal({
  365. title: '提示',
  366. content: '请打开位置权限~',
  367. cancelText: "去设置",
  368. confirmText: "已打开",
  369. success: function (resp) {
  370. if (resp.cancel) {
  371. wx.openSetting({
  372. success: function (res) {
  373. // console.log(res)
  374. // console.log(res.authSetting)
  375. }
  376. })
  377. }
  378. }
  379. })
  380. }
  381. })
  382. }, 1000),
  383. rent_start: function () {
  384. this.setData({
  385. show: true
  386. })
  387. },
  388. over: function () {
  389. //如果当前未实名 弹窗显示后 点击关闭按钮
  390. this.setData({
  391. realname: false,
  392. background: false,
  393. scanfail: false,
  394. over: false,
  395. })
  396. },
  397. jiance:function(){
  398. var userStatus = this.data.userStatus;
  399. var setting = wx.getStorageSync('setting');
  400. console.log(userStatus)
  401. console.log(setting)
  402. var that = this;
  403. if (setting.is_card == 1) {
  404. if (userStatus.is_card_certified == 0) {
  405. that.setData({
  406. realname: true,
  407. background: true,
  408. over: true
  409. })
  410. return;
  411. }
  412. }
  413. if (userStatus.is_bind_mobile == 0) {
  414. wx.showModal({
  415. title: '提示',
  416. content: '您还未绑定手机号,去绑定?',
  417. success: function (res) {
  418. if (res.confirm) {
  419. wx.navigateTo({
  420. url: '/pages/real_name/real_name?state1=1&index=0',
  421. })
  422. }
  423. }
  424. })
  425. return;
  426. }
  427. if (userStatus.is_deposit == 0 && setting.is_deposit != 0 && userStatus.is_coupon_deposit_free == false) {
  428. console.log('else===>else===>else if')
  429. that.setData({
  430. deposit: true,
  431. background: true
  432. })
  433. return;
  434. }else{
  435. this.openBike()
  436. }
  437. // if (userStatus.is_card_certified == 0 && setting.is_card !=0) {
  438. // this.setData({
  439. // realname: true,
  440. // background: true,
  441. // over: true
  442. // })
  443. // return;
  444. // } else {
  445. // if (userStatus.is_deposit == 0 && setting.is_deposit != 0 && userStatus.is_coupon_deposit_free==false) {
  446. // this.setData({
  447. // deposit: true,
  448. // background: true
  449. // })
  450. // return;
  451. // }else{
  452. // }
  453. // }
  454. },
  455. rent_startBike() {
  456. var that = this;
  457. if(that.data.deposit==true) return;
  458. wx.getLocation({
  459. success: function (res) {
  460. console.log(res)
  461. if (app.globalData.req) {
  462. var data = {
  463. 'type': 'D',
  464. 'bike_no': that.data.code,
  465. 'area_id': wx.getStorageSync('home').id,
  466. 'lat': res.latitude,
  467. 'lng': res.longitude
  468. }
  469. app.request('/rent/store-order', data, 'POST', app.globalData.req).then(res => {
  470. console.log(res)
  471. if (res.statusCode == 200) {
  472. console.log(res.data.nonceStr == undefined)
  473. if (res.data.nonceStr == undefined) {
  474. wx.reLaunch({
  475. url: '/pages/daily_riding/daily_riding?order=' + res.data.no,
  476. })
  477. } else {
  478. wx.reLaunch({
  479. url: '/pages/daily_riding/daily_riding?order=' + res.data.no,
  480. })
  481. }
  482. }
  483. })
  484. } else {
  485. wx.showToast({
  486. title: '您的操作过于频繁,请稍后再试~',
  487. icon: 'none'
  488. })
  489. }
  490. },
  491. })
  492. },
  493. btn: util.throttle(function () {
  494. var that = this;
  495. // that.rent_startBike()
  496. wx.getLocation({
  497. success: function (res) {
  498. wx.requestSubscribeMessage({
  499. tmplIds: ['ahWdpxZJ48d3K9ZxnrNvXLvx7NEI2j-Ckp5LODNlYNU', 'N7etCOUMjvsyGxx0JroDfMwEmi8daKC20czG6aqkpPc'],
  500. success(res) {
  501. console.log(res)
  502. },
  503. fail: function (err) {
  504. console.log(err)
  505. },
  506. complete: function () {
  507. that.rent_startBike()
  508. }
  509. })
  510. },
  511. fail: function (err) {
  512. wx.showModal({
  513. title: '提示',
  514. content: '请打开位置权限~',
  515. cancelText: "去设置",
  516. confirmText: "已打开",
  517. success: function (resp) {
  518. if (resp.cancel) {
  519. wx.openSetting({
  520. success: function (res) {
  521. // console.log(res)
  522. // console.log(res.authSetting)
  523. }
  524. })
  525. }
  526. }
  527. })
  528. }
  529. })
  530. }, 1000),
  531. over: function () {
  532. this.setData({
  533. show: false
  534. })
  535. },
  536. iKnow: function (e) {
  537. console.log(e)
  538. this.setData({
  539. useBikeTip: true
  540. })
  541. console.log(this.data.useBikeTip)
  542. },
  543. onReady: function () {
  544. },
  545. onShow: function () {
  546. this.setData({
  547. setting: wx.getStorageSync('setting')
  548. })
  549. var data = {
  550. 'area_id': wx.getStorageSync('mead_area_id')
  551. }
  552. app.request("/user/status", data, "GET").then(res=>{
  553. console.log(res)
  554. this.setData({userStatus:res.data})
  555. wx.setStorageSync('userState', res.data)
  556. })
  557. },
  558. onHide: function () {
  559. clearInterval(interval)
  560. this.setData({
  561. time: 5
  562. })
  563. },
  564. onUnload: function () {
  565. clearInterval(interval)
  566. this.setData({
  567. time: 5
  568. })
  569. },
  570. //用户隐私协议
  571. // 同意
  572. agree(e) {
  573. wx.getLocation({
  574. type: 'gcj02',
  575. success: (res) => {
  576. console.log('经纬度为:+++++++++++++++++++++' + res.latitude + '++++++++' + res.longitude)
  577. var latitude = res.latitude
  578. var longitude = res.longitude
  579. that.setData({
  580. longitude: longitude,
  581. latitude: latitude
  582. })
  583. },
  584. fail: function (err) {
  585. console.log(err)
  586. }
  587. })
  588. },
  589. //不同意
  590. disagree(e) {
  591. console.log("用户拒绝隐私授权, 未同意过的隐私协议中的接口将不能调用")
  592. // wx.exitMiniProgram()
  593. },
  594. onPullDownRefresh: function () {
  595. },
  596. onReachBottom: function () {
  597. },
  598. onShareAppMessage: function () {
  599. }
  600. })