addSpaceDialog.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  1. <!-- 添加空间 -->
  2. <template>
  3. <el-dialog
  4. custom-class="space-detail-dialog"
  5. append-to-body
  6. title="添加显示空间"
  7. :visible="dialogTableVisible"
  8. @close="close"
  9. :close-on-press-escape="false"
  10. >
  11. <div class="header">
  12. <!-- 空间分区类型 菜单 -->
  13. <Select
  14. width="220"
  15. tipPlace="top"
  16. multiple
  17. caption="分区类型:"
  18. @confirm="spacePartitionTypeConfirm"
  19. v-model="spacePartitionType"
  20. :selectdata="spacePartitionTypeData"
  21. :placeholder="'请选择'"
  22. />
  23. <!-- 空间 分区下实例 菜单 -->
  24. <Select
  25. width="220"
  26. tipPlace="top"
  27. multiple
  28. caption="分区下实例:"
  29. @confirm="selectConfirm"
  30. :disabled="!spacePartitionType.length"
  31. v-model="spacePartitionInstance"
  32. :selectdata="selectData"
  33. :placeholder="'请选择'"
  34. />
  35. <!-- 空间功能类型 树 -->
  36. <TreeSelect
  37. title="已选项"
  38. unit="个"
  39. placeholder="请选择"
  40. :width="240"
  41. :height="300"
  42. :caption="'空间功能类型:'"
  43. :notNull="true"
  44. :returnParentNode="false"
  45. :isShowAllChoice="true"
  46. :selectedIds="selectedIds3"
  47. :choseArea="true"
  48. :disabled="!spacePartitionType.length"
  49. :data="dataTree3"
  50. @change="treeChange3"
  51. id="treeSelect"
  52. />
  53. </div>
  54. <!-- 表格 -->
  55. <el-table
  56. v-show="tableData.length"
  57. :data="tableData"
  58. max-height="420"
  59. :span-method="objectSpanMethod"
  60. style="width: 100%; margin-top: 10px"
  61. :row-class-name="tableRowClassName"
  62. >
  63. <el-table-column prop="codeName" label="业务分区名称" style="width: 30%"> </el-table-column>
  64. <el-table-column prop="total" label="空间实例数量" tyle="width: 30%"> </el-table-column>
  65. <el-table-column prop="classCode" label="操作">
  66. <template slot-scope="scope">
  67. <el-link type="primary" @click="editInfo(scope.row)" :underline="false">编辑信息点</el-link>
  68. </template>
  69. </el-table-column>
  70. </el-table>
  71. <!-- 无数据 -->
  72. <div class="no-data-body" v-show="!tableData.length">
  73. <img src="@/assets/images/no-data.png" style="width: 116px; height: 116px" />
  74. <p style="font-size: 16px; margin-top: 15px">暂无数据</p>
  75. </div>
  76. <!-- 确定,取消按钮 -->
  77. <div slot="footer" class="dialog-footer">
  78. <el-button @click="close">取 消</el-button>
  79. <el-button :disabled="!tableData.length" :type="tableData.length ? 'primary' : 'info'" @click="confirm">确 定</el-button>
  80. </div>
  81. <!-- 编辑信息点 -->
  82. <edit-info-point type="space" @closeModal="showEditInfoPoint = false" :code="currentInfo.classCode || ''" :showDialog="showEditInfoPoint" />
  83. </el-dialog>
  84. </template>
  85. <script>
  86. /**
  87. * 添加显示实例
  88. */
  89. import { Select, TreeSelect } from "meri-design";
  90. import { mapState, mapMutations } from "vuex";
  91. import editInfoPoint from "./editInfoPoint";
  92. import { ruleCreate } from "@/api/labsl";
  93. import { dictCategoryQuery, dictQuery, PartiInstancQuery } from "@/api/datacenter";
  94. import { spaceQuery } from "@/api/equipcomponent";
  95. import { array2Tree } from "@/utils/utils";
  96. import bus from "@/bus/bus";
  97. export default {
  98. name: "addSpaceDialog",
  99. props: {
  100. showDialog: {
  101. type: Boolean,
  102. required: true,
  103. },
  104. },
  105. components: { Select, TreeSelect, editInfoPoint },
  106. data() {
  107. return {
  108. dataTree3: [],
  109. selectedIds3: [],
  110. spacePartitionType: [],
  111. spacePartitionTypeData: [],
  112. curentSelectTree3: [], //选中的空间 功能类型
  113. dialogTableVisible: false,
  114. spacePartitionInstance: [], //选中的空间分区下实例
  115. selectData: [
  116. // { id: "test1", name: "选择项" },
  117. ],
  118. tableData: [],
  119. tableDataBak: [],
  120. currentInfo: {}, //点击的设备类数据
  121. showEditInfoPoint: false, //显示编辑信息点弹窗
  122. };
  123. },
  124. computed: {
  125. ...mapState(["buildingId", "floorId", "id", "graphId"]),
  126. },
  127. watch: {
  128. // 是否打开弹窗
  129. showDialog(val) {
  130. this.dialogTableVisible = val;
  131. if (val) {
  132. this.initModal();
  133. }
  134. },
  135. /**
  136. * 监听分区类型变化(点击下拉框删除按钮,触发表格数据查询)
  137. */
  138. spacePartitionType: {
  139. handler(newV, oldV) {
  140. if (!newV.length && oldV.length) {
  141. this.spacePartitionInstance = [];
  142. this.curentSelectTree3 = [];
  143. // this.getTableData();
  144. this.tableData = [];
  145. this.tableDataBak = [];
  146. }
  147. },
  148. deep: true,
  149. },
  150. /**
  151. * 监听分区类型值,修复treeSelect禁用时,点击caption仍然能点击开的问题
  152. */
  153. "spacePartitionType.length"(val) {
  154. // 分区类型无数据
  155. if (!val) {
  156. this.$nextTick(() => {
  157. const el = document.querySelector("#treeSelect .p-select-input-caption");
  158. const elClone = el.cloneNode(true);
  159. el.parentNode.replaceChild(elClone, el);
  160. });
  161. } else {
  162. // 分区类型有数据
  163. this.$nextTick(() => {
  164. const el = document.querySelector("#treeSelect .p-select-input-caption");
  165. const elClone = el.cloneNode(true);
  166. el.parentNode.replaceChild(this.el, el);
  167. });
  168. }
  169. },
  170. /**
  171. * 监听分区下实例变化(点击下拉框删除按钮,触发表格数据查询)
  172. */
  173. spacePartitionInstance: {
  174. handler(newV, oldV) {
  175. if (!newV.length && oldV.length) {
  176. this.getTableData();
  177. }
  178. },
  179. deep: true,
  180. },
  181. },
  182. mounted() {
  183. //
  184. },
  185. methods: {
  186. ...mapMutations(["ADDRULE"]),
  187. /**
  188. * 空间 分区类型
  189. */
  190. spacePartitionTypeConfirm(data) {
  191. // 查询分区下实例列表
  192. if (this.spacePartitionType.length) {
  193. this.getPartiInstance();
  194. }
  195. // 查询表格
  196. this.getTableData();
  197. },
  198. /**
  199. * 空间 分区下实例
  200. */
  201. selectConfirm(data) {
  202. // 查询表格
  203. this.getTableData();
  204. },
  205. /**
  206. * 空间功能类型
  207. */
  208. treeChange3(data, dataObj) {
  209. if (!dataObj) {
  210. this.curentSelectTree3 = [];
  211. } else {
  212. // 筛选树的最后一级,按照组件返回数组的name中/的个数
  213. this.curentSelectTree3 = dataObj.filter((v) => v.name.split("/").length === 3).map((v) => v.id);
  214. }
  215. // 查询表格
  216. this.getTableData();
  217. },
  218. /**
  219. * 显示弹窗时的处理
  220. */
  221. initModal() {
  222. this.spacePartitionType = [];
  223. this.spacePartitionInstance = [];
  224. this.tableDataBak = [];
  225. this.tableData = [];
  226. // 分区类型 列表
  227. this.getType();
  228. // 空间功能类型
  229. this.getDict();
  230. this.$nextTick(() => {
  231. const el = document.querySelector("#treeSelect .p-select-input-caption");
  232. this.el = el;
  233. const elClone = el.cloneNode(true);
  234. el.parentNode.replaceChild(elClone, el);
  235. });
  236. },
  237. /**
  238. * 空间分区类型 列表
  239. */
  240. async getType() {
  241. const res = await dictCategoryQuery({ type: "space" });
  242. const data = res?.content || [];
  243. data.map((v) => (v.id = v.code));
  244. // name,code--> { id: "test1", name: "选择项" },
  245. this.spacePartitionTypeData = data;
  246. },
  247. /**
  248. * 空间分区实例
  249. */
  250. async getPartiInstance() {
  251. const postParams = {
  252. pageNumber: 1,
  253. pageSize: 1000,
  254. floorId: this.floorId, // "Fl11010500296bc7ca3a0d5d41419cf95c5b45116400",
  255. buildingId: this.buildingId, // "Bd1101050029cb77fbd1846611eaac87cd1cd6a961c6",
  256. zoneTypeList: this.spacePartitionType,
  257. };
  258. const res = await PartiInstancQuery(postParams);
  259. const data = res.content.map((v) => {
  260. return { id: v.id, name: v.localName || "--" };
  261. });
  262. this.spacePartitionInstance = [];
  263. if (data.length) {
  264. this.selectData = data;
  265. } else {
  266. this.selectData = [{ disabled: true, name: "暂无数据", id: "" }];
  267. }
  268. },
  269. // 空间功能类型
  270. async getDict() {
  271. const res = await dictQuery({
  272. filters: "code='roomFuncType'",
  273. type: "GeneralZone",
  274. });
  275. const data = res?.content[0]?.dataSource || [];
  276. data.map((v) => (v.id = v.code));
  277. // 构造树
  278. this.dataTree3 = array2Tree(data, "parentCode");
  279. },
  280. async getTableData() {
  281. // console.trace("getTableData");
  282. // 东坝地上二层
  283. const postParams = {
  284. zoneTypes: this.spacePartitionType, //空间类型
  285. spaceIds: this.spacePartitionInstance, //空间实例id
  286. funcTypes: this.curentSelectTree3, //空间功能区类型
  287. floorId: this.floorId, // "Fl1101050029ecc5d3aec0644d7f88647618f7bdd023",
  288. buildingId: this.buildingId, // "Bd1101050029cb77fbd1846611eaac87cd1cd6a961c6",
  289. };
  290. const res = await spaceQuery(postParams);
  291. const data = res.content || [];
  292. this.tableDataBak = data;
  293. const map = {};
  294. data.map((item) => {
  295. if (!map[item.classCode]) {
  296. map[item.classCode] = {
  297. classCode: item.classCode,
  298. codeName: item.codeName,
  299. total: 1,
  300. };
  301. } else {
  302. map[item.classCode].total++;
  303. }
  304. });
  305. const tableData = Object.values(map);
  306. tableData.length && tableData.unshift({ codeName: "实例总数量: " + data.length });
  307. this.tableData = tableData;
  308. console.log(tableData);
  309. },
  310. /**
  311. * 合并第一行
  312. */
  313. objectSpanMethod({ row, column, rowIndex, columnIndex }) {
  314. if (rowIndex === 0) {
  315. if (columnIndex === 0) {
  316. return {
  317. rowspan: 1,
  318. colspan: 3,
  319. };
  320. } else {
  321. return {
  322. rowspan: 1,
  323. colspan: 0,
  324. };
  325. }
  326. }
  327. },
  328. /**
  329. * 行样式
  330. */
  331. tableRowClassName({ row, rowIndex }) {
  332. if (rowIndex === 0) {
  333. return "";
  334. }
  335. return "m-row";
  336. },
  337. /**
  338. * 编辑信息点
  339. */
  340. editInfo(data) {
  341. this.currentInfo = data;
  342. this.showEditInfoPoint = true;
  343. },
  344. /**
  345. * 关闭弹窗
  346. */
  347. close() {
  348. this.dialogTableVisible = false;
  349. this.$emit("closeModal");
  350. },
  351. /**
  352. * 点击弹窗确定,提交接口
  353. */
  354. async confirm() {
  355. const postParams = {
  356. content: [
  357. {
  358. graphCoding: this.id,
  359. graphId: this.graphId,
  360. returnType: "zone", // 返回类型(equip: 设备, equipGroup: 设备组, zone: 空间)
  361. commond: "query", // 命令类型(query: 查询, delete: 删除)
  362. params: {
  363. equipTypes: [], //设备类型,添加空间无此字段
  364. zoneTypes: this.spacePartitionType, //空间类型
  365. spaceIds: this.spacePartitionInstance, //空间实例id
  366. funcTypes: this.curentSelectTree3, //空间功能区类型
  367. },
  368. },
  369. ],
  370. };
  371. const res = await ruleCreate(postParams);
  372. if (res.result === "success") {
  373. this.$message.success("添加成功");
  374. // 在vuex中添加规则
  375. if (res.entityList && res.entityList[0]) {
  376. this.ADDRULE(res.entityList[0]);
  377. // 接口成功之后,发出添加空间指令
  378. // TODO: 添加空间指令
  379. bus.$emit("addZone", this.tableDataBak);
  380. }
  381. this.dialogTableVisible = false;
  382. this.showPopover = false;
  383. } else {
  384. this.$message.error(res.message || "添加失败");
  385. }
  386. },
  387. },
  388. };
  389. </script>
  390. <style lang='less' scoped>
  391. /deep/ .space-detail-dialog {
  392. margin-top: 8vh !important;
  393. width: 1200px;
  394. height: 648px;
  395. // background-color: blueviolet;
  396. .header {
  397. display: flex;
  398. align-items: center;
  399. .text1,
  400. .text2 {
  401. margin-right: 10px;
  402. }
  403. .text2 {
  404. margin-left: 15px;
  405. }
  406. & > div {
  407. margin-right: 10px;
  408. }
  409. }
  410. .m-row {
  411. color: #1f2429;
  412. font-weight: 600;
  413. }
  414. .no-data-body {
  415. width: 100%;
  416. height: 420px;
  417. display: flex;
  418. flex-direction: column;
  419. justify-content: center;
  420. align-items: center;
  421. }
  422. /deep/ .el-dialog__footer {
  423. position: absolute;
  424. right: 0;
  425. bottom: 0;
  426. }
  427. }
  428. </style>