addEquipmentDialog.vue 18 KB

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