addsystem.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493
  1. <template>
  2. <div id="deviceList">
  3. <el-row class="right">
  4. <span style="width:20px;float:left;display:block;height:20px;cursor: pointer;" @click="changeAssetsFalg">
  5. <i class="el-icon-fa el-icon-fa-compass"></i>
  6. </span>
  7. <span style="float:left;">当前选择的系统类型:{{category.CategoryName}}</span>
  8. <el-select v-model="showType" @change="initTable" style="width:125px;margin-right:10px;vertical-align:bottom;">
  9. <el-option v-for="item in showTypes" :key="item.value" :label="item.label" :value="item.value"></el-option>
  10. </el-select>
  11. <span>增加</span>
  12. <el-input v-model="addNum" style="width:50px;" size="small"></el-input>
  13. <span>个{{category.CategoryName}}</span>
  14. <el-button @click="handleAddTableRow">增加</el-button>
  15. </el-row>
  16. <div class="tableBox">
  17. <div class="center middle_sty" style="flex:2;" v-show="tableData && !tableData.length">
  18. <p>
  19. <i class="icon-wushuju iconfont"></i>
  20. 暂无数据
  21. </p>
  22. </div>
  23. <div class="tableLeft" v-show="tableData && tableData.length">
  24. <handson-table ref="table"></handson-table>
  25. </div>
  26. </div>
  27. <el-row class="center">
  28. <el-button type="primary" size="medium" @click="handleCreateTableData" class="create_button">创建系统</el-button>
  29. </el-row>
  30. </div>
  31. </template>
  32. <script>
  33. import tools from "@/utils/scan/tools";
  34. import handsonUtils from "@/utils/hasontableUtils";
  35. import showTools from "@/utils/handsontable/notShow";
  36. import text from "@/utils/handsontable/mainText";
  37. import session from "@/framework/utils/storage";
  38. import handsonTable from "@/components/common/handsontable";
  39. import {
  40. getDataDictionary,
  41. createGeneralSys,
  42. buildingQuery
  43. } from "@/api/scan/request";
  44. import { mapGetters, mapActions } from "vuex";
  45. import qrcode from "@/components/ledger/lib/qrcode";
  46. export default {
  47. components: {
  48. handsonTable
  49. },
  50. data() {
  51. return {
  52. addNum: 1,
  53. onlyRead: false,
  54. showTypes: [{ value: "partInfo", label: '隐藏信息点' }, { value: "all", label: '全部' }, { value: "Visible", label: '只看采集信息' }],
  55. tableHeader: [],
  56. tableData: session.get("systemAddData")
  57. ? session.get("systemAddData").length
  58. ? session.get("systemAddData")
  59. : [{}]
  60. : [{}],
  61. copyTableData: [],
  62. category: "", //当前设备类
  63. myDialog: {
  64. qrcode: false, //二维码弹窗
  65. firm: false, //厂商弹窗
  66. supply: false, //选择供应合同
  67. supplier: false, //供应商选择
  68. guarantee: false, //选择保单
  69. maintainer: false, //选择维修商
  70. insurer: false, //选择保险公司
  71. uploadFiles: false, //上传文件
  72. uploadImgs: false, //上传单个图片
  73. pic: false, //多个图片
  74. addDevice: false,
  75. systemType: false,
  76. details: false, //详情页
  77. changeRea: false,
  78. lookPic: false //图片查看
  79. },
  80. qrcodeUrl: "", //二维码图片地址
  81. filesArr: [], //保存临时的文件key
  82. imgsArr: [], //临时保存的图片key数组
  83. picsArr: [], //临时设备图片keys数组
  84. systemId: null,
  85. graphyId: null,
  86. id: 0,
  87. showType: 'partInfo',
  88. EquipmentList: [],
  89. };
  90. },
  91. computed: {
  92. ...mapGetters("layout", ["projectId", "secret", "userId"])
  93. },
  94. created() {
  95. this.category = this.$route.query;
  96. this.getBuildData();
  97. this.getTableHeader();
  98. },
  99. methods: {
  100. //维护建筑
  101. changeAssetsFalg() {
  102. if (this.floorFlag) {
  103. this.floorFlag = false
  104. } else {
  105. this.$confirm('<p>维护设备所在建筑楼层后,对后续数据影响较大,如业务空间中的所在关系or其他?暂未梳理明白……</p><p>后续要修改设备所属建筑楼层,只能通过模型中的待建模清单操作</p>', '提示', {
  106. dangerouslyUseHTMLString: true,
  107. confirmButtonText: '就要维护设备所属建筑楼层',
  108. cancelButtonText: '暂时不搞了',
  109. confirmButtonClass: 'confirmButtonClass',
  110. cancelButtonClass: 'cancelButtonClass'
  111. }).then(_ => {
  112. this.floorFlag = true
  113. this.getTableHeader()
  114. }).catch(_ => {
  115. this.$message("取消")
  116. })
  117. }
  118. },
  119. //获取建筑数据
  120. getBuildData() {
  121. let param = {
  122. PageNumber: 1,
  123. PageSize: 500,
  124. Projection: [
  125. "BuildID",
  126. "BuildLocalName"
  127. ]
  128. }
  129. buildingQuery(param, res => {
  130. let data = res.Content.map(t => {
  131. return {
  132. Code: t.BuildID,
  133. Name: t.BuildLocalName,
  134. }
  135. })
  136. data.unshift({ Code: '', Name: '未明确建筑' })
  137. this.buildingData = data;
  138. })
  139. },
  140. // 获取表头数据(初始化表格)
  141. async getTableHeader() {
  142. let params = {
  143. data: {
  144. Orders: "sort asc",
  145. PageNumber: 1,
  146. PageSize: 500
  147. },
  148. type: this.category.Category
  149. };
  150. await getDataDictionary(params, res => {
  151. this.tableHeader = res.Content;
  152. this.initTable();
  153. });
  154. },
  155. // 创建设备数据
  156. async handleCreateTableData() {
  157. let params = {}
  158. let newData = this.tableData.filter(item => {
  159. let keys = Object.keys(item);
  160. keys.map(key => {
  161. //将值为空字符串的属性删除
  162. if (item[key] == "") {
  163. delete item[key];
  164. }
  165. });
  166. let newK = Object.keys(item)
  167. if (newK.length) {
  168. return item;
  169. }
  170. });
  171. if (!newData.length) {
  172. this.$message("创建信息为空,请录入信息后再创建!");
  173. return;
  174. }
  175. let flag = false;
  176. newData.map(item => {
  177. if (!item.SysLocalName) {
  178. flag = true;
  179. }
  180. // 处理建筑
  181. if (item.flowBuild) {
  182. item.BuildingId = item.flowBuild
  183. }
  184. item.Category = this.category.Category
  185. })
  186. if (flag) {
  187. this.$message.info("存在系统的本地名称为空,请检查")
  188. return;
  189. }
  190. params.Content = newData
  191. createGeneralSys(params, res => {
  192. this.$message.success('创建成功')
  193. session.remove("systemAddData")
  194. this.$router.push({
  195. name: "systemlist",
  196. params: { deviceId: this.category.Category }
  197. });
  198. })
  199. },
  200. // 删除表格行
  201. handleDeleteTableRow() {
  202. this.$message.success("删除成功");
  203. this.formaTableData();
  204. },
  205. // 添加行
  206. handleAddTableRow() {
  207. let addRowLength = this.addNum;
  208. for (let i = 0; i < addRowLength; i++) {
  209. this.tableData.push({});
  210. }
  211. this.initTable();
  212. this.formaTableData();
  213. },
  214. //修改
  215. handleUpdataTable(changeData, source) {
  216. this.formaTableData();
  217. },
  218. //保存去掉空字段的新增数据
  219. formaTableData() {
  220. let newData = this.tableData.filter(item => {
  221. let keys = Object.keys(item);
  222. keys.map(key => {
  223. //将值为空字符串的属性删除
  224. if (item[key] == "") {
  225. delete item[key];
  226. }
  227. });
  228. if (keys.length && Object.keys(item).length) {
  229. return item;
  230. }
  231. });
  232. session.set("systemAddData", newData);
  233. },
  234. //格式化表头显示的数据
  235. formatHeaderData(list) {
  236. let arr = tools.copyArr(list);
  237. let data = showTools.headerTextFilter(arr, 'system', this.onlyRead, this.showType);
  238. data.unshift("所属建筑");
  239. return data;
  240. },
  241. formatHeaderType(list) {
  242. //格式化表头头映射的数据
  243. let arr = tools.copyArr(list);
  244. let data = showTools.headerTypeFilter(arr, 'system', this.onlyRead, this.showType);
  245. data.unshift({
  246. data: "flowBuild",
  247. renderer: tools.customDropdownRenderer,
  248. editor: "chosen",
  249. chosenOptions: {
  250. // multiple: true,//多选
  251. data: this.buildingData
  252. }
  253. });
  254. return data;
  255. },
  256. initTable() {
  257. //实例化表格
  258. let settings = {
  259. data: this.tableData,
  260. colHeaders: this.formatHeaderData(this.tableHeader),
  261. columns: this.formatHeaderType(this.tableHeader),
  262. rowHeights: 30,
  263. maxRows: this.tableData.length,
  264. contextMenu: this.onlyRead ? false :{
  265. items: {
  266. remove_row: {
  267. name: "删除设备"
  268. }
  269. }
  270. },
  271. // 事件
  272. afterChange: this.handleUpdataTable, //修改后
  273. afterFilter: this.trimmedRows, //排序前
  274. afterRemoveRow: this.handleDeleteTableRow, //右键删除
  275. afterOnCellMouseDown: this.handleTdClick //鼠标点击
  276. };
  277. this.$nextTick(() => {
  278. this.tableExample = this.$refs.table.init(settings);
  279. });
  280. },
  281. //去除数组中相同的元素
  282. array_diff(a, b) {
  283. for (var i = 0; i < b.length; i++) {
  284. for (var j = 0; j < a.length; j++) {
  285. if (a[j] == b[i]) {
  286. a.splice(j, 1);
  287. j = j - 1;
  288. }
  289. }
  290. }
  291. return a;
  292. },
  293. //表格点击事件
  294. handleTdClick(el, rowArr) {
  295. //点击的是表头
  296. if (rowArr.row < 0) {
  297. return;
  298. }
  299. //被筛选过后的数组
  300. let trimmedArr = this.trimmedRows();
  301. //是否启用了排序
  302. let isSort = this.tableExample.getPlugin("columnSorting").isSorted();
  303. if (trimmedArr.length && isSort) {
  304. let sortArr = this.myHotArr.getPlugin("columnSorting").rowsMapper
  305. .__arrayMap;
  306. let infos = this.tableData[trimmedArr[sortArr[rowArr.row]]];
  307. this.getInfors(infos, { row: sortArr[rowArr.row], col: rowArr.col });
  308. } else if (isSort) {
  309. //排序后的数组
  310. let sortArr = this.tableExample.getPlugin("columnSorting").rowsMapper
  311. .__arrayMap;
  312. let infos = this.tableData[sortArr[rowArr.row]];
  313. this.getInfors(infos, { row: sortArr[rowArr.row], col: rowArr.col });
  314. } else if (trimmedArr.length) {
  315. let infos = this.tableData[trimmedArr[rowArr.row]];
  316. this.getInfors(infos, { row: trimmedArr[rowArr.row], col: rowArr.col });
  317. } else {
  318. let infos = this.tableData[rowArr.row];
  319. this.getInfors(infos, rowArr);
  320. }
  321. },
  322. //获取被筛选掉的行号
  323. trimmedRows() {
  324. var plugin = this.tableExample.getPlugin("trimRows").trimmedRows;
  325. let dataLength = this.tableData.length;
  326. let dataArr = new Array();
  327. for (let i = 0; i < dataLength; i++) {
  328. dataArr.push(i);
  329. }
  330. if (plugin.length <= 0) {
  331. dataArr = undefined;
  332. } else {
  333. dataArr = this.array_diff(dataArr, plugin);
  334. }
  335. return dataArr || [];
  336. },
  337. getInfors(infos, row) {
  338. let val = this.tableExample.colToProp(row.col);
  339. console.log(val)
  340. switch (val) {
  341. //操作
  342. case 'caozuo':
  343. // window.open(`http://adm.sagacloud.cn:8058/spread?id=${infos.EquipID}&pid=${this.projectId}&secret=${this.secret}`,"_blank")
  344. this.$message("开发中...")
  345. break;
  346. //设备二维码图片
  347. case 'EquipQRCode':
  348. this.qrcodeUrl = this.tableData[row.row].EquipQRCode;
  349. if (!!this.qrcodeUrl) {
  350. this.myDialog.qrcode = true;
  351. } else {
  352. this.$message("此设备没有设备二维码");
  353. }
  354. break;
  355. //关联系统
  356. case 'linkSystem':
  357. if (!this.onlyRead) {
  358. this.systemList = this.tableData[row.row].LinkSystem || [];
  359. this.myDialog.systemType = true;
  360. }
  361. break;
  362. //关联资产
  363. case 'LinkEquipLocalName':
  364. if (this.linkNameFalg) {
  365. this.myDialog.changeRea = true;
  366. }
  367. break;
  368. //品牌型号弹窗
  369. case 'DPManufacturerID':
  370. if (!this.onlyRead) {
  371. this.myDialog.firm = true;
  372. }
  373. break;
  374. //供应商信息弹窗
  375. case 'DPSupplierID':
  376. if (!this.onlyRead) {
  377. this.myDialog.supplier = true;
  378. }
  379. break;
  380. //维修商信息弹窗
  381. case 'DPMaintainerID':
  382. if (!this.onlyRead) {
  383. this.myDialog.maintainer = true;
  384. }
  385. break;
  386. //保险公司信息
  387. case 'DPInsurerID':
  388. if (!this.onlyRead) {
  389. this.myDialog.insurer = true;
  390. }
  391. break;
  392. //供应合同编号
  393. case 'LedgerParam.SupplyPurchase.SupplierContractID':
  394. if (!this.onlyRead) {
  395. let ContractIDflag = null;
  396. let DPSdata = this.tableData[row.row].DPSupplierID;
  397. if (DPSdata) {
  398. ContractIDflag = DPSdata.split("-")[0];
  399. }
  400. if (!!ContractIDflag) {
  401. this.id = ContractIDflag;
  402. this.myDialog.supply = true;
  403. } else {
  404. this.$message("请先选择供应商");
  405. }
  406. }
  407. break;
  408. //保险单号
  409. case 'LedgerParam.InsuranceDoc.InsuranceNum':
  410. if (!this.onlyRead) {
  411. let DPInsurerIDflag = null;
  412. let DPIdata = this.tableData[row.row].DPInsurerID;
  413. if (DPIdata) {
  414. DPInsurerIDflag = DPIdata.split("-")[0];
  415. }
  416. if (!!DPInsurerIDflag) {
  417. this.id = DPInsurerIDflag;
  418. this.myDialog.guarantee = true;
  419. } else {
  420. this.$message("请先选择保险商");
  421. }
  422. }
  423. break;
  424. //保险文件--设备文档--安装质检报告
  425. case 'LedgerParam.InsuranceDoc.InsuranceFile':
  426. case 'LedgerParam.PhotoDoc.Archive':
  427. case 'LedgerParam.Siteinstall.CheckReport':
  428. let IPSdata = tools.dataForKey(this.tableData[row.row], val);
  429. this.filesArr = IPSdata ? IPSdata : [];
  430. this.myDialog.uploadFiles = true;
  431. break;
  432. //安装照片--安装图纸--设备铭牌照片--设备图纸
  433. case 'LedgerParam.Siteinstall.InstallPic':
  434. case 'LedgerParam.Siteinstall.InstallDrawing':
  435. case 'LedgerParam.PhotoDoc.Nameplate':
  436. case 'LedgerParam.PhotoDoc.Drawing':
  437. let SSPPdata = tools.dataForKey(this.tableData[row.row], val);
  438. this.imgsArr = SSPPdata ? SSPPdata : [];
  439. this.myDialog.uploadImgs = true;
  440. break;
  441. //设备照片
  442. case 'LedgerParam.PhotoDoc.Pic':
  443. let Pdata = tools.dataForKey(this.tableData[row.row], val);
  444. this.picsArr = Pdata ? Pdata : [];
  445. this.myDialog.pic = true;
  446. break;
  447. //包含的部件字段
  448. case 'Count':
  449. if (this.onlyRead) {
  450. this.$router.push({ path: '/ledger/parts', query: { deviceId: infos.EquipID } });
  451. } else {
  452. this.$router.push({ path: '/ledger/partsmanage', query: { deviceId: infos.EquipID, typeId: this.mess.deviceId } });
  453. }
  454. break;
  455. default:
  456. break;
  457. }
  458. this.row = row.row;
  459. this.messKey = val;
  460. },
  461. }
  462. };
  463. </script>
  464. <style lang="less" scoped>
  465. #deviceList {
  466. overflow: hidden;
  467. height: 100%;
  468. background-color: #fff;
  469. padding: 10px;
  470. position: relative;
  471. .right {
  472. background: #fff;
  473. }
  474. .search-header {
  475. overflow: hidden;
  476. padding: 0 10px 10px 10px;
  477. border-bottom: 1px solid #bcbcbc;
  478. }
  479. .tableBox {
  480. display: flex;
  481. height: calc(100% - 100px);
  482. margin-top: 10px;
  483. .tableLeft {
  484. flex: 1;
  485. }
  486. }
  487. .create_button {
  488. margin-top: 10px;
  489. }
  490. }
  491. </style>