index.vue 16 KB

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