bikeTest.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  1. <template>
  2. <view class="bikeTest">
  3. <view class="testFind">
  4. <input placeholder="请输入车牌号" placeholder-class="place" type="number" v-model="bike_no" @input="bindKeyInput" @blur="bindKeyInput"></input>
  5. <text class="saomiao" @click="scanCode">扫描</text>
  6. <view class="find" @click="getBike_info">查找</view>
  7. </view>
  8. <view class="model" v-if="bikeBolear">
  9. <text>当前输入编号车辆</text>
  10. <text v-for="(item,index) in bikesArr" @click="getBike(item)">
  11. {{item}}
  12. </text>
  13. </view>
  14. <view class="beijing" v-if="bikeBolear" @click="bikesHidden" catchtouchmove="return"></view>
  15. <view class="testMess">
  16. <view class="messTitle">
  17. <view class="">
  18. 车辆检测信息
  19. </view>
  20. <view class="flexC">
  21. <image src="http://resource.bike.hanyiyun.com/yunwei/bikeDe.png" style="width:45rpx;height:45rpx;" @click="skipDetail"></image>
  22. </view>
  23. </view>
  24. <view class="messList">
  25. <view class="listChid">
  26. 车牌号:{{bikeDetail.bike_no}}
  27. </view>
  28. <view class="listChid">
  29. 当前电量:{{bikeDetail.battery_power}}%
  30. </view>
  31. <view class="listChid">
  32. 车辆状态:{{bikeDetail.tab_name}}
  33. </view>
  34. <view class="listChid">
  35. 最后定位:{{bikeDetail.last_time}}
  36. </view>
  37. </view>
  38. </view>
  39. <view class="orderTest">
  40. <view class="orderTop">
  41. <view class="topLeft">
  42. 车辆检测指令
  43. </view>
  44. <view class="topRight">
  45. 只开启蓝牙操控
  46. <switch @change="switchChange" style="transform:scale(0.7)" v-if="checked==true" checked="checked" />
  47. <switch @change="switchChange" style="transform:scale(0.7)" v-if="checked==false" />
  48. </view>
  49. </view>
  50. <view class="orderDetail">
  51. <view class="children" @click="whistle">
  52. <image src="../../static/img/open-lock.png" mode=""></image>
  53. <view class="">
  54. 鸣笛
  55. </view>
  56. </view>
  57. <view class="children" @click="unlock">
  58. <image src="../../static/img/open-lock.png" mode=""></image>
  59. <view class="">
  60. 开电车锁
  61. </view>
  62. </view>
  63. <view class="children" @click="close_lock">
  64. <image src="../../static/img/close-lock.png" mode=""></image>
  65. <view class="">
  66. 关电车锁
  67. </view>
  68. </view>
  69. <view class="children" @click="battery_load">
  70. <image src="../../static/img/battery-load.png" mode=""></image>
  71. <view class="">
  72. 开电池锁
  73. </view>
  74. </view>
  75. <view class="children" @click="online">
  76. <image src="../../static/img/online.png" mode=""></image>
  77. <view class="">
  78. 上线
  79. </view>
  80. </view>
  81. <view class="children" @click="more">
  82. <image src="../../static/img/more.png" mode=""></image>
  83. <view class="">
  84. 更多
  85. </view>
  86. </view>
  87. </view>
  88. <view class="background" v-if="moreShow" @click="coverHidn(1)" catchtouchmove="true"></view>
  89. <view class="more" v-if="moreShow">
  90. <view @click="Offline">
  91. <image src="/static/img/offline.png" style="width:62upx;height:60upx;"></image>
  92. <view>下线</view>
  93. </view>
  94. <view @click="renewalPower">
  95. <image src="/static/img/renewalPower.png" style="width:62upx;height:60upx;"></image>
  96. <text>更新电量</text>
  97. </view>
  98. <view @click="renewalLocation">
  99. <image src="/static/img/renewalLocation.png" style="width:62upx;height:60upx;"></image>
  100. <text>更新位置</text>
  101. </view>
  102. <view @click="renewal">
  103. <image src="/static/img/renewal.png" style="width:62upx;height:60upx;"></image>
  104. <text>重启中控</text>
  105. </view>
  106. <view @click="recover">
  107. <image src="http://resource.weilaibike.com/bike_yunwei/park.png" style="width:50upx;height:50upx;"></image>
  108. <text>设为停车区</text>
  109. </view>
  110. </view>
  111. </view>
  112. </view>
  113. </template>
  114. <script>
  115. var app = getApp();
  116. import {
  117. BluetoothManager,
  118. BtErrorCode,
  119. CMD
  120. } from '../../static/js/bluWKM.js';
  121. const bluM = new BluetoothManager;
  122. export default {
  123. data() {
  124. return {
  125. bike_no: '', //车牌号
  126. box_no: '', //中控编号
  127. bikeDetail: [],
  128. bikeId: '',
  129. areaID: '',
  130. moreShow: false,
  131. checked: false, //是否只开启蓝牙操控
  132. bikeBolear:false,
  133. bikesArr:[]
  134. }
  135. },
  136. methods: {
  137. switchChange: function(e) {
  138. console.log('switch1 发生 change 事件,携带值为', e.target.value)
  139. this.checked = e.target.value;
  140. },
  141. getBike:function(e){
  142. console.log(e)
  143. // this.bike_no = e;
  144. this.bike_info(e)
  145. this.bikeBolear=false;
  146. },
  147. bikesHidden:function(){
  148. this.bikeBolear=false;
  149. },
  150. coverHidn: function(e) {
  151. this.moreShow = false
  152. },
  153. more: function() {
  154. this.moreShow = true;
  155. },
  156. skipDetail:function() {
  157. if (!this.bike_no) {
  158. wx.showToast({
  159. title: '请先输入车牌号',
  160. icon: 'none'
  161. })
  162. } else {
  163. uni.navigateTo({
  164. url: '../manage/bikeDetail?bike_no=' + this.bike_no + '&id=' + this.bikeDetail.id
  165. })
  166. }
  167. },
  168. scanCode: function() {
  169. var that = this;
  170. console.log('scanCode')
  171. uni.scanCode({
  172. success: function(res) {
  173. let index = res.result.lastIndexOf("\=");
  174. var code = res.result.substring(index + 1, res.result.length);
  175. that.bikeId = code;
  176. that.bike_info(code)
  177. },
  178. fail: function() {
  179. uni.showModal({
  180. title: '提示',
  181. content: '手动输入车辆标号',
  182. success: function(res) {
  183. if (res.confirm) {
  184. uni.navigateTo({
  185. url: '/pages/manualInp/manualInp',
  186. })
  187. }
  188. }
  189. })
  190. }
  191. })
  192. },
  193. bike_info:function(bikeId = false){
  194. uni.showLoading({
  195. title: '加载中...',
  196. })
  197. if (typeof bikeId === 'object') {
  198. bikeId = this.bikeId
  199. }
  200. console.log(bikeId, 'bikeId')
  201. this.bike_no = bikeId;
  202. app.request('bike/getBikeInfo?bike_no=' + this.bike_no, '', 'GET').then(res => {
  203. uni.hideLoading();
  204. console.log(res, '获取车辆信息')
  205. if (res.data.bike_info == '' || res.statusCode!=200) {
  206. uni.showToast({
  207. title: '暂无该车辆信息~',
  208. })
  209. } else {
  210. console.log(res.data, '车辆信息')
  211. this.bikeDetail = res.data.bike_info;
  212. }
  213. if (res.data.bike_info.tab_name == '中控离线') {
  214. console.log(1111)
  215. uni.openBluetoothAdapter({
  216. success(res) {
  217. console.log(res)
  218. that.checked = true;
  219. },
  220. fail(err) {
  221. console.log(err)
  222. uni.showModal({
  223. title: '提示',
  224. content: '当前车辆请开启蓝牙进行操作',
  225. showCancel: false
  226. })
  227. that.checked = false;
  228. }
  229. })
  230. }
  231. })
  232. },
  233. // 获取车辆信息
  234. getBike_info: function(bikeId = false) {
  235. uni.showLoading({
  236. title: '加载中...',
  237. })
  238. var that = this;
  239. if (typeof bikeId === 'object') {
  240. bikeId = this.bikeId
  241. }
  242. console.log(bikeId, 'bikeId')
  243. this.bike_no = bikeId;
  244. app.request('bike/searchBike?bike_no='+this.bike_no,'','GET').then(res=>{
  245. console.log(res)
  246. if(res.statusCode==200){
  247. uni.hideLoading()
  248. var bikes = Object.values(res.data.bikes)
  249. if(bikes.length>1){
  250. that.bikeBolear=true;
  251. that.bikesArr = bikes
  252. }else if(bikes.length==1){
  253. that.bike_info(bikes[0])
  254. }else{
  255. uni.showToast({
  256. title: '暂无该车辆信息~',
  257. icon:'none'
  258. })
  259. }
  260. }else{
  261. uni.showToast({
  262. title: '暂无该车辆信息~',
  263. icon:'none'
  264. })
  265. }
  266. })
  267. },
  268. //获取输入框的值
  269. bindKeyInput: function(e) {
  270. // console.log(e.detail.value, 11111)
  271. this.bikeId = e.detail.value;
  272. },
  273. // 鸣笛
  274. whistle: function() {
  275. var that = this;
  276. console.log(that.bikeDetail)
  277. if (this.checked) {
  278. bluM.connectDeivece(that.bikeDetail.box_no, CMD.bell)
  279. } else {
  280. uni.showLoading({
  281. title: '响铃中...'
  282. })
  283. app.request('bike/bikeBell?bike_id=' + that.bikeDetail.id, '', 'GET').then(res => {
  284. if (res.statusCode == 200) {
  285. uni.showToast({
  286. title: '响铃成功',
  287. icon: 'none'
  288. })
  289. }
  290. })
  291. }
  292. },
  293. //开锁
  294. unlock: function() {
  295. var that = this;
  296. if (this.checked) {
  297. bluM.connectDeivece(that.bikeDetail.box_no, CMD.unlock)
  298. } else {
  299. uni.showLoading({
  300. title: '开锁中...'
  301. })
  302. app.request('bike/openBikeLock?bike_id=' + that.bikeDetail.id, '', 'GET').then(res => {
  303. if (res.statusCode == 200) {
  304. uni.showToast({
  305. title: '开锁成功',
  306. icon: 'none'
  307. })
  308. }
  309. })
  310. }
  311. },
  312. //关锁
  313. close_lock: function() {
  314. var that = this;
  315. if (this.checked) {
  316. bluM.connectDeivece(that.bikeDetail.box_no, CMD.lock)
  317. } else {
  318. uni.showLoading({
  319. title: '关锁中...'
  320. })
  321. app.request('bike/closeBikeLock?bike_id=' + that.bikeDetail.id, '', 'GET').then(res => {
  322. if (res.statusCode == 200) {
  323. uni.showToast({
  324. title: '关锁成功',
  325. icon: 'none'
  326. })
  327. }
  328. })
  329. }
  330. },
  331. //开电池锁
  332. battery_load: function() {
  333. var that = this;
  334. if (this.checked) {
  335. bluM.connectDeivece(that.bikeDetail.box_no, CMD.batteryUnlock)
  336. } else {
  337. uni.showLoading({
  338. title: '开电池锁中...'
  339. })
  340. app.request('bike/openBatteryLock?bike_id=' + that.bikeDetail.id, '', 'GET').then(res => {
  341. if (res.statusCode == 200) {
  342. uni.showToast({
  343. title: '开电池锁成功',
  344. icon: 'none'
  345. })
  346. }
  347. })
  348. }
  349. },
  350. renewalPower: function() {
  351. //更新电量
  352. app.request('bike/newBikeBatteryMSG?bike_id=' + this.bikeDetail.id, '', 'GET').then(res => {
  353. // console.log(res)
  354. if (res.statusCode == 200) {
  355. uni.showToast({
  356. title: '更新电量成功',
  357. icon: 'none'
  358. })
  359. }
  360. })
  361. },
  362. renewalLocation: function() {
  363. //更新位置
  364. app.request('bike/newBikeLocation?bike_id=' + this.bikeDetail.id, '', 'GET').then(res => {
  365. if (res.statusCode == 200) {
  366. uni.showToast({
  367. title: '更新位置成功',
  368. icon: 'none'
  369. })
  370. }
  371. })
  372. },
  373. renewal: function() {
  374. //重启中控
  375. var that = this;
  376. app.request('bike/rebootBox?bike_id=' + that.bikeDetail.id, '', 'GET').then(res => {
  377. if (res.statusCode == 200) {
  378. uni.showToast({
  379. title: '重启中控成功',
  380. icon: 'none'
  381. })
  382. }
  383. })
  384. },
  385. // 设为停车区
  386. recover: function() {
  387. app.request('bike/repairInParking?bike_id=' + this.bikeDetail.id, '', 'GET').then(res => {
  388. // console.log(res)
  389. if (res.statusCode == 200) {
  390. uni.showToast({
  391. title: '操作成功',
  392. icon: 'none'
  393. })
  394. } else {
  395. uni.showToast({
  396. title: '操作失败',
  397. icon: 'none'
  398. })
  399. }
  400. })
  401. },
  402. //上线
  403. online: function() {
  404. app.request('bike/login?bike_id=' + this.bikeDetail.id, '', 'GET').then(res => {
  405. // console.log(res)
  406. if (res.statusCode == 200) {
  407. uni.showToast({
  408. title: '上线成功',
  409. icon: 'none'
  410. })
  411. }
  412. })
  413. },
  414. //下线
  415. Offline: function() {
  416. app.request('bike/logout?bike_id=' + this.bikeDetail.id, '', 'GET').then(res => {
  417. console.log(res)
  418. if (res.statusCode == 200) {
  419. uni.showToast({
  420. title: '下线成功',
  421. icon: 'none'
  422. })
  423. }
  424. })
  425. },
  426. },
  427. onLoad(options) {
  428. // console.log(app.request())
  429. console.log(uni.getStorageSync('allArea'), 'allArea')
  430. var that = this;
  431. let timer = setTimeout(function() {
  432. if (uni.getStorageSync('allArea')) {
  433. that.allArea = uni.getStorageSync('allArea');
  434. that.allStatus = uni.getStorageSync('allState');
  435. }
  436. console.log(that.allArea)
  437. let curVal = uni.getStorageSync('curVal')
  438. console.log(curVal, 'log_curVal')
  439. if (curVal) {
  440. that.area = curVal;
  441. }
  442. let areaID = uni.getStorageSync('curId')
  443. console.log(areaID, 'log_areaID')
  444. if (areaID) {
  445. that.areaID = areaID;
  446. } else {
  447. let id = that.allArea[0].areaID
  448. that.areaID = id
  449. }
  450. }, 500)
  451. },
  452. }
  453. </script>
  454. <style>
  455. .orderTest {
  456. /* height: 100%; */
  457. margin-top: 30upx;
  458. padding: 20upx;
  459. border-radius: 12upx;
  460. background-color: #FFFFFF;
  461. }
  462. .orderTop {
  463. display: flex;
  464. font-size: 30upx;
  465. }
  466. .topLeft {
  467. flex: 1;
  468. }
  469. .topRight {
  470. flex: 1;
  471. }
  472. .orderDetail {
  473. text-align: center;
  474. border-top: solid 1upx #f2f2f2;
  475. display: flex;
  476. flex-direction: row;
  477. flex-wrap: wrap;
  478. }
  479. .children {
  480. flex: 0 0 33%;
  481. margin-top: 30upx;
  482. }
  483. .children view {
  484. margin-top: 10upx;
  485. font-size: 28upx;
  486. }
  487. .children image {
  488. height: 58upx;
  489. width: 58upx;
  490. }
  491. .topRight view {
  492. display: inline-block;
  493. vertical-align: top;
  494. }
  495. .topRight switch {
  496. display: inline-block;
  497. vertical-align: top;
  498. }
  499. .testMess {
  500. margin-top: 30upx;
  501. padding: 20upx;
  502. border-radius: 12upx;
  503. background-color: #FFFFFF;
  504. }
  505. .messTitle {
  506. padding-bottom: 20upx;
  507. font-size: 32upx;
  508. display: flex;
  509. align-items: center;
  510. justify-content: space-between;
  511. }
  512. .messTitle {
  513. border-bottom: solid 1upx #f2f2f2;
  514. }
  515. .listChid {
  516. padding: 20upx;
  517. font-size: 30upx;
  518. color: #a6a6a6;
  519. }
  520. .bikeTest {
  521. padding: 30upx;
  522. background-color: #f3f3f3;
  523. }
  524. .testFind {
  525. padding: 30upx 50upx;
  526. background-color: #FFFFFF;
  527. border-radius: 12upx;
  528. }
  529. .testFind input {
  530. width: 70%;
  531. font-size: 28upx;
  532. padding: 0 0 5upx 5upx;
  533. display: inline-block;
  534. border-bottom: 2upx solid #0b0b0b;
  535. }
  536. .saomiao {
  537. display: inline-block;
  538. background-color: #18D3B8;
  539. vertical-align: bottom;
  540. padding: 5upx 30upx;
  541. border-radius: 15upx;
  542. color: #FFFFFF;
  543. margin-left: 50upx;
  544. font-size: 30upx;
  545. }
  546. .find {
  547. margin-top: 30upx;
  548. display: block;
  549. width: 70%;
  550. margin-left: 15%;
  551. padding: 10upx;
  552. border-radius: 15upx;
  553. background-color: #18D3B8;
  554. color: #FFFFFF;
  555. text-align: center;
  556. }
  557. .background {
  558. background: #282828;
  559. width: 100%;
  560. height: 100%;
  561. position: fixed;
  562. top: 0upx;
  563. left: 0upx;
  564. z-index: 8888;
  565. opacity: 0.5;
  566. }
  567. .more {
  568. display: flex;
  569. flex-wrap: wrap;
  570. position: fixed;
  571. top: 41%;
  572. left: 28%;
  573. background: white;
  574. z-index: 9999;
  575. width: 392upx;
  576. height: 392upx;
  577. background: rgba(229, 229, 229, 1);
  578. border-radius: 10upx;
  579. }
  580. .more view {
  581. display: flex;
  582. flex-direction: column;
  583. align-items: center;
  584. font-size: 26upx;
  585. width: 50%;
  586. justify-content: center;
  587. }
  588. .flexC {
  589. display: flex;
  590. justify-content: center;
  591. align-items: center;
  592. }
  593. .beijing{
  594. width: 100%;
  595. height: 100%;
  596. position: fixed;
  597. z-index: 888;
  598. background: #333333;
  599. opacity: .5;
  600. left: 0;
  601. top: 0;
  602. right: 0;
  603. bottom: 0;
  604. }
  605. .model{
  606. width: 400upx;
  607. height: auto;
  608. padding: 30upx 0upx;
  609. display: flex;
  610. flex-direction: column;
  611. align-items: center;
  612. position: fixed;
  613. z-index: 999;
  614. background: white;
  615. border-radius: 10upx;
  616. top: 50%;
  617. left: 50%;
  618. transform: translate(-50%,-50%);
  619. max-height: 600upx;
  620. overflow:scroll ;
  621. }
  622. .model text{
  623. padding: 15upx 0upx;
  624. font-size: 30upx;
  625. }
  626. </style>