index.vue 17 KB

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