index.vue 17 KB

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