index.vue 17 KB

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