index.vue 17 KB

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