equipmentStatusList.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583
  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 ddd = this.timeAll.get(id);
  240. if (that.timeAll.get(id) != null) {
  241. var stamp = Date.parse(new Date());
  242. var t = (stamp - that.timeAll.get(id)) / 1000;
  243. if (t < 30) {
  244. var s = 30 - t;
  245. uni.showModal({
  246. title: that.$t('equipmentStatusList.onoff'),
  247. content: that.$t('equipmentStatusList.remainingtime') + s + "s",
  248. success: function(res) {
  249. that.getEquipmentListData();
  250. }
  251. });
  252. return;
  253. }
  254. }
  255. var code1 = code;
  256. if (code1 == 0) {
  257. uni.showModal({
  258. title: that.$t('equipmentStatusList.tip'),
  259. content: that.$t('equipmentStatusList.onoffTip'),
  260. success: function(res) {
  261. if (res.confirm) {
  262. var serverurl = that.serverurl;
  263. var code2 = code1;
  264. var equipmentId = id;
  265. var token = uni.getStorageSync("token");
  266. uni.request({
  267. url: serverurl + '/TEquipment/onOff',
  268. data: {
  269. "adminId": code2,
  270. "equipmentId": equipmentId
  271. },
  272. method: "POST",
  273. header:{
  274. 'token':token
  275. },
  276. success: (res) => {
  277. var list = res.data.data;
  278. that.input = 2;
  279. var timestamp = Date.parse(new Date());
  280. that.timeAll.set(id, timestamp);
  281. var oo = that.timeAll;
  282. // that.time = timestamp;
  283. that.getEquipmentListData();
  284. if (list == 'SUCCESS') {
  285. uni.showModal({
  286. title: that.$t('equipmentStatusList.guanji'),
  287. content: that.$t('equipmentStatusList.tishi'),
  288. success: function(res) {
  289. that.getEquipmentListData();
  290. setTimeout(function () {
  291. that.network(id);
  292. }, 7000);
  293. }
  294. })
  295. } else {
  296. uni.showModal({
  297. title: that.$t('equipmentStatusList.error'),
  298. content: that.$t('equipmentStatusList.guanjierror'),
  299. success: function(res) {
  300. that.onffChecked = true;
  301. that.getEquipmentListData();
  302. }
  303. })
  304. }
  305. }
  306. });
  307. } else if (res.cancel) {
  308. that.onffChecked = false;
  309. that.getEquipmentListData();
  310. }
  311. }
  312. });
  313. } else {
  314. var serverurl = that.serverurl;
  315. var code = code;
  316. var equipmentId = id;
  317. var token = uni.getStorageSync("token");
  318. uni.request({
  319. url: serverurl + '/TEquipment/onOff',
  320. data: {
  321. "adminId": code,
  322. "equipmentId": equipmentId
  323. },
  324. method: "POST",
  325. header:{
  326. 'token':token
  327. },
  328. success: (res) => {
  329. that.input = 2;
  330. var list = res.data.data;
  331. that.getEquipmentListData();
  332. var timestamp = Date.parse(new Date());
  333. that.timeAll.set(id, timestamp);
  334. var oo = that.timeAll;
  335. // that.time = timestamp;
  336. if (list == "SUCCESS") {
  337. uni.showModal({
  338. title: that.$t('equipmentStatusList.kaiji'),
  339. content: that.$t('equipmentStatusList.tishi'),
  340. success: function(res) {
  341. that.getEquipmentListData();
  342. setTimeout(function () {
  343. that.network(id);
  344. }, 7000);
  345. }
  346. })
  347. } else {
  348. uni.showModal({
  349. title: that.$t('equipmentStatusList.error'),
  350. content: that.$t('equipmentStatusList.kaijierror'),
  351. success: function(res) {
  352. that.onffChecked = false;
  353. that.getEquipmentListData();
  354. }
  355. })
  356. }
  357. }
  358. });
  359. }
  360. },
  361. network(id){
  362. var token = uni.getStorageSync("token");
  363. var equipmentId = id;
  364. uni.request({
  365. url: this.serverurl + '/TEquipment/checkStatus',
  366. data: {
  367. "equipmentId": id
  368. },
  369. method: "POST",
  370. header:{
  371. 'token':token
  372. },
  373. success: (res) => {
  374. var data = res.data.data;
  375. if(data=='fail'){
  376. uni.showToast({
  377. title: this.$t('equipmentStatusList.network'),
  378. icon:'none',
  379. duration: 3000
  380. });
  381. this.getEquipmentListData();
  382. }
  383. }
  384. });
  385. },
  386. openDoor(id) {
  387. var token = uni.getStorageSync("token");
  388. uni.request({
  389. url: this.serverurl + '/TEquipment/openDoor',
  390. data: {
  391. "equipmentId": id
  392. },
  393. method: "POST",
  394. header:{
  395. 'token':token
  396. },
  397. success: (res) => {
  398. uni.showModal({
  399. title: this.$t('equipmentStatusList.open'),
  400. content: this.$t('equipmentStatusList.opensuccess'),
  401. success: function(res) {
  402. }
  403. })
  404. }
  405. });
  406. },
  407. change(id, code) {
  408. var that = this;
  409. var code1 = code;
  410. if (code1 == 1) {
  411. uni.showModal({
  412. title: that.$t('equipmentStatusList.tip'),
  413. content: that.$t('equipmentStatusList.sleepTip'),
  414. success: function(res) {
  415. if (res.confirm) {
  416. var serverurl = that.serverurl;
  417. var code2 = code1;
  418. var equipmentId = id;
  419. var token = uni.getStorageSync("token");
  420. uni.request({
  421. url: serverurl + '/TEquipment/sleep',
  422. data: {
  423. "adminId": code2,
  424. "equipmentId": equipmentId
  425. },
  426. method: "POST",
  427. header:{
  428. 'token':token
  429. },
  430. success: (res) => {
  431. var list = res.data.data;
  432. that.getEquipmentListData();
  433. }
  434. });
  435. } else if (res.cancel) {
  436. that.sleepChecked = false;
  437. that.getEquipmentListData();
  438. }
  439. }
  440. });
  441. } else {
  442. var serverurl = that.serverurl;
  443. var code = code;
  444. var equipmentId = id;
  445. var token = uni.getStorageSync("token");
  446. uni.request({
  447. url: serverurl + '/TEquipment/sleep',
  448. data: {
  449. "adminId": code,
  450. "equipmentId": equipmentId
  451. },
  452. method: "POST",
  453. header:{
  454. 'token':token
  455. },
  456. success: (res) => {
  457. var list = res.data.data;
  458. that.getEquipmentListData();
  459. }
  460. });
  461. }
  462. },
  463. }
  464. }
  465. </script>
  466. <style>
  467. .status-css {
  468. position: absolute;
  469. width: 30upx;
  470. height: 30upx;
  471. right: 86upx;
  472. top: 30upx;
  473. border-radius: 30upx;
  474. color: "#596D83";
  475. font-size: 12upx;
  476. }
  477. .status-error {
  478. background-color: #dd524d
  479. }
  480. .status-normal {
  481. background-color: #4cd964
  482. }
  483. .baojing {
  484. padding-left: 120upx;
  485. }
  486. .titleFlag {
  487. height: 56upx;
  488. background-color: #F8F8F8;
  489. color: #8C959F;
  490. font-size: 22upx;
  491. display: flex;
  492. flex-direction: row;
  493. }
  494. .opendoor {
  495. /* #ifdef H5 */
  496. /* #endif */
  497. padding-top: 10upx;
  498. padding-bottom: 10upx;
  499. /* text-align: center; */
  500. display: flex;
  501. flex-direction: row;
  502. }
  503. .button {
  504. /* #ifdef H5 */
  505. text-align: center;
  506. height: 50upx;
  507. weight:20upx ;
  508. /* #endif */
  509. padding-left: 15upx;
  510. /* padding-top: 2upx; */
  511. }
  512. .p {
  513. /* #ifdef H5 */
  514. font-size: 28upx;
  515. height: 50upx;
  516. weight:20upx ;
  517. transform: translateY(-14upx);
  518. /* text-align: center; */
  519. /* #endif */
  520. /* padding-bottom: 50upx; */
  521. text-align: center;
  522. padding-left: 13upx;
  523. }
  524. .img {
  525. padding-top: 20upx;
  526. padding-left: 30upx;
  527. width: 15upx;
  528. height: 15upx;
  529. }
  530. .wenziT {
  531. padding-top: 10upx;
  532. padding-left: 10upx;
  533. }
  534. .titlelist {
  535. color: #363D44;
  536. font-size: 16upx;
  537. font-family: "PingFang-SC-Medium";
  538. }
  539. .swithBox {
  540. display: flex;
  541. flex-direction: row;
  542. padding-bottom: 15upx;
  543. padding-top: 5upx;
  544. }
  545. .switch {
  546. width: 44upx;
  547. height: 22upx;
  548. }
  549. .swichFont {
  550. width: 85%;
  551. padding-top: 12upx;
  552. }
  553. .line1 {
  554. width: 100%;
  555. height: 3upx;
  556. background: #000000;
  557. }
  558. </style>