index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671
  1. <template>
  2. <view class="container">
  3. <view class="header">
  4. <view class="header-status chong-active" v-if="portDetail.portStatus == 1">
  5. 充电枪未连接
  6. </view>
  7. <view class="header-status chong-active" v-if="portDetail.portStatus == 0">
  8. 正在读取状态
  9. </view>
  10. <view class="header-status chong-active" v-if="portDetail.portStatus == 5">
  11. 充电枪已连接
  12. </view>
  13. <view class="header-status chong-active" v-if="portDetail.portStatus == 2">
  14. 充电枪已连接
  15. </view>
  16. <view class="header-img" v-if="portDetail.portStatus == 2">
  17. <image :src="imgUrl+'/chargedetail/chonging.png'">
  18. </image>
  19. </view>
  20. <view class="header-img" v-if="portDetail.portStatus != 2">
  21. <image :src="imgUrl+'/chargedetail/chongoff.png'">
  22. </image>
  23. </view>
  24. <view class="header-status-desc" v-if="portDetail.portStatus == 2">
  25. 充电中
  26. </view>
  27. <view class="header-status-desc" style="color: #B2B2B2" v-if="portDetail.portStatus != 2">
  28. 未充电
  29. </view>
  30. </view>
  31. <view class="port" @click="showPort = true">
  32. <view class="port-image">
  33. <image class="btn-image" :src="imgUrl+'/index/device.png'" >
  34. </image>
  35. </view>
  36. <view class="port-text">
  37. 设备编号:{{ deviceInfo.qrcode }}
  38. </view>
  39. <view class="port-num">
  40. <view>
  41. {{portList[0][choosePort-1]["text"]}}
  42. </view>
  43. </view>
  44. <view class="port-icon">
  45. <image class="btn-image" :src="imgUrl+'/index/right.png'" >
  46. </image>
  47. </view>
  48. </view>
  49. <view class="plan" @click="planCharge">
  50. <view class="port-image">
  51. <image class="btn-image" :src="imgUrl+'/index/clock.png'" >
  52. </image>
  53. </view>
  54. <view class="port-text" v-if="planInfo != null" style="top:8px">
  55. 预约充电时间:
  56. </view>
  57. <view v-if="planInfo != null" class="port-text" style="top:30px;">
  58. <text style="font-size: 10px">{{ planInfo.runTime }}</text>
  59. </view>
  60. <view class="port-text" style="top:24px" v-else>
  61. 点击预约充电
  62. </view>
  63. <view class="port-num" style="top:48px;font-size: 12px" v-if="planInfo != null">
  64. 点击取消预约
  65. </view>
  66. <view class="port-icon" v-if="planInfo==null">
  67. <image class="btn-image" :src="imgUrl+'/index/right.png'" >
  68. </image>
  69. </view>
  70. <view class="port-icon" v-if="planInfo !=null" style="width: 18px;height: 18px;right:1px;">
  71. <image class="btn-image" :src="imgUrl+'/index/del.png'" >
  72. </image>
  73. </view>
  74. </view>
  75. <view class="info-body">
  76. <view>
  77. <view class="info-content">
  78. <view class="info-content-value">{{ portDetail.voltage }}V</view>
  79. <view class="info-content-text">
  80. 充电电压
  81. </view>
  82. </view>
  83. <view class="info-content">
  84. <view class="info-content-value" v-if="portDetail.voltage == 0">0A</view>
  85. <view class="info-content-value" v-else>{{portDetail.POWER/portDetail.voltage}}A</view>
  86. <view class="info-content-text">
  87. 充电电流
  88. </view>
  89. </view>
  90. <view class="info-content">
  91. <view class="info-content-value">{{portDetail.dev_temper}}℃</view>
  92. <view class="info-content-text">
  93. 设备温度
  94. </view>
  95. </view>
  96. <view class="info-content">
  97. <view class="info-content-value">{{portDetail.wire_temper}}℃</view>
  98. <view class="info-content-text">
  99. 线路温度
  100. </view>
  101. </view>
  102. </view>
  103. <view class="body-bottom">
  104. <view class="info-content">
  105. <view class="info-content-value">{{ portDetail.time }}分钟</view>
  106. <view class="info-content-text">
  107. 已冲时间
  108. </view>
  109. </view>
  110. <view class="info-content">
  111. <view class="info-content-value">{{ portDetail.power }}W</view>
  112. <view class="info-content-text">
  113. 充电功率
  114. </view>
  115. </view>
  116. <view class="info-content">
  117. <view class="info-content-value">{{ portDetail.elec }} 度</view>
  118. <view class="info-content-text">
  119. 已冲电量
  120. </view>
  121. </view>
  122. </view>
  123. </view>
  124. <u-picker @cancel="showPort=false" @confirm="confirmPort" :show="showPort" :columns="portList" keyName="text"></u-picker>
  125. <view class="bottom-control">
  126. <view class="control-btn" @click="trigger()" v-if="portDetail.portStatus == 2">
  127. <image class="btn-image" :src="imgUrl+'/control/stop.png'" >
  128. </image>
  129. <view>停止充电</view>
  130. </view>
  131. <view class="control-btn" @click="trigger()" v-if="portDetail.portStatus != 2">
  132. <image class="btn-image" :src="imgUrl+'/control/charge.png'" >
  133. </image>
  134. <view>立即充电</view>
  135. </view>
  136. <view class="control-btn" @click="getInfo">
  137. <image class="btn-image" :src="imgUrl+'/control/getstatus.png'" >
  138. </image>
  139. <view>获取状态</view>
  140. </view>
  141. <view class="control-btn" @click="toSet">
  142. <image class="btn-image" :src="imgUrl+'/control/control.png'" >
  143. </image>
  144. <view>设备控制</view>
  145. </view>
  146. <view class="control-btn">
  147. <image class="btn-image" :src="imgUrl+'/control/record.png'" >
  148. </image>
  149. <view>使用记录</view>
  150. </view>
  151. </view>
  152. </view>
  153. </template>
  154. <script>
  155. import {getDeviceInfo,getPortDetail,startCharge,stopCharge,sendPortDetailCmd,checkStatusChange,getPlanInfo,cancelPlan} from "@/utils/weitiandi/device/device.js";
  156. // #ifdef APP
  157. import ecUI from '@/utils/ecUI.js'
  158. import ecBLE from '@/utils/ecBLE/ecBLE.js'
  159. // #endif
  160. // #ifdef MP
  161. const ecUI = require('@/utils/ecUI.js')
  162. const ecBLE = require('@/utils/ecBLE/ecBLE.js')
  163. // #endif
  164. let ctx
  165. let isCheckScroll = true
  166. let isCheckRevHex = false
  167. let isCheckSendHex = false
  168. let sendData = ''
  169. export default {
  170. data() {
  171. return {
  172. deviceInfo:{},
  173. visitTime:"",
  174. timer:null,
  175. showPort:false,
  176. portDetail:{portStatus:0,POWER:0,voltage:0},
  177. statusTimer:"",
  178. connected:false,
  179. scriptTask:null,
  180. choosePort:1,
  181. portList:[[{port:1,text:"端口一"}]],
  182. planInfo:null,
  183. days:["","周一","周二","周三","周四","周五","周六","周日"],
  184. textRevData: '',
  185. }
  186. },
  187. computed: {
  188. imgUrl() {
  189. return getApp().globalData.config.imgUrl;
  190. }
  191. },
  192. onLoad(opt) {
  193. this.deviceInfo.deviceId = opt.id;
  194. this.deviceInfo.ccid = opt.ccid;
  195. this.deviceInfo.qrcode = opt.qrcode;
  196. this.buletooth();
  197. this.checkPassword();
  198. },
  199. onShow(){
  200. this.getInfo();
  201. },
  202. onUnload (){
  203. this.closeSocket();
  204. },
  205. methods: {
  206. checkPassword(){
  207. },
  208. buletooth(){
  209. let self = this;
  210. ctx = this
  211. isCheckScroll = true
  212. isCheckRevHex = false
  213. isCheckSendHex = false
  214. sendData = ''
  215. //on disconnect
  216. ecBLE.onBLEConnectionStateChange(() => {
  217. ecUI.showModal('提示', '设备断开连接')
  218. })
  219. //receive data
  220. ecBLE.onBLECharacteristicValueChange((str, strHex) => {
  221. ctx.textRevData = str
  222. console.log("收到消息:"+str);
  223. let data = JSON.parse(str);
  224. let type = data.type;
  225. let real_data = data.real_data;
  226. if(type == 103){
  227. self.portDetail = real_data
  228. self.portList = [[]];
  229. let port_first_status = self.portDetail["port_first_status"];
  230. let port_second_status = self.portDetail["port_second_status"]
  231. if(port_first_status){
  232. self.portList[0].push({port:1,text:"端口一"});
  233. }
  234. if(port_second_status){
  235. self.portList[0].push({port:2,text:"端口二"});
  236. }
  237. let choosePort = self.choosePort
  238. if(choosePort == 1){
  239. self.portDetail.portStatus = port_first_status;
  240. }else if(choosePort == 2){
  241. self.portDetail.portStatus = port_second_status;
  242. }
  243. self.$modal.closeLoading();
  244. }
  245. if(type == 116){
  246. self.$modal.closeLoading();
  247. self.getInfo();
  248. }
  249. if(type == 113){
  250. self.$modal.closeLoading();
  251. self.getInfo();
  252. }
  253. if(type == 96){
  254. self.mainBoardInfo = real_data;
  255. self.formatMainboardData();
  256. self.$modal.closeLoading();
  257. }
  258. self.$forceUpdate();
  259. console.log('收到服务器内容:' + JSON.stringify(data));
  260. })
  261. },
  262. planCharge(){
  263. if(this.planInfo != null){
  264. this.$modal.confirm("确认取消预约?").then(res=>{
  265. this.cancelPlan();
  266. })
  267. }else{
  268. this.toPlan()
  269. }
  270. },
  271. sendBlueData(){
  272. ecBLE.writeBLECharacteristicValue(tempSendData, false)
  273. },
  274. cancelPlan(){
  275. cancelPlan(this.planInfo.id).then(res=>{
  276. this.$modal.msg("取消成功");
  277. this.planInfo = null;
  278. this.getPlanInfo();
  279. })
  280. },
  281. getPlanInfo(){
  282. getPlanInfo(this.deviceInfo.deviceId,this.choosePort).then(res=>{
  283. let data = res.data;
  284. if(data != null){
  285. let planType = data.planType;
  286. if(planType == 1){//单次预约
  287. let planInfo = {};
  288. planInfo.runTime = data.runTime;
  289. this.planInfo = planInfo;
  290. this.planInfo.id = data.id;
  291. }else{
  292. let planInfo = {};
  293. planInfo.runTime = data.runTime;
  294. let repeatDays = data.repeatDays;
  295. let days = repeatDays.split(",")
  296. let strs = "";
  297. for (let i = 0; i < days.length; i++) {
  298. if(strs.length>0){
  299. strs+=",";
  300. }
  301. strs +=this.days[days[i]];
  302. }
  303. this.planInfo = planInfo;
  304. this.planInfo.runTime = strs+" "+data.repeatTime;
  305. this.planInfo.id = data.id;
  306. }
  307. }
  308. })
  309. },
  310. confirmPort(e){
  311. let value = e.value[0]
  312. this.choosePort = value.port;
  313. this.showPort = false;
  314. this.getInfo()
  315. },
  316. initSocket(key){
  317. let self = this;
  318. },
  319. toSet(){
  320. this.closeSocket();
  321. uni.navigateTo({
  322. url: '/pages/weitiandi/device/setting?id='+this.deviceInfo.deviceId+"&ccid="+this.deviceInfo.ccid
  323. });
  324. },
  325. toPlan(){
  326. uni.navigateTo({
  327. url: '/pages/weitiandi/device/plan?port='+this.choosePort+'&id='+this.deviceInfo.deviceId+"&ccid="+this.deviceInfo.ccid
  328. });
  329. },
  330. trigger(){
  331. let portStatus = this.portDetail.portStatus;
  332. if(portStatus == 2){//需要停止充电
  333. this.$modal.confirm("需要停止充电么?").then(res=>{
  334. this.stopCharge();
  335. })
  336. }else{
  337. if(portStatus == 1){
  338. this.$modal.msg("请先将充电枪插入后再点击充电");
  339. }
  340. if(portStatus == 5){
  341. this.$modal.confirm("确认开始充电么?").then(res=>{
  342. this.startCharge();
  343. })
  344. }
  345. }
  346. },
  347. getInfo() {
  348. this.$modal.loading("正在获取状态,请稍等...");
  349. sendPortDetailCmd().then(res => {
  350. this.$modal.loading("正在获取状态,请稍等...");
  351. this.visitTime = res.msg;
  352. if(!this.visitTime){
  353. this.$modal.msg("请重新进入页面");
  354. return;
  355. }
  356. if(!this.scriptTask){
  357. // this.initSocket(this.deviceInfo.deviceId);
  358. }
  359. // this.getPortInfo()
  360. })
  361. },
  362. stopCharge(){
  363. let self = this;
  364. this.deviceInfo.port = this.choosePort;
  365. stopCharge(this.deviceInfo).then(()=>{
  366. self.$modal.loading("停止成功");
  367. setTimeout((()=>{
  368. self.getInfo();
  369. }),1000);
  370. })
  371. },
  372. startCharge(){
  373. let self = this;
  374. this.deviceInfo.port = this.choosePort;
  375. startCharge(this.deviceInfo).then(res=>{
  376. self.$modal.loading("启动成功");
  377. setTimeout((()=>{
  378. self.getInfo();
  379. }),1000);
  380. })
  381. },
  382. getPortInfo(){
  383. this.startPortDetailTimer();
  384. },
  385. startPortDetailTimer(){
  386. let self = this;
  387. this.timer = setTimeout(function (){
  388. getPortDetail(self.deviceInfo,self.visitTime).then(res=>{
  389. let data = res.data;
  390. if(data != null){
  391. self.portDetail = data;
  392. self.checkStatusCheck();
  393. self.$modal.closeLoading();
  394. }else{
  395. self.startPortDetailTimer();
  396. }
  397. });
  398. },1000);
  399. },
  400. checkStatusCheck(){
  401. this.statusChangeTimer();
  402. },
  403. checkOnPage(){
  404. var pages = getCurrentPages() // 获取栈实例
  405. let currentRoute = pages[pages.length - 1].route; // 获取当前页面路由
  406. if("pages/weitiandi/device/index" != currentRoute){
  407. return false;
  408. }
  409. return true;
  410. },
  411. closeSocket(){
  412. ecBLE.onBLEConnectionStateChange(() => {})
  413. ecBLE.onBLECharacteristicValueChange(() => {})
  414. ecBLE.closeBLEConnection()
  415. },
  416. statusChangeTimer(){
  417. let self = this;
  418. this.statusTimer = setTimeout(function(){
  419. if(!this.checkOnPage()){
  420. return;
  421. }
  422. checkStatusChange(self.deviceInfo,self.visitTime).then(res=>{
  423. let data = res.data;
  424. if(data != null){
  425. self.getInfo();
  426. }else{
  427. self.statusChangeTimer();
  428. }
  429. });
  430. },3000);
  431. }
  432. }
  433. }
  434. </script>
  435. <style>
  436. .container {
  437. background: rgb(249, 252, 255);
  438. inset: 0;
  439. position: absolute;
  440. }
  441. .header {
  442. position: relative;
  443. margin-top:4vw;
  444. }
  445. .header-status-desc {
  446. position: absolute;
  447. text-align: center;
  448. width: 100%;
  449. bottom:1vh;
  450. font-size: 5vw;
  451. font-weight: bold;
  452. color: #0E9F9B;
  453. }
  454. .header-status {
  455. font-weight: bold;
  456. padding-left: 5vw;
  457. }
  458. .chong-active {
  459. color: #0E9F9B
  460. }
  461. .header-img {
  462. width: 100%;
  463. padding: 5% 10%;
  464. text-align: center;
  465. }
  466. .header-img image {
  467. width: 100%;
  468. height: 23vh;
  469. }
  470. .info-body{
  471. background: #0E9F9B;
  472. height: 20vh;
  473. margin: 0 2%;
  474. border-radius: 1vw;
  475. margin-top:2vh;
  476. color: #F8FCFF;
  477. line-height: 3vh;
  478. }
  479. .info-content{
  480. display: inline-block;
  481. width: 23%;
  482. text-align: center;
  483. margin: 1%;
  484. margin-top:2.5vh;
  485. }
  486. .info-content-value{
  487. font-weight: bold;
  488. }
  489. .info-content-text{
  490. }
  491. .info-summary{
  492. display: flex;
  493. flex-direction: row;
  494. text-align: center;
  495. margin:3vh 0;
  496. }
  497. .summary{
  498. width: 33%;
  499. line-height: 2.5vh;
  500. }
  501. .charge-num{
  502. color: #0E9F9B;
  503. font-weight: bold;
  504. font-size: 4.5vw;
  505. }
  506. .charge-title{
  507. color: #B2B2B2;
  508. font-weight: 400;
  509. }
  510. .btn-image{
  511. width: 90%;
  512. height: 100%;
  513. }
  514. .info-bottom-btn{
  515. display: flex;
  516. flex-direction: row;
  517. text-align: center;
  518. position: relative;
  519. margin-top: 10vh
  520. ;
  521. }
  522. .btn-area{
  523. width: 50%;
  524. height: 50px;
  525. }
  526. .left{
  527. position: relative;
  528. left: 10px;
  529. text-align: right;
  530. }
  531. .right{
  532. text-align: left;
  533. position: relative;
  534. right: 10px;
  535. }
  536. .info-plan{
  537. text-align: center;
  538. color: #0E9F9B;
  539. margin-top:1vh;
  540. font-weight: 400;
  541. }
  542. .setting{
  543. position: fixed;
  544. right: -1px;
  545. top: 10vh;
  546. z-index: 999;
  547. background: rgb(227,243,245);
  548. color: #0E9F9B;
  549. font-size: 10px;
  550. border-radius: 5px;
  551. padding: 3px;
  552. }
  553. .port{
  554. height: 70px;
  555. background: #F8FCFF;
  556. border: 0px solid #F8FCFF;
  557. box-shadow: 0px 0px 6px 1px rgba(101,101,101,0.29);
  558. border-radius: 4px;
  559. margin:0 10px;
  560. position: relative;
  561. margin-top:10px;
  562. }
  563. .plan{
  564. height: 70px;
  565. background: #F8FCFF;
  566. border: 0px solid #F8FCFF;
  567. box-shadow: 0px 0px 6px 1px rgba(101,101,101,0.29);
  568. border-radius: 4px;
  569. margin:0 10px;
  570. position: relative;
  571. margin-top:15px;
  572. }
  573. .port-image{
  574. height: 40px;
  575. width: 40px;
  576. position: absolute;
  577. top:15px;
  578. left:20px;
  579. }
  580. .port-text{
  581. position: absolute;
  582. top:13px;
  583. left:75px;
  584. font-weight: bold;
  585. }
  586. .port-num{
  587. position: absolute;
  588. top:38px;
  589. left:75px;
  590. color: #B2B2B2;
  591. }
  592. .port-icon{
  593. position: absolute;
  594. top:30px;
  595. right:5px;
  596. width: 10px;
  597. height: 16px;
  598. }
  599. .port-icon image{
  600. width: 90%;
  601. }
  602. .body-bottom{
  603. padding:0 22px;
  604. }
  605. .body-bottom .info-content{
  606. width: 30%;
  607. }
  608. .bottom-control{
  609. height: 20vh;
  610. margin: 0 2%;
  611. margin-top:2vh;
  612. line-height: 3vh;
  613. background: #F8FCFF;
  614. border: 0px solid #F8FCFF;
  615. box-shadow: 0px 0px 6px 1px rgba(101,101,101,0.29);
  616. border-radius: 4px;
  617. padding:3%;
  618. }
  619. .control-btn{
  620. display: inline-block;;
  621. height: 60px;
  622. width: 25%;
  623. padding:10px 20px;
  624. text-align: center;
  625. font-size: 12px;
  626. color: black;
  627. }
  628. .control-btn .btn-image{
  629. }
  630. </style>