logs.js 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333
  1. const App = getApp()
  2. let regeneratorRuntime = require("../../utils/regenerator-runtime/runtime");
  3. //获取应用实例
  4. const app = getApp();
  5. var token = wx.getStorageSync('token');
  6. var http = require("../../utils/config.js");
  7. import {
  8. BluetoothManager,
  9. BtErrorCode
  10. } from '../../service/BlueMgr'
  11. const bluM = new BluetoothManager
  12. Page({
  13. data: {
  14. current: 3,
  15. bike_no: '', //车牌号
  16. hintShow: false, //是否显示提示弹窗
  17. sideShow: false, //是否显示侧边栏
  18. footerShow: true,
  19. iconList1: [{
  20. icon: "http://resource.weilaibike.com/xiaobanma_yunwei/outline_xbm.png",
  21. con: "下线"
  22. },
  23. {
  24. icon: "http://resource.weilaibike.com/xiaobanma_yunwei/lowPower_xbm.png",
  25. con: "低电量"
  26. },
  27. {
  28. icon: "http://resource.weilaibike.com/xiaobanma_yunwei/noUser_xbm.png",
  29. con: "未使用"
  30. },
  31. {
  32. icon: "http://resource.weilaibike.com/trobole.png",
  33. con: "故障"
  34. },
  35. {
  36. icon: "http://resource.weilaibike.com/xiaobanma_yunwei/repair_xbm.png",
  37. con: "待维修"
  38. },
  39. {
  40. icon: "http://resource.weilaibike.com/xiaobanma_yunwei/noInPark_xbm.png",
  41. con: "未在停车区"
  42. },
  43. {
  44. icon: "http://resource.weilaibike.com/xiaobanma_yunwei/riding_xbm.png",
  45. con: "骑行中"
  46. },
  47. {
  48. icon: "http://resource.weilaibike.com/bike_yunwei/outLi.png",
  49. con: "离线"
  50. },
  51. {
  52. icon: "http://resource.weilaibike.com/bike_yunwei/work.png",
  53. con: "运维人员骑行"
  54. },
  55. ],
  56. markers: [], //显示单车、停车的P
  57. polygons: [], //区域
  58. longitude: '113.779801',
  59. latitude: '34.753993',
  60. // allArea: [{
  61. // text: '全部区域',
  62. // value: 0,
  63. // areaID: ''
  64. // }],
  65. allArea: [],
  66. allEle: [{
  67. text: '全部电量',
  68. value: 0,
  69. areaID: ''
  70. },
  71. {
  72. text: '70%以下',
  73. value: 1,
  74. areaID: '70'
  75. },
  76. {
  77. text: '60%以下',
  78. value: 2,
  79. areaID: '60'
  80. },
  81. {
  82. text: '50%以下',
  83. value: 3,
  84. areaID: '50'
  85. },
  86. {
  87. text: '30%以下',
  88. value: 4,
  89. areaID: '30'
  90. },
  91. {
  92. text: '20%以下',
  93. value: 5,
  94. areaID: '20'
  95. },
  96. ],
  97. allStatus: [{
  98. text: '全部状态',
  99. value: 0,
  100. areaID: ''
  101. }],
  102. allDay: [{
  103. text: '使用状态',
  104. value: 0
  105. },
  106. {
  107. text: '1天未使用',
  108. value: 1
  109. },
  110. {
  111. text: '3天未使用',
  112. value: 2
  113. },
  114. {
  115. text: '7天未使用',
  116. value: 3
  117. }
  118. ],
  119. area: 0,
  120. ele: 0,
  121. status: 0,
  122. day: 0,
  123. show: false, //车子详情的布尔值
  124. longitude: '113.779801',
  125. latitude: '34.753993',
  126. id: '', //停车区域的ID
  127. stopP: false, //判断是否显示停车区域
  128. polygons1: [], //可骑行区域 先用这个变量代表
  129. controls: [], //地图上当前定位的箭头
  130. background: '', //弹窗的背景颜色
  131. over: '', //关闭图标
  132. location: '', //是否有位置权限
  133. bluetooth: false, //是否开启蓝牙 false开始 true未开启
  134. box_no: '', //中控编号
  135. bikeDetail: [],
  136. bikeId: '',
  137. areaID: '',
  138. low_power: '',
  139. state: '',
  140. use_state: '',
  141. parkAreaShow: false, //还车点是否显示
  142. noParkAreaShow: true, //禁停区是否显示
  143. ridding: true,
  144. moreShow: false,
  145. screenHeight: '', //屏幕可视高度
  146. areas: [],
  147. parking: [],
  148. parking_points: [],
  149. no_parking: [],
  150. no_parking_points: [],
  151. parkShow: '',
  152. switch1Checked: '',
  153. delBtnWidth: 200, //删除或完成 按钮宽度
  154. typeName: '', //1 待认领工单 2已领工单
  155. page: 1, //当前页面
  156. workShow: false, //工单弹窗
  157. workCount: '', //侧边栏报修数量(未读)
  158. list: [], //工单列表
  159. workState: 1, //工单列表状态【1 待领取 2已领】
  160. repairsList: [], //报修列表
  161. repairsCount: '', //侧边栏工单数量(未认领)
  162. repairsState: 1, //报修列表状态【1 未读 2已读】
  163. repairsShow: false, //是否显示报修弹窗 【false 不显示 true 显示】
  164. topNum: 0,
  165. },
  166. touchS: function (e) {
  167. if (e.touches.length == 1) {
  168. this.setData({
  169. //设置触摸起始点水平方向位置
  170. startX: e.touches[0].clientX
  171. });
  172. }
  173. },
  174. touchM: function (e) {
  175. // console.log(this.data.list[index].txtStyle)
  176. // console.log(e);
  177. if (e.touches.length == 1) {
  178. //手指移动时水平方向位置
  179. var moveX = e.touches[0].clientX;
  180. //手指起始点位置与移动期间的差值
  181. var disX = this.data.startX - moveX;
  182. // console.log(disX,'disX')
  183. var delBtnWidth = this.data.delBtnWidth;
  184. var txtStyle = "";
  185. if (disX == 0 || disX < 0) { //如果移动距离小于等于0,文本层位置不变
  186. txtStyle = "left:0rpx";
  187. } else if (disX > 0) { //移动距离大于0,文本层left值等于手指移动距离
  188. txtStyle = "left:-" + disX + "rpx";
  189. if (disX >= delBtnWidth) {
  190. //控制手指移动距离最大值为删除按钮的宽度
  191. txtStyle = "left:-" + delBtnWidth + "rpx";
  192. }
  193. }
  194. //获取手指触摸的是哪一项
  195. var index = e.currentTarget.dataset.idx;
  196. var list = this.data.list;
  197. list[index].txtStyle = txtStyle;
  198. //更新列表的状态
  199. this.setData({
  200. list: list
  201. });
  202. }
  203. },
  204. touchE: function (e) {
  205. if (e.changedTouches.length == 1) {
  206. //手指移动结束后水平位置
  207. var endX = e.changedTouches[0].clientX;
  208. //触摸开始与结束,手指移动的距离
  209. var disX = this.data.startX - endX;
  210. var delBtnWidth = this.data.delBtnWidth;
  211. //如果距离小于删除按钮的1/2,不显示删除按钮
  212. var txtStyle = disX > delBtnWidth / 2 ? "left:-" + delBtnWidth + "rpx" : "left:0rpx";
  213. //获取手指触摸的是哪一项
  214. var index = e.currentTarget.dataset.idx;
  215. var list = this.data.list;
  216. list[index].txtStyle = txtStyle;
  217. //更新列表的状态
  218. this.setData({
  219. list: list
  220. });
  221. }
  222. },
  223. goTop: function (e) { // 一键回到顶部
  224. this.setData({
  225. topNum: 0
  226. });
  227. },
  228. // //获取元素自适应后的实际宽度
  229. // getEleWidth: function (w) {
  230. // var real = 0;
  231. // try {
  232. // var res = wx.getSystemInfoSync().windowWidth;
  233. // var scale = (750 / 2) / (w / 2); //以宽度750px设计稿做宽度的自适应
  234. // // console.log(scale);
  235. // real = Math.floor(res / scale);
  236. // return real;
  237. // } catch (e) {
  238. // return false;
  239. // // Do something when catch error
  240. // }
  241. // },
  242. // initEleWidth: function () {
  243. // var delBtnWidth = this.getEleWidth(this.data.delBtnWidth);
  244. // this.setData({
  245. // delBtnWidth: delBtnWidth
  246. // });
  247. // },
  248. async onLoad(options) {
  249. console.log(wx.getStorageSync('allArea'), 'allArea')
  250. var that = this;
  251. that.setData({
  252. screenHeight: app.globalData.screenHeight,
  253. })
  254. let timer = setTimeout(function () {
  255. if (wx.getStorageSync('allArea')) {
  256. let allArea = wx.getStorageSync('allArea')
  257. let allState = wx.getStorageSync('allState')
  258. that.setData({
  259. allArea,
  260. allStatus: allState
  261. })
  262. }
  263. console.log(that.data.allArea)
  264. let curVal = wx.getStorageSync('curVal')
  265. console.log(curVal, 'log_curVal')
  266. if (curVal) {
  267. that.setData({
  268. area: curVal
  269. })
  270. }
  271. let areaID = wx.getStorageSync('curId')
  272. console.log(areaID, 'log_areaID')
  273. if (areaID) {
  274. that.setData({
  275. areaID
  276. })
  277. } else {
  278. let id = that.data.allArea[0].areaID
  279. that.setData({
  280. areaID: id
  281. })
  282. }
  283. that.menu = that.selectComponent("#menu");
  284. that.menu.changeTitle(that.data.allArea[that.data.area].text);
  285. }, 500)
  286. that.posi(); //获取当前位置
  287. await this.initData(1)
  288. if (options.bike_no) {
  289. that.getBike_info(options.bike_no)
  290. }
  291. if (options.scan == 1) {
  292. this.scanCode();
  293. }
  294. that.getBikes();
  295. // that.lookWork();
  296. // that.initEleWidth();
  297. },
  298. // lookWork() {
  299. // let url = url = "work_order/list?planned=" + 1 + "&bike_no=" + 10010010101
  300. // app.request(url, '', 'GET').then(res => {
  301. // console.log(res)
  302. // this.setData({
  303. // list: res.data.data
  304. // })
  305. // })
  306. // },
  307. /*
  308. * 工单弹窗 报修弹窗 begin
  309. */
  310. //关闭弹窗
  311. coverHidn(e) {
  312. let show = e.currentTarget.dataset.show;
  313. if (show == 1) {
  314. this.setData({
  315. moreShow: false,
  316. workState: 1
  317. })
  318. } else if (show == 2) {
  319. this.setData({
  320. workShow: false,
  321. typeName: ''
  322. })
  323. } else if (show == 3) {
  324. this.setData({
  325. repairsShow: false,
  326. typeName: '',
  327. repairsState: 1
  328. })
  329. }
  330. },
  331. //点击可拨打电话
  332. phone(e) {
  333. console.log(1111)
  334. wx.makePhoneCall({
  335. phoneNumber: e.currentTarget.dataset.phone
  336. })
  337. },
  338. showPop(e) {
  339. let show = e.currentTarget.dataset.idx;
  340. this.setData({
  341. typeName: show
  342. })
  343. if (show == 1) {
  344. this.setData({
  345. workShow: true
  346. });
  347. this.lookWork();
  348. } else if (show == 2) {
  349. this.setData({
  350. repairsShow: true
  351. });
  352. this.lookRepairs();
  353. }
  354. },
  355. workChoose(e) {
  356. wx.showLoading({
  357. title: '加载中...',
  358. })
  359. let state = e.currentTarget.dataset.state;
  360. this.setData({
  361. workState: state,
  362. list: []
  363. })
  364. this.lookWork();
  365. this.goTop();
  366. },
  367. //工单列表
  368. lookWork() {
  369. wx.showLoading({
  370. title: '加载中...',
  371. })
  372. let that = this;
  373. let planned = '';
  374. let url = "";
  375. let state = that.data.workState
  376. // console.log(state, 'workState')
  377. if (state == 1) {
  378. planned = 1
  379. url = "work_order/list?planned=" + planned + "&bike_no=" + that.data.bikeId
  380. } else {
  381. let planned = 2;
  382. url = 'work_order/myWorkOrderList?planned=' + planned + "&bike_no=" + that.data.bikeId
  383. }
  384. app.request(url, '', 'GET').then(res => {
  385. wx.hideLoading();
  386. let work = res.data.data;
  387. // console.log(work, '工单列表')
  388. if (work.length == 0) {
  389. // wx.showToast({
  390. // title: '暂无工单~',
  391. // icon: 'none'
  392. // })
  393. that.setData({
  394. list: ''
  395. })
  396. } else {
  397. work.map(i => {
  398. i.txtStyle = 'left:0rpx'
  399. })
  400. that.setData({
  401. workShow: true,
  402. list: work
  403. })
  404. // console.log(that.data.list, 'list')
  405. }
  406. })
  407. },
  408. //接单
  409. getWork(e) {
  410. wx.showLoading({
  411. title: '领取中...',
  412. })
  413. let id = e.currentTarget.dataset.id
  414. console.log(id, 'getWorkid');
  415. app.request('work_order/receive?work_order_id=' + id, '', 'GET').then(res => {
  416. wx.hideLoading();
  417. console.log(res)
  418. if (res.statusCode == 200) {
  419. wx.showToast({
  420. title: '接单成功',
  421. icon: "none"
  422. })
  423. let work = this.data.list;
  424. work.map((i, index) => {
  425. if (i.id == id) {
  426. work.splice(index, 1)
  427. console.log(i)
  428. }
  429. })
  430. let count = this.data.workCount
  431. count = count - 1
  432. this.setData({
  433. list: work,
  434. workCount: count
  435. })
  436. if (work.length == 0) {
  437. wx.showToast({
  438. title: '该车辆已无待领工单~',
  439. icon: 'none'
  440. })
  441. this.setData({
  442. workShow: false,
  443. workCount: ''
  444. })
  445. }
  446. }
  447. })
  448. },
  449. //完成
  450. finishWork(e) {
  451. wx.showLoading({
  452. title: '操作中...',
  453. })
  454. // console.log('finishWork')
  455. let id = e.currentTarget.dataset.id
  456. console.log(id, 'finishWorkId')
  457. app.request('work_order/over?work_order_id=' + id, '', 'GET').then(res => {
  458. wx.hideLoading();
  459. if (res.statusCode == 200) {
  460. console.log(res)
  461. wx.showToast({
  462. title: '操作成功',
  463. icon: "none"
  464. })
  465. let list = this.data.list
  466. list.map((i, index) => {
  467. if (i.id == id) {
  468. console.log(i)
  469. list.splice(index, 1)
  470. }
  471. })
  472. this.setData({
  473. list
  474. })
  475. if (list.length == 0) {
  476. wx.showToast({
  477. title: '已完成所有认领工单~',
  478. icon: 'none'
  479. })
  480. this.setData({
  481. workShow: false
  482. })
  483. }
  484. }
  485. })
  486. },
  487. //上拉加载
  488. moreWork() {
  489. wx.showLoading({
  490. title: '加载中...',
  491. })
  492. let that = this;
  493. var page = that.data.page + 1;
  494. let planned = '';
  495. let url = "";
  496. if (that.data.workState == 1) {
  497. planned = 1
  498. url = "work_order/list?planned=" + planned + "&bike_no=" + that.data.bikeId + '&page=' + page
  499. } else {
  500. planned = 2
  501. url = 'work_order/myWorkOrderList?planned=' + planned + "&bike_no=" + that.data.bikeId + '&page=' + page
  502. }
  503. app.request(url, '', 'GET').then(res => {
  504. wx.hideLoading();
  505. if (res.data.data.length > 0) {
  506. let work = res.data.data
  507. work.map(i => {
  508. i.txtStyle = 'left:0rpx'
  509. })
  510. this.setData({
  511. workShow: true,
  512. list: that.data.list.concat(work),
  513. page
  514. })
  515. } else {
  516. wx.showToast({
  517. title: '没有更多数据了~',
  518. icon: 'none'
  519. })
  520. }
  521. })
  522. },
  523. //报修列表
  524. lookRepairs() {
  525. wx.showLoading({
  526. title: '加载中...',
  527. })
  528. let status = ''
  529. let state = this.data.repairsState
  530. if (state == 1) {
  531. status = 0
  532. } else if (state == 2) {
  533. status = 1
  534. }
  535. app.request('user/userRepaired?bike_no=' + this.data.bikeId + '&status=' + status, '', 'GET').then(res => {
  536. if (res.statusCode == 200) {
  537. wx.hideLoading();
  538. // console.log(res, '报修列表')
  539. let list = res.data.data;
  540. if (list.length == 0) {
  541. // wx.showToast({
  542. // title: '暂无报修记录~',
  543. // icon: 'none'
  544. // })
  545. this.setData({
  546. repairsList: []
  547. })
  548. } else {
  549. let repairs = res.data.data;
  550. repairs.map(i => {
  551. i.txtStyle = 'left:0rpx'
  552. })
  553. this.setData({
  554. repairsList: res.data.data
  555. })
  556. }
  557. }
  558. })
  559. },
  560. repairsChoose(e) {
  561. let state = e.currentTarget.dataset.state;
  562. this.setData({
  563. repairsState: state,
  564. repairsList: []
  565. })
  566. this.lookRepairs();
  567. this.goTop();
  568. },
  569. markRead(e) {
  570. let id = e.currentTarget.dataset.id
  571. app.request('user/userRepaired/status?id=' + id, '', 'GET').then(res => {
  572. if (res.statusCode == 200) {
  573. console.log(res)
  574. this.lookRepairs();
  575. let list = this.data.repairsList;
  576. if (list.length == 0) {
  577. wx.showToast({
  578. title: '暂无报修~',
  579. icon: 'none'
  580. })
  581. this.setData({
  582. repairsCount: ''
  583. })
  584. } else {
  585. let count = this.data.repairsCount;
  586. count = count - 1;
  587. this.setData({
  588. repairsCount: count
  589. })
  590. }
  591. }
  592. })
  593. },
  594. morkRepairs() {
  595. wx.showLoading({
  596. title: '加载中...',
  597. })
  598. let that = this;
  599. let status = '';
  600. var page = that.data.page + 1;
  601. let state = this.data.repairsState
  602. if (state == 1) {
  603. status = 0
  604. } else if (state == 2) {
  605. status = 1
  606. }
  607. app.request('user/userRepaired?bike_no=' + this.data.bikeId + '&status=' + status + '&page=' + page, '', 'GET').then(res => {
  608. wx.hideLoading();
  609. if (res.statusCode == 200) {
  610. let list = res.data.data;
  611. if (list.length > 0) {
  612. this.setData({
  613. repairsList: that.data.repairsList.concat(list),
  614. page
  615. })
  616. } else {
  617. wx.showToast({
  618. title: '没有更多数据了~',
  619. icon: 'none'
  620. })
  621. }
  622. }
  623. })
  624. },
  625. /*
  626. * 工单弹窗 报修弹窗 end
  627. */
  628. more: function () {
  629. this.setData({
  630. moreShow: true
  631. })
  632. },
  633. async initData(isLoad = false) {
  634. var that = this;
  635. that.setData({
  636. markers: []
  637. })
  638. wx.showLoading({
  639. title: '加载中...',
  640. })
  641. await app.request('getAreas?put_area_id=' + that.data.areaID, '', 'GET').then(res => {
  642. wx.hideLoading();
  643. // console.log(res.data.ridding_area);
  644. let data = res.data
  645. that.setData({
  646. ridding_area: data.ridding_area,
  647. no_parking: data.no_parking_area,
  648. no_parking_points: data.no_parking_points,
  649. parking: data.parking_area,
  650. parking_points: data.parking_points
  651. })
  652. if (isLoad) {
  653. this.showArea(1)
  654. if (this.data.noParkAreaShow) this.showNoParking(0)
  655. if (this.data.parkAreaShow) this.showParking(0)
  656. }
  657. })
  658. },
  659. showArea(type = 0) {
  660. if (type) {
  661. this.setData({
  662. polygons: this.data.ridding_area,
  663. })
  664. } else {
  665. this.setData({
  666. polygons: this.data.polygons.concat(this.data.ridding_area),
  667. })
  668. }
  669. },
  670. clear(type = 0) {
  671. if (type === 0) {
  672. let polygons = this.data.polygons.filter((polygons) => {
  673. if (polygons.id.slice(0, 1) === 'A') {
  674. return false
  675. }
  676. return true
  677. })
  678. this.setData({
  679. 'polygons': polygons
  680. })
  681. }
  682. if (type === 1) {
  683. let polygons = this.data.polygons.filter((polygons) => {
  684. if (polygons.id.slice(0, 1) !== 'P') {
  685. return true
  686. }
  687. return false
  688. })
  689. let markers = this.data.markers.filter((polygons) => {
  690. if (polygons.id.slice(0, 1) !== 'p') {
  691. return true
  692. }
  693. return false
  694. })
  695. this.setData({
  696. 'polygons': polygons,
  697. 'markers': markers
  698. })
  699. }
  700. if (type === 2) {
  701. let polygons = this.data.polygons.filter((polygons) => {
  702. if (polygons.id.slice(0, 1) !== 'N') {
  703. return true
  704. }
  705. return false
  706. })
  707. let markers = this.data.markers.filter((polygons) => {
  708. if (polygons.id.slice(0, 1) !== 'n') {
  709. return true
  710. }
  711. return false
  712. })
  713. this.setData({
  714. 'polygons': polygons,
  715. 'markers': markers
  716. })
  717. }
  718. },
  719. //显示还车点 0:追加停车点 1:只显示停车点 2:删除停车点
  720. showParking(type = 0) {
  721. if (type === 0) {
  722. this.setData({
  723. polygons: this.data.polygons.concat(this.data.parking),
  724. markers: this.data.markers.concat(this.data.parking_points)
  725. })
  726. }
  727. if (type === 1) {
  728. this.setData({
  729. polygons: this.data.parking,
  730. markers: this.data.parking_points
  731. })
  732. }
  733. if (type === 2) {
  734. this.clear(1)
  735. }
  736. },
  737. showNoParking(type = 0) {
  738. if (type === 0) {
  739. this.setData({
  740. polygons: this.data.polygons.concat(this.data.no_parking),
  741. markers: this.data.markers.concat(this.data.no_parking_points)
  742. })
  743. }
  744. if (type === 1) {
  745. this.setData({
  746. polygons: this.data.no_parking,
  747. markers: this.data.no_parking_points
  748. })
  749. }
  750. if (type === 2) {
  751. this.clear(2)
  752. }
  753. },
  754. scanCode: function () {
  755. var that = this;
  756. console.log('scanCode')
  757. wx.scanCode({
  758. success: function (res) {
  759. let index = res.result.lastIndexOf("\=");
  760. var code = res.result.substring(index + 1, res.result.length);
  761. that.setData({
  762. bikeId: code
  763. })
  764. that.getBike_info(code)
  765. },
  766. fail: function () {
  767. wx.showModal({
  768. title: '提示',
  769. content: '手动输入车辆标号',
  770. success: function (res) {
  771. if (res.confirm) {
  772. wx.navigateTo({
  773. url: '/pages/manualInp/manualInp',
  774. })
  775. }
  776. }
  777. })
  778. }
  779. })
  780. },
  781. getBikes: function (clear = 0) {
  782. wx.showLoading({
  783. title: '加载中...',
  784. })
  785. var that = this;
  786. var areaId = that.data.areaID;
  787. var low_power = that.data.low_power;
  788. var state = that.data.state;
  789. var use_state = that.data.use_state;
  790. let time = parseInt(use_state / 1000)
  791. if (time === 0) {
  792. time = ''
  793. }
  794. var data = {
  795. put_area_id: areaId,
  796. battery_power: low_power,
  797. all_states: state,
  798. last_use_bike_end_time: time
  799. };
  800. app.request('getBikes', data, 'POST').then(res => {
  801. wx.hideLoading();
  802. console.log(res, 'bikes')
  803. let markers = this.data.markers
  804. if (clear) {
  805. markers = that.data.markers.filter((marker) => {
  806. if (marker.id.slice(0, 1) === 'B') {
  807. return false
  808. }
  809. return true
  810. })
  811. }
  812. that.setData({
  813. markers: markers.concat(res.data)
  814. })
  815. })
  816. },
  817. load: function () {
  818. wx.showLoading({
  819. title: '刷新中...',
  820. })
  821. this.setData({
  822. markers: []
  823. })
  824. if (this.data.noParkAreaShow) {
  825. this.showNoParking(0);
  826. } else {
  827. this.showNoParking(2);
  828. }
  829. if (this.data.parkAreaShow) {
  830. this.showParking(0)
  831. } else {
  832. this.showParking(2)
  833. }
  834. this.getBikes(1);
  835. wx.hideLoading();
  836. },
  837. posi: function () {
  838. wx.showLoading({
  839. title: '定位中...',
  840. })
  841. //点击定位
  842. var that = this;
  843. wx.getLocation({
  844. type: 'gcj02',
  845. success: (res) => {
  846. wx.hideLoading();
  847. // console.log(res, )
  848. var latitude = res.latitude
  849. var longitude = res.longitude
  850. that.setData({
  851. longitude: longitude,
  852. latitude: latitude
  853. })
  854. },
  855. fail: function (err) {
  856. wx.hideLoading();
  857. console.log(err)
  858. }
  859. })
  860. },
  861. change: function (e) {
  862. let that = this;
  863. console.log(e.detail)
  864. wx.setStorageSync('curVal', that.data.allArea[e.detail].value)
  865. wx.setStorageSync('curId', that.data.allArea[e.detail].areaID)
  866. this.setData({
  867. areaID: that.data.allArea[e.detail].areaID
  868. })
  869. this.initData(1)
  870. that.getBikes(1)
  871. },
  872. change2: function (e) { //选择电量
  873. console.log(e)
  874. this.setData({
  875. low_power: this.data.allEle[e.detail].areaID
  876. })
  877. this.getBikes(1);
  878. },
  879. change3: function (e) { //选择状态
  880. console.log(e)
  881. this.setData({
  882. state: this.data.allStatus[e.detail].areaID
  883. })
  884. this.getBikes(1)
  885. },
  886. change4: function (e) { //选择使用状态
  887. var time = new Date().getTime();
  888. var index = e.detail
  889. if (index == 0) {
  890. time = "";
  891. } else if (index == 1) {
  892. time = time - 86400000 * 1;
  893. } else if (index == 2) {
  894. time = time - 86400000 * 3;
  895. } else if (index == 3) {
  896. time = time - 86400000 * 7;
  897. }
  898. this.setData({
  899. use_state: time
  900. })
  901. this.getBikes(1)
  902. },
  903. marker: function ({
  904. markerId
  905. }) {
  906. if (this.data.repairsShow || this.data.sideShow || this.data.workShow) return;
  907. let type = markerId.slice(0, 1)
  908. //车辆索引
  909. if (type === 'B') {
  910. this.getBike_info(markerId.slice(1))
  911. }
  912. },
  913. // 获取车辆信息
  914. getBike_info: function (bikeId = false) {
  915. wx.showLoading({
  916. title: '加载中...',
  917. })
  918. if (typeof bikeId === 'object') {
  919. bikeId = this.data.bikeId
  920. }
  921. console.log(bikeId, 'bikeId')
  922. this.setData({
  923. bikeId
  924. })
  925. console.log(this.data.bikeId, 'bike_no')
  926. app.request('bike/getBikeInfo?bike_no=' + this.data.bikeId, '', 'GET').then(res => {
  927. wx.hideLoading();
  928. console.log(res, '获取车辆信息')
  929. if (res.data.bike_info == '') {
  930. this.setData({
  931. sideShow: false
  932. })
  933. wx.showToast({
  934. title: '暂无该车辆信息~',
  935. })
  936. } else {
  937. this.setData({
  938. bikeDetail: res.data,
  939. sideShow: true,
  940. footerShow: false
  941. })
  942. }
  943. })
  944. app.request("work_order/list?planned=" + 1 + "&bike_no=" + bikeId, '', 'GET').then(res => {
  945. if (res.statusCode == 200) {
  946. // console.log(res.data.meta.total, '工单数量')
  947. this.setData({
  948. workCount: res.data.meta.total
  949. })
  950. }
  951. })
  952. app.request('user/userRepaired?bike_no=' + bikeId + '&&status=' + 0, '', 'GET').then(res => {
  953. // console.log(res.data)
  954. // console.log(res.data.meta.total, '报修数量')
  955. this.setData({
  956. repairsCount: res.data.meta.total
  957. })
  958. })
  959. },
  960. //获取输入框的值
  961. bindKeyInput(e) {
  962. // console.log(e.detail.value, 11111)
  963. this.setData({
  964. bikeId: e.detail.value
  965. })
  966. },
  967. refresh_power: function () {
  968. this.getBike_info(this.data.bikeId), wx.showToast({
  969. title: '刷新完成',
  970. icon: 'none'
  971. })
  972. },
  973. bikePosition: function () {
  974. wx.navigateTo({
  975. url: '/pages/carPosition/carPosition?id=' + this.data.bikeDetail.bike_info.id + '&bike_no=' + this.data.bikeDetail.bike_info.bike_no,
  976. })
  977. },
  978. recentOrder: function () {
  979. wx.navigateTo({
  980. url: '/pages/recentOrder/recentOrder?id=' + this.data.bikeDetail.bike_info.id,
  981. })
  982. },
  983. showPopup() {
  984. this.setData({
  985. show: true
  986. });
  987. },
  988. onClose() {
  989. this.setData({
  990. show: false
  991. });
  992. },
  993. modify: function () {
  994. //跳转修改车辆信息
  995. var bike = this.data.bikeDetail.bike_info
  996. wx.navigateTo({
  997. url: '/pages/amendCar/amendCar?id=' + bike.id + '&bike_no=' + bike.bike_no + '&box_no=' + bike.box_no,
  998. })
  999. },
  1000. parkShow() {
  1001. this.setData({
  1002. parkAreaShow: !this.data.parkAreaShow
  1003. })
  1004. if (this.data.parkAreaShow) {
  1005. this.showParking(0)
  1006. } else {
  1007. this.showParking(2)
  1008. }
  1009. },
  1010. forbidShow() {
  1011. this.setData({
  1012. noParkAreaShow: !this.data.noParkAreaShow
  1013. })
  1014. if (this.data.noParkAreaShow) {
  1015. this.showNoParking(0);
  1016. } else {
  1017. this.showNoParking(2);
  1018. }
  1019. },
  1020. //显示图标提示弹窗
  1021. hintIcon() {
  1022. this.setData({
  1023. hintShow: true
  1024. })
  1025. wx.hideTabBar({});
  1026. },
  1027. // 关闭图标提示弹窗
  1028. closeHint() {
  1029. this.setData({
  1030. hintShow: false
  1031. })
  1032. wx.showTabBar({})
  1033. },
  1034. //关闭侧边栏
  1035. closeSide() {
  1036. this.setData({
  1037. sideShow: false,
  1038. footerShow: true,
  1039. workShow: false,
  1040. workState: 1,
  1041. repairsState: 1,
  1042. typeName: ''
  1043. })
  1044. wx.showTabBar({})
  1045. },
  1046. //调转我的工单
  1047. skipWork() {
  1048. wx.navigateTo({
  1049. url: '/pages/myWork/myWork',
  1050. })
  1051. },
  1052. // 鸣笛
  1053. whistle() {
  1054. var that = this;
  1055. if (that.data.switch1Checked) {
  1056. wx.showLoading({
  1057. title: '连接蓝牙中...',
  1058. })
  1059. bluM.connectDeivece(that.data.bikeDetail.bike_info.box_no).then(res => {
  1060. wx.showToast({
  1061. title: '响铃成功',
  1062. icon: 'none'
  1063. })
  1064. return bluM.bellBike()
  1065. })
  1066. } else {
  1067. app.request('bike/bikeBell?bike_id=' + that.data.bikeDetail.bike_info.id, '', 'GET').then(res => {
  1068. if (res.statusCode == 200) {
  1069. bluM.connectDeivece(that.data.bikeDetail.bike_info.box_no).then(res => {
  1070. return bluM.bellBike()
  1071. })
  1072. wx.showToast({
  1073. title: '响铃成功',
  1074. icon: 'none'
  1075. })
  1076. }
  1077. })
  1078. }
  1079. },
  1080. //开锁
  1081. unlock() {
  1082. var that = this;
  1083. if (that.data.switch1Checked) {
  1084. wx.showLoading({
  1085. title: '连接蓝牙中...',
  1086. })
  1087. bluM.connectDeivece(that.data.bikeDetail.bike_info.box_no).then(res => {
  1088. wx.showToast({
  1089. title: '开锁成功',
  1090. icon: 'none'
  1091. })
  1092. return bluM.unlockBike()
  1093. })
  1094. } else {
  1095. app.request('bike/openBikeLock?bike_id=' + that.data.bikeDetail.bike_info.id, '', 'GET').then(res => {
  1096. if (res.statusCode == 200) {
  1097. bluM.connectDeivece(that.data.bikeDetail.bike_info.box_no).then(res => {
  1098. return bluM.unlockBike()
  1099. })
  1100. wx.showToast({
  1101. title: '开锁成功',
  1102. icon: 'none'
  1103. })
  1104. }
  1105. })
  1106. }
  1107. },
  1108. //关锁
  1109. close_lock() {
  1110. var that = this;
  1111. if (that.data.switch1Checked) {
  1112. wx.showLoading({
  1113. title: '连接蓝牙中...',
  1114. })
  1115. bluM.connectDeivece(that.data.bikeDetail.bike_info.box_no).then(res => {
  1116. wx.showToast({
  1117. title: '关锁成功',
  1118. icon: 'none'
  1119. })
  1120. return bluM.lockBike()
  1121. })
  1122. } else {
  1123. // console.log('接口')
  1124. app.request('bike/closeBikeLock?bike_id=' + that.data.bikeDetail.bike_info.id, '', 'GET').then(res => {
  1125. if (res.statusCode == 200) {
  1126. bluM.connectDeivece(that.data.bikeDetail.bike_info.box_no).then(res => {
  1127. return bluM.lockBike()
  1128. })
  1129. wx.showToast({
  1130. title: '关锁成功',
  1131. icon: 'none'
  1132. })
  1133. }
  1134. })
  1135. }
  1136. },
  1137. bike_detail: function () {
  1138. //车辆详情页面
  1139. var bike = this.data.bikeDetail.bike_info;
  1140. wx.navigateTo({
  1141. url: '/pages/carDetails/carDetails?bike_no=' + bike.bike_no + '&id=' + bike.id,
  1142. })
  1143. },
  1144. reqair: function () {
  1145. var bike = this.data.bikeDetail.bike_info;
  1146. wx.navigateTo({
  1147. url: '/pages/reqair/reqair?bike_no=' + bike.bike_no,
  1148. })
  1149. },
  1150. //开电池锁
  1151. battery_load() {
  1152. var that = this;
  1153. if (that.data.switch1Checked) {
  1154. wx.showLoading({
  1155. title: '连接蓝牙中...',
  1156. })
  1157. bluM.connectDeivece(that.data.bikeDetail.bike_info.box_no).then(res => {
  1158. wx.showToast({
  1159. title: '开电池锁成功',
  1160. icon: 'none'
  1161. })
  1162. return bluM.batteryUnlockBike()
  1163. })
  1164. } else {
  1165. app.request('bike/openBatteryLock?bike_id=' + that.data.bikeDetail.bike_info.id, '', 'GET').then(res => {
  1166. if (res.statusCode == 200) {
  1167. bluM.connectDeivece(that.data.bikeDetail.bike_info.box_no).then(res => {
  1168. return bluM.batteryUnlockBike()
  1169. })
  1170. wx.showToast({
  1171. title: '开电池锁成功',
  1172. icon: 'none'
  1173. })
  1174. }
  1175. })
  1176. }
  1177. },
  1178. renewalPower: function () {
  1179. //更新电量
  1180. app.request('bike/newBikeBatteryMSG?bike_id=' + this.data.bikeDetail.bike_info.id, '', 'GET').then(res => {
  1181. // console.log(res)
  1182. if (res.statusCode == 200) {
  1183. wx.showToast({
  1184. title: '更新电量成功',
  1185. icon: 'none'
  1186. })
  1187. }
  1188. })
  1189. },
  1190. renewalLocation: function () {
  1191. //更新位置
  1192. app.request('bike/newBikeLocation?bike_id=' + this.data.bikeDetail.bike_info.id, '', 'GET').then(res => {
  1193. if (res.statusCode == 200) {
  1194. wx.showToast({
  1195. title: '更新位置成功',
  1196. icon: 'none'
  1197. })
  1198. }
  1199. })
  1200. },
  1201. renewal: function () {
  1202. //重启中控
  1203. var that = this;
  1204. if (that.data.switch1Checked) {
  1205. wx.showLoading({
  1206. title: '连接蓝牙中...',
  1207. })
  1208. bluM.connectDeivece(that.data.bikeDetail.bike_info.box_no).then(res => {
  1209. wx.showToast({
  1210. title: '重启中控成功',
  1211. icon: 'none'
  1212. })
  1213. return bluM.boxReboot()
  1214. })
  1215. } else {
  1216. app.request('bike/rebootBox?bike_id=' + that.data.bikeDetail.bike_info.id, '', 'GET').then(res => {
  1217. if (res.statusCode == 200) {
  1218. bluM.connectDeivece(that.data.bikeDetail.bike_info.box_no).then(res => {
  1219. return bluM.boxReboot()
  1220. })
  1221. wx.showToast({
  1222. title: '重启中控成功',
  1223. icon: 'none'
  1224. })
  1225. }
  1226. })
  1227. }
  1228. },
  1229. // 设为停车区
  1230. recover() {
  1231. app.request('bike/repairInParking?bike_id=' + this.data.bikeDetail.bike_info.id, '', 'GET').then(res => {
  1232. // console.log(res)
  1233. if (res.statusCode == 200) {
  1234. wx.showToast({
  1235. title: '操作成功',
  1236. icon: 'none'
  1237. })
  1238. } else {
  1239. wx.showToast({
  1240. title: '操作失败',
  1241. icon: 'none'
  1242. })
  1243. }
  1244. })
  1245. },
  1246. //上线
  1247. online() {
  1248. app.request('bike/login?bike_id=' + this.data.bikeDetail.bike_info.id, '', 'GET').then(res => {
  1249. // console.log(res)
  1250. if (res.statusCode == 200) {
  1251. wx.showToast({
  1252. title: '上线成功',
  1253. icon: 'none'
  1254. })
  1255. }
  1256. })
  1257. },
  1258. //下线
  1259. Offline() {
  1260. app.request('bike/logout?bike_id=' + this.data.bikeDetail.bike_info.id, '', 'GET').then(res => {
  1261. console.log(res)
  1262. if (res.statusCode == 200) {
  1263. wx.showToast({
  1264. title: '下线成功',
  1265. icon: 'none'
  1266. })
  1267. }
  1268. })
  1269. },
  1270. onShow() {
  1271. // console.log(app.globalData.swichChecked)
  1272. this.setData({
  1273. switch1Checked: app.globalData.swichChecked,
  1274. })
  1275. },
  1276. operate(){
  1277. wx.navigateTo({
  1278. url: '/pages/bikeInfo/bikeInfo'
  1279. })
  1280. },
  1281. switch1Change: function (e) {
  1282. console.log(e)
  1283. var that = this;
  1284. wx.openBluetoothAdapter({
  1285. success(res) {
  1286. console.log(res)
  1287. that.setData({
  1288. switch1Checked: e.detail.value
  1289. })
  1290. app.globalData.swichChecked = e.detail.value;
  1291. },
  1292. fail(err) {
  1293. console.log(err)
  1294. wx.showModal({
  1295. title: '提示',
  1296. content: '请开启蓝牙',
  1297. showCancel: false
  1298. })
  1299. that.setData({
  1300. switch1Checked: false
  1301. })
  1302. app.globalData.swichChecked = false;
  1303. }
  1304. })
  1305. },
  1306. onShareAppMessage: function () {
  1307. return {
  1308. path: "/pages/login/login",
  1309. title: "轻松出行,方便你我~"
  1310. };
  1311. },
  1312. })