sweep_code.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  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. useruserState:wx.getStorageSync('userState')
  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. that.openBike()
  361. }
  362. })
  363. },
  364. fail: function (err) {
  365. wx.showModal({
  366. title: '提示',
  367. content: '请打开位置权限~',
  368. cancelText: "去设置",
  369. confirmText: "已打开",
  370. success: function (resp) {
  371. if (resp.cancel) {
  372. wx.openSetting({
  373. success: function (res) {
  374. // console.log(res)
  375. // console.log(res.authSetting)
  376. }
  377. })
  378. }
  379. }
  380. })
  381. }
  382. })
  383. }, 1000),
  384. rent_start: function () {
  385. this.setData({
  386. show: true
  387. })
  388. },
  389. over: function () {
  390. //如果当前未实名 弹窗显示后 点击关闭按钮
  391. this.setData({
  392. realname: false,
  393. background: false,
  394. scanfail: false,
  395. over: false,
  396. })
  397. },
  398. jiance:function(){
  399. var userStatus = wx.getStorageSync('userState');
  400. var setting = wx.getStorageSync('setting');
  401. if (userStatus.is_card_certified == 0 && setting.is_card !=0) {
  402. this.setData({
  403. realname: true,
  404. background: true,
  405. over: true
  406. })
  407. return;
  408. } else if (userStatus.is_bind_mobile == 0) {
  409. wx.showModal({
  410. title: '提示',
  411. content: '您还未绑定手机号,去绑定?',
  412. success: function (res) {
  413. if (res.confirm) {
  414. wx.navigateTo({
  415. url: '/pages/real_name/real_name?state1=1&index=0',
  416. })
  417. }
  418. }
  419. })
  420. return;
  421. } else {
  422. if (userStatus.is_deposit == 0 && setting.is_deposit != 0 && userStatus.is_coupon_deposit_free==false) {
  423. this.setData({
  424. deposit: true,
  425. background: true
  426. })
  427. return;
  428. }
  429. }
  430. },
  431. rent_startBike() {
  432. var that = this;
  433. if(that.data.deposit==true) return;
  434. wx.getLocation({
  435. success: function (res) {
  436. console.log(res)
  437. if (app.globalData.req) {
  438. var data = {
  439. 'type': 'D',
  440. 'bike_no': that.data.code,
  441. 'area_id': wx.getStorageSync('home').id,
  442. 'lat': res.latitude,
  443. 'lng': res.longitude
  444. }
  445. app.request('/rent/store-order', data, 'POST', app.globalData.req).then(res => {
  446. console.log(res)
  447. if (res.statusCode == 200) {
  448. console.log(res.data.nonceStr == undefined)
  449. if (res.data.nonceStr == undefined) {
  450. wx.reLaunch({
  451. url: '/pages/daily_riding/daily_riding?order=' + res.data.no,
  452. })
  453. } else {
  454. wx.reLaunch({
  455. url: '/pages/daily_riding/daily_riding?order=' + res.data.no,
  456. })
  457. }
  458. }
  459. })
  460. } else {
  461. wx.showToast({
  462. title: '您的操作过于频繁,请稍后再试~',
  463. icon: 'none'
  464. })
  465. }
  466. },
  467. })
  468. },
  469. btn: util.throttle(function () {
  470. var that = this;
  471. // that.rent_startBike()
  472. wx.getLocation({
  473. success: function (res) {
  474. wx.requestSubscribeMessage({
  475. tmplIds: ['ahWdpxZJ48d3K9ZxnrNvXLvx7NEI2j-Ckp5LODNlYNU', 'N7etCOUMjvsyGxx0JroDfMwEmi8daKC20czG6aqkpPc'],
  476. success(res) {
  477. console.log(res)
  478. },
  479. fail: function (err) {
  480. console.log(err)
  481. },
  482. complete: function () {
  483. that.rent_startBike()
  484. }
  485. })
  486. },
  487. fail: function (err) {
  488. wx.showModal({
  489. title: '提示',
  490. content: '请打开位置权限~',
  491. cancelText: "去设置",
  492. confirmText: "已打开",
  493. success: function (resp) {
  494. if (resp.cancel) {
  495. wx.openSetting({
  496. success: function (res) {
  497. // console.log(res)
  498. // console.log(res.authSetting)
  499. }
  500. })
  501. }
  502. }
  503. })
  504. }
  505. })
  506. }, 1000),
  507. over: function () {
  508. this.setData({
  509. show: false
  510. })
  511. },
  512. iKnow: function (e) {
  513. console.log(e)
  514. this.setData({
  515. useBikeTip: true
  516. })
  517. console.log(this.data.useBikeTip)
  518. },
  519. onReady: function () {
  520. },
  521. onShow: function () {
  522. this.setData({
  523. setting: wx.getStorageSync('setting')
  524. })
  525. },
  526. onHide: function () {
  527. clearInterval(interval)
  528. this.setData({
  529. time: 5
  530. })
  531. },
  532. onUnload: function () {
  533. clearInterval(interval)
  534. this.setData({
  535. time: 5
  536. })
  537. },
  538. onPullDownRefresh: function () {
  539. },
  540. onReachBottom: function () {
  541. },
  542. onShareAppMessage: function () {
  543. }
  544. })