index.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  1. <template>
  2. <!-- 设备列表 -->
  3. <div class="devicePage flex-col">
  4. <s-header :name="sys ? sys.title : $t('device.managementCenter')" :noback="true"></s-header>
  5. <div class="listBox">
  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="layer2 flex-row justify-between o-ptb-7 kBordBott">
  87. <span class="info1 o-ptb-7 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-7">
  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-ptb-7 kBordBott" justify="space-between"
  153. v-if="(item.machineType == '0' || item.machineType == null) && item.equimentType != 'P30'">
  154. <van-col class="word5">{{ $t("device.furnaceHeadTemperature") }}:{{
  155. item.furnaceTm
  156. }}{{ $t("device.degree") }}</van-col>
  157. <van-col class="word5">{{ $t("device.temperatureInCabinet") }}:{{
  158. item.cabinetTm
  159. }}{{ $t("device.degree") }}</van-col>
  160. <van-col class="word5">{{ $t("device.humidityInCabinet") }}:{{ item.cabinetHd
  161. }}{{ $t("device.humidity") }}</van-col>
  162. </van-row>
  163. <van-row class="layer5 o-ptb-7 kBordBott" justify="space-between" v-else>
  164. <van-col class="word5">{{ $t("device.stirringTemperature") }}:{{
  165. item.stirTm
  166. }}{{ $t("device.degree") }}</van-col>
  167. <van-col class="word5">{{ $t("device.cornGeneratorTemperature") }}:{{
  168. item.cornGeneratorTm
  169. }}{{ $t("device.degree") }}</van-col>
  170. <van-col class="word5">{{ $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-ptb-7 kBordBott">
  175. <van-col>
  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>
  185. {{ $t("device.blueSugar") }}:{{ Format_calcuDecial(item.blueSugar) }}%
  186. </van-col>
  187. </van-row>
  188. <div class="sugarTxt o-ptb-7 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="txt5 o-ptb-7 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 o-pr-10 kBordBott">{{ $t("device.alarmContent") }}:{{
  215. item.alarmList && item.alarmList[0]
  216. ? item.alarmList[0].alarmContent
  217. : item.alarmContent
  218. }}
  219. </span>
  220. <van-button v-if="item.alarmList && item.alarmList[0]" type="primary" size="small" color="#07c160"
  221. :text="$t('device.eliminateAlarm')" @click="clearAlarm(item.alarmList[0])"></van-button>
  222. </div>
  223. <div class="editDeviceBtnCon l-flex-center o-mt-10">
  224. <div class="l-flex-RC" @click="deviceSet(item)">
  225. <span class="c-text-14">{{
  226. $t("device.editDevice")
  227. }}</span>
  228. <div class="box2 flex-col"></div>
  229. </div>
  230. <div class="l-flex-RC o-ml-30" @click="deviceOprShow(item)">
  231. <span class="c-text-14">{{
  232. $t("device.commonOperations")
  233. }}</span>
  234. <div class="box2 flex-col"></div>
  235. </div>
  236. </div>
  237. </div>
  238. <div class="bd6 l-flex-center o-ptb-7" @click="item.checkType = !item.checkType">
  239. <div class="l-flex-RC">
  240. <span class="info2 o-mr-2">{{
  241. item.checkType ? $t("device.stow") : $t("device.seeMore")
  242. }}</span>
  243. <div class="group2 flex-col" :class="{ checkType: item.checkType }"></div>
  244. </div>
  245. </div>
  246. </div>
  247. <van-back-top @click="backTop" right="5vw" bottom="10vh" />
  248. </div>
  249. </div>
  250. </div>
  251. </van-list>
  252. </div>
  253. <deviceOper ref="oprRef" @operfinish="operFinish"></deviceOper>
  254. <!-- 搜索弹出框 -->
  255. <deviceSearch ref="searchRef" @search="search($event)"></deviceSearch>
  256. <div style="height: 50px;"></div>
  257. <nav-bar></nav-bar>
  258. </div>
  259. </template>
  260. <script>
  261. import {
  262. Api_postMachineNum,
  263. } from "../../service/home";
  264. import { onMounted, reactive, toRefs, ref, onActivated } from "vue";
  265. import { showFailToast, showSuccessToast, showToast, showDialog } from "vant";
  266. import navBar from "../../components/NavBar";
  267. import sHeader from "../../components/SimpleHeader";
  268. import { getLoginUser, Format_calcuDecial } from "../../common/js/utils";
  269. import {
  270. getDeviceList,
  271. eliminate,
  272. Api_getReplenishment,
  273. changeSleepDesc,
  274. } from "../../service/device/index";
  275. import deviceSearch from "./deviceSearch";
  276. import deviceOper from "./deviceOper";
  277. import { onBeforeRouteLeave, useRouter } from "vue-router";
  278. import dateUtil from "../../utils/dateUtil";
  279. import { useI18n } from "vue-i18n";
  280. import { onBeforeUnmount } from "vue";
  281. export default {
  282. name: "device",
  283. components: { sHeader, navBar, deviceSearch, deviceOper },
  284. setup() {
  285. const { t } = useI18n();
  286. const searchRef = ref(null);
  287. const oprRef = ref(null);
  288. const list = ref([]);
  289. const loading = ref(true);
  290. const error = ref(false);
  291. const finished = ref(false);
  292. const router = useRouter();
  293. const sys = ref(null);
  294. const user = getLoginUser();
  295. const verticalScrollPosition = ref(0);
  296. // 返回顶部
  297. const backTop = () => {
  298. window.scrollY = 0;
  299. }
  300. onActivated(() => {
  301. // 当组件被激活时,可能是从 keep-alive 缓存中激活的
  302. // 这时重新添加滚动事件监听器
  303. console.log("进入时的位置", verticalScrollPosition.value);
  304. document.documentElement.scrollTop = verticalScrollPosition.value;
  305. document.body.scrollTop = verticalScrollPosition.value;
  306. window.scrollY = verticalScrollPosition.value;
  307. // window.addEventListener('scroll', handleScroll);
  308. });
  309. onBeforeRouteLeave(() => {
  310. verticalScrollPosition.value = document.documentElement.scrollTop || document.body.scrollTop || window.scrollY;
  311. console.log("离开时的位置", verticalScrollPosition.value);
  312. })
  313. // 在组件卸载前清除定时器
  314. onBeforeUnmount(() => {
  315. clearInterval(updateDataInterval);
  316. });
  317. const updateDataInterval = () => {
  318. // 每隔5分钟更新数据
  319. setInterval(() => {
  320. init();
  321. if (oprRef.value) {
  322. oprRef.value.closeOper();
  323. }
  324. // verticalScrollPosition.value = 0;
  325. }, 5 * 60 * 1000); // 5分钟的毫秒数
  326. };
  327. //控制睡眠描述的显示隐藏
  328. const sleepDescBoxShow = ref(true);
  329. // 页面列表查询参数
  330. let searchParams = reactive({
  331. id: "", // 用户账户id
  332. // adminName: '', // 用户登录名
  333. current: 1, // 页数
  334. size: 15, // 页大小
  335. todayDate: dateUtil.formateDate(new Date(), "yyyy-MM-dd"), // 当天时间
  336. });
  337. // 初始化页面获取列表
  338. onMounted(() => {
  339. init();
  340. updateDataInterval();
  341. // window.addEventListener('scroll', handleScroll);
  342. // 加载样式
  343. // styleUrl('device');
  344. });
  345. // 初始化
  346. const init = () => {
  347. // 获取设备情况
  348. getMachineNum();
  349. if (localStorage.getItem("loginSys")) {
  350. const loginSysString = localStorage.getItem("loginSys");
  351. sys.value = JSON.parse(loginSysString);
  352. }
  353. list.value = [];
  354. searchParams.current = 1;
  355. if (user) {
  356. searchParams.id = user.id;
  357. // if (user.isAdmined) {
  358. // searchParams.adminName = user.username;
  359. // }
  360. getList();
  361. }
  362. };
  363. // 获取设备列表数据
  364. const getList = async () => {
  365. finished.value = false;
  366. const { data } = await getDeviceList(Object.assign({}, searchParams));
  367. if (data.code === "00000") {
  368. if (searchParams.current === 0) {
  369. list.value = [];
  370. }
  371. // 列表值叠加
  372. list.value = list.value.concat(
  373. data.data.records.map((item) => {
  374. if (item.sleepDesc == null) {
  375. item.sleepDesc = t("device.SuspendBusiness");
  376. }
  377. return {
  378. ...item,
  379. checkType: false,
  380. };
  381. })
  382. );
  383. if (list.value.length === data.data.total) {
  384. finished.value = true;
  385. }
  386. loading.value = false;
  387. } else {
  388. showFailToast(data.message);
  389. }
  390. };
  391. // 滚动加载
  392. const onLoad = () => {
  393. if (!finished.value) {
  394. // console.log("滚动加载")
  395. searchParams.current = searchParams.current + 1;
  396. getList();
  397. }
  398. };
  399. // 搜索点击
  400. const searchClick = () => {
  401. searchRef.value.showSearch();
  402. };
  403. // 搜索条件触发查询
  404. const search = (e) => {
  405. list.value = [];
  406. loading.value = true;
  407. searchParams.current = 1;
  408. searchParams = Object.assign(searchParams, e);
  409. getList();
  410. getMachineNum();
  411. };
  412. // 跳转设备编辑
  413. const deviceSet = (e) => {
  414. router.push({ path: "deviceSet", query: { deviceId: e.id } });
  415. };
  416. // 常用操作弹窗展示触发
  417. const deviceOprShow = (e) => {
  418. oprRef.value.showOper(e);
  419. };
  420. // 消除报警
  421. const clearAlarm = async (e) => {
  422. const params = {
  423. id: e.id,
  424. name: e.name,
  425. selfName: e.selfName,
  426. areaId: e.areaId,
  427. channel: e.channel,
  428. contactName: e.contactName,
  429. contactPhone: e.contactPhone,
  430. flowers: e.flowers,
  431. operationalName: e.operationalName,
  432. operationalPhone: e.operationalPhone,
  433. timeRuleId: e.timeRuleId,
  434. };
  435. const { data } = await eliminate(Object.assign({}, params));
  436. if (data.code) {
  437. showSuccessToast(t("device.successfullyEliminatedTheAlarm"));
  438. e.alarmList = [];
  439. } else {
  440. showFailToast(data.message);
  441. }
  442. console.log("/tEquipment/eliminate", e);
  443. };
  444. const showDateTime = (date) => {
  445. if (!date) {
  446. return "";
  447. }
  448. const currentDate = new Date(dateUtil.formateDate(new Date(date), "yyyy-MM-dd hh:mm:ss"));
  449. return dateUtil.timeZoneDate(currentDate);
  450. };
  451. // 点击查看定位
  452. const viewPosiClk = (row) => {
  453. console.log("row 是 >>>", row);
  454. if (row.latitude) {
  455. router.push({
  456. path: "viewPosition",
  457. query: {
  458. latitude: row.latitude,
  459. longitude: row.longitude,
  460. fullName: row.fullName,
  461. },
  462. });
  463. } else {
  464. showToast(`${t("device.noPosition")}!!!`);
  465. }
  466. };
  467. // 点击补料
  468. const replenishmentClk = (row) => {
  469. console.log("row >>>", row);
  470. Api_getReplenishment({ equipmentId: row.id }).then((res) => {
  471. console.log("res >>>", res);
  472. // Toast(res.data.message);
  473. showDialog({
  474. message: t('device.sentSuccessfully'),
  475. }).then(() => {
  476. //返回上一页
  477. router.go(0);
  478. });
  479. setTimeout(() => {
  480. getList();
  481. }, 500);
  482. });
  483. };
  484. // 操作弹窗完成的回调
  485. const operFinish = () => {
  486. init();
  487. };
  488. // 设备状况
  489. const equipStatus = ref({});
  490. // 获取设备情况
  491. const getMachineNum = () => {
  492. Api_postMachineNum({
  493. adminId: user.id,
  494. companyType: searchParams.companyType
  495. }).then((res) => {
  496. equipStatus.value = res.data.data || {};
  497. });
  498. };
  499. // 点击运行总数和总设备数
  500. const eqeStatusClk = (val) => {
  501. searchParams.eqeStatus = val;
  502. // 初始化
  503. searchParams.current = 1;
  504. list.value = [];
  505. getList();
  506. };
  507. // 点击修改图标
  508. const editSleepDesc = () => {
  509. sleepDescBoxShow.value = !sleepDescBoxShow.value;
  510. }
  511. // 点击睡眠描述的确定按钮
  512. const sleepDescChg = async (sleepDesc, id) => {
  513. console.log(sleepDesc);
  514. if (!sleepDesc) {
  515. showToast(t("device.sleepDescPlace"));
  516. } else {
  517. const { data } = await changeSleepDesc({
  518. equipmentId: id,
  519. sleepDesc,
  520. });
  521. if (data.code === "00000") {
  522. sleepDescBoxShow.value = true;
  523. showToast(data.message);
  524. // setTimeout(() => {
  525. // gettAdminGetRelation();
  526. // }, 500);
  527. }
  528. }
  529. }
  530. return {
  531. ...toRefs(searchParams),
  532. list,
  533. loading,
  534. error,
  535. finished,
  536. onLoad,
  537. searchRef,
  538. searchClick,
  539. search,
  540. deviceSet,
  541. clearAlarm,
  542. oprRef,
  543. deviceOprShow,
  544. showDateTime,
  545. sys,
  546. viewPosiClk,
  547. replenishmentClk,
  548. Format_calcuDecial,
  549. operFinish,
  550. equipStatus,
  551. eqeStatusClk,
  552. editSleepDesc,
  553. sleepDescBoxShow,
  554. sleepDescChg,
  555. backTop,
  556. };
  557. },
  558. };
  559. </script>
  560. <style lang="less" scoped>
  561. @import "../../common/style/common";
  562. @import "../../styles/device/index";
  563. </style>