addEquip.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  1. <template>
  2. <div>
  3. <div class="search" style="margin-bottom:10px;">
  4. <div>
  5. <el-input
  6. placeholder="输入设备名称或设备本地编码进行查询"
  7. style="width:300px;float:left;margin-right:10px;"
  8. v-model="search.filter"
  9. clearable
  10. ></el-input>
  11. <el-button @click="filterBox" plain>查 找</el-button>
  12. </div>
  13. <div style="margin-top:10px;">
  14. <span>所属楼层</span>
  15. <el-cascader
  16. @change="filterBox"
  17. v-model="search.floor"
  18. :options="optionsWithDisabled"
  19. ></el-cascader>
  20. <el-checkbox
  21. style="margin-left:20px;"
  22. @change="filterBox"
  23. :checked="search.checkbox"
  24. label="只显示在当前业务空间中的设备"
  25. ></el-checkbox>
  26. </div>
  27. </div>
  28. <el-table
  29. ref="multipleTable"
  30. :data="tableData"
  31. v-loading="isLoading"
  32. tooltip-effect="dark"
  33. class="data-table border"
  34. height="300"
  35. style="width: 100%"
  36. @selection-change="handleSelectionChange"
  37. >
  38. <el-table-column type="selection" width="55"></el-table-column>
  39. <el-table-column width="180" label="设备名称">
  40. <template slot-scope="scope">
  41. <span>
  42. <el-tooltip
  43. :content="scope.row.infos.EquipLocalName ||scope.row.infos.EquipName"
  44. placement="top"
  45. >
  46. <span>{{scope.row.infos.EquipLocalName || scope.row.infos.EquipName | cutString(15)}}</span>
  47. </el-tooltip>
  48. </span>
  49. </template>
  50. </el-table-column>
  51. <el-table-column width="180" label="设备本地编码">
  52. <template slot-scope="scope">
  53. <span>
  54. <el-tooltip :content="scope.row.infos.EquipLocalID || '--'" placement="top">
  55. <span>{{scope.row.infos.EquipLocalID || "--" | cutString(15)}}</span>
  56. </el-tooltip>
  57. </span>
  58. </template>
  59. </el-table-column>
  60. <el-table-column width="160" label="设备类">
  61. <template slot-scope="scope">
  62. <span>
  63. <span>{{getName(scope.row.category)}}</span>
  64. </span>
  65. </template>
  66. </el-table-column>
  67. <el-table-column width="160" label="已关联其他业务空间">
  68. <template slot-scope="scope">
  69. <span>
  70. <el-tooltip :content="changeArray(scope.row.spaceName)" placement="top">
  71. <span>{{changeArray(scope.row.spaceName) | cutString(6)}}</span>
  72. </el-tooltip>
  73. </span>
  74. </template>
  75. </el-table-column>
  76. <el-table-column label="操作">
  77. <template slot-scope="scope">
  78. <el-button plain @click="lockDetails(scope.row)">设备详情</el-button>
  79. </template>
  80. </el-table-column>
  81. </el-table>
  82. <el-dialog width="40%" title="设备详情" :visible.sync="innerVisible" append-to-body>
  83. <iframe height="400px" width="100%" :src="iframeSrc"></iframe>
  84. </el-dialog>
  85. <div class="right" v-if="tableData.length">
  86. <my-pagination :page="page" @change="pageChange"></my-pagination>
  87. </div>
  88. <div class="el-dialog__footer">
  89. <span class="dialog-footer">
  90. <el-button@click="clearBox">取 消</el-button>
  91. <el-button type="primary" @click="addReal">确 定</el-button>
  92. </span>
  93. </div>
  94. </div>
  95. </template>
  96. <script>
  97. import {
  98. getSpaceEquip,
  99. searchCode,
  100. getEqCode,
  101. getSpaceFloor,
  102. createRelation,
  103. getGraphyId,
  104. getEquipSearch,
  105. getListForBuss
  106. } from "@/api/scan/request";
  107. import myPagination from "@/components/common/myPagination.vue";
  108. import tools from "@/utils/scan/tools";
  109. import {
  110. mapGetters,
  111. mapActions
  112. } from "vuex";
  113. export default {
  114. name: "equip-table",
  115. components: {
  116. myPagination
  117. },
  118. computed: {
  119. ...mapGetters("layout", [
  120. "projectId",
  121. "secret",
  122. "userId"
  123. ])
  124. },
  125. data() {
  126. return {
  127. search: {
  128. filter: "",
  129. checkbox: false,
  130. floor: [],
  131. leiArr: []
  132. },
  133. innerVisible: false,
  134. iframeSrc: "",
  135. page: {
  136. size: 50,
  137. sizes: [10, 30, 50, 100, 150, 200],
  138. total: 400,
  139. currentPage: 1
  140. },
  141. optionsWithDisabled: [],
  142. tableData: [],
  143. allData: [], //全部的数据
  144. multipleSelection: [],
  145. list: {},
  146. build: {},
  147. graphyId: "",
  148. isLoading: false,
  149. activeTabType: null,
  150. };
  151. },
  152. created() {
  153. // this.getData();
  154. this.getEqCode();
  155. // this.getFloor();
  156. },
  157. methods: {
  158. getEqCode() {
  159. getEqCode()
  160. .then(res => {
  161. if (res.data.Result == "success") {
  162. this.EqCode = res.data.Content;
  163. } else {
  164. this.$message.error(res.data.ResultMsg);
  165. }
  166. })
  167. .catch(() => {
  168. this.$message.error("请求失败");
  169. });
  170. },
  171. changeArray(val) {
  172. if (val instanceof Array) {
  173. return val.join(",");
  174. } else {
  175. return "--";
  176. }
  177. },
  178. clearBox() {
  179. this.$refs.multipleTable.clearSelection();
  180. },
  181. //获取设备关系
  182. getGraphyId() {
  183. let param = {
  184. type: this.type,
  185. ProjId: this.projectId, //项目id
  186. secret: this.secret
  187. };
  188. getGraphyId(param)
  189. .then(res => {
  190. if (res.data.Result == "success") {
  191. this.graphyId = res.data.graph_id;
  192. this.getEquip()
  193. } else {
  194. this.$message.error(res.data.ResultMsg);
  195. }
  196. })
  197. .catch(() => {
  198. this.$message.error("请求错误");
  199. });
  200. },
  201. //获取楼层
  202. // getFloor() { // 物理世界 已无接口
  203. // let param = {
  204. // ProjId: this.projectId,
  205. // UserId: this.userId,
  206. // secret: this.secret
  207. // };
  208. // getSpaceFloor(param)
  209. // .then(res => {
  210. // if (res.data.Result == "success") {
  211. // this.optionsWithDisabled = this.changeArr(res.data.Content);
  212. // this.optionsWithDisabled = this.optionsWithDisabled.map(item => {
  213. // if (item.children && item.children.length) {
  214. // item.children.unshift({
  215. // value: "no",
  216. // label: "未指定楼层的设备"
  217. // });
  218. // } else {
  219. // item.children = [{
  220. // value: "no",
  221. // label: "未指定楼层的设备"
  222. // }];
  223. // }
  224. // return item;
  225. // });
  226. // } else {
  227. // this.$message.error(res.data.ResultMsg);
  228. // }
  229. // })
  230. // .catch(() => {
  231. // this.$message.error("请求出错");
  232. // });
  233. // },
  234. getName(code) {
  235. let text = "",
  236. myClass = code.substring(0, 2),
  237. system = code.substring(2, 4),
  238. last = code.substring(2, 6);
  239. if (this.EqCode && this.EqCode.length) {
  240. this.EqCode.map(item => {
  241. if (item.code == myClass) {
  242. item.content.map(i => {
  243. if (i.code == system) {
  244. i.content.map(e => {
  245. if ((e.code == last)) {
  246. text = e.facility;
  247. }
  248. });
  249. }
  250. });
  251. }
  252. });
  253. }
  254. return text;
  255. },
  256. //工具函数,获取下拉列表
  257. changeArr(arr) {
  258. return arr.map(item => {
  259. if (item.floors && item.floors.length) {
  260. return {
  261. value: item.id,
  262. label: item.infos.BuildLocalName || "--",
  263. children: item.floors.map(i => {
  264. return {
  265. value: i.id,
  266. label: i.infos.FloorLocalName || "--"
  267. };
  268. })
  269. };
  270. } else {
  271. return {
  272. value: item.id,
  273. label: item.infos.BuildLocalName || "--",
  274. children: null
  275. };
  276. }
  277. });
  278. },
  279. /**
  280. * 过滤条件
  281. */
  282. filterBox(val) {
  283. if (typeof val == "boolean") {
  284. this.search.checkbox = val;
  285. }
  286. if (this.search.checkbox) {
  287. this.getEquip()
  288. } else {
  289. if (!!this.search.filter) {
  290. searchCode({
  291. key: this.search.filter
  292. })
  293. .then(res => {
  294. if (res.data.Result == "success") {
  295. this.search.leiArr = res.data.Content;
  296. this.getEquip();
  297. } else {
  298. this.$message.error(res.data.ResultMsg);
  299. }
  300. })
  301. .catch(() => {
  302. this.$message.error("请求出错");
  303. });
  304. } else {
  305. this.getEquip();
  306. }
  307. }
  308. },
  309. /**
  310. * 删除
  311. * @param row 点击的当条数据
  312. */
  313. deleteSpace(row) { },
  314. /**
  315. * 获取数据
  316. * @param data 由上级页面传入,初始化table表格
  317. */
  318. getData(list, build, type, activeTabType) {
  319. this.activeTabType = activeTabType
  320. this.list = list;
  321. this.build = build;
  322. this.search.floor = [build.buildCode, build.code];
  323. this.type = type
  324. this.getGraphyId();
  325. this.page = {
  326. size: 50,
  327. sizes: [10, 30, 50, 100, 150, 200],
  328. total: 0,
  329. currentPage: 1
  330. };
  331. this.getEquip();
  332. },
  333. //获取数据
  334. getEquip() {
  335. this.isLoading = true;
  336. let relType = ""
  337. if (this.activeTabType.rel_type == 99) {
  338. relType = "1"
  339. } else {
  340. if (this.activeTabType.rel_type > 9) {
  341. relType = (this.activeTabType.rel_type * 100).toString()
  342. } else {
  343. relType = '0' + this.activeTabType.rel_type * 100
  344. }
  345. }
  346. if (this.type == "EquipinSpace" && this.activeTabType.rel_type == 99) {
  347. if (this.search.checkbox) {
  348. this.isLoading = false
  349. this.tableData = []
  350. this.page.total = 0
  351. } else {
  352. if (!this.search.filter) {
  353. this.search.leiArr = []
  354. }
  355. let param = {
  356. data: {
  357. limit: {
  358. // 可选
  359. skip: this.page.size * (this.page.currentPage - 1), // 跳过多少数据
  360. count: this.page.size // 查询跳过300条数据之后的50条 (默认按照创建时间从大-->小排序)
  361. },
  362. criteria: {
  363. building: this.search.floor[0], //建筑
  364. floor: this.search.floor[1] == "no" ? null : this.search.floor[1], // 选填, 指定楼层id
  365. name: this.search.filter, // 选填, 模糊搜索指定信息点的值
  366. type: this.search.leiArr.length ? this.search.leiArr : ["Eq"],
  367. space: this.list.id, // 必填, 指定业务空间id
  368. excludeGraphType: this.type,
  369. excludeRelType: relType,
  370. isGeneralZone: true,
  371. type: ["Eq"] // 必填, 查询类型, 允许四位编码的详细设备类
  372. }
  373. },
  374. ProjId: this.projectId, //项目id
  375. secret: this.secret
  376. };
  377. getEquipSearch(param)
  378. .then(res => {
  379. if (res.data.Result == "success") {
  380. this.page.total = res.data.TotalCount;
  381. this.tableData = res.data.Content;
  382. this.isLoading = false;
  383. } else {
  384. this.$message.error(res.data.ResultMsg);
  385. }
  386. })
  387. .catch(() => this.$message.error("请求失败"));
  388. }
  389. } else {
  390. if (this.search.checkbox) {
  391. let param = {
  392. data: {
  393. limit: {
  394. // 可选
  395. skip: this.page.size * (this.page.currentPage - 1), // 跳过多少数据
  396. count: this.page.size // 查询跳过300条数据之后的50条 (默认按照创建时间从大-->小排序)
  397. },
  398. criteria: {
  399. building: this.search.floor[0], //建筑
  400. floor: this.search.floor[1] == "no" ? null : this.search.floor[1], // 选填, 指定楼层id
  401. name: this.search.filter, // 选填, 模糊搜索指定信息点的值
  402. type: this.search.leiArr.length ? this.search.leiArr : ["Eq"],
  403. space: this.list.id, // 必填, 指定业务空间id
  404. excludeGraphType: this.type,
  405. excludeRelType: relType
  406. }
  407. },
  408. ProjId: this.projectId, //项目id
  409. secret: this.secret
  410. };
  411. getListForBuss(param, res => {
  412. this.page.total = res.TotalCount;
  413. this.tableData = res.Content;
  414. this.isLoading = false;
  415. })
  416. } else {
  417. let param = {
  418. data: {
  419. limit: {
  420. // 可选
  421. skip: this.page.size * (this.page.currentPage - 1), // 跳过多少数据
  422. count: this.page.size // 查询跳过300条数据之后的50条 (默认按照创建时间从大-->小排序)
  423. },
  424. criteria: {
  425. building: this.search.floor[0], //建筑
  426. floor: this.search.floor[1] == "no" ? null : this.search.floor[1], // 选填, 指定楼层id
  427. name: this.search.filter, // 选填, 模糊搜索指定信息点的值
  428. type: this.search.leiArr.length ? this.search.leiArr : ["Eq"],
  429. space: this.list.id, // 必填, 指定业务空间id
  430. excludeGraphType: this.type,
  431. excludeRelType: relType,
  432. type: ["Eq"] // 必填, 查询类型, 允许四位编码的详细设备类
  433. }
  434. },
  435. ProjId: this.projectId, //项目id
  436. secret: this.secret
  437. };
  438. getEquipSearch(param)
  439. .then(res => {
  440. if (res.data.Result == "success") {
  441. this.page.total = res.data.TotalCount;
  442. this.tableData = res.data.Content;
  443. this.isLoading = false;
  444. } else {
  445. this.$message.error(res.data.ResultMsg);
  446. }
  447. })
  448. .catch(() => this.$message.error("请求失败"));
  449. }
  450. }
  451. },
  452. /**
  453. * 分页函数
  454. * @param pageNo 当前页数
  455. * @param pageSize 当前条数
  456. * @param array 全部数据
  457. */
  458. pagination(pageNo, pageSize, array) {
  459. let offset = (pageNo - 1) * pageSize;
  460. return offset + pageSize >= array.length ?
  461. array.slice(offset, array.length) :
  462. array.slice(offset, offset + pageSize);
  463. },
  464. /**
  465. * 查看详情
  466. * @param row 点击的当条数据
  467. */
  468. lockDetails(row) {
  469. this.innerVisible = true;
  470. this.iframeSrc = this.iframeSrc =
  471. // process.env.BASE_URL +
  472. window.__systemConf.BASE_URL +
  473. ":8889/#/details?perjectId=" +
  474. this.projectId +
  475. "&secret=" +
  476. this.secret +
  477. "&FmId=" +
  478. row.id +
  479. "&type=0&code=" +
  480. row.category.substring(2, 6);
  481. },
  482. pageChange() {
  483. this.getEquip();
  484. },
  485. handleSelectionChange(val) {
  486. this.multipleSelection = val;
  487. },
  488. //添加关系,点击确定按钮
  489. addReal() {
  490. if (this.multipleSelection && this.multipleSelection.length) {
  491. let param = {
  492. data: {
  493. criterias: []
  494. },
  495. ProjId: this.projectId, //项目id
  496. secret: this.secret
  497. };
  498. let falg = false;
  499. if (!!!this.activeTabType) {
  500. this.$message.error("没有rel_type")
  501. }
  502. this.multipleSelection.map(item => {
  503. let rel_type = ""
  504. if (this.activeTabType.rel_type < 10) {
  505. rel_type = '0' + (this.activeTabType.rel_type * 100)
  506. } else {
  507. rel_type = (this.activeTabType.rel_type * 100).toString()
  508. }
  509. param.data.criterias.push({
  510. from_id: item.id,
  511. to_id: this.list.id,
  512. graph_id: this.graphyId,
  513. rel_type: this.activeTabType.rel_type == "99" ? "1" : rel_type
  514. });
  515. if (!!item.spaceName) {
  516. falg = true;
  517. }
  518. });
  519. if (falg) {
  520. this.$confirm("选择的部分设备不在业务空间中确定添加?", "删除", {
  521. confirmButtonText: "确定",
  522. cancelButtonText: "取消",
  523. type: "warning"
  524. })
  525. .then(() => {
  526. this.createReal(param);
  527. })
  528. .catch(() => {
  529. this.$message({
  530. type: "info",
  531. message: "已取消添加"
  532. });
  533. this.clearBox();
  534. });
  535. } else {
  536. this.createReal(param);
  537. }
  538. } else {
  539. this.$message.error("请选择设备再确定关联");
  540. }
  541. },
  542. createReal(param) {
  543. createRelation(param)
  544. .then(res => {
  545. if (res.data.Result == "success") {
  546. this.$message.success("添加成功");
  547. this.getEquip();
  548. } else {
  549. this.$message.error(res.data.ResultMsg);
  550. }
  551. })
  552. .catch(() => {
  553. this.$message.error("请求出错");
  554. });
  555. }
  556. },
  557. filters: {
  558. cutString: function (str, len) {
  559. //length属性读出来的汉字长度为1
  560. if (!!str && typeof str == "string" && str.length > len) {
  561. return str.substring(0, len) + "...";
  562. } else {
  563. return str || "--";
  564. }
  565. }
  566. }
  567. };
  568. </script>