equipmentStatusList.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597
  1. <!-- 机器状态页面 -->
  2. <template>
  3. <view v-if="merchantList.length>1">
  4. <uni-collapse :accordion="true">
  5. <view class="titleFlag">
  6. <image class="img" src="../../static/img/red.png"></image>
  7. <font class="wenziT">红色代表机器报警</font>
  8. <image class="img" src="../../static/img/green.png"></image>
  9. <font class="wenziT">绿色代表机器正常</font>
  10. </view>
  11. <view class="titlelist" v-for="(merchant,index) in merchantList" :key="merchant.id">
  12. <uni-collapse-item :title="getMerchantTitle(merchant)" :open="index===0">
  13. <view style="padding: 20upx;background-color: aliceblue;">
  14. <view v-if="merchant.equipmentList.length==0" style="text-align: center;">暂无数据</view>
  15. <view v-if="merchant.equipmentList.length>0">
  16. <uni-collapse :show-animation="true">
  17. <view style="position: relative;" v-for="equipment in merchant.equipmentList" :key="equipment.id">
  18. <span class="status-css" :class="equipment.hasTodayAlarm===true?statusError : statusNormal"></span>
  19. <uni-collapse-item :title="getEquipmentTitle(equipment)">
  20. <view style="padding: 20upx;background-color: antiquewhite;">
  21. <view class="swithBox" v-if="equipment.isSleep">
  22. <view class="swichFont">睡眠状态:机器已睡眠</view>
  23. <view class="switch">
  24. <switch style="transform:scale(0.65)" checked @change="change(equipment.id,0)" />
  25. </view>
  26. </view>
  27. <view class="swithBox" v-else>
  28. <view class="swichFont">睡眠状态:未睡眠</view>
  29. <view class="switch">
  30. <switch style="transform:scale(0.65)" :checked="sleepChecked" @change="change(equipment.id,1)" />
  31. </view>
  32. </view>
  33. <view class="line1"></view>
  34. <view class="swithBox" v-if="equipment.eqeStatus==0">
  35. <view class="swichFont">关机:已关机</view>
  36. <view class="switch">
  37. <switch style="transform:scale(0.65)" checked @change="OnOff(equipment.id,1)" />
  38. </view>
  39. </view>
  40. <view class="swithBox" v-else>
  41. <view class="swichFont">关机:未关机</view>
  42. <view class="switch">
  43. <switch style="transform:scale(0.65)" :checked="onffChecked" @change="OnOff(equipment.id,0)" />
  44. </view>
  45. </view>
  46. <view class="line1"></view>
  47. <view><span>机器唯一码:</span><span>{{equipment.clientId}}</span></view>
  48. <view><span>所在地:</span><span>{{equipment.fullName?equipment.fullName:''}}</span></view>
  49. <view><span>炉头温度:</span><span>{{equipment.furnaceTm?equipment.furnaceTm:''}}</span></view>
  50. <view><span>柜内湿度:</span><span>{{equipment.cabinetHd?equipment.cabinetHd:''}}</span></view>
  51. <view><span>柜内温度:</span><span>{{equipment.cabinetTm?equipment.cabinetTm:''}}</span></view>
  52. <view v-if="equipment.hasTodayAlarm">
  53. <view><span>报警内容:</span></view>
  54. <view v-for="(alarm,index) in equipment.alarmList" :key="index">
  55. <view><span class="baojing">{{alarm.occurrenceTime?alarm.occurrenceTime:''}} {{alarm.alarmContent}}</span></view>
  56. </view>
  57. </view>
  58. <view v-else>
  59. <view><span>报警内容:</span><span>{{equipment.occurrenceTime?equipment.occurrenceTime:''}}
  60. {{equipment.alarmContent}}</span></view>
  61. </view>
  62. </view>
  63. </uni-collapse-item>
  64. </view>
  65. </uni-collapse>
  66. </view>
  67. </view>
  68. </uni-collapse-item>
  69. </view>
  70. </uni-collapse>
  71. </view>
  72. <view v-else>
  73. <uni-collapse :show-animation="true">
  74. <view class="titleFlag">
  75. <image class="img" src="../../static/img/red.png"></image>
  76. <font class="wenziT">{{$t('equipmentStatusList.red')}}</font>
  77. <image class="img" src="../../static/img/green.png"></image>
  78. <font class="wenziT">{{$t('equipmentStatusList.green')}}</font>
  79. </view>
  80. <view class="titlelist" style="position: relative;" v-for="equipment in merchantList[0].equipmentList" :key="equipment.id">
  81. <span class="status-css" :class="equipment.hasTodayAlarm===true?statusError : statusNormal"></span>
  82. <uni-collapse-item :title="getEquipmentTitle(equipment)">
  83. <!-- 睡眠 -->
  84. <view style="padding: 20upx;background-color: antiquewhite;">
  85. <view class="swithBox" v-if="equipment.isSleep">
  86. <view class="swichFont">{{$t('equipmentStatusList.sleep')}}</view>
  87. <view class="switch">
  88. <switch style="transform:scale(0.65)" checked @change="change(equipment.id,0)" />
  89. </view>
  90. </view>
  91. <view class="swithBox" v-else>
  92. <view class="swichFont">{{$t('equipmentStatusList.unsleep')}}</view>
  93. <view class="switch">
  94. <switch style="transform:scale(0.65)" :checked="sleepChecked" @change="change(equipment.id,1)" />
  95. </view>
  96. </view>
  97. <view class="line1"></view>
  98. <!-- 关机 -->
  99. <view class="" v-if="globalUser.open==0">
  100. <view class="swithBox" v-if="equipment.eqeStatus==0">
  101. <view class="swichFont">{{$t('equipmentStatusList.off')}}</view>
  102. <view class="switch">
  103. <switch style="transform:scale(0.65)" checked @change="OnOff(equipment.id,1)" />
  104. </view>
  105. </view>
  106. <view class="swithBox" v-else>
  107. <view class="swichFont">{{$t('equipmentStatusList.on')}}</view>
  108. <view class="switch">
  109. <switch style="transform:scale(0.65)" :checked="onffChecked" @change="OnOff(equipment.id,0)" />
  110. </view>
  111. </view>
  112. </view>
  113. <view class="line1"></view>
  114. <!-- 远程开门 -->
  115. <view class="opendoor"><span>{{$t('equipmentStatusList.door')}}:</span>
  116. <view class="">
  117. <button type="primary" @click="openDoor(equipment.id)" class="button">
  118. <p class="p">{{$t('equipmentStatusList.open')}}</p>
  119. </button>
  120. </view>
  121. </view>
  122. <view><span>{{$t('equipmentStatusList.equipmentNo')}}:</span><span>{{equipment.clientId}}</span></view>
  123. <view><span>{{$t('equipmentStatusList.area')}}:</span><span>{{equipment.fullName?equipment.fullName:''}}</span></view>
  124. <view><span>{{$t('equipmentStatusList.temperature')}}:</span><span>{{equipment.furnaceTm?equipment.furnaceTm:''}}</span></view>
  125. <view><span>{{$t('equipmentStatusList.humidity')}}:</span><span>{{equipment.cabinetHd?equipment.cabinetHd:''}}</span></view>
  126. <view><span>{{$t('equipmentStatusList.equipmentTemperature')}}:</span><span>{{equipment.cabinetTm?equipment.cabinetTm:''}}</span></view>
  127. <view class="" v-if="equipment.hasTodayAlarm">
  128. <view><span>{{$t('equipmentStatusList.alarm')}}:</span></view>
  129. <view v-for="(alarm,index) in equipment.alarmList" :key="index">
  130. <view><span class="baojing">{{alarm.occurrenceTime?alarm.occurrenceTime:''}} {{alarm.alarmContent}}</span></view>
  131. </view>
  132. </view>
  133. <view class="" v-else>
  134. <view><span>{{$t('equipmentStatusList.alarm')}}:</span><span>{{equipment.occurrenceTime?equipment.occurrenceTime:''}}
  135. {{equipment.alarmContent}}</span></view>
  136. </view>
  137. </view>
  138. </uni-collapse-item>
  139. </view>
  140. </uni-collapse>
  141. </view>
  142. </template>
  143. <script>
  144. import {
  145. mapState,
  146. mapActions,
  147. mapMutations
  148. } from 'vuex'
  149. import uniCollapse from '@/components/uni-collapse/uni-collapse.vue'
  150. import uniCollapseItem from '@/components/uni-collapse-item/uni-collapse-item.vue'
  151. import uniList from '@/components/uni-list/uni-list.vue'
  152. import uniListItem from '@/components/uni-list-item/uni-list-item.vue'
  153. import {
  154. dateUtils
  155. } from '@/common/util.js';
  156. export default {
  157. components: {
  158. uniCollapse,
  159. uniCollapseItem,
  160. uniList,
  161. uniListItem,
  162. },
  163. data() {
  164. return {
  165. globalUser: {},
  166. merchantList: [{
  167. equipmentList: []
  168. }],
  169. extraIcon: {
  170. color: '#4cd964',
  171. size: '22',
  172. type: 'spinner'
  173. },
  174. statusNormal: 'status-normal',
  175. statusError: 'status-error',
  176. sleepChecked: null,
  177. onffChecked: null,
  178. time: null,
  179. timeAll: {
  180. },
  181. input: 0,
  182. }
  183. },
  184. computed: {
  185. ...mapState(['loginUser']),
  186. },
  187. onPullDownRefresh() {
  188. this.getEquipmentListData();
  189. },
  190. onShow() {
  191. this.input = this.input + 1;
  192. this.globalUser = uni.getStorageSync("globalUser");
  193. uni.setNavigationBarTitle({
  194. title: this.$t('equipmentStatusList.title')
  195. });
  196. uni.setTabBarItem({
  197. index: 3,
  198. text: this.$t('tabs.tab4')
  199. });
  200. var token = uni.getStorageSync("token");
  201. if (token.length>1) {
  202. this.getEquipmentListData();
  203. }else{
  204. uni.reLaunch({
  205. url: '../Login/Login',
  206. });
  207. }
  208. },
  209. methods: {
  210. ...mapActions('chart', ['getEquipmentListByUser']),
  211. getMerchantTitle(merchant) {
  212. return merchant.name ? merchant.name : merchant.username;
  213. },
  214. getEquipmentTitle(equipment) {
  215. return equipment.name ? equipment.name : '暂无名称';
  216. },
  217. getEquipmentListData() {
  218. this.getEquipmentListByUser(this.globalUser)
  219. .then(data => {
  220. this.merchantList = data;
  221. var listName = data[0].equipmentList;
  222. var times = new Map;
  223. if (this.input == 1) {
  224. for (var i = 0; i < listName.length; i++) {
  225. var k = listName[i].id;
  226. times.set(k, null);
  227. }
  228. this.timeAll = times;
  229. }
  230. var listId = data[0].id;
  231. if (listId != null && listId != '1') {
  232. uni.setStorageSync("listName", listName);
  233. }
  234. uni.stopPullDownRefresh();
  235. }, _ => void uni.stopPullDownRefresh());
  236. },
  237. OnOff(id, code) {
  238. var that = this;
  239. // var token = uni.getStorageSync("token");
  240. // uni.request({
  241. // url: that.serverurl + '/TEquipment/onoffStatus',
  242. // data: {
  243. // "equipmentId": id
  244. // },
  245. // header:{
  246. // 'token':token
  247. // },
  248. // method: "POST",
  249. // success: (res) => {
  250. // },
  251. // });
  252. var ddd = this.timeAll.get(id);
  253. if (that.timeAll.get(id) != null) {
  254. var stamp = Date.parse(new Date());
  255. var t = (stamp - that.timeAll.get(id)) / 1000;
  256. if (t < 30) {
  257. var s = 30 - t;
  258. uni.showModal({
  259. title: that.$t('equipmentStatusList.onoff'),
  260. content: that.$t('equipmentStatusList.remainingtime') + s + "s",
  261. success: function(res) {
  262. that.getEquipmentListData();
  263. }
  264. });
  265. return;
  266. }
  267. }
  268. var code1 = code;
  269. if (code1 == 0) {
  270. uni.showModal({
  271. title: that.$t('equipmentStatusList.tip'),
  272. content: that.$t('equipmentStatusList.onoffTip'),
  273. success: function(res) {
  274. if (res.confirm) {
  275. var serverurl = that.serverurl;
  276. var code2 = code1;
  277. var equipmentId = id;
  278. var token = uni.getStorageSync("token");
  279. uni.request({
  280. url: serverurl + '/TEquipment/onOff',
  281. data: {
  282. "adminId": code2,
  283. "equipmentId": equipmentId
  284. },
  285. method: "POST",
  286. header:{
  287. 'token':token
  288. },
  289. success: (res) => {
  290. var list = res.data.data;
  291. that.input = 2;
  292. var timestamp = Date.parse(new Date());
  293. that.timeAll.set(id, timestamp);
  294. var oo = that.timeAll;
  295. // that.time = timestamp;
  296. that.getEquipmentListData();
  297. if (list == 'SUCCESS') {
  298. uni.showModal({
  299. title: that.$t('equipmentStatusList.guanji'),
  300. content: that.$t('equipmentStatusList.tishi'),
  301. success: function(res) {
  302. that.getEquipmentListData();
  303. setTimeout(function () {
  304. that.network(id);
  305. }, 7000);
  306. }
  307. })
  308. } else {
  309. uni.showModal({
  310. title: that.$t('equipmentStatusList.error'),
  311. content: that.$t('equipmentStatusList.guanjierror'),
  312. success: function(res) {
  313. that.onffChecked = true;
  314. that.getEquipmentListData();
  315. }
  316. })
  317. }
  318. }
  319. });
  320. } else if (res.cancel) {
  321. that.onffChecked = false;
  322. that.getEquipmentListData();
  323. }
  324. }
  325. });
  326. } else {
  327. var serverurl = that.serverurl;
  328. var code = code;
  329. var equipmentId = id;
  330. var token = uni.getStorageSync("token");
  331. uni.request({
  332. url: serverurl + '/TEquipment/onOff',
  333. data: {
  334. "adminId": code,
  335. "equipmentId": equipmentId
  336. },
  337. method: "POST",
  338. header:{
  339. 'token':token
  340. },
  341. success: (res) => {
  342. that.input = 2;
  343. var list = res.data.data;
  344. that.getEquipmentListData();
  345. var timestamp = Date.parse(new Date());
  346. that.timeAll.set(id, timestamp);
  347. var oo = that.timeAll;
  348. // that.time = timestamp;
  349. if (list == "SUCCESS") {
  350. uni.showModal({
  351. title: that.$t('equipmentStatusList.kaiji'),
  352. content: that.$t('equipmentStatusList.tishi'),
  353. success: function(res) {
  354. that.getEquipmentListData();
  355. setTimeout(function () {
  356. that.network(id);
  357. }, 7000);
  358. }
  359. })
  360. } else {
  361. uni.showModal({
  362. title: that.$t('equipmentStatusList.error'),
  363. content: that.$t('equipmentStatusList.kaijierror'),
  364. success: function(res) {
  365. that.onffChecked = false;
  366. that.getEquipmentListData();
  367. }
  368. })
  369. }
  370. }
  371. });
  372. }
  373. },
  374. network(id){
  375. var token = uni.getStorageSync("token");
  376. var equipmentId = id;
  377. uni.request({
  378. url: this.serverurl + '/TEquipment/checkStatus',
  379. data: {
  380. "equipmentId": id
  381. },
  382. method: "POST",
  383. header:{
  384. 'token':token
  385. },
  386. success: (res) => {
  387. var data = res.data.data;
  388. if(data=='fail'){
  389. uni.showToast({
  390. title: this.$t('equipmentStatusList.network'),
  391. icon:'none',
  392. duration: 3000
  393. });
  394. this.getEquipmentListData();
  395. }
  396. }
  397. });
  398. },
  399. openDoor(id) {
  400. var token = uni.getStorageSync("token");
  401. uni.request({
  402. url: this.serverurl + '/TEquipment/openDoor',
  403. data: {
  404. "equipmentId": id
  405. },
  406. method: "POST",
  407. header:{
  408. 'token':token
  409. },
  410. success: (res) => {
  411. uni.showModal({
  412. title: this.$t('equipmentStatusList.open'),
  413. content: this.$t('equipmentStatusList.opensuccess'),
  414. success: function(res) {
  415. }
  416. })
  417. }
  418. });
  419. },
  420. change(id, code) {
  421. var that = this;
  422. var code1 = code;
  423. if (code1 == 1) {
  424. uni.showModal({
  425. title: that.$t('equipmentStatusList.tip'),
  426. content: that.$t('equipmentStatusList.sleepTip'),
  427. success: function(res) {
  428. if (res.confirm) {
  429. var serverurl = that.serverurl;
  430. var code2 = code1;
  431. var equipmentId = id;
  432. var token = uni.getStorageSync("token");
  433. uni.request({
  434. url: serverurl + '/TEquipment/sleep',
  435. data: {
  436. "adminId": code2,
  437. "equipmentId": equipmentId
  438. },
  439. method: "POST",
  440. header:{
  441. 'token':token
  442. },
  443. success: (res) => {
  444. var list = res.data.data;
  445. that.getEquipmentListData();
  446. }
  447. });
  448. } else if (res.cancel) {
  449. that.sleepChecked = false;
  450. that.getEquipmentListData();
  451. }
  452. }
  453. });
  454. } else {
  455. var serverurl = that.serverurl;
  456. var code = code;
  457. var equipmentId = id;
  458. var token = uni.getStorageSync("token");
  459. uni.request({
  460. url: serverurl + '/TEquipment/sleep',
  461. data: {
  462. "adminId": code,
  463. "equipmentId": equipmentId
  464. },
  465. method: "POST",
  466. header:{
  467. 'token':token
  468. },
  469. success: (res) => {
  470. var list = res.data.data;
  471. that.getEquipmentListData();
  472. }
  473. });
  474. }
  475. },
  476. }
  477. }
  478. </script>
  479. <style>
  480. .status-css {
  481. position: absolute;
  482. width: 30upx;
  483. height: 30upx;
  484. right: 86upx;
  485. top: 30upx;
  486. border-radius: 30upx;
  487. color: "#596D83";
  488. font-size: 12upx;
  489. }
  490. .status-error {
  491. background-color: #dd524d
  492. }
  493. .status-normal {
  494. background-color: #4cd964
  495. }
  496. .baojing {
  497. padding-left: 120upx;
  498. }
  499. .titleFlag {
  500. height: 56upx;
  501. background-color: #F8F8F8;
  502. color: #8C959F;
  503. font-size: 22upx;
  504. display: flex;
  505. flex-direction: row;
  506. }
  507. .opendoor {
  508. /* #ifdef H5 */
  509. /* #endif */
  510. padding-top: 10upx;
  511. padding-bottom: 10upx;
  512. /* text-align: center; */
  513. display: flex;
  514. flex-direction: row;
  515. }
  516. .button {
  517. /* #ifdef H5 */
  518. text-align: center;
  519. height: 50upx;
  520. weight:20upx ;
  521. /* #endif */
  522. padding-left: 15upx;
  523. /* padding-top: 2upx; */
  524. }
  525. .p {
  526. /* #ifdef H5 */
  527. font-size: 28upx;
  528. height: 50upx;
  529. weight:20upx ;
  530. transform: translateY(-14upx);
  531. /* text-align: center; */
  532. /* #endif */
  533. /* padding-bottom: 50upx; */
  534. text-align: center;
  535. padding-left: 13upx;
  536. }
  537. .img {
  538. padding-top: 20upx;
  539. padding-left: 30upx;
  540. width: 15upx;
  541. height: 15upx;
  542. }
  543. .wenziT {
  544. padding-top: 10upx;
  545. padding-left: 10upx;
  546. }
  547. .titlelist {
  548. color: #363D44;
  549. font-size: 16upx;
  550. font-family: "PingFang-SC-Medium";
  551. }
  552. .swithBox {
  553. display: flex;
  554. flex-direction: row;
  555. padding-bottom: 15upx;
  556. padding-top: 5upx;
  557. }
  558. .switch {
  559. width: 44upx;
  560. height: 22upx;
  561. }
  562. .swichFont {
  563. width: 85%;
  564. padding-top: 12upx;
  565. }
  566. .line1 {
  567. width: 100%;
  568. height: 3upx;
  569. background: #000000;
  570. }
  571. </style>