addEquipmentDialog.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519
  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. <!-- TODO: -->
  106. <edit-info-point
  107. type="equipment"
  108. @closeModal="showEditInfoPoint = false"
  109. :code="currentInfo.classCode || ''"
  110. :showDialog="showEditInfoPoint"
  111. />
  112. </el-dialog>
  113. </template>
  114. <script>
  115. /**
  116. * 添加显示实例
  117. */
  118. import { mapState } from "vuex";
  119. import editInfoPoint from "./editInfoPoint";
  120. import { Select, TreeSelect } from "meri-design";
  121. import { cloneDeep } from "lodash";
  122. import { ruleCreate } from "@/api/labsl";
  123. import { dictCategoryQuery, dictQuery, PartiInstancQuery } from "@/api/datacenter";
  124. import { equipQuery } from "@/api/equipcomponent";
  125. import { array2Tree, mapTree } from "@/utils/utils";
  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. dataTree2: [], // cloneDeep(dataTree),
  141. dataTree3: [], // cloneDeep(dataTree),
  142. selectedIds1: [],
  143. selectedIds2: [],
  144. selectedIds3: [],
  145. curentSelectTree1: [], //选中的设备 实例范围
  146. curentSelectTree2: [], //选中的空间 分区类型
  147. spacePartitionType: [],
  148. spacePartitionTypeData: [],
  149. curentSelectTree3: [], //选中的空间 功能类型
  150. dialogTableVisible: false,
  151. spacePartitionInstance: [], //选中的空间分区下实例
  152. selectData: [
  153. // { id: "test1", name: "选择项" },
  154. ],
  155. tableData: [
  156. // {
  157. // date: "实例总数量 111111",
  158. // },
  159. // {
  160. // date: "监控器",
  161. // name: "111",
  162. // address: "dfadfasdfa",
  163. // },
  164. ],
  165. tableDataBak: [],
  166. currentInfo: {}, //点击的设备类数据
  167. showEditInfoPoint: false, //显示编辑信息点弹窗
  168. };
  169. },
  170. computed: {
  171. ...mapState(["buildingId", "floorId", "id", "graphId"]),
  172. },
  173. watch: {
  174. // 是否打开弹窗
  175. showDialog(val) {
  176. this.dialogTableVisible = val;
  177. if (val) {
  178. this.initModal();
  179. }
  180. },
  181. /**
  182. * 点击x号,清空列表
  183. */
  184. curentSelectTree1: {
  185. handler(newV, oldV) {
  186. if (!newV.length && oldV.length) {
  187. this.tableData = [];
  188. }
  189. },
  190. deep: true,
  191. },
  192. /**
  193. * 监听分区类型变化(点击下拉框删除按钮,触发表格数据查询)
  194. */
  195. spacePartitionType: {
  196. handler(newV, oldV) {
  197. if (!newV.length && oldV.length) {
  198. this.spacePartitionInstance = [];
  199. this.curentSelectTree3 = [];
  200. // this.getTableData();
  201. }
  202. },
  203. deep: true,
  204. },
  205. /**
  206. * 监听分区下实例变化(点击下拉框删除按钮,触发表格数据查询)
  207. */
  208. spacePartitionInstance: {
  209. handler(newV, oldV) {
  210. if (!newV.length && oldV.length) {
  211. this.getTableData();
  212. }
  213. },
  214. deep: true,
  215. },
  216. },
  217. // eslint-disable-next-line @typescript-eslint/no-empty-function
  218. created() {},
  219. mounted() {
  220. window.vm = this;
  221. /* setTimeout(() => {
  222. this.showPopover = true;
  223. }, 2000); */
  224. },
  225. methods: {
  226. /**
  227. * 设备实例范围树更改
  228. */
  229. treeChange1(data, dataObj) {
  230. if (!dataObj) {
  231. this.curentSelectTree1 = [];
  232. } else {
  233. // 筛选树的最后一级,按照组件返回数组的name中/的个数
  234. this.curentSelectTree1 = dataObj.filter((v) => v.name.split("/").length === 3).map((v) => v.id);
  235. }
  236. // 查询设备列表
  237. this.curentSelectTree1.length && this.getTableData();
  238. },
  239. /**
  240. * 空间 分区类型
  241. */
  242. spacePartitionTypeConfirm(data) {
  243. // 查询分区下实例列表
  244. if (this.spacePartitionType.length) {
  245. this.getPartiInstance();
  246. }
  247. // 查询表格
  248. this.getTableData();
  249. },
  250. /**
  251. * 空间 分区下实例
  252. */
  253. selectConfirm(data) {
  254. // 查询表格
  255. this.getTableData();
  256. },
  257. /**
  258. * 空间功能类型
  259. */
  260. treeChange3(data, dataObj) {
  261. if (!dataObj) {
  262. this.curentSelectTree3 = [];
  263. } else {
  264. // 筛选树的最后一级,按照组件返回数组的name中/的个数
  265. this.curentSelectTree3 = dataObj.filter((v) => v.name.split("/").length === 3).map((v) => v.id);
  266. }
  267. // 查询表格
  268. this.getTableData();
  269. },
  270. /**
  271. * 显示弹窗时的处理
  272. */
  273. initModal() {
  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. console.log("==================");
  315. console.log(res);
  316. console.log(res.content);
  317. const data = res.content.map((v) => {
  318. return { id: v.id, name: v.localName };
  319. });
  320. this.selectData = data;
  321. this.spacePartitionInstance = [];
  322. // v-model="spacePartitionInstance"
  323. // :selectdata="selectData"
  324. },
  325. // 空间功能类型
  326. async getDict() {
  327. const res = await dictQuery({
  328. filters: "code='roomFuncType'",
  329. type: "GeneralZone",
  330. });
  331. const data = res?.content[0]?.dataSource || [];
  332. data.map((v) => (v.id = v.code));
  333. // 构造树
  334. this.dataTree3 = array2Tree(data, "parentCode");
  335. },
  336. async getTableData() {
  337. // console.trace("getTableData");
  338. // 东坝地上二层
  339. const postParams = {
  340. equipTypes: this.curentSelectTree1, //设备类型 //["FFFSSN"],
  341. zoneTypes: this.spacePartitionType, //空间类型
  342. spaceIds: this.spacePartitionInstance, //空间实例id
  343. funcTypes: this.curentSelectTree3, //空间功能区类型
  344. floorId: this.floorId, // "Fl1101050029ecc5d3aec0644d7f88647618f7bdd023",
  345. buildingId: this.buildingId, // "Bd1101050029cb77fbd1846611eaac87cd1cd6a961c6",
  346. };
  347. const res = await equipQuery(postParams);
  348. const data = res.content || [];
  349. this.tableDataBak = data;
  350. const map = {};
  351. data.map((item) => {
  352. if (!map[item.classCode]) {
  353. map[item.classCode] = {
  354. classCode: item.classCode,
  355. codeName: item.codeName,
  356. total: 1,
  357. };
  358. } else {
  359. map[item.classCode].total++;
  360. }
  361. });
  362. const tableData = Object.values(map);
  363. tableData.length && tableData.unshift({ codeName: "实例总数量: " + data.length });
  364. this.tableData = tableData;
  365. },
  366. /**
  367. * 合并第一行
  368. */
  369. objectSpanMethod({ row, column, rowIndex, columnIndex }) {
  370. if (rowIndex === 0) {
  371. if (columnIndex === 0) {
  372. return {
  373. rowspan: 1,
  374. colspan: 3,
  375. };
  376. } else {
  377. return {
  378. rowspan: 1,
  379. colspan: 0,
  380. };
  381. }
  382. }
  383. },
  384. /**
  385. * 行样式
  386. */
  387. tableRowClassName({ row, rowIndex }) {
  388. if (rowIndex === 0) {
  389. return "";
  390. }
  391. return "m-row";
  392. },
  393. /**
  394. * 编辑信息点
  395. */
  396. editInfo(data) {
  397. console.log(data);
  398. this.currentInfo = data;
  399. this.showEditInfoPoint = true;
  400. },
  401. /**
  402. * 关闭弹窗
  403. */
  404. close() {
  405. console.log("close");
  406. // dialogTableVisible
  407. this.dialogTableVisible = false;
  408. this.showPopover = false;
  409. // clearTimeout(this.timer);
  410. this.$emit("closeModal");
  411. },
  412. /**
  413. * 点击弹窗确定,提交接口
  414. */
  415. async confirm() {
  416. const postParams = {
  417. content: [
  418. {
  419. graphCoding: this.id,
  420. graphId: this.graphId,
  421. returnType: "equip", // 返回类型(equip: 设备, equipGroup: 设备组, zone: 空间)
  422. commond: "query", // 命令类型(query: 查询, delete: 删除)
  423. params: {
  424. equipTypes: this.curentSelectTree1, //设备类型 //["FFFSSN"],
  425. zoneTypes: this.spacePartitionType, //空间类型
  426. spaceIds: this.spacePartitionInstance, //空间实例id
  427. funcTypes: this.curentSelectTree3, //空间功能区类型
  428. },
  429. },
  430. ],
  431. };
  432. console.log(postParams);
  433. const res = await ruleCreate(postParams);
  434. console.log("===============");
  435. console.log(res);
  436. if (res.result === "success") {
  437. this.$message.success("添加成功");
  438. this.dialogTableVisible = false;
  439. this.showPopover = false;
  440. } else {
  441. this.$message.error(res.message || "添加失败");
  442. }
  443. // clearTimeout(this.timer);
  444. },
  445. },
  446. };
  447. </script>
  448. <style lang="less">
  449. .init-popover {
  450. width: 240px;
  451. height: 115px;
  452. background: #0091ff;
  453. box-shadow: 0px 2px 10px 0px rgba(31, 36, 41, 0.1);
  454. .popper__arrow::after {
  455. border-bottom-color: #0091ff !important;
  456. }
  457. p {
  458. text-align: center;
  459. font-size: 14px;
  460. font-family: PingFangSC-Regular, PingFang SC;
  461. font-weight: 400;
  462. color: #ffffff;
  463. line-height: 22px;
  464. }
  465. .m-btn {
  466. display: flex;
  467. align-items: center;
  468. font-size: 14px;
  469. font-family: PingFangSC-Regular, PingFang SC;
  470. font-weight: 400;
  471. color: #0091ff;
  472. height: 28px !important;
  473. position: absolute;
  474. bottom: 15px;
  475. right: 20px;
  476. }
  477. }
  478. </style>
  479. <style lang='less' scoped>
  480. /deep/ .equipment-detail-dialog {
  481. width: 1200px;
  482. height: 648px;
  483. // background-color: blueviolet;
  484. .header {
  485. display: flex;
  486. align-items: center;
  487. .text1,
  488. .text2 {
  489. margin-right: 10px;
  490. }
  491. .text2 {
  492. margin-left: 15px;
  493. }
  494. & > div {
  495. margin-right: 10px;
  496. }
  497. }
  498. .m-row {
  499. color: #1f2429;
  500. font-weight: 600;
  501. }
  502. .no-data-body {
  503. width: 100%;
  504. height: 420px;
  505. display: flex;
  506. flex-direction: column;
  507. justify-content: center;
  508. align-items: center;
  509. }
  510. /deep/ .el-dialog__footer {
  511. position: absolute;
  512. right: 0;
  513. bottom: 0;
  514. }
  515. }
  516. </style>