index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509
  1. <template>
  2. <div id="partsList">
  3. <el-row>
  4. <el-tabs @tab-click="getTableHeader" v-model="tabVal">
  5. <el-tab-pane v-for="t in partsTypeList" :key="t.category" :name="t.category"
  6. :label="`${t.categoryName}(${t.count?t.count:0})`"></el-tab-pane>
  7. </el-tabs>
  8. </el-row>
  9. <el-row class="left">
  10. <el-button size="small" type="default" icon="el-icon-back" @click="goback" style="margin-right:10px;"></el-button>
  11. <el-select v-model="showType" @change="initTable" style="width:100px;margin-right:10px;vertical-align:bottom;">
  12. <el-option v-for="item in showTypes" :key="item.value" :label="item.label" :value="item.value">
  13. </el-option>
  14. </el-select>
  15. <el-button @click="getTableHeader">刷新</el-button>
  16. </el-row>
  17. <div class="tableBox">
  18. <div class="center middle_sty" v-show="tableData && !tableData.length" style="flex:2;">
  19. <p>
  20. <i class="icon-wushuju iconfont"></i>
  21. 暂无数据
  22. </p>
  23. </div>
  24. <div class="tableLeft" v-show="tableData && tableData.length">
  25. <handson-table ref="table"></handson-table>
  26. </div>
  27. </div>
  28. <el-pagination class="right" v-show="tableData && tableData.length" @size-change="handleSizeChange"
  29. @current-change="handleCurrentChange"
  30. :current-page="page.pageNumber" :page-sizes="page.pageSizes" :page-size="page.pageSize"
  31. layout="total, sizes, prev, pager, next, jumper"
  32. :total="page.total"></el-pagination>
  33. <!-- 二维码弹窗 -->
  34. <qrcode :dialog="myDialog" :qrcodeUrl="qrcodeUrl" :addBody="true" ref="qrcode"></qrcode>
  35. <upload-files-dialog :read="onlyRead ? true : false" ref="upload" @changeFile="fileChange" :keysArr="filesArr"
  36. :dialog="myDialog">
  37. </upload-files-dialog>
  38. <upload-img-dialog :read="onlyRead ? true : false" @changeFile="imgChange" :keysArr="imgsArr"
  39. :dialog="myDialog"></upload-img-dialog>
  40. <pic-dialog :read="onlyRead ? true : false" :dialog="myDialog" :keysArr="picsArr" @change="changePics"></pic-dialog>
  41. </div>
  42. </template>
  43. <script>
  44. import tools from "@/utils/scan/tools";
  45. import showTools from "@/utils/handsontable/notShow";
  46. import qrcode from "@/components/ledger/lib/qrcode";
  47. import uploadFilesDialog from "@/components/dialogs/list/filesDialog";
  48. import uploadImgDialog from "@/components/dialogs/list/uploadImgDialog";
  49. import picDialog from "@/components/dialogs/list/picDialog";
  50. import systemType from "@/components/dialogs/list/systemType";
  51. import handsonTable from "@/components/common/handsontable";
  52. import {BeatchQueryParam, deleteParts, getEquipPartsCon, getEquipPartsType} from "@/api/scan/request";
  53. import {getDataDictionary} from "@/api/dict";
  54. import {mapGetters} from "vuex";
  55. export default {
  56. components: {
  57. qrcode, //二维码页面
  58. uploadFilesDialog,
  59. uploadImgDialog,
  60. picDialog,
  61. systemType,
  62. handsonTable
  63. },
  64. data() {
  65. return {
  66. deviceId: "", //设备id
  67. isTableRightShow: false,
  68. spaceList: "",
  69. onlyRead: true,
  70. tableHeader: [],
  71. page: {
  72. pageSize: 50,
  73. pageSizes: [10, 20, 50, 100],
  74. pageNumber: 1,
  75. total: 0
  76. },
  77. showTypes: [
  78. { value: "Visible", label: '只看采集信息' },
  79. { value: "all", label: '全部' }
  80. ],
  81. showType: "Visible",
  82. tableData: [],
  83. copyTableData: [],
  84. tableExample: null,
  85. tabVal: "",
  86. partsTypeList: [], //tabs
  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. qrcodeUrl: "", //二维码图片地址
  100. filesArr: [], //保存临时的文件key
  101. imgsArr: [], //临时保存的图片key数组
  102. picsArr: [], //临时设备图片keys数组
  103. systemId: null,
  104. graphyId: null,
  105. mess: {},
  106. id: 0,
  107. EquipmentList: [],
  108. firmId: "", //品牌型号所需字段
  109. queryParam: {}, //返回到指定位置
  110. };
  111. },
  112. computed: {
  113. ...mapGetters("layout", ["projectId", "secret", "userId", "group_code"])
  114. },
  115. created() {
  116. this.queryParam = this.$route.query;
  117. this.deviceId = this.$route.query.deviceId;
  118. this.getTypes();
  119. },
  120. methods: {
  121. //获取当前设备下的部件类
  122. async getTypes() {
  123. let params = {
  124. filters: `id='${this.deviceId}'`,
  125. pageNumber: 1,
  126. pageSize: 50
  127. };
  128. await getEquipPartsType(params, res => {
  129. this.partsTypeList = res.content;
  130. if (this.partsTypeList.length) {
  131. this.tabVal = this.partsTypeList[0].category;
  132. this.getTableHeader();
  133. }
  134. });
  135. },
  136. // 获取表头数据(初始化表格)
  137. async getTableHeader() {
  138. let params = {
  139. orders: "sort asc, name desc",
  140. pageNumber: 1,
  141. pageSize: 1000,
  142. type: this.tabVal
  143. };
  144. await getDataDictionary(params, res => {
  145. this.tableHeader = res.content;
  146. this.codeToDataSource = {}
  147. this.tableHeader.forEach(item => {
  148. if (item.path) {
  149. this.inputMap[item.path] = item;
  150. }
  151. if (item.dataSource) {
  152. try {
  153. this.codeToDataSource[item.code] = {}
  154. item.dataSource.forEach(dic => {
  155. this.codeToDataSource[item.code][dic.code] = dic.name;
  156. })
  157. } catch (e) {
  158. console.log(e);
  159. }
  160. }
  161. });
  162. this.getTableData();
  163. });
  164. },
  165. //获取表格数据
  166. async getTableData() {
  167. let params = {
  168. pageNumber: this.page.pageNumber,
  169. pageSize: this.page.PageSize,
  170. orders: "createTime desc, localName desc, localId desc, id desc",
  171. filters: `category='${this.tabVal}';parentId='${this.deviceId}'`
  172. };
  173. await getEquipPartsCon(params, res => {
  174. this.tableData = res.content;
  175. this.copyTableData = tools.deepCopy(res.content);
  176. this.page.pageNumber = res.pageNumber;
  177. this.page.total = res.total;
  178. if (this.tableData && this.tableData.length) {
  179. this.getBatch(res.content);
  180. this.initTable();
  181. }
  182. });
  183. },
  184. //切换每页显示多少条数据
  185. handleSizeChange(val) {
  186. this.page.pageSize = val;
  187. this.getTableHeader();
  188. },
  189. //切换页数
  190. handleCurrentChange(val) {
  191. this.page.pageNumber = val;
  192. this.getTableHeader();
  193. },
  194. formatHeaderData(list) {
  195. //格式化表头显示的数据
  196. let arr = tools.copyArr(list);
  197. let data = showTools.headerTextFilter(arr, "parts", this.onlyRead, this.showType, true)
  198. data.unshift("查看详情", "当前关联的资产");
  199. return data;
  200. },
  201. formatHeaderType(list) {
  202. //格式化表头头映射的数据
  203. let arr = tools.copyArr(list);
  204. let data = showTools.headerTypeFilter(arr, "parts", this.onlyRead, this.showType, true)
  205. data.unshift(
  206. {
  207. data: "caozuo",
  208. renderer: tools.lookDetails,
  209. readOnly: true
  210. },
  211. {
  212. data: "PropertyLocalName",
  213. readOnly: true
  214. }
  215. );
  216. return data;
  217. },
  218. initTable() {
  219. //实例化表格
  220. let settings = {
  221. data: this.tableData,
  222. colHeaders: this.formatHeaderData(this.tableHeader),
  223. columns: this.formatHeaderType(this.tableHeader),
  224. rowHeights: 30,
  225. fillHandle: 'vertical', //允许纵向填充
  226. maxRows: this.tableData.length,
  227. contextMenu: this.onlyRead ? false : {
  228. items: {
  229. remove_row: {
  230. name: "删除部件"
  231. }
  232. }
  233. },
  234. // 事件
  235. afterRemoveRow: this.handleDeleteTableRow, //右键删除
  236. afterOnCellMouseDown: this.handleTdClick //鼠标点击
  237. };
  238. this.$nextTick(() => {
  239. this.tableExample = this.$refs.table.init(settings);
  240. });
  241. },
  242. //表格点击事件
  243. handleTdClick(el, rowArr) {
  244. //点击的是表头
  245. if (rowArr.row < 0) {
  246. return;
  247. }
  248. //被筛选过后的数组
  249. let trimmedArr = this.trimmedRows();
  250. //是否启用了排序
  251. let isSort = this.tableExample.getPlugin("columnSorting").isSorted();
  252. if (trimmedArr.length && isSort) {
  253. let sortArr = this.myHotArr.getPlugin("columnSorting").rowsMapper
  254. .__arrayMap;
  255. let infos = this.tableData[trimmedArr[sortArr[rowArr.row]]];
  256. this.getInfors(infos, { row: sortArr[rowArr.row], col: rowArr.col });
  257. } else if (isSort) {
  258. //排序后的数组
  259. let sortArr = this.tableExample.getPlugin("columnSorting").rowsMapper
  260. .__arrayMap;
  261. let infos = this.tableData[sortArr[rowArr.row]];
  262. this.getInfors(infos, { row: sortArr[rowArr.row], col: rowArr.col });
  263. } else if (trimmedArr.length) {
  264. let infos = this.tableData[trimmedArr[rowArr.row]];
  265. this.getInfors(infos, { row: trimmedArr[rowArr.row], col: rowArr.col });
  266. } else {
  267. let infos = this.tableData[rowArr.row];
  268. this.getInfors(infos, rowArr);
  269. }
  270. },
  271. //获取被筛选掉的行号
  272. trimmedRows() {
  273. var plugin = this.tableExample.getPlugin("trimRows").trimmedRows;
  274. let dataLength = this.tableData.length;
  275. let dataArr = new Array();
  276. for (let i = 0; i < dataLength; i++) {
  277. dataArr.push(i);
  278. }
  279. if (plugin.length <= 0) {
  280. dataArr = undefined;
  281. } else {
  282. dataArr = this.array_diff(dataArr, plugin);
  283. }
  284. return dataArr || [];
  285. },
  286. getInfors(infos, row) {
  287. //其他的开始判断
  288. let val = this.tableExample.colToProp(row.col);
  289. if (val == "caozuo") {
  290. // window.open(`http://adm.sagacloud.cn:8058/spread?id=${infos.EquipID}&pid=${this.projectId}&secret=${this.secret}`,"_blank")
  291. this.$message("开发中...");
  292. }
  293. //设备二维码图片
  294. if (val == "defaultQRCode") {
  295. this.qrcodeUrl = this.tableData[row.row].defaultQRCode;
  296. if (!!this.qrcodeUrl) {
  297. this.myDialog.qrcode = true;
  298. } else {
  299. this.$message("此设备没有设备二维码");
  300. }
  301. }
  302. //关联系统
  303. if (val == "linkSystem") {
  304. // this.systemList = this.tableData[row.row].linkSystem || [];
  305. this.myDialog.systemType = true;
  306. }
  307. //保险文件--设备文档--安装质检报告
  308. if (
  309. val == "infos.insuranceFile" || //保险文件
  310. val == "infos.archive" || //设备文档
  311. val == "infos.checkReport" || //安装质检报告
  312. val == "infos.maintainManual" || //维修保养手册
  313. val == "infos.approachingAcceptance" || //进场验收单
  314. val == "infos.acceptanceReport" || //验收报告
  315. val == "infos.operationManual" || //操作说明书
  316. val == "infos.originalCertificate" || //原厂证明
  317. val == "infos.testReport" || //检测报告
  318. val == "infos.productCertification" || //产品合格证
  319. val == "infos.installInstruction" || //
  320. val == 'infos.supplierContract' || //供应合同
  321. val == "infos.drawing" || //设备图纸
  322. val == "infos.installDrawing" //安装图纸
  323. ) {
  324. let data = tools.dataForKey(this.tableData[row.row], val);
  325. this.filesArr = data ? data : [];
  326. this.myDialog.uploadFiles = true;
  327. }
  328. //安装照片--设备铭牌照片
  329. if (
  330. val == "infos.installPic" ||
  331. val == "infos.nameplate"
  332. ) {
  333. let data = tools.dataForKey(this.tableData[row.row], val);
  334. this.imgsArr = data ? data : [];
  335. this.myDialog.uploadImgs = true;
  336. }
  337. //设备照片
  338. if (val == "infos.pic") {
  339. let data = tools.dataForKey(this.tableData[row.row], val);
  340. this.picsArr = data ? data : [];
  341. this.myDialog.pic = true;
  342. }
  343. this.row = row.row;
  344. this.messKey = val;
  345. },
  346. //去除数组中相同的元素
  347. array_diff(a, b) {
  348. for (var i = 0; i < b.length; i++) {
  349. for (var j = 0; j < a.length; j++) {
  350. if (a[j] == b[i]) {
  351. a.splice(j, 1);
  352. j = j - 1;
  353. }
  354. }
  355. }
  356. return a;
  357. },
  358. // 删除表格行
  359. handleDeleteTableRow() {
  360. let params = tools.differenceArr(this.tableData, this.copyTableData);
  361. if (params.length < 1 || this.tableData > this.copyTableData) {
  362. return;
  363. }
  364. let param = {
  365. projectId: this.projectId,
  366. data: []
  367. };
  368. params.map(item => {
  369. param.data.push({ EquipID: item.EquipID });
  370. });
  371. this.$confirm("此操作将删除部件,是否继续?", "提示", {
  372. confirmButtonText: "确定",
  373. cancelButtonText: "取消",
  374. type: "warning"
  375. })
  376. .then(() => {
  377. this.deleteTableData(param);
  378. })
  379. .catch(() => {
  380. this.getTableHeader();
  381. this.$message("取消删除");
  382. });
  383. },
  384. // 删除表格数据
  385. async deleteTableData(params) {
  386. await deleteParts(params, res => {
  387. this.$message.success("删除成功!");
  388. this.getTypes();
  389. });
  390. },
  391. //上传文件弹窗触发事件
  392. fileChange(keys) {
  393. this.setDataToMain(keys, this.messKey, this.row);
  394. },
  395. //上传图片弹窗触发事件
  396. imgChange(keys) {
  397. this.setDataToMain(keys, this.messKey, this.row);
  398. },
  399. //设备图片弹窗改变事件
  400. changePics(keys) {
  401. this.setDataToMain(keys, this.messKey, this.row);
  402. },
  403. //获取动态参数
  404. getBatch(data) {
  405. let param = {
  406. groupCode: this.group_code,
  407. appId: "datacenter",
  408. projectId: this.projectId,
  409. data: []
  410. };
  411. this.tableHeader.map(head => {
  412. if (head.category != 'STATIC') {
  413. data.map(item => {
  414. let cur = tools.dataForKey(item, head.path);
  415. if (cur) {
  416. param.data.push({
  417. objectId: item.id,
  418. infoCode: head.code
  419. });
  420. }
  421. });
  422. }
  423. });
  424. if (param.data.length) {
  425. BeatchQueryParam(param, res => {
  426. this.tableData = data.map(item => {
  427. res.data.map(child => {
  428. if (item.id == child.objectId) {
  429. if (child.data || child.data == 0) {
  430. this.tableHeader.map(head => {
  431. if (head.code == child.infoCode) {
  432. let contentVal = child.data
  433. if (this.codeToDataSource[child.infoCode]) {
  434. contentVal = this.codeToDataSource[child.infoCode][child.data]
  435. }
  436. tools.setDataForKey(item, head.path, contentVal);
  437. }
  438. });
  439. } else {
  440. this.tableHeader.map(head => {
  441. if (head.code == child.infoCode) {
  442. tools.setDataForKey(
  443. item,
  444. head.path,
  445. child.error
  446. // child.error ? child.value ? "表号功能号格式错误" : "表号功能号不存在" : "暂未采集到实时数据"
  447. );
  448. }
  449. });
  450. }
  451. }
  452. });
  453. return item;
  454. });
  455. this.tableExample.loadData(this.tableData);
  456. });
  457. }
  458. },
  459. // 返回
  460. goback() {
  461. this.$router.push({
  462. name: 'facilityLedger',
  463. params: {
  464. deviceId: this.queryParam.typeId,
  465. pageNo: this.queryParam.pageNo,
  466. pageSize: this.queryParam.pageSize,
  467. readOnly: true
  468. }
  469. })
  470. }
  471. }
  472. };
  473. </script>
  474. <style lang="less" scoped>
  475. #partsList {
  476. overflow: hidden;
  477. height: 100%;
  478. background-color: #fff;
  479. padding: 10px;
  480. position: relative;
  481. .right {
  482. background: #fff;
  483. }
  484. .search-header {
  485. overflow: hidden;
  486. padding: 0 10px 10px 10px;
  487. border-bottom: 1px solid #bcbcbc;
  488. }
  489. .tableBox {
  490. display: flex;
  491. height: calc(100% - 150px);
  492. margin-top: 10px;
  493. .tableLeft {
  494. flex: 1;
  495. }
  496. }
  497. }
  498. .el-pagination button,
  499. .el-pagination span:not([class*="suffix"]) {
  500. vertical-align: middle;
  501. }
  502. </style>