addEquipmentDialog.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526
  1. <!-- 添加显示实例(设备) -->
  2. <template>
  3. <el-dialog
  4. custom-class="equipment-detail-dialog"
  5. @click.native="showPopover && (showPopover = false)"
  6. append-to-body
  7. title="添加显示实例"
  8. :visible="dialogTableVisible"
  9. @close="close"
  10. :close-on-press-escape="false"
  11. >
  12. <div class="header">
  13. <span class="text1">
  14. <el-popover v-model="showPopover" width="240" placement="bottom-start" trigger="manual" popper-class="init-popover">
  15. <p>请先选择需展示的设备实例范围</p>
  16. <el-button size="mini" class="m-btn" @click="showPopover = false">我知道了</el-button>
  17. <span slot="reference">选择设备:</span>
  18. </el-popover>
  19. </span>
  20. <!-- 设备实例范围 树 -->
  21. <TreeSelect
  22. title="已选项"
  23. unit="个"
  24. placeholder="请选择"
  25. :width="240"
  26. :height="300"
  27. :caption="'设备实例范围'"
  28. :notNull="true"
  29. :returnParentNode="false"
  30. :isShowAllChoice="true"
  31. :selectedIds="selectedIds1"
  32. :choseArea="true"
  33. :data="dataTree1"
  34. @change="treeChange1"
  35. />
  36. <span class="text2">选择空间:</span>
  37. <!-- 空间分区类型 菜单 -->
  38. <Select
  39. width="220"
  40. tipPlace="top"
  41. multiple
  42. caption="分区类型:"
  43. @confirm="spacePartitionTypeConfirm"
  44. v-model="spacePartitionType"
  45. :selectdata="spacePartitionTypeData"
  46. :placeholder="'请选择'"
  47. />
  48. <!-- 空间 分区下实例 菜单 -->
  49. <Select
  50. width="220"
  51. tipPlace="top"
  52. multiple
  53. caption="分区下实例:"
  54. @confirm="selectConfirm"
  55. :disabled="!spacePartitionType.length"
  56. v-model="spacePartitionInstance"
  57. :selectdata="selectData"
  58. :placeholder="'请选择'"
  59. />
  60. <!-- 空间功能类型 树 -->
  61. <TreeSelect
  62. title="已选项"
  63. unit="个"
  64. placeholder="请选择"
  65. :width="240"
  66. :height="300"
  67. :caption="'空间功能类型:'"
  68. :notNull="true"
  69. :returnParentNode="false"
  70. :isShowAllChoice="true"
  71. :selectedIds="selectedIds3"
  72. :choseArea="true"
  73. :disabled="!spacePartitionType.length"
  74. :data="dataTree3"
  75. @change="treeChange3"
  76. />
  77. </div>
  78. <!-- 表格 -->
  79. <el-table
  80. v-show="tableData.length"
  81. :data="tableData"
  82. max-height="420"
  83. :span-method="objectSpanMethod"
  84. style="width: 100%; margin-top: 10px"
  85. :row-class-name="tableRowClassName"
  86. >
  87. <el-table-column prop="codeName" label="设备类" style="width: 30%"> </el-table-column>
  88. <el-table-column prop="total" label="设备实例数量" tyle="width: 30%"> </el-table-column>
  89. <el-table-column prop="classCode" label="操作">
  90. <template slot-scope="scope">
  91. <el-link type="primary" @click="editInfo(scope.row)" :underline="false">编辑信息点</el-link>
  92. </template>
  93. </el-table-column>
  94. </el-table>
  95. <!-- 无数据 -->
  96. <div class="no-data-body" v-show="!tableData.length">
  97. <img src="@/assets/images/no-data.png" style="width: 116px; height: 116px" />
  98. <p style="font-size: 16px; margin-top: 15px">暂无数据</p>
  99. </div>
  100. <!-- 确定,取消按钮 -->
  101. <div slot="footer" class="dialog-footer">
  102. <el-button @click="close">取 消</el-button>
  103. <el-button :disabled="!tableData.length" :type="tableData.length ? 'primary' : 'info'" @click="confirm">确 定</el-button>
  104. </div>
  105. <edit-info-point
  106. type="equipment"
  107. @closeModal="showEditInfoPoint = false"
  108. :code="currentInfo.classCode || ''"
  109. :showDialog="showEditInfoPoint"
  110. />
  111. </el-dialog>
  112. </template>
  113. <script>
  114. /**
  115. * 添加显示实例
  116. */
  117. import { mapState, mapMutations } from "vuex";
  118. import editInfoPoint from "./editInfoPoint";
  119. import { Select, TreeSelect } from "meri-design";
  120. import { cloneDeep } from "lodash";
  121. import { ruleCreate } from "@/api/labsl";
  122. import { dictCategoryQuery, dictQuery, PartiInstancQuery } from "@/api/datacenter";
  123. import { equipQuery } from "@/api/equipcomponent";
  124. import { array2Tree, mapTree } from "@/utils/utils";
  125. import bus from "@/bus/bus";
  126. export default {
  127. name: "addEquipmentDialog",
  128. props: {
  129. showDialog: {
  130. type: Boolean,
  131. required: true,
  132. },
  133. },
  134. components: { Select, TreeSelect, editInfoPoint },
  135. data() {
  136. return {
  137. timer: null,
  138. showPopover: false, //选择设备 popover是否显示
  139. dataTree1: [],
  140. dataTree3: [],
  141. selectedIds1: [],
  142. selectedIds3: [],
  143. curentSelectTree1: [], //选中的设备 实例范围
  144. curentSelectTree2: [], //选中的空间 分区类型
  145. spacePartitionType: [],
  146. spacePartitionTypeData: [],
  147. curentSelectTree3: [], //选中的空间 功能类型
  148. dialogTableVisible: false,
  149. spacePartitionInstance: [], //选中的空间分区下实例
  150. selectData: [
  151. // { id: "test1", name: "选择项" },
  152. ],
  153. tableData: [
  154. // {
  155. // date: "实例总数量 111111",
  156. // },
  157. // {
  158. // date: "监控器",
  159. // name: "111",
  160. // address: "dfadfasdfa",
  161. // },
  162. ],
  163. tableDataBak: [],
  164. currentInfo: {}, //点击的设备类数据
  165. showEditInfoPoint: false, //显示编辑信息点弹窗
  166. };
  167. },
  168. computed: {
  169. ...mapState(["buildingId", "floorId", "id", "graphId"]),
  170. },
  171. watch: {
  172. // 是否打开弹窗
  173. showDialog(val) {
  174. this.dialogTableVisible = val;
  175. if (val) {
  176. this.initModal();
  177. }
  178. },
  179. /**
  180. * 点击x号,清空列表
  181. */
  182. curentSelectTree1: {
  183. handler(newV, oldV) {
  184. if (!newV.length && oldV.length) {
  185. this.tableData = [];
  186. }
  187. },
  188. deep: true,
  189. },
  190. /**
  191. * 监听分区类型变化(点击下拉框删除按钮,触发表格数据查询)
  192. */
  193. spacePartitionType: {
  194. handler(newV, oldV) {
  195. if (!newV.length && oldV.length) {
  196. this.spacePartitionInstance = [];
  197. this.curentSelectTree3 = [];
  198. // this.getTableData();
  199. }
  200. },
  201. deep: true,
  202. },
  203. /**
  204. * 监听分区下实例变化(点击下拉框删除按钮,触发表格数据查询)
  205. */
  206. spacePartitionInstance: {
  207. handler(newV, oldV) {
  208. if (!newV.length && oldV.length) {
  209. this.getTableData();
  210. }
  211. },
  212. deep: true,
  213. },
  214. },
  215. // eslint-disable-next-line @typescript-eslint/no-empty-function
  216. created() { },
  217. mounted() {
  218. /* setTimeout(() => {
  219. this.showPopover = true;
  220. }, 2000); */
  221. },
  222. methods: {
  223. ...mapMutations(["ADDRULE"]),
  224. /**
  225. * 设备实例范围树更改
  226. */
  227. treeChange1(data, dataObj) {
  228. if (!dataObj) {
  229. this.curentSelectTree1 = [];
  230. } else {
  231. // 筛选树的最后一级,按照组件返回数组的name中/的个数
  232. this.curentSelectTree1 = dataObj.filter((v) => v.name.split("/").length === 3).map((v) => v.id);
  233. }
  234. // 查询设备列表
  235. this.curentSelectTree1.length && this.getTableData();
  236. },
  237. /**
  238. * 空间 分区类型
  239. */
  240. spacePartitionTypeConfirm(data) {
  241. // 查询分区下实例列表
  242. if (this.spacePartitionType.length) {
  243. this.getPartiInstance();
  244. }
  245. // 查询表格
  246. this.getTableData();
  247. },
  248. /**
  249. * 空间 分区下实例
  250. */
  251. selectConfirm(data) {
  252. // 查询表格
  253. this.getTableData();
  254. },
  255. /**
  256. * 空间功能类型
  257. */
  258. treeChange3(data, dataObj) {
  259. if (!dataObj) {
  260. this.curentSelectTree3 = [];
  261. } else {
  262. // 筛选树的最后一级,按照组件返回数组的name中/的个数
  263. this.curentSelectTree3 = dataObj.filter((v) => v.name.split("/").length === 3).map((v) => v.id);
  264. }
  265. // 查询表格
  266. this.getTableData();
  267. },
  268. /**
  269. * 显示弹窗时的处理
  270. */
  271. initModal() {
  272. this.tableDataBak = [];
  273. this.tableData = [];
  274. // 查询设备实例树
  275. this.getCategory();
  276. // 分区类型 列表
  277. this.getType();
  278. this.getDict();
  279. },
  280. /**
  281. * 查询设备实例树
  282. */
  283. async getCategory() {
  284. const res = await dictCategoryQuery({ type: "majorSystemEquip" });
  285. console.log(res);
  286. const tree = res?.content || [];
  287. // 遍历tree,使其id属性变为为_id属性, code属性变成id属性
  288. console.time(1);
  289. this.dataTree1 = mapTree(tree, "id->_id", "code->id");
  290. console.timeEnd(1);
  291. },
  292. /**
  293. * 空间分区类型 列表
  294. */
  295. async getType() {
  296. const res = await dictCategoryQuery({ type: "space" });
  297. const data = res?.content || [];
  298. data.map((v) => (v.id = v.code));
  299. // name,code--> { id: "test1", name: "选择项" },
  300. this.spacePartitionTypeData = data;
  301. },
  302. /**
  303. * 空间分区实例
  304. */
  305. async getPartiInstance() {
  306. const postParams = {
  307. pageNumber: 1,
  308. pageSize: 1000,
  309. floorId: this.floorId, // "Fl1101050029ecc5d3aec0644d7f88647618f7bdd023",
  310. buildingId: this.buildingId, // "Bd1101050029cb77fbd1846611eaac87cd1cd6a961c6",
  311. zoneTypeList: this.spacePartitionType,
  312. };
  313. const res = await PartiInstancQuery(postParams);
  314. const data = res.content.map((v) => {
  315. return { id: v.id, name: v.localName || '--' };
  316. });
  317. this.spacePartitionInstance = [];
  318. if (data.length) {
  319. this.selectData = data;
  320. } else {
  321. this.selectData = [{ disabled: true, name: "暂无数据", id: "" }];
  322. }
  323. // v-model="spacePartitionInstance"
  324. // :selectdata="selectData"
  325. },
  326. // 空间功能类型
  327. async getDict() {
  328. const res = await dictQuery({
  329. filters: "code='roomFuncType'",
  330. type: "GeneralZone",
  331. });
  332. const data = res?.content[0]?.dataSource || [];
  333. data.map((v) => (v.id = v.code));
  334. // 构造树
  335. this.dataTree3 = array2Tree(data, "parentCode");
  336. },
  337. async getTableData() {
  338. // console.trace("getTableData");
  339. // 东坝地上二层
  340. const postParams = {
  341. equipTypes: this.curentSelectTree1, //设备类型 //["FFFSSN"],
  342. zoneTypes: this.spacePartitionType, //空间类型
  343. spaceIds: this.spacePartitionInstance, //空间实例id
  344. funcTypes: this.curentSelectTree3, //空间功能区类型
  345. floorId: this.floorId, // "Fl1101050029ecc5d3aec0644d7f88647618f7bdd023",
  346. buildingId: this.buildingId, // "Bd1101050029cb77fbd1846611eaac87cd1cd6a961c6",
  347. };
  348. const res = await equipQuery(postParams);
  349. const data = res.content || [];
  350. this.tableDataBak = data;
  351. const map = {};
  352. data.map((item) => {
  353. if (!map[item.classCode]) {
  354. map[item.classCode] = {
  355. classCode: item.classCode,
  356. codeName: item.codeName,
  357. total: 1,
  358. };
  359. } else {
  360. map[item.classCode].total++;
  361. }
  362. });
  363. const tableData = Object.values(map);
  364. tableData.length && tableData.unshift({ codeName: "实例总数量: " + data.length });
  365. this.tableData = tableData;
  366. },
  367. /**
  368. * 合并第一行
  369. */
  370. objectSpanMethod({ row, column, rowIndex, columnIndex }) {
  371. if (rowIndex === 0) {
  372. if (columnIndex === 0) {
  373. return {
  374. rowspan: 1,
  375. colspan: 3,
  376. };
  377. } else {
  378. return {
  379. rowspan: 1,
  380. colspan: 0,
  381. };
  382. }
  383. }
  384. },
  385. /**
  386. * 行样式
  387. */
  388. tableRowClassName({ row, rowIndex }) {
  389. if (rowIndex === 0) {
  390. return "";
  391. }
  392. return "m-row";
  393. },
  394. /**
  395. * 编辑信息点
  396. */
  397. editInfo(data) {
  398. console.log(data);
  399. this.currentInfo = data;
  400. this.showEditInfoPoint = true;
  401. },
  402. /**
  403. * 关闭弹窗
  404. */
  405. close() {
  406. this.dialogTableVisible = false;
  407. this.showPopover = false;
  408. this.$emit("closeModal");
  409. },
  410. /**
  411. * 点击弹窗确定,提交接口
  412. */
  413. async confirm() {
  414. const postParams = {
  415. content: [
  416. {
  417. graphCoding: this.id,
  418. graphId: this.graphId,
  419. returnType: "equip", // 返回类型(equip: 设备, equipGroup: 设备组, zone: 空间)
  420. commond: "query", // 命令类型(query: 查询, delete: 删除)
  421. params: {
  422. equipTypes: this.curentSelectTree1, //设备类型 //["FFFSSN"],
  423. zoneTypes: this.spacePartitionType, //空间类型
  424. spaceIds: this.spacePartitionInstance, //空间实例id
  425. funcTypes: this.curentSelectTree3, //空间功能区类型
  426. },
  427. },
  428. ],
  429. };
  430. console.log(postParams);
  431. const res = await ruleCreate(postParams);
  432. console.log("===============");
  433. console.log(res);
  434. if (res.result === "success") {
  435. this.$message.success("添加成功");
  436. // 在vuex中添加规则
  437. if (res.entityList && res.entityList[0]) {
  438. this.ADDRULE(res.entityList[0]);
  439. // 接口成功之后,发出添加设备指令
  440. bus.$emit("addEquipment", this.tableDataBak);
  441. }
  442. // let timer = setTimeout(() => {
  443. this.dialogTableVisible = false;
  444. this.showPopover = false;
  445. // }, 1000);
  446. // timer = null;
  447. } else {
  448. this.$message.error(res.message || "添加失败");
  449. }
  450. // clearTimeout(this.timer);
  451. },
  452. },
  453. };
  454. </script>
  455. <style lang="less">
  456. .init-popover {
  457. width: 240px;
  458. height: 115px;
  459. background: #0091ff;
  460. box-shadow: 0px 2px 10px 0px rgba(31, 36, 41, 0.1);
  461. .popper__arrow::after {
  462. border-bottom-color: #0091ff !important;
  463. }
  464. p {
  465. text-align: center;
  466. font-size: 14px;
  467. font-family: PingFangSC-Regular, PingFang SC;
  468. font-weight: 400;
  469. color: #ffffff;
  470. line-height: 22px;
  471. }
  472. .m-btn {
  473. display: flex;
  474. align-items: center;
  475. font-size: 14px;
  476. font-family: PingFangSC-Regular, PingFang SC;
  477. font-weight: 400;
  478. color: #0091ff;
  479. height: 28px !important;
  480. position: absolute;
  481. bottom: 15px;
  482. right: 20px;
  483. }
  484. }
  485. </style>
  486. <style lang='less' scoped>
  487. /deep/ .equipment-detail-dialog {
  488. margin-top: 8vh !important;
  489. width: 1200px;
  490. height: 648px;
  491. // background-color: blueviolet;
  492. .header {
  493. display: flex;
  494. align-items: center;
  495. .text1,
  496. .text2 {
  497. margin-right: 10px;
  498. }
  499. .text2 {
  500. margin-left: 15px;
  501. }
  502. & > div {
  503. margin-right: 10px;
  504. }
  505. }
  506. .m-row {
  507. color: #1f2429;
  508. font-weight: 600;
  509. }
  510. .no-data-body {
  511. width: 100%;
  512. height: 420px;
  513. display: flex;
  514. flex-direction: column;
  515. justify-content: center;
  516. align-items: center;
  517. }
  518. /deep/ .el-dialog__footer {
  519. position: absolute;
  520. right: 0;
  521. bottom: 0;
  522. }
  523. }
  524. </style>