addfacility.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  1. <template>
  2. <div id="deviceList">
  3. <el-row class="right">
  4. <span style="float:left;">当前选择的设备类型:{{ category.name }}</span>
  5. <el-select v-model="showType" @change="initTable" style="width:125px;margin-right:10px;vertical-align:bottom;">
  6. <el-option v-for="item in showTypes" :key="item.value" :label="item.label" :value="item.value"></el-option>
  7. </el-select>
  8. <span>增加</span>
  9. <el-input v-model="addNum" style="width:50px;" size="small"></el-input>
  10. <span>个{{ category.name }}</span>
  11. <el-button @click="handleAddTableRow">增加</el-button>
  12. </el-row>
  13. <div class="tableBox">
  14. <div class="center middle_sty" style="flex:2;" v-show="tableData && !tableData.length">
  15. <p>
  16. <i class="icon-wushuju iconfont"></i>
  17. 暂无数据
  18. </p>
  19. </div>
  20. <div class="tableLeft" v-show="tableData && tableData.length">
  21. <handson-table ref="table"></handson-table>
  22. </div>
  23. </div>
  24. <el-row class="center">
  25. <el-button type="primary" size="medium" @click.prevent.once="handleCreateTableData" class="create_button">创建设备</el-button>
  26. </el-row>
  27. <!-- 二维码弹窗 -->
  28. <qrcode :dialog="myDialog" :qrcodeUrl="qrcodeUrl" :addBody="true" ref="qrcode"></qrcode>
  29. <upload-files-dialog :read="onlyRead ? true : false" ref="upload" @changeFile="fileChange" :keysArr="filesArr"
  30. :dialog="myDialog">
  31. </upload-files-dialog>
  32. <upload-img-dialog :read="onlyRead ? true : false" @changeFile="imgChange" :keysArr="imgsArr"
  33. :dialog="myDialog"></upload-img-dialog>
  34. <pic-dialog :read="onlyRead ? true : false" :dialog="myDialog" :keysArr="picsArr" @change="changePics"></pic-dialog>
  35. <system-type :device="category" :dialog="myDialog" :type="onlyRead?'read':'edit'" @change="changeSystemType"
  36. :list="systemList"></system-type>
  37. <details-dialog :iframeSrc="iframeSrc" v-if="myDialog.details" :dialog="myDialog"></details-dialog>
  38. </div>
  39. </template>
  40. <script>
  41. import tools from "@/utils/scan/tools";
  42. import handsonUtils from "@/utils/hasontableUtils";
  43. import showTools from "@/utils/handsontable/notShow";
  44. import text from "@/utils/handsontable/mainText";
  45. import session from "@/framework/utils/storage";
  46. import buildFloor from '@/utils/handsontable/buildFloorData'
  47. import handsonTable from "@/components/common/handsontable";
  48. import {
  49. // getDataDictionary,
  50. createEquip,
  51. createPropertyData,
  52. getEquipBelongs,
  53. createEquipAndProperty
  54. } from "@/api/scan/request";
  55. import { getDataDictionary } from "@/api/dict";
  56. import { mapGetters, mapActions } from "vuex";
  57. import qrcode from "@/components/ledger/lib/qrcode";
  58. import uploadFilesDialog from "@/components/dialogs/list/filesDialog";
  59. import uploadImgDialog from "@/components/dialogs/list/uploadImgDialog";
  60. import picDialog from "@/components/dialogs/list/picDialog";
  61. import systemType from "@/components/dialogs/list/systemType";
  62. export default {
  63. components: {
  64. qrcode, //二维码页面
  65. uploadFilesDialog,
  66. uploadImgDialog,
  67. picDialog,
  68. systemType,
  69. handsonTable
  70. },
  71. data() {
  72. return {
  73. addNum: 1,
  74. onlyRead: false,
  75. showTypes: [
  76. { value: "all", label: '全部' },
  77. { value: "Visible", label: '只看采集信息' }
  78. ],
  79. tableHeader: [],
  80. tableData: session.get("deviceAddData")
  81. ? session.get("deviceAddData").length
  82. ? session.get("deviceAddData")
  83. : [{ checked: 1 }]
  84. : [{ checked: 1 }],
  85. copyTableData: [],
  86. category: "", //当前设备类
  87. myDialog: {
  88. qrcode: false, //二维码弹窗
  89. uploadFiles: false, //上传文件
  90. uploadImgs: false, //上传单个图片
  91. pic: false, //多个图片
  92. addDevice: false,
  93. systemType: false,
  94. details: false, //详情页
  95. changeRea: false,
  96. lookPic: false //图片查看
  97. },
  98. inputMap: {
  99. flowBuild: {
  100. editable: true,
  101. code: "flowBuild",
  102. name: "建筑楼层",
  103. path: "flowBuild",
  104. category: 'STATIC',
  105. dataType: "ENUM"
  106. }
  107. }, //信息点和输入方式映射表
  108. qrcodeUrl: "", //二维码图片地址
  109. filesArr: [], //保存临时的文件key
  110. imgsArr: [], //临时保存的图片key数组
  111. picsArr: [], //临时设备图片keys数组
  112. systemList: [], //关联的系统
  113. systemId: null,
  114. graphyId: null,
  115. id: 0,
  116. showType: this.$route.query.showType,
  117. EquipmentList: [],
  118. firmId: "", //品牌型号所需字段--族id三位编码(传设备类id或部件类id)
  119. buildFloorData: [],
  120. floorFlag: true,
  121. };
  122. },
  123. computed: {
  124. ...mapGetters("layout", ["projectId", "secret", "userId"])
  125. },
  126. created() {
  127. this.category = this.$route.query;
  128. buildFloor.getData(this.buildFloorData)
  129. this.getBelongs();
  130. this.getTableHeader();
  131. },
  132. methods: {
  133. //查询设备类对应的 族
  134. getBelongs() {
  135. let params = {
  136. data: {
  137. filters: `equipCode='${this.category.deviceId}'`,
  138. pageNumber: 1,
  139. pageSize: 50
  140. }
  141. }
  142. getEquipBelongs(params, res => {
  143. if (res.content.length) {
  144. this.firmId = res.content[0].family
  145. }
  146. })
  147. },
  148. //将数组转换成optiosn格式
  149. changeArr(arr) {
  150. return arr.map(item => {
  151. if (item.floors && item.floors.length) {
  152. return {
  153. value: item.id,
  154. label: item.infos.BuildLocalName,
  155. children: item.floors.map(i => {
  156. return {
  157. value: i.id,
  158. label: i.infos.FloorLocalName || "未知",
  159. }
  160. })
  161. }
  162. } else {
  163. return {
  164. value: item.id,
  165. label: item.infos.BuildLocalName,
  166. children: null,
  167. isChilren: 1,
  168. }
  169. }
  170. })
  171. },
  172. // 获取表头数据(初始化表格)
  173. async getTableHeader() {
  174. let params = {
  175. orders: "sort asc, name desc",
  176. pageNumber: 1,
  177. pageSize: 1000,
  178. type: this.category.deviceId
  179. };
  180. await getDataDictionary(params, res => {
  181. this.tableHeader = res.content;
  182. this.tableHeader.forEach(item => {
  183. if (item.path) {
  184. this.inputMap[item.path] = item;
  185. }
  186. });
  187. this.initTable();
  188. });
  189. },
  190. // 创建设备数据
  191. async handleCreateTableData() {
  192. let newData = this.tableData.filter(item => {
  193. let keys = Object.keys(item);
  194. keys.map(key => {
  195. //将值为空字符串的属性删除
  196. if (item[key] == "") {
  197. delete item[key];
  198. }
  199. });
  200. let newK = Object.keys(item)
  201. if ((item.checked && newK.length > 1) || (!item.checked && newK.length)) {
  202. return item;
  203. }
  204. });
  205. if (!newData.length) {
  206. this.$message("创建信息为空,请录入信息后再创建!");
  207. return;
  208. }
  209. let flag = false;
  210. newData.map(item => {
  211. if (item.checked && !item.localName) {
  212. flag = true;
  213. }
  214. // 处理建筑-楼层
  215. if (item.flowBuild) {
  216. let bid = item.flowBuild.split("-");
  217. item.buildingId = item.flowBuild.split("-")[0]
  218. if (bid[1]) {
  219. item.floorId = item.flowBuild.split("-")[1]
  220. }
  221. }
  222. //处理管理的系统
  223. if (item.linkSystem && item.linkSystem.length) {
  224. item.SystemList = []
  225. item.linkSystem.map(t => {
  226. // todo 测试 t.SysID === ? id
  227. item.SystemList.push(t.id)
  228. })
  229. }
  230. item.propertyId = !!item.checked;
  231. item.classCode = this.category.deviceId;
  232. })
  233. if (flag) {
  234. this.$message.info("存在设备的本地名称为空,请检查")
  235. return;
  236. }
  237. // for (let i = 0; i < newData.length; i++) {
  238. // let params = newData[i]
  239. // params.Family = this.firmId;
  240. // params.Category = this.category.deviceId;
  241. // if (newData[i].PropertyId) {//同时创建资产
  242. // await createPropertyData([params], async res => {
  243. // params.PropertyId = res.EntityList[0].EquipID
  244. // await createEquip([params], res => {
  245. // if (i == newData.length - 1) {
  246. // this.$router.push({
  247. // path: "/ledger/facility",
  248. // query: { deviceId: this.category.deviceId }
  249. // });
  250. // session.remove("deviceAddData")
  251. // }
  252. // })
  253. // })
  254. // } else {
  255. // await createEquip([params], res => {
  256. // if (i == newData.length - 1) {
  257. // this.$router.push({
  258. // path: "/ledger/facility",
  259. // query: { deviceId: this.category.deviceId }
  260. // });
  261. // session.remove("deviceAddData")
  262. // }
  263. // });
  264. // }
  265. // }
  266. //待接口修改为关联创建即可修改
  267. let param = {
  268. cascade: [],
  269. content: newData
  270. }
  271. createEquipAndProperty(param, res => {
  272. this.$message.success('创建成功')
  273. session.remove("deviceAddData")
  274. this.$router.push({
  275. name: "facilityLedger",
  276. params: { deviceId: this.category.deviceId }
  277. });
  278. })
  279. },
  280. // 删除表格行
  281. handleDeleteTableRow() {
  282. this.$message.success("删除成功");
  283. this.formaTableData();
  284. },
  285. // 添加行
  286. handleAddTableRow() {
  287. let addRowLength = this.addNum;
  288. for (let i = 0; i < addRowLength; i++) {
  289. this.tableData.push({ checked: 1 });
  290. }
  291. this.initTable();
  292. this.formaTableData();
  293. },
  294. //修改
  295. handleUpdataTable(changeData, source) {
  296. if (!this.onlyRead && source != 'ObserveChanges.change') {
  297. this.formaTableData();
  298. }
  299. },
  300. //保存去掉空字段的新增数据
  301. formaTableData() {
  302. let newData = this.tableData.filter(item => {
  303. let keys = Object.keys(item);
  304. keys.map(key => {
  305. //将值为空字符串的属性删除
  306. if (item[key] == "") {
  307. delete item[key];
  308. }
  309. });
  310. if (keys.length && Object.keys(item).length) {
  311. return item;
  312. }
  313. });
  314. session.set("deviceAddData", newData);
  315. },
  316. //格式化表头显示的数据
  317. formatHeaderData(list) {
  318. let arr = tools.copyArr(list);
  319. let data = showTools.headerTextFilter(arr, 'equipment', this.onlyRead, this.showType, true);
  320. data.unshift("同时创建资产", "所属系统实例");
  321. if (this.floorFlag) {
  322. data.splice(1, 0, "所属建筑楼层")
  323. }
  324. return data;
  325. },
  326. formatHeaderType(list) {
  327. //格式化表头头映射的数据
  328. let arr = tools.copyArr(list);
  329. let data = showTools.headerTypeFilter(arr, 'equipment', this.onlyRead, this.showType, true);
  330. data.unshift({
  331. type: "checkbox",
  332. checkedTemplate: 1,
  333. uncheckedTemplate: 0,
  334. data: "Checked",
  335. label: {
  336. position: "after"
  337. }
  338. }, {
  339. data: "linkSystem",
  340. renderer: text.systemList,
  341. readOnly: true
  342. });
  343. if (this.floorFlag) {
  344. data.splice(1, 0, {
  345. data: "flowBuild",
  346. renderer: tools.customDropdownRenderer,
  347. editor: "chosen",
  348. chosenOptions: {
  349. // multiple: true,//多选
  350. data: this.buildFloorData
  351. }
  352. })
  353. }
  354. return data;
  355. },
  356. initTable() {
  357. //实例化表格
  358. let settings = {
  359. data: this.tableData,
  360. colHeaders: this.formatHeaderData(this.tableHeader),
  361. columns: this.formatHeaderType(this.tableHeader),
  362. rowHeights: 30,
  363. maxRows: this.tableData.length,
  364. contextMenu: this.onlyRead ? false : {
  365. items: {
  366. remove_row: {
  367. name: "删除设备"
  368. }
  369. }
  370. },
  371. // 事件
  372. afterChange: this.handleUpdataTable, //修改后
  373. afterFilter: this.trimmedRows, //排序前
  374. afterRemoveRow: this.handleDeleteTableRow, //右键删除
  375. afterOnCellMouseDown: this.handleTdClick //鼠标点击
  376. };
  377. this.$nextTick(() => {
  378. this.tableExample = this.$refs.table.init(settings);
  379. });
  380. },
  381. //去除数组中相同的元素
  382. array_diff(a, b) {
  383. for (var i = 0; i < b.length; i++) {
  384. for (var j = 0; j < a.length; j++) {
  385. if (a[j] == b[i]) {
  386. a.splice(j, 1);
  387. j = j - 1;
  388. }
  389. }
  390. }
  391. return a;
  392. },
  393. //上传文件弹窗触发事件
  394. fileChange(keys) {
  395. this.setDataToMain(keys, this.messKey, this.row);
  396. },
  397. //上传图片弹窗触发事件
  398. imgChange(keys) {
  399. this.setDataToMain(keys, this.messKey, this.row);
  400. },
  401. //设备图片弹窗改变事件
  402. changePics(keys) {
  403. this.setDataToMain(keys, this.messKey, this.row);
  404. },
  405. //关联系统变更
  406. changeSystemType(data) {
  407. tools.setDataForKey(this.tableData[this.row], "linkSystem", data)
  408. },
  409. //表格点击事件
  410. handleTdClick(el, rowArr) {
  411. //点击的是表头
  412. if (rowArr.row < 0) {
  413. return;
  414. }
  415. //被筛选过后的数组
  416. let trimmedArr = this.trimmedRows();
  417. //是否启用了排序
  418. let isSort = this.tableExample.getPlugin("columnSorting").isSorted();
  419. if (trimmedArr.length && isSort) {
  420. let sortArr = this.myHotArr.getPlugin("columnSorting").rowsMapper
  421. .__arrayMap;
  422. let infos = this.tableData[trimmedArr[sortArr[rowArr.row]]];
  423. this.getInfors(infos, { row: sortArr[rowArr.row], col: rowArr.col });
  424. } else if (isSort) {
  425. //排序后的数组
  426. let sortArr = this.tableExample.getPlugin("columnSorting").rowsMapper
  427. .__arrayMap;
  428. let infos = this.tableData[sortArr[rowArr.row]];
  429. this.getInfors(infos, { row: sortArr[rowArr.row], col: rowArr.col });
  430. } else if (trimmedArr.length) {
  431. let infos = this.tableData[trimmedArr[rowArr.row]];
  432. this.getInfors(infos, { row: trimmedArr[rowArr.row], col: rowArr.col });
  433. } else {
  434. let infos = this.tableData[rowArr.row];
  435. this.getInfors(infos, rowArr);
  436. }
  437. },
  438. //获取被筛选掉的行号
  439. trimmedRows() {
  440. var plugin = this.tableExample.getPlugin("trimRows").trimmedRows;
  441. let dataLength = this.tableData.length;
  442. let dataArr = new Array();
  443. for (let i = 0; i < dataLength; i++) {
  444. dataArr.push(i);
  445. }
  446. if (plugin.length <= 0) {
  447. dataArr = undefined;
  448. } else {
  449. dataArr = this.array_diff(dataArr, plugin);
  450. }
  451. return dataArr || [];
  452. },
  453. getInfors(infos, row) {
  454. let val = this.tableExample.colToProp(row.col);
  455. let inputData = this.inputMap[val];
  456. this.row = row.row;
  457. this.messKey = val;
  458. switch (val) {
  459. //操作
  460. case 'caozuo':
  461. // window.open(`http://adm.sagacloud.cn:8058/spread?id=${infos.EquipID}&pid=${this.projectId}&secret=${this.secret}`,"_blank")
  462. this.$message("开发中...")
  463. break;
  464. case "defaultQRCode":
  465. this.qrcodeUrl = this.tableData[row.row][val];
  466. if (this.qrcodeUrl) {
  467. this.myDialog.qrcode = true;
  468. } else {
  469. this.$message("此设备没有设备二维码");
  470. }
  471. break;
  472. //关联系统
  473. case 'linkSystem':
  474. if (!this.onlyRead) {
  475. this.systemList = this.tableData[row.row].linkSystem || [];
  476. this.myDialog.systemType = true;
  477. }
  478. break;
  479. //关联资产
  480. case 'linkEquipLocalName':
  481. if (this.linkNameFalg) {
  482. this.myDialog.changeRea = true;
  483. }
  484. break;
  485. /**
  486. * 关联资产后才可维护的信息点
  487. */
  488. case 'flowBuild': //所属建筑楼层
  489. case 'infos.productDate': //生产日期
  490. case 'infos.serialNum': //出厂编号
  491. case 'infos.assetID': //资产编号
  492. case 'infos.purchasePrice': //采购价格
  493. case 'infos.insuranceNum': //保险单号
  494. case 'infos.insuranceFile': //保险文件
  495. if (!this.onlyRead) {
  496. const linkId = this.tableData[row.row].linkId;
  497. if (!linkId) { //未关联资产
  498. this.$confirm('请先关联资产后再维护该信息!', '提示', {
  499. confirmButtonText: '确定',
  500. showCancelButton: false,
  501. type: 'warning'
  502. }).then(() => {
  503. return false;
  504. });
  505. }
  506. }
  507. break
  508. //保险文件--设备文档--安装质检报告
  509. case 'infos.insuranceFile': //保险文件
  510. case 'infos.archive': //设备文档
  511. case 'infos.checkReport': //安装质检报告
  512. case 'infos.maintainManual': //维修保养手册
  513. case 'infos.approachingAcceptance': //进场验收单
  514. case 'infos.acceptanceReport': //验收报告
  515. case 'infos.operationManual': //操作说明书
  516. case 'infos.originalCertificate': //原厂证明
  517. case 'infos.testReport': //检测报告
  518. case 'infos.productCertification': //产品合格证
  519. case 'infos.installInstruction': //安装说明书
  520. case 'infos.supplierContract': //供应合同
  521. case 'infos.drawing': //设备图纸
  522. case 'infos.installDrawing': //安装图纸
  523. let IPSdata = tools.dataForKey(this.tableData[row.row], val);
  524. this.filesArr = IPSdata ? IPSdata : [];
  525. this.myDialog.uploadFiles = true;
  526. break;
  527. //安装照片--设备铭牌照片
  528. case 'infos.installPic':
  529. case 'infos.nameplate':
  530. let SSPPdata = tools.dataForKey(this.tableData[row.row], val);
  531. this.imgsArr = SSPPdata ? SSPPdata : [];
  532. this.myDialog.uploadImgs = true;
  533. break;
  534. //设备照片
  535. case 'infos.pic':
  536. let Pdata = tools.dataForKey(this.tableData[row.row], val);
  537. this.picsArr = Pdata ? Pdata : [];
  538. this.myDialog.pic = true;
  539. break;
  540. //包含的部件字段
  541. case 'count':
  542. if (this.onlyRead) {
  543. this.$router.push({ path: '/ledger/parts', query: { deviceId: infos.EquipID } });
  544. } else {
  545. this.$router.push({
  546. path: '/ledger/partsmanage',
  547. query: { deviceId: infos.EquipID, typeId: this.mess.deviceId }
  548. });
  549. }
  550. break;
  551. default:
  552. break;
  553. }
  554. if (!this.onlyRead && !inputData.editable) {
  555. this.$message("该信息点的值为自动生成,不可人工维护!");
  556. return false;
  557. }
  558. },
  559. utilToKey(key, name, data, messName) {
  560. if (key == name) {
  561. this.setDataToMain(data[key], messName, this.row);
  562. }
  563. },
  564. //判断是否有值,有值赋值
  565. setDataToMain(data, key, row) {
  566. if (!!data && data != "--") {
  567. if (!!this.tableData[row]) {
  568. //铭牌照片特殊处理
  569. tools.setDataForKey(this.tableData[row], key, data)
  570. // this.tableData[row][key] = data;
  571. } else {
  572. this.tableData[row] = {};
  573. tools.setDataForKey(this.tableData[row], key, data)
  574. }
  575. } else {
  576. tools.setDataForKey(this.tableData[row], key, "")
  577. }
  578. }
  579. }
  580. };
  581. </script>
  582. <style lang="less" scoped>
  583. #deviceList {
  584. overflow: hidden;
  585. height: 100%;
  586. background-color: #fff;
  587. padding: 10px;
  588. position: relative;
  589. .right {
  590. background: #fff;
  591. }
  592. .search-header {
  593. overflow: hidden;
  594. padding: 0 10px 10px 10px;
  595. border-bottom: 1px solid #bcbcbc;
  596. }
  597. .tableBox {
  598. display: flex;
  599. height: calc(100% - 100px);
  600. margin-top: 10px;
  601. .tableLeft {
  602. flex: 1;
  603. }
  604. }
  605. .create_button {
  606. margin-top: 10px;
  607. }
  608. }
  609. </style>