index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651
  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 "@/api/device/device";
  156. import websocket from '@/utils/websocket'
  157. export default {
  158. data() {
  159. return {
  160. deviceInfo:{},
  161. visitTime:"",
  162. timer:null,
  163. showPort:false,
  164. portDetail:{portStatus:0,POWER:0,voltage:0},
  165. statusTimer:"",
  166. connected:false,
  167. scriptTask:null,
  168. choosePort:1,
  169. portList:[[{port:1,text:"端口一"}]],
  170. planInfo:null,
  171. days:["","周一","周二","周三","周四","周五","周六","周日"]
  172. }
  173. },
  174. computed: {
  175. imgUrl() {
  176. return getApp().globalData.config.imgUrl;
  177. }
  178. },
  179. onLoad(opt) {
  180. this.deviceInfo.deviceId = opt.id;
  181. this.deviceInfo.ccid = opt.ccid;
  182. this.deviceInfo.qrcode = opt.qrcode;
  183. },
  184. onShow(){
  185. this.getInfo();
  186. this.getPlanInfo();
  187. },
  188. onUnload (){
  189. this.closeSocket();
  190. },
  191. methods: {
  192. planCharge(){
  193. if(this.planInfo != null){
  194. this.$modal.confirm("确认取消预约?").then(res=>{
  195. this.cancelPlan();
  196. })
  197. }else{
  198. this.toPlan()
  199. }
  200. },
  201. cancelPlan(){
  202. cancelPlan(this.planInfo.id).then(res=>{
  203. this.$modal.msg("取消成功");
  204. this.planInfo = null;
  205. this.getPlanInfo();
  206. })
  207. },
  208. getPlanInfo(){
  209. getPlanInfo(this.deviceInfo.deviceId,this.choosePort).then(res=>{
  210. let data = res.data;
  211. if(data != null){
  212. let planType = data.planType;
  213. if(planType == 1){//单次预约
  214. let planInfo = {};
  215. planInfo.runTime = data.runTime;
  216. this.planInfo = planInfo;
  217. this.planInfo.id = data.id;
  218. }else{
  219. let planInfo = {};
  220. planInfo.runTime = data.runTime;
  221. let repeatDays = data.repeatDays;
  222. let days = repeatDays.split(",")
  223. let strs = "";
  224. for (let i = 0; i < days.length; i++) {
  225. if(strs.length>0){
  226. strs+=",";
  227. }
  228. strs +=this.days[days[i]];
  229. }
  230. this.planInfo = planInfo;
  231. this.planInfo.runTime = strs+" "+data.repeatTime;
  232. this.planInfo.id = data.id;
  233. }
  234. }
  235. })
  236. },
  237. confirmPort(e){
  238. let value = e.value[0]
  239. this.choosePort = value.port;
  240. this.showPort = false;
  241. this.getInfo()
  242. },
  243. initSocket(key){
  244. let self = this;
  245. let socketUrl = getApp().globalData.config.socketUrl
  246. this.scriptTask = websocket({
  247. url:"/"+key+"/",
  248. });
  249. let scriptTask = this.scriptTask;
  250. scriptTask.onOpen(function (res) {
  251. console.log('WebSocket连接已打开!');
  252. self.connected = true;
  253. });
  254. scriptTask.onError(function (res) {
  255. self.connected = false;
  256. console.log(res);
  257. });
  258. scriptTask.onMessage(function (res) {
  259. let data = JSON.parse(res.data);
  260. let type = data.type;
  261. let real_data = data.real_data;
  262. if(type == 103){
  263. self.portDetail = real_data
  264. self.portList = [[]];
  265. let port_first_status = self.portDetail["port_first_status"];
  266. let port_second_status = self.portDetail["port_second_status"]
  267. if(port_first_status){
  268. self.portList[0].push({port:1,text:"端口一"});
  269. }
  270. if(port_second_status){
  271. self.portList[0].push({port:2,text:"端口二"});
  272. }
  273. let choosePort = self.choosePort
  274. if(choosePort == 1){
  275. self.portDetail.portStatus = port_first_status;
  276. }else if(choosePort == 2){
  277. self.portDetail.portStatus = port_second_status;
  278. }
  279. self.$modal.closeLoading();
  280. }
  281. if(type == 116){
  282. self.$modal.closeLoading();
  283. self.getInfo();
  284. }
  285. if(type == 113){
  286. self.$modal.closeLoading();
  287. self.getInfo();
  288. }
  289. if(type == 96){
  290. self.mainBoardInfo = real_data;
  291. self.formatMainboardData();
  292. self.$modal.closeLoading();
  293. }
  294. self.$forceUpdate();
  295. console.log('收到服务器内容:' + JSON.stringify(data));
  296. });
  297. scriptTask.onClose(function (res) {
  298. console.log('WebSocket 已关闭!');
  299. });
  300. },
  301. toSet(){
  302. this.closeSocket();
  303. uni.navigateTo({
  304. url: '/pages/weitiandi/device/setting?id='+this.deviceInfo.deviceId+"&ccid="+this.deviceInfo.ccid
  305. });
  306. },
  307. toPlan(){
  308. uni.navigateTo({
  309. url: '/pages/weitiandi/device/plan?port='+this.choosePort+'&id='+this.deviceInfo.deviceId+"&ccid="+this.deviceInfo.ccid
  310. });
  311. },
  312. trigger(){
  313. let portStatus = this.portDetail.portStatus;
  314. if(portStatus == 2){//需要停止充电
  315. this.$modal.confirm("需要停止充电么?").then(res=>{
  316. this.stopCharge();
  317. })
  318. }else{
  319. if(portStatus == 1){
  320. this.$modal.msg("请先将充电枪插入后再点击充电");
  321. }
  322. if(portStatus == 5){
  323. this.$modal.confirm("确认开始充电么?").then(res=>{
  324. this.startCharge();
  325. })
  326. }
  327. }
  328. },
  329. getInfo() {
  330. this.$modal.loading("正在获取状态,请稍等...");
  331. sendPortDetailCmd(this.deviceInfo).then(res => {
  332. this.$modal.loading("正在获取状态,请稍等...");
  333. this.visitTime = res.msg;
  334. if(!this.visitTime){
  335. this.$modal.msg("请重新进入页面");
  336. return;
  337. }
  338. if(!this.scriptTask){
  339. this.initSocket(this.deviceInfo.deviceId);
  340. }
  341. // this.getPortInfo()
  342. })
  343. },
  344. stopCharge(){
  345. let self = this;
  346. this.deviceInfo.port = this.choosePort;
  347. stopCharge(this.deviceInfo).then(()=>{
  348. self.$modal.loading("停止成功");
  349. setTimeout((()=>{
  350. self.getInfo();
  351. }),1000);
  352. })
  353. },
  354. startCharge(){
  355. let self = this;
  356. this.deviceInfo.port = this.choosePort;
  357. startCharge(this.deviceInfo).then(res=>{
  358. self.$modal.loading("启动成功");
  359. setTimeout((()=>{
  360. self.getInfo();
  361. }),1000);
  362. })
  363. },
  364. getPortInfo(){
  365. this.startPortDetailTimer();
  366. },
  367. startPortDetailTimer(){
  368. let self = this;
  369. this.timer = setTimeout(function (){
  370. getPortDetail(self.deviceInfo,self.visitTime).then(res=>{
  371. let data = res.data;
  372. if(data != null){
  373. self.portDetail = data;
  374. self.checkStatusCheck();
  375. self.$modal.closeLoading();
  376. }else{
  377. self.startPortDetailTimer();
  378. }
  379. });
  380. },1000);
  381. },
  382. checkStatusCheck(){
  383. this.statusChangeTimer();
  384. },
  385. checkOnPage(){
  386. var pages = getCurrentPages() // 获取栈实例
  387. let currentRoute = pages[pages.length - 1].route; // 获取当前页面路由
  388. if("pages/weitiandi/device/index" != currentRoute){
  389. return false;
  390. }
  391. return true;
  392. },
  393. closeSocket(){
  394. this.scriptTask.close();
  395. this.scriptTask = null;
  396. },
  397. statusChangeTimer(){
  398. let self = this;
  399. this.statusTimer = setTimeout(function(){
  400. if(!this.checkOnPage()){
  401. return;
  402. }
  403. checkStatusChange(self.deviceInfo,self.visitTime).then(res=>{
  404. let data = res.data;
  405. if(data != null){
  406. self.getInfo();
  407. }else{
  408. self.statusChangeTimer();
  409. }
  410. });
  411. },3000);
  412. }
  413. }
  414. }
  415. </script>
  416. <style>
  417. .container {
  418. background: rgb(249, 252, 255);
  419. inset: 0;
  420. position: absolute;
  421. }
  422. .header {
  423. position: relative;
  424. margin-top:4vw;
  425. }
  426. .header-status-desc {
  427. position: absolute;
  428. text-align: center;
  429. width: 100%;
  430. bottom:1vh;
  431. font-size: 5vw;
  432. font-weight: bold;
  433. color: #0E9F9B;
  434. }
  435. .header-status {
  436. font-weight: bold;
  437. padding-left: 5vw;
  438. }
  439. .chong-active {
  440. color: #0E9F9B
  441. }
  442. .header-img {
  443. width: 100%;
  444. padding: 5% 10%;
  445. text-align: center;
  446. }
  447. .header-img image {
  448. width: 100%;
  449. height: 23vh;
  450. }
  451. .info-body{
  452. background: #0E9F9B;
  453. height: 20vh;
  454. margin: 0 2%;
  455. border-radius: 1vw;
  456. margin-top:2vh;
  457. color: #F8FCFF;
  458. line-height: 3vh;
  459. }
  460. .info-content{
  461. display: inline-block;
  462. width: 23%;
  463. text-align: center;
  464. margin: 1%;
  465. margin-top:2.5vh;
  466. }
  467. .info-content-value{
  468. font-weight: bold;
  469. }
  470. .info-content-text{
  471. }
  472. .info-summary{
  473. display: flex;
  474. flex-direction: row;
  475. text-align: center;
  476. margin:3vh 0;
  477. }
  478. .summary{
  479. width: 33%;
  480. line-height: 2.5vh;
  481. }
  482. .charge-num{
  483. color: #0E9F9B;
  484. font-weight: bold;
  485. font-size: 4.5vw;
  486. }
  487. .charge-title{
  488. color: #B2B2B2;
  489. font-weight: 400;
  490. }
  491. .btn-image{
  492. width: 90%;
  493. height: 100%;
  494. }
  495. .info-bottom-btn{
  496. display: flex;
  497. flex-direction: row;
  498. text-align: center;
  499. position: relative;
  500. margin-top: 10vh
  501. ;
  502. }
  503. .btn-area{
  504. width: 50%;
  505. height: 50px;
  506. }
  507. .left{
  508. position: relative;
  509. left: 10px;
  510. text-align: right;
  511. }
  512. .right{
  513. text-align: left;
  514. position: relative;
  515. right: 10px;
  516. }
  517. .info-plan{
  518. text-align: center;
  519. color: #0E9F9B;
  520. margin-top:1vh;
  521. font-weight: 400;
  522. }
  523. .setting{
  524. position: fixed;
  525. right: -1px;
  526. top: 10vh;
  527. z-index: 999;
  528. background: rgb(227,243,245);
  529. color: #0E9F9B;
  530. font-size: 10px;
  531. border-radius: 5px;
  532. padding: 3px;
  533. }
  534. .port{
  535. height: 70px;
  536. background: #F8FCFF;
  537. border: 0px solid #F8FCFF;
  538. box-shadow: 0px 0px 6px 1px rgba(101,101,101,0.29);
  539. border-radius: 4px;
  540. margin:0 10px;
  541. position: relative;
  542. margin-top:10px;
  543. }
  544. .plan{
  545. height: 70px;
  546. background: #F8FCFF;
  547. border: 0px solid #F8FCFF;
  548. box-shadow: 0px 0px 6px 1px rgba(101,101,101,0.29);
  549. border-radius: 4px;
  550. margin:0 10px;
  551. position: relative;
  552. margin-top:15px;
  553. }
  554. .port-image{
  555. height: 40px;
  556. width: 40px;
  557. position: absolute;
  558. top:15px;
  559. left:20px;
  560. }
  561. .port-text{
  562. position: absolute;
  563. top:13px;
  564. left:75px;
  565. font-weight: bold;
  566. }
  567. .port-num{
  568. position: absolute;
  569. top:38px;
  570. left:75px;
  571. color: #B2B2B2;
  572. }
  573. .port-icon{
  574. position: absolute;
  575. top:30px;
  576. right:5px;
  577. width: 10px;
  578. height: 16px;
  579. }
  580. .port-icon image{
  581. width: 90%;
  582. }
  583. .body-bottom{
  584. padding:0 22px;
  585. }
  586. .body-bottom .info-content{
  587. width: 30%;
  588. }
  589. .bottom-control{
  590. height: 20vh;
  591. margin: 0 2%;
  592. margin-top:2vh;
  593. line-height: 3vh;
  594. background: #F8FCFF;
  595. border: 0px solid #F8FCFF;
  596. box-shadow: 0px 0px 6px 1px rgba(101,101,101,0.29);
  597. border-radius: 4px;
  598. padding:3%;
  599. }
  600. .control-btn{
  601. display: inline-block;;
  602. height: 60px;
  603. width: 25%;
  604. padding:10px 20px;
  605. text-align: center;
  606. font-size: 12px;
  607. color: black;
  608. }
  609. .control-btn .btn-image{
  610. }
  611. </style>