index.vue 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582
  1. <template>
  2. <!-- 设备列表 -->
  3. <div class="devicePage flex-col">
  4. <div class="listBox">
  5. <s-header :name="sys ? sys.title : $t('device.managementCenter')" :noback="true" :isFixed="false"></s-header>
  6. <van-list v-model:loading="loading" v-model:error="error" :error-text="$t('public.requestFailed')"
  7. :finished="finished" :finished-text="$t('public.noMore')" offset="100" :immediate-check="false" @load="onLoad">
  8. <div class="deviceBox1 flex-col">
  9. <div class="searchRow flex-row justify-between">
  10. <div class="flex-col">
  11. <div class="flex-row justify-between bd3">
  12. <div class="flex-col outer4"></div>
  13. <span class="flex-col txt2">{{
  14. $t("device.dataOverview")
  15. }}</span>
  16. </div>
  17. </div>
  18. <div class="flex-col">
  19. <div class="main5 flex-row justify-between" @click="searchClick">
  20. <img class="label2" src="../../assets/device/searchIcon.png" />
  21. <div class="TextGroup2 flex-col">
  22. <span class="txt3">{{ $t("device.search") }}</span>
  23. </div>
  24. </div>
  25. </div>
  26. </div>
  27. <img class="pic1" src="../../assets/device/line.png" />
  28. <div class="o-plr-15 o-ptb-20">
  29. <div class="bd1 flex-col">
  30. <div class="box2 l-f l-flex-c l-flex-j-a">
  31. <div @click="eqeStatusClk(1)" class="TextGroup3 flex-col">
  32. <div class="group1 flex-col justify-between align-center">
  33. <span class="word4">{{ equipStatus.machineUseNum }}</span>
  34. <span class="info1">{{
  35. $t("device.totalNumberOfRuns")
  36. }}</span>
  37. </div>
  38. </div>
  39. <div @click="eqeStatusClk('')" class="TextGroup4 flex-col">
  40. <div class="main6 flex-col justify-between align-center">
  41. <span class="word5">{{ equipStatus.machineTotalNum }}</span>
  42. <span class="word6">{{
  43. $t("device.totalNumberOfEquipment")
  44. }}</span>
  45. </div>
  46. </div>
  47. </div>
  48. </div>
  49. </div>
  50. </div>
  51. <div class="deviceBox2 flex-col justify-between">
  52. <div class="section1 flex-col">
  53. <div class="outer1 flex-col o-plr-15">
  54. <div v-for="item in list" :key="item" class="o-pb-20">
  55. <div class="bd1 l-flex-between">
  56. <div class="l-flex-RC">
  57. <div class="layer1 flex-col"></div>
  58. <div class="txtBox">
  59. <span class="txt1">{{ item.name == null ? item.clientId.slice(-6) : item.name }}</span>
  60. </div>
  61. </div>
  62. <div class="l-flex-RC">
  63. <!-- 报警标志 -->
  64. <!-- <div v-if="item.hasTodayAlarm" class="box4 flex-col"> -->
  65. <!-- <img class="pic1" src="../../assets/device/alarm.png" /> -->
  66. <!-- <img class="pic1" src="../../assets/home/M15.png" /> -->
  67. <!-- </div> -->
  68. <div v-if="item.hasTodayAlarm" class="l-flex-between o-pl-5">
  69. <div class="box4 flex-col "></div>
  70. <span class="o-pl-2" style="color: #fe5d55">{{ $t("device.alarmClock") }}</span>
  71. </div>
  72. <div class="layer2 flex-col" :class="{
  73. deviceOn: item.eqeStatus === 1,
  74. layerLeft: item.hasTodayAlarm,
  75. }"></div>
  76. </div>
  77. </div>
  78. <span class="txt1 o-mt-10">{{ $t("device.affiliatedMerchants") }}:{{
  79. item.adminUserName
  80. }}</span>
  81. <span class="txt1 o-mt-10 kBordBott">{{ $t("device.machineUniqueCode") }}:{{
  82. item.clientId
  83. }}</span>
  84. <div class="contentBottomCon" v-if="item.checkType">
  85. <img class="pic1" referrerpolicy="no-referrer" src="../../assets/home/line.png" />
  86. <div class="word4 flex-row justify-between o-ptb-5 kBordBott">
  87. <span class="info1 o-ptb-5 kBordBott">{{ $t("device.sleepState") }}:{{
  88. item.isSleep
  89. ? $t("device.sleeping")
  90. : $t("device.notSleeping")
  91. }}</span>
  92. </div>
  93. <div v-if="item.isSleep" class="layer3 o-ptb-7">
  94. <span class="word1">
  95. <div v-if="!sleepDescBoxShow">
  96. <van-field colon center class="word2" v-model="item.sleepDesc"
  97. :placeholder="$t('device.sleepDescPlace')" :label="$t('device.sleepDesc')" label-width="auto">
  98. <template #button class="button_1">
  99. <van-button size="small" type="primary" @click="sleepDescChg(item.sleepDesc, item.id)">{{
  100. $t("device.confirm") }}
  101. </van-button>
  102. <van-button size="small" type="primary" @click="editSleepDesc()">{{ $t("device.cancel")
  103. }}</van-button>
  104. </template>
  105. </van-field>
  106. <!-- </span> -->
  107. </div>
  108. <div v-else>
  109. <span class="word3 o-pr-10">{{ $t("device.sleepDesc") }}:</span>
  110. <span class="word3">{{ item.sleepDesc == null ? $t("device.SuspendBusiness") :
  111. item.sleepDesc }}</span>
  112. <van-icon name="edit" size="18" class="editIcon" @click="editSleepDesc()" />
  113. </div>
  114. </span>
  115. </div>
  116. <!-- <span class="txt5 o-ptb-10 kBordBott l-flex-RC"><span>一键重启炉头:</span>
  117. <van-button type="primary">重启</van-button>
  118. </span> -->
  119. <div class="word4 o-ptb-5">
  120. <span class="word3 o-pr-5" v-if="item.machineType == '0' || item.machineType == null">{{
  121. $t("device.furnHeadStatus") }}: </span>
  122. <span class="word3 o-pr-5" v-else>{{ $t("device.deviceStatus") }}: </span>
  123. <span>{{ item.eqeStatus === 1 ? $t("device.opened") : $t("device.closed") }}
  124. </span>
  125. <!-- <div class="l-flex-RC">
  126. <van-button type="primary">开启</van-button>
  127. <van-button type="primary">关闭</van-button>
  128. </div> -->
  129. </div>
  130. <!-- <span class="txt5 o-ptb-10 kBordBott l-flex-RC"><span>远程开门:</span>
  131. <van-button type="primary">开门</van-button>
  132. </span> -->
  133. <!-- 设备地址 -->
  134. <!-- <span class="txt1 o-ptb-7">{{ item.fullName }}</span> -->
  135. <!-- 定位: -->
  136. <!-- <div>
  137. <span v-if="item.latitude" class="txt5 o-ptb-7 kBordBott l-flex-RC">
  138. <span class="info1">{{
  139. $t("device.position") }}:</span>
  140. <van-button @click="viewPosiClk(item)" type="primary">{{
  141. $t("device.view")
  142. }}</van-button>
  143. </span>
  144. </div> -->
  145. <!-- 定位: -->
  146. <div>
  147. <span v-if="item.latitude" class="txt5 o-ptb-7 kBordBott l-flex-RC">
  148. <span class="info1">{{ $t("device.position") }}:</span>
  149. <a class="clickable-link o-ptb-7" @click="viewPosiClk(item)">{{ item.fullName }}</a>
  150. </span>
  151. </div>
  152. <van-row class="layer5 o-pt-7 kBordBott" justify="space-between"
  153. v-if="(item.machineType == '0' || item.machineType == null) && item.equimentType != 'P30'">
  154. <van-col class="word5" style="margin-bottom: 13px;">{{ $t("device.furnaceHeadTemperature") }}:{{
  155. item.furnaceTm
  156. }}{{ $t("device.degree") }}</van-col>
  157. <van-col class="word5" style="margin-bottom: 13px;">{{ $t("device.temperatureInCabinet") }}:{{
  158. item.cabinetTm
  159. }}{{ $t("device.degree") }}</van-col>
  160. <van-col class="word5" style="margin-bottom: 13px;">{{ $t("device.humidityInCabinet") }}:{{ item.cabinetHd
  161. }}{{ $t("device.humidity") }}</van-col>
  162. </van-row>
  163. <van-row class="layer5 o-pt-7 kBordBott" justify="space-between" v-else>
  164. <van-col class="word5" style="margin-bottom: 13px;">{{ $t("device.stirringTemperature") }}:{{
  165. item.stirTm
  166. }}{{ $t("device.degree") }}</van-col>
  167. <van-col class="word5" style="margin-bottom: 13px;">{{ $t("device.cornGeneratorTemperature") }}:{{
  168. item.cornGeneratorTm
  169. }}{{ $t("device.degree") }}</van-col>
  170. <van-col class="word5" style="margin-bottom: 13px;">{{ $t("device.cupQuantity") }}:{{ item.cupQuantity
  171. }}</van-col>
  172. </van-row>
  173. <template v-if="item.isMaterialUse === '1' && (item.machineType == '0' || item.machineType == null)">
  174. <van-row justify="space-between" class="sugarTxt o-pt-7 kBordBott">
  175. <van-col style="margin-bottom: 15px;">
  176. {{ $t("device.whiteSugar") }}:{{ Format_calcuDecial(item.whiteSugar) }}%
  177. </van-col>
  178. <van-col>
  179. {{ $t("device.redSugar") }}:{{ Format_calcuDecial(item.redSugar) }}%
  180. </van-col>
  181. <van-col>
  182. {{ $t("device.yellowSugar") }}:{{ Format_calcuDecial(item.yellowSugar) }}%
  183. </van-col>
  184. <van-col style="margin-bottom: 10px;">
  185. {{ $t("device.blueSugar") }}:{{ Format_calcuDecial(item.blueSugar) }}%
  186. </van-col>
  187. </van-row>
  188. <div class="info1 o-ptb-5 kBordBott">
  189. <span>{{ $t("device.stick") }}:{{
  190. Format_calcuDecial(item.stick)
  191. }}%</span>
  192. </div>
  193. <van-row gutter="50" class="sugarTxt o-ptb-7 kBordBott">
  194. <van-col>
  195. {{ $t("device.water") }}:{{ Format_calcuDecial(item.water) }}%
  196. </van-col>
  197. <van-col>
  198. {{ $t("device.wasteWater") }}:{{ Format_calcuDecial(item.wasteWater) }}%
  199. </van-col>
  200. </van-row>
  201. <!-- 一键补料 -->
  202. <span class="info1 o-ptb-5 kBordBott l-flex-RC"><span>{{ $t("device.oneKeyFeed") }}:</span>
  203. <!-- <van-button @click="replenishmentClk(item)" type="primary">{{ $t("device.replenishment") }}
  204. </van-button> -->
  205. <a class="replenishment o-ptb-7" @click="replenishmentClk(item)">{{ $t("device.replenishment")
  206. }}</a>
  207. </span>
  208. </template>
  209. <span class="info1 o-ptb-7 kBordBott">{{ $t("device.lastRefreshTime") }}:{{
  210. showDateTime(item.lastUpdateTime)
  211. }}</span>
  212. <span class="info2 o-ptb-7 kBordBott">{{ $t("device.volume") }}:{{ item.volume }}</span>
  213. <div class="l-flex-RC o-ptb-7">
  214. <span class="info3 kBordBott">{{ $t("device.alarmContent") }}:</span>
  215. <div class="info4 l-flex-RC">
  216. <span class="info5 o-pr-10 kBordBott">{{
  217. item.alarmList && item.alarmList[0]
  218. ? item.alarmList[0].alarmContent
  219. : $t("device.alarmContentNoData")
  220. }}
  221. </span>
  222. <van-button v-if="item.alarmList && item.alarmList[0]" type="primary" size="small" color="#07c160"
  223. :text="$t('device.eliminateAlarm')" @click="clearAlarm(item.alarmList[0])"></van-button>
  224. </div>
  225. </div>
  226. <div class="editDeviceBtnCon l-flex-center o-mt-10">
  227. <div class="l-flex-RC" @click="deviceSet(item)">
  228. <span class="c-text-14">{{
  229. $t("device.editDevice")
  230. }}</span>
  231. <div class="box2 flex-col"></div>
  232. </div>
  233. <div class="l-flex-RC o-ml-30" @click="deviceOprShow(item)">
  234. <span class="c-text-14">{{
  235. $t("device.commonOperations")
  236. }}</span>
  237. <div class="box2 flex-col"></div>
  238. </div>
  239. </div>
  240. </div>
  241. <div class="bd6 l-flex-center o-ptb-7" @click="item.checkType = !item.checkType">
  242. <div class="l-flex-RC">
  243. <span class="info2 o-mr-2">{{
  244. item.checkType ? $t("device.stow") : $t("device.seeMore")
  245. }}</span>
  246. <div class="group2 flex-col" :class="{ checkType: item.checkType }"></div>
  247. </div>
  248. </div>
  249. </div>
  250. <van-back-top @click="backTop" right="5vw" bottom="10vh" />
  251. </div>
  252. </div>
  253. </div>
  254. </van-list>
  255. </div>
  256. <deviceOper ref="oprRef" @operfinish="operFinish"></deviceOper>
  257. <!-- 搜索弹出框 -->
  258. <deviceSearch ref="searchRef" @search="search($event)"></deviceSearch>
  259. <div style="height: 50px;"></div>
  260. <!-- <nav-bar></nav-bar> -->
  261. </div>
  262. </template>
  263. <script>
  264. import {
  265. Api_postMachineNum,
  266. } from "../../service/home";
  267. import { onMounted, reactive, toRefs, ref, onActivated } from "vue";
  268. import { showFailToast, showSuccessToast, showToast, showDialog } from "vant";
  269. // import navBar from "../../components/NavBar";
  270. import sHeader from "../../components/SimpleHeader";
  271. import { getLoginUser, Format_calcuDecial } from "../../common/js/utils";
  272. import {
  273. getDeviceList,
  274. eliminate,
  275. Api_getReplenishment,
  276. changeSleepDesc,
  277. } from "../../service/device/index";
  278. import deviceSearch from "./deviceSearch";
  279. import deviceOper from "./deviceOper";
  280. import { onBeforeRouteLeave, useRouter } from "vue-router";
  281. import dateUtil from "../../utils/dateUtil";
  282. import { useI18n } from "vue-i18n";
  283. import { onBeforeUnmount } from "vue";
  284. export default {
  285. name: "device",
  286. components: { sHeader, deviceSearch, deviceOper },
  287. setup() {
  288. const { t } = useI18n();
  289. const searchRef = ref(null);
  290. const oprRef = ref(null);
  291. const list = ref([]);
  292. const loading = ref(true);
  293. const error = ref(false);
  294. const finished = ref(false);
  295. const router = useRouter();
  296. const sys = ref(null);
  297. const user = getLoginUser();
  298. const verticalScrollPosition = ref(0);
  299. // 返回顶部
  300. const backTop = () => {
  301. window.scrollY = 0;
  302. }
  303. onActivated(() => {
  304. // 当组件被激活时,可能是从 keep-alive 缓存中激活的
  305. // 这时重新添加滚动事件监听器
  306. console.log("进入时的位置", verticalScrollPosition.value);
  307. document.documentElement.scrollTop = verticalScrollPosition.value;
  308. document.body.scrollTop = verticalScrollPosition.value;
  309. window.scrollY = verticalScrollPosition.value;
  310. // window.addEventListener('scroll', handleScroll);
  311. });
  312. onBeforeRouteLeave(() => {
  313. verticalScrollPosition.value = document.documentElement.scrollTop || document.body.scrollTop || window.scrollY;
  314. console.log("离开时的位置", verticalScrollPosition.value);
  315. })
  316. // 在组件卸载前清除定时器
  317. onBeforeUnmount(() => {
  318. clearInterval(updateDataInterval);
  319. });
  320. const updateDataInterval = () => {
  321. // 每隔5分钟更新数据
  322. setInterval(() => {
  323. init();
  324. if (oprRef.value) {
  325. oprRef.value.closeOper();
  326. }
  327. // verticalScrollPosition.value = 0;
  328. }, 5 * 60 * 1000); // 5分钟的毫秒数
  329. };
  330. //控制睡眠描述的显示隐藏
  331. const sleepDescBoxShow = ref(true);
  332. // 页面列表查询参数
  333. let searchParams = reactive({
  334. id: "", // 用户账户id
  335. // adminName: '', // 用户登录名
  336. current: 1, // 页数
  337. size: 10, // 页大小
  338. todayDate: dateUtil.formateDate(new Date(), "yyyy-MM-dd"), // 当天时间
  339. });
  340. // 初始化页面获取列表
  341. onMounted(() => {
  342. init();
  343. updateDataInterval();
  344. // window.addEventListener('scroll', handleScroll);
  345. // 加载样式
  346. // styleUrl('device');
  347. });
  348. // 初始化
  349. const init = () => {
  350. // 获取设备情况
  351. getMachineNum();
  352. if (localStorage.getItem("loginSys")) {
  353. const loginSysString = localStorage.getItem("loginSys");
  354. sys.value = JSON.parse(loginSysString);
  355. }
  356. list.value = [];
  357. searchParams.current = 1;
  358. if (user) {
  359. searchParams.id = user.id;
  360. // if (user.isAdmined) {
  361. // searchParams.adminName = user.username;
  362. // }
  363. getList();
  364. }
  365. };
  366. // 获取设备列表数据
  367. const getList = async () => {
  368. finished.value = false;
  369. const { data } = await getDeviceList(Object.assign({}, searchParams));
  370. if (data.code === "00000") {
  371. if (searchParams.current === 0) {
  372. list.value = [];
  373. }
  374. // 列表值叠加
  375. list.value = list.value.concat(
  376. data.data.records.map((item) => {
  377. if (item.sleepDesc == null) {
  378. item.sleepDesc = t("device.SuspendBusiness");
  379. }
  380. return {
  381. ...item,
  382. checkType: false,
  383. };
  384. })
  385. );
  386. if (list.value.length === data.data.total) {
  387. finished.value = true;
  388. }
  389. loading.value = false;
  390. } else {
  391. showFailToast(data.message);
  392. }
  393. };
  394. // 滚动加载
  395. const onLoad = () => {
  396. if (!finished.value) {
  397. // console.log("滚动加载")
  398. searchParams.current = searchParams.current + 1;
  399. getList();
  400. }
  401. };
  402. // 搜索点击
  403. const searchClick = () => {
  404. searchRef.value.showSearch();
  405. };
  406. // 搜索条件触发查询
  407. const search = (e) => {
  408. list.value = [];
  409. loading.value = true;
  410. searchParams.current = 1;
  411. searchParams = Object.assign(searchParams, e);
  412. getList();
  413. getMachineNum();
  414. };
  415. // 跳转设备编辑
  416. const deviceSet = (e) => {
  417. router.push({ path: "deviceSet", query: { deviceId: e.id } });
  418. };
  419. // 常用操作弹窗展示触发
  420. const deviceOprShow = (e) => {
  421. oprRef.value.showOper(e);
  422. };
  423. // 消除报警
  424. const clearAlarm = async (e) => {
  425. const params = {
  426. id: e.id,
  427. name: e.name,
  428. selfName: e.selfName,
  429. areaId: e.areaId,
  430. channel: e.channel,
  431. contactName: e.contactName,
  432. contactPhone: e.contactPhone,
  433. flowers: e.flowers,
  434. operationalName: e.operationalName,
  435. operationalPhone: e.operationalPhone,
  436. timeRuleId: e.timeRuleId,
  437. };
  438. const { data } = await eliminate(Object.assign({}, params));
  439. if (data.code) {
  440. showSuccessToast(t("device.successfullyEliminatedTheAlarm"));
  441. e.alarmList = [];
  442. } else {
  443. showFailToast(data.message);
  444. }
  445. console.log("/tEquipment/eliminate", e);
  446. };
  447. const showDateTime = (date) => {
  448. if (!date) {
  449. return "";
  450. }
  451. const currentDate = new Date(dateUtil.formateDate(new Date(date), "yyyy-MM-dd hh:mm:ss"));
  452. return dateUtil.timeZoneDate(currentDate);
  453. };
  454. // 点击查看定位
  455. const viewPosiClk = (row) => {
  456. console.log("row 是 >>>", row);
  457. if (row.latitude) {
  458. router.push({
  459. path: "viewPosition",
  460. query: {
  461. latitude: row.latitude,
  462. longitude: row.longitude,
  463. fullName: row.fullName,
  464. },
  465. });
  466. } else {
  467. showToast(`${t("device.noPosition")}!!!`);
  468. }
  469. };
  470. // 点击补料
  471. const replenishmentClk = (row) => {
  472. console.log("row >>>", row);
  473. Api_getReplenishment({ equipmentId: row.id }).then((res) => {
  474. console.log("res >>>", res);
  475. // Toast(res.data.message);
  476. showDialog({
  477. message: t('device.sentSuccessfully'),
  478. }).then(() => {
  479. //返回上一页
  480. router.go(0);
  481. });
  482. setTimeout(() => {
  483. getList();
  484. }, 500);
  485. });
  486. };
  487. // 操作弹窗完成的回调
  488. const operFinish = () => {
  489. init();
  490. };
  491. // 设备状况
  492. const equipStatus = ref({});
  493. // 获取设备情况
  494. const getMachineNum = () => {
  495. Api_postMachineNum({
  496. adminId: user.id,
  497. companyType: searchParams.companyType
  498. }).then((res) => {
  499. equipStatus.value = res.data.data || {};
  500. });
  501. };
  502. // 点击运行总数和总设备数
  503. const eqeStatusClk = (val) => {
  504. searchParams.eqeStatus = val;
  505. // 初始化
  506. searchParams.current = 1;
  507. list.value = [];
  508. getList();
  509. };
  510. // 点击修改图标
  511. const editSleepDesc = () => {
  512. sleepDescBoxShow.value = !sleepDescBoxShow.value;
  513. }
  514. // 点击睡眠描述的确定按钮
  515. const sleepDescChg = async (sleepDesc, id) => {
  516. console.log(sleepDesc);
  517. if (!sleepDesc) {
  518. showToast(t("device.sleepDescPlace"));
  519. } else {
  520. const { data } = await changeSleepDesc({
  521. equipmentId: id,
  522. sleepDesc,
  523. });
  524. if (data.code === "00000") {
  525. sleepDescBoxShow.value = true;
  526. showToast(data.message);
  527. // setTimeout(() => {
  528. // gettAdminGetRelation();
  529. // }, 500);
  530. }
  531. }
  532. }
  533. return {
  534. ...toRefs(searchParams),
  535. list,
  536. loading,
  537. error,
  538. finished,
  539. onLoad,
  540. searchRef,
  541. searchClick,
  542. search,
  543. deviceSet,
  544. clearAlarm,
  545. oprRef,
  546. deviceOprShow,
  547. showDateTime,
  548. sys,
  549. viewPosiClk,
  550. replenishmentClk,
  551. Format_calcuDecial,
  552. operFinish,
  553. equipStatus,
  554. eqeStatusClk,
  555. editSleepDesc,
  556. sleepDescBoxShow,
  557. sleepDescChg,
  558. backTop,
  559. };
  560. },
  561. };
  562. </script>
  563. <style lang="less" scoped>
  564. @import "../../common/style/common";
  565. @import "../../styles/device/index";
  566. </style>