index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  1. <template>
  2. <div class="curtain" v-if="curtainData && curtainData.length">
  3. <div class="curtain-top">
  4. <div class="curtain-desc">
  5. <p class="curtain-title">
  6. {{
  7. curtainData.length && curtainData.length == 1
  8. ? curtainData[0].name
  9. : "窗帘"
  10. }}
  11. </p>
  12. </div>
  13. <div class="curtain-right">
  14. <img
  15. v-if="
  16. curtainData[0].equipmentType !== 4 &&
  17. curtainData[0].equipmentType !== 5
  18. "
  19. :src="parseImgUrl('page-officehome', 'curtain_new.svg')"
  20. alt=""
  21. />
  22. <img
  23. v-else
  24. :src="parseImgUrl('page-officehome', 'curtain_roll.svg')"
  25. alt=""
  26. />
  27. </div>
  28. </div>
  29. <div
  30. class="curtain-box"
  31. v-if="curtainData.length && curtainData.length > 1"
  32. >
  33. <div class="top-nav">
  34. <span
  35. :class="type == 'all' ? 'nav-active' : ''"
  36. @click="checkNav('all')"
  37. >
  38. 总控制
  39. </span>
  40. <span
  41. :class="type == 'child' ? 'nav-active' : ''"
  42. @click="checkNav('child')"
  43. >
  44. 子设备
  45. </span>
  46. </div>
  47. </div>
  48. <template v-if="type == 'all'">
  49. <div
  50. class="line"
  51. v-if="curtainData.length && curtainData.length > 1"
  52. ></div>
  53. <div class="top-control">
  54. <div
  55. class="control-item"
  56. v-if="curtainData[0].isOpenSet"
  57. @click="openCurtainOpening(curtainData)"
  58. >
  59. <img
  60. class="curtain-opening-icon"
  61. :src="parseImgUrl('page-officehome', 'curtain_opening.svg')"
  62. alt=""
  63. />
  64. </div>
  65. <!--左关-下关-->
  66. <div
  67. class="control-item"
  68. :class="activeIndex == 1 ? 'control-item-active' : ''"
  69. @click="openCurtainMain(1)"
  70. >
  71. <template v-if="activeIndex !== 1">
  72. <img
  73. v-if="
  74. curtainData[0].equipmentType !== 4 &&
  75. curtainData[0].equipmentType !== 5
  76. "
  77. :src="parseImgUrl('page-officehome', 'curtain_left.svg')"
  78. alt=""
  79. />
  80. <img
  81. v-else
  82. :src="parseImgUrl('page-officehome', 'curtain_down.svg')"
  83. alt=""
  84. />
  85. </template>
  86. <span v-else>{{ count }}</span>
  87. </div>
  88. <!--暂停-->
  89. <div
  90. class="control-item"
  91. @click="openCurtainMain(3)"
  92. v-if="curtainData[0].stopSet"
  93. >
  94. <img
  95. :src="parseImgUrl('page-officehome', 'curtain_stop.svg')"
  96. alt=""
  97. />
  98. </div>
  99. <!--右开-->
  100. <div
  101. class="control-item"
  102. @click="openCurtainMain(2)"
  103. :class="activeIndex == 2 ? 'control-item-active' : ''"
  104. >
  105. <template v-if="activeIndex !== 2">
  106. <img
  107. v-if="
  108. curtainData[0].equipmentType !== 4 &&
  109. curtainData[0].equipmentType !== 5
  110. "
  111. :src="parseImgUrl('page-officehome', 'curtain_right.svg')"
  112. alt=""
  113. />
  114. <img
  115. v-else
  116. :src="parseImgUrl('page-officehome', 'curtain_up.svg')"
  117. alt=""
  118. />
  119. </template>
  120. <span v-else>{{ count }}</span>
  121. </div>
  122. </div>
  123. </template>
  124. <div class="curtain-child" v-if="type == 'child'">
  125. <div class="child-item" :key="item.id" v-for="item in curtainData">
  126. <div class="curtain-name">
  127. <div class="name">{{ item.name }}</div>
  128. <span v-if="item.isOpenSet">开度{{ item.openValue }}%</span>
  129. </div>
  130. <div class="curtain-control top-control">
  131. <div
  132. class="control-item"
  133. @click="openCurtainOpening([item])"
  134. v-if="item.isOpenSet"
  135. >
  136. <img
  137. :src="parseImgUrl('page-officehome', 'curtain_opening.svg')"
  138. alt=""
  139. />
  140. </div>
  141. <!--左边-->
  142. <div
  143. class="control-item"
  144. @click="openCurtainClid(item, 1)"
  145. :class="item.activeIndex == 1 ? 'control-item-active' : ''"
  146. >
  147. <template v-if="item.activeIndex != 1">
  148. <img
  149. v-if="item.equipmentType !== 4 && item.equipmentType !== 5"
  150. :src="parseImgUrl('page-officehome', 'curtain_left.svg')"
  151. alt=""
  152. />
  153. <img
  154. v-else
  155. :src="parseImgUrl('page-officehome', 'curtain_down.svg')"
  156. alt=""
  157. />
  158. </template>
  159. <span v-else>{{ item.count }}</span>
  160. </div>
  161. <!--暂停-->
  162. <div
  163. class="control-item"
  164. @click="openCurtainClid(item, 3)"
  165. :class="item.activeIndex == 3 ? 'control-item-active' : ''"
  166. v-if="item.stopSet"
  167. >
  168. <img
  169. :src="parseImgUrl('page-officehome', 'curtain_stop.svg')"
  170. alt=""
  171. />
  172. </div>
  173. <!-- {{ item }} -->
  174. <!--右边-->
  175. <div
  176. class="control-item"
  177. @click="openCurtainClid(item, 2)"
  178. :class="item.activeIndex == 2 ? 'control-item-active' : ''"
  179. >
  180. <template v-if="item.activeIndex != 2">
  181. <img
  182. v-if="item.equipmentType !== 4 && item.equipmentType !== 5"
  183. :src="parseImgUrl('page-officehome', 'curtain_right.svg')"
  184. alt=""
  185. />
  186. <img
  187. v-else
  188. :src="parseImgUrl('page-officehome', 'curtain_up.svg')"
  189. alt=""
  190. />
  191. </template>
  192. <span v-else>{{ item.count }}</span>
  193. </div>
  194. </div>
  195. </div>
  196. </div>
  197. </div>
  198. </template>
  199. <script lang="ts">
  200. import {
  201. computed,
  202. defineComponent,
  203. onBeforeUnmount,
  204. onMounted,
  205. reactive,
  206. toRefs,
  207. watch,
  208. } from "vue";
  209. import {
  210. getObjectDataEqpGroupHttp,
  211. setEquipeHttp,
  212. setSpaceCondtioners,
  213. } from "@/apis/envmonitor";
  214. import { formatDate, parseImgUrl } from "@/utils";
  215. import { Toast } from "vant";
  216. export default defineComponent({
  217. props: {
  218. projectId: {
  219. type: String,
  220. default: () => "",
  221. },
  222. spaceId: {
  223. type: String,
  224. default: () => "",
  225. },
  226. userIsControl: {
  227. type: Boolean,
  228. default: () => false,
  229. },
  230. },
  231. setup(props, contx) {
  232. let curtainData: any = [];
  233. let timer: any = null;
  234. let projectId: any = props.projectId;
  235. let type: any = "all";
  236. let interval: any = {};
  237. let oldTime: any = null;
  238. const proxyData = reactive({
  239. curtainData: curtainData,
  240. userIsControl: props.userIsControl,
  241. lightIcon: "arrow-down",
  242. projectId: projectId,
  243. type: type,
  244. countText: "", // 到记时文案
  245. count: 2, // 到记时
  246. curtainOpen: false,
  247. curtainClose: false,
  248. parseImgUrl: parseImgUrl,
  249. // 开度弹窗
  250. activeIndex: 0,
  251. // 打开开度弹窗
  252. openCurtainOpening(selectData: any) {
  253. contx.emit("showCurtainOpening", selectData);
  254. },
  255. // 导航切换
  256. checkNav(type: any) {
  257. proxyData.type = type;
  258. console.log("proxyData.type==", proxyData.type);
  259. },
  260. // 获取窗帘列表
  261. getEqpGroup() {
  262. const params: any = {
  263. criteria: {
  264. projectId: props.projectId,
  265. spaceId: props.spaceId, // 空间ID
  266. type: 0, // 0.窗帘
  267. },
  268. orders: [
  269. {
  270. column: "sortNum",
  271. asc: true,
  272. },
  273. ],
  274. };
  275. getObjectDataEqpGroupHttp(params).then((res) => {
  276. const resData: any = res;
  277. proxyData.curtainData = resData.count ? resData.content : [];
  278. // 初始化状态数据
  279. proxyData.curtainData.map((item: any) => {
  280. item.count = 0;
  281. item.activeIndex = 0;
  282. });
  283. });
  284. },
  285. // 定时器定时计算
  286. interval: interval,
  287. countInterval() {
  288. proxyData.interval = setInterval(() => {
  289. proxyData.count--;
  290. if (proxyData.count == 0) {
  291. proxyData.count = 2;
  292. proxyData.activeIndex = 0;
  293. clearInterval(proxyData.interval);
  294. }
  295. }, 1000);
  296. },
  297. countChildInterval(item: any) {
  298. // debugger
  299. proxyData.interval = setInterval(() => {
  300. item.count--;
  301. if (item.count == 0) {
  302. item.count = 2;
  303. item.activeIndex = 0;
  304. clearInterval(proxyData.interval);
  305. }
  306. // console.log(item.count)
  307. }, 1000);
  308. },
  309. // 窗帘总开关
  310. openCurtainMain(type: any) {
  311. // type=1(关) type=2(开) type=3(暂停)
  312. if (proxyData.activeIndex == type && proxyData.count !== 0) {
  313. return;
  314. }
  315. proxyData.activeIndex = type;
  316. proxyData.count = 2;
  317. proxyData.countInterval();
  318. proxyData.formateCurtainData(type);
  319. },
  320. formateValue(type: any) {
  321. let value: any = 0;
  322. if (type == 1) {
  323. value = 0;
  324. } else if (type == 2) {
  325. value = 1;
  326. } else {
  327. value = 2;
  328. }
  329. return value;
  330. },
  331. // 处理窗帘数据
  332. formateCurtainData(type: any) {
  333. let data: any = [];
  334. let value: any = proxyData.formateValue(type);
  335. proxyData.curtainData.map((item: any) => {
  336. let obj: any = {
  337. id: item.equipId,
  338. code: "EquipSwitchSet",
  339. value: value,
  340. };
  341. data.push(obj);
  342. });
  343. proxyData.changeCurtainStatus(data);
  344. },
  345. // 修改窗帘的状态
  346. changeCurtainStatus(data: any) {
  347. console.log("窗帘==", data);
  348. setSpaceCondtioners(data).then((res) => {
  349. proxyData.oldTime = formatDate("YYYY.MM.DD HH:mm:ss");
  350. if (!proxyData.timer) {
  351. proxyData.updateGroupPeing();
  352. }
  353. });
  354. },
  355. // 单个窗帘操作
  356. openCurtainClid(item: any, type: any) {
  357. if (item.activeIndex == type && item.count !== 0) {
  358. return;
  359. }
  360. item.activeIndex = type;
  361. let data: any = [];
  362. let obj: any = {
  363. id: item.equipId,
  364. // id: "Eq110108025995ec5bdc23fc47a0a9d8debb150d18eb",
  365. code: "EquipSwitchSet",
  366. value: proxyData.formateValue(type),
  367. };
  368. data.push(obj);
  369. item.count = 2;
  370. proxyData.countChildInterval(item);
  371. proxyData.changeCurtainStatus(data);
  372. },
  373. oldTime: oldTime,
  374. timer: timer,
  375. clearTimer() {
  376. clearInterval(proxyData.timer);
  377. proxyData.timer = null;
  378. },
  379. // 更新窗帘的开度
  380. updateGroupPeing() {
  381. // debugger
  382. proxyData.timer = setInterval(() => {
  383. let nowTime: any = formatDate("YYYY.MM.DD HH:mm:ss");
  384. if (proxyData.oldTime) {
  385. let secondTimeDiff: any = proxyData.getTimeDifference(
  386. proxyData.oldTime,
  387. nowTime
  388. );
  389. // console.log("secondTimeDiff==",secondTimeDiff)
  390. if (secondTimeDiff > 60) {
  391. proxyData.getEqpGroup();
  392. proxyData.clearTimer();
  393. }
  394. } else {
  395. proxyData.oldTime = formatDate("YYYY.MM.DD HH:mm:ss");
  396. }
  397. }, 1000);
  398. },
  399. //计算时间差-分钟
  400. getTimeDifference(Stime: any, Ttime: any) {
  401. // debugger
  402. let startDate: any = new Date(Stime);
  403. let stopDate: any = new Date(Ttime);
  404. let startTime: any = startDate.getTime();
  405. let stopTime: any = stopDate.getTime();
  406. let cTime: any = Number(stopTime) - Number(startTime);
  407. let secondTime: any = cTime / 1000;
  408. return parseInt(secondTime);
  409. },
  410. });
  411. watch(props, (newProps: any) => {
  412. if (newProps.spaceId) {
  413. // 当前空间的控制权限
  414. proxyData.getEqpGroup();
  415. proxyData.userIsControl = newProps.userIsControl;
  416. }
  417. });
  418. onBeforeUnmount(() => {
  419. proxyData.clearTimer();
  420. clearInterval(proxyData.interval);
  421. });
  422. onMounted(() => {
  423. // 获取窗帘信息
  424. proxyData.getEqpGroup();
  425. });
  426. return {
  427. ...toRefs(proxyData),
  428. };
  429. },
  430. });
  431. </script>
  432. <style lang="scss" scoped>
  433. .curtain {
  434. width: 100%;
  435. padding-top: 17px;
  436. padding-bottom: 16px;
  437. background: #ffffff;
  438. box-shadow: 0px 0px 2px rgba(0, 0, 0, 0.07), 0px 4px 10px rgba(0, 0, 0, 0.05);
  439. border-radius: 25px;
  440. margin: 15px 0px;
  441. }
  442. .curtain-top {
  443. padding-right: 20px;
  444. padding-left: 20px;
  445. display: flex;
  446. justify-content: space-between;
  447. padding-bottom: 20px;
  448. .curtain-desc {
  449. .curtain-title {
  450. padding-top: 7px;
  451. font-family: "PingFang SC";
  452. font-style: normal;
  453. font-weight: 600;
  454. font-size: 16px;
  455. line-height: 22px;
  456. /* TUI/Subtitle */
  457. color: #4d5262;
  458. }
  459. }
  460. .curtain-right {
  461. position: relative;
  462. width: 100px;
  463. text-align: center;
  464. margin-right: 33px;
  465. img {
  466. width: 100px;
  467. height: 62px;
  468. }
  469. }
  470. }
  471. .curtain-box {
  472. display: flex;
  473. justify-content: space-between;
  474. padding: 0px 20px;
  475. padding-bottom: 25px;
  476. padding-top: 10px;
  477. .top-nav {
  478. height: 28px;
  479. line-height: 28px;
  480. border-radius: 21px;
  481. background: #f1f4f6;
  482. span {
  483. box-sizing: border-box;
  484. display: inline-block;
  485. font-family: "PingFang SC";
  486. font-style: normal;
  487. font-weight: 400;
  488. font-size: 14px;
  489. line-height: 28px;
  490. padding: 0 8px;
  491. color: #424c59;
  492. }
  493. .nav-active {
  494. background: #fff;
  495. border: 1px solid #e1e5eb;
  496. border-radius: 21px;
  497. }
  498. }
  499. }
  500. .line {
  501. border-top: 1px solid #e8ecf0;
  502. }
  503. .top-control {
  504. text-align: right;
  505. padding: 16px 20px;
  506. padding-bottom: 0;
  507. .control-item {
  508. position: relative;
  509. display: inline-block;
  510. margin-left: 8px;
  511. width: 40px;
  512. height: 40px;
  513. background: #f1f4f6;
  514. border-radius: 50%;
  515. &:active {
  516. background: rgba(206, 159, 39, 0.4);
  517. }
  518. // &:hover {
  519. // background: rgba(206, 159, 39, 0.4);
  520. // }
  521. img {
  522. position: absolute;
  523. width: 16px;
  524. height: 16px;
  525. left: 50%;
  526. top: 50%;
  527. transform: translate(-50%, -50%);
  528. }
  529. .curtain-opening-icon {
  530. width: 20px;
  531. height: 20px;
  532. }
  533. }
  534. .control-item-active {
  535. background: rgba(206, 159, 39, 0.4);
  536. span {
  537. position: absolute;
  538. font-family: "Persagy";
  539. font-style: normal;
  540. font-weight: 400;
  541. font-size: 16px;
  542. left: 50%;
  543. top: 50%;
  544. transform: translate(-50%, -50%);
  545. }
  546. }
  547. }
  548. .curtain-child {
  549. .child-item {
  550. display: flex;
  551. justify-content: space-between;
  552. padding-top: 16px;
  553. padding-bottom: 16px;
  554. padding-left: 20px;
  555. padding-right: 20px;
  556. border-top: 1px solid #e8ecf0;
  557. .curtain-name {
  558. display: inline-block;
  559. vertical-align: middle;
  560. .name {
  561. font-family: "PingFang SC";
  562. font-style: normal;
  563. font-weight: 600;
  564. font-size: 16px;
  565. line-height: 22px;
  566. padding-top: 5px;
  567. color: #4d5262;
  568. }
  569. span {
  570. display: block;
  571. padding-top: 4px;
  572. font-family: "PingFang SC";
  573. font-style: normal;
  574. font-weight: 400;
  575. font-size: 14px;
  576. line-height: 20px;
  577. color: #c4c4c4;
  578. }
  579. }
  580. }
  581. .top-control {
  582. display: inline-block;
  583. vertical-align: middle;
  584. padding: 0;
  585. // padding-top: 5px;
  586. }
  587. }
  588. </style>