addEquipmentDialog.vue 18 KB

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