index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  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="icon-wushuju 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. Orders: "sort asc",
  161. PageNumber: 1,
  162. PageSize: 500
  163. },
  164. type: this.tabVal
  165. };
  166. await getDataDictionary(params, res => {
  167. this.tableHeader = res.Content;
  168. this.getTableData();
  169. });
  170. },
  171. //获取表格数据
  172. async getTableData() {
  173. let params = {
  174. PageNumber: this.page.pageNumber,
  175. PageSize: this.page.PageSize,
  176. Filters: `category='${this.tabVal}';parentId='${this.deviceId}'`
  177. };
  178. await getEquipPartsCon(params, res => {
  179. this.tableData = res.Content;
  180. this.copyTableData = tools.deepCopy(res.Content);
  181. this.page.pageNumber = res.PageNumber;
  182. this.page.total = res.Total;
  183. if (this.tableData && this.tableData.length) {
  184. this.getBatch(res.Content);
  185. this.initTable();
  186. }
  187. });
  188. },
  189. //切换每页显示多少条数据
  190. handleSizeChange(val) {
  191. this.page.pageSize = val;
  192. this.getTableHeader();
  193. },
  194. //切换页数
  195. handleCurrentChange(val) {
  196. this.page.pageNumber = val;
  197. this.getTableHeader();
  198. },
  199. formatHeaderData(list) {
  200. //格式化表头显示的数据
  201. let arr = tools.copyArr(list);
  202. let data = showTools.headerTextFilter(arr, "parts", this.onlyRead, this.showType, true)
  203. data.unshift("查看详情", "当前关联的资产");
  204. return data;
  205. },
  206. formatHeaderType(list) {
  207. //格式化表头头映射的数据
  208. let arr = tools.copyArr(list);
  209. let data = showTools.headerTypeFilter(arr, "parts", this.onlyRead, this.showType, true)
  210. data.unshift(
  211. {
  212. data: "caozuo",
  213. renderer: tools.lookDetails,
  214. readOnly: true
  215. },
  216. {
  217. data: "PropertyLocalName",
  218. readOnly: true
  219. }
  220. );
  221. return data;
  222. },
  223. initTable() {
  224. //实例化表格
  225. let settings = {
  226. data: this.tableData,
  227. colHeaders: this.formatHeaderData(this.tableHeader),
  228. columns: this.formatHeaderType(this.tableHeader),
  229. rowHeights: 30,
  230. maxRows: this.tableData.length,
  231. contextMenu: this.onlyRead ? false :{
  232. items: {
  233. remove_row: {
  234. name: "删除部件"
  235. }
  236. }
  237. },
  238. // 事件
  239. afterRemoveRow: this.handleDeleteTableRow, //右键删除
  240. afterOnCellMouseDown: this.handleTdClick //鼠标点击
  241. };
  242. this.$nextTick(() => {
  243. this.tableExample = this.$refs.table.init(settings);
  244. });
  245. },
  246. //表格点击事件
  247. handleTdClick(el, rowArr) {
  248. //点击的是表头
  249. if (rowArr.row < 0) {
  250. return;
  251. }
  252. //被筛选过后的数组
  253. let trimmedArr = this.trimmedRows();
  254. //是否启用了排序
  255. let isSort = this.tableExample.getPlugin("columnSorting").isSorted();
  256. if (trimmedArr.length && isSort) {
  257. let sortArr = this.myHotArr.getPlugin("columnSorting").rowsMapper
  258. .__arrayMap;
  259. let infos = this.tableData[trimmedArr[sortArr[rowArr.row]]];
  260. this.getInfors(infos, { row: sortArr[rowArr.row], col: rowArr.col });
  261. } else if (isSort) {
  262. //排序后的数组
  263. let sortArr = this.tableExample.getPlugin("columnSorting").rowsMapper
  264. .__arrayMap;
  265. let infos = this.tableData[sortArr[rowArr.row]];
  266. this.getInfors(infos, { row: sortArr[rowArr.row], col: rowArr.col });
  267. } else if (trimmedArr.length) {
  268. let infos = this.tableData[trimmedArr[rowArr.row]];
  269. this.getInfors(infos, { row: trimmedArr[rowArr.row], col: rowArr.col });
  270. } else {
  271. let infos = this.tableData[rowArr.row];
  272. this.getInfors(infos, rowArr);
  273. }
  274. },
  275. //获取被筛选掉的行号
  276. trimmedRows() {
  277. var plugin = this.tableExample.getPlugin("trimRows").trimmedRows;
  278. let dataLength = this.tableData.length;
  279. let dataArr = new Array();
  280. for (let i = 0; i < dataLength; i++) {
  281. dataArr.push(i);
  282. }
  283. if (plugin.length <= 0) {
  284. dataArr = undefined;
  285. } else {
  286. dataArr = this.array_diff(dataArr, plugin);
  287. }
  288. return dataArr || [];
  289. },
  290. getInfors(infos, row) {
  291. //其他的开始判断
  292. let val = this.tableExample.colToProp(row.col);
  293. if (val == "caozuo") {
  294. // window.open(`http://adm.sagacloud.cn:8058/spread?id=${infos.EquipID}&pid=${this.projectId}&secret=${this.secret}`,"_blank")
  295. this.$message("开发中...");
  296. }
  297. //设备二维码图片
  298. if (val == "EquipQRCode") {
  299. this.qrcodeUrl = this.tableData[row.row].EquipQRCode;
  300. if (!!this.qrcodeUrl) {
  301. this.myDialog.qrcode = true;
  302. } else {
  303. this.$message("此设备没有设备二维码");
  304. }
  305. }
  306. //关联系统
  307. if (val == "linkSystem") {
  308. // this.systemList = this.tableData[row.row].linkSystem || [];
  309. this.myDialog.systemType = true;
  310. }
  311. //品牌型号弹窗
  312. if (val == "DPManufacturerID") {
  313. this.myDialog.firm = true;
  314. }
  315. //供应商信息弹窗
  316. if (val == "DPSupplierID") {
  317. this.myDialog.supplier = true;
  318. }
  319. //维修商信息弹窗
  320. if (val == "DPMaintainerID") {
  321. this.myDialog.maintainer = true;
  322. }
  323. //保险公司信息
  324. if (val == "DPInsurerID") {
  325. this.myDialog.insurer = true;
  326. }
  327. //供应合同编号
  328. if (val == "LedgerParam.SupplyPurchase.SupplierContractID") {
  329. let falg = null;
  330. let data = this.tableData[row.row].DPSupplierID;
  331. if (data) {
  332. falg = data.split("-")[0];
  333. }
  334. if (!!falg) {
  335. this.id = falg;
  336. this.myDialog.supply = true;
  337. } else {
  338. this.$message("请先选择供应商");
  339. }
  340. }
  341. //保险单号
  342. if (val == "LedgerParam.InsuranceDoc.InsuranceNum") {
  343. //选择保单
  344. let falg = null;
  345. let data = this.tableData[row.row].DPInsurerID;
  346. if (data) {
  347. falg = data.split("-")[0];
  348. }
  349. if (!!falg) {
  350. this.id = falg;
  351. this.myDialog.guarantee = true;
  352. } else {
  353. this.$message("请先选择保险商");
  354. }
  355. }
  356. //保险文件--设备文档--安装质检报告
  357. if (
  358. val == "LedgerParam.InsuranceDoc.InsuranceFile" ||
  359. val == "LedgerParam.PhotoDoc.Archive" ||
  360. val == "LedgerParam.Siteinstall.CheckReport"
  361. ) {
  362. let data = tools.dataForKey(this.tableData[row.row], val);
  363. this.filesArr = data ? data : [];
  364. this.myDialog.uploadFiles = true;
  365. }
  366. //安装照片--安装图纸--设备铭牌照片--设备图纸
  367. if (
  368. val == "LedgerParam.Siteinstall.InstallPic" ||
  369. val == "LedgerParam.Siteinstall.InstallDrawing" ||
  370. val == "LedgerParam.PhotoDoc.Nameplate" ||
  371. val == "LedgerParam.PhotoDoc.Drawing"
  372. ) {
  373. let data = tools.dataForKey(this.tableData[row.row], val);
  374. this.imgsArr = data ? data : [];
  375. this.myDialog.uploadImgs = true;
  376. }
  377. //设备照片
  378. if (val == "LedgerParam.PhotoDoc.Pic") {
  379. let data = tools.dataForKey(this.tableData[row.row], val);
  380. this.picsArr = data ? data : [];
  381. this.myDialog.pic = true;
  382. }
  383. this.row = row.row;
  384. this.messKey = val;
  385. },
  386. //去除数组中相同的元素
  387. array_diff(a, b) {
  388. for (var i = 0; i < b.length; i++) {
  389. for (var j = 0; j < a.length; j++) {
  390. if (a[j] == b[i]) {
  391. a.splice(j, 1);
  392. j = j - 1;
  393. }
  394. }
  395. }
  396. return a;
  397. },
  398. // 删除表格行
  399. handleDeleteTableRow() {
  400. let params = tools.differenceArr(this.tableData, this.copyTableData);
  401. if (params.length < 1 || this.tableData > this.copyTableData) {
  402. return;
  403. }
  404. let param = {
  405. projectId: this.projectId,
  406. data: []
  407. };
  408. params.map(item => {
  409. param.data.push({ EquipID: item.EquipID });
  410. });
  411. this.$confirm("此操作将删除部件,是否继续?", "提示", {
  412. confirmButtonText: "确定",
  413. cancelButtonText: "取消",
  414. type: "warning"
  415. })
  416. .then(() => {
  417. this.deleteTableData(param);
  418. })
  419. .catch(() => {
  420. this.getTableHeader();
  421. this.$message("取消删除");
  422. });
  423. },
  424. // 删除表格数据
  425. async deleteTableData(params) {
  426. await deleteParts(params, res => {
  427. this.$message.success("删除成功!");
  428. this.getTypes();
  429. });
  430. },
  431. //上传文件弹窗触发事件
  432. fileChange(keys) {
  433. this.setDataToMain(keys, this.messKey, this.row);
  434. },
  435. //上传图片弹窗触发事件
  436. imgChange(keys) {
  437. this.setDataToMain(keys, this.messKey, this.row);
  438. },
  439. //设备图片弹窗改变事件
  440. changePics(keys) {
  441. this.setDataToMain(keys, this.messKey, this.row);
  442. },
  443. //获取动态参数
  444. getBatch(data) {
  445. let param = {
  446. secret: this.secret,
  447. ProjId: this.projectId,
  448. data: {
  449. criterias: []
  450. }
  451. };
  452. this.tableHeader.map(head => {
  453. if (
  454. head.InputMode == "L" ||
  455. head.InputMode == "L1" ||
  456. head.InputMode == "L2" ||
  457. head.InputMode == "M"
  458. ) {
  459. data.map(item => {
  460. let cur = tools.dataForKey(item, head.Path);
  461. if (cur) {
  462. param.data.criterias.push({
  463. id: item.EquipID,
  464. code: head.InfoPointCode
  465. });
  466. }
  467. });
  468. }
  469. });
  470. if (param.data.criterias.length) {
  471. BeatchQueryParam(param, res => {
  472. this.tableData = data.map(item => {
  473. res.Content.map(child => {
  474. if (item.EquipID == child.id) {
  475. if (child.data || child.data == 0) {
  476. this.tableHeader.map(head => {
  477. if (head.InfoPointCode == child.code) {
  478. tools.setDataForKey(item, head.Path, child.data);
  479. }
  480. });
  481. } else {
  482. this.tableHeader.map(head => {
  483. if (head.InfoPointCode == child.code) {
  484. tools.setDataForKey(
  485. item,
  486. head.Path,
  487. // child.error ? "表号功能号格式错误" : "表号功能号不存在"
  488. child.error ? child.value? "表号功能号格式错误" : "表号功能号不存在" : "暂未采集到实时数据"
  489. );
  490. }
  491. });
  492. }
  493. }
  494. });
  495. return item;
  496. });
  497. this.tableExample.loadData(this.tableData);
  498. });
  499. }
  500. }
  501. }
  502. };
  503. </script>
  504. <style lang="less" scoped>
  505. #partsList {
  506. overflow: hidden;
  507. height: 100%;
  508. background-color: #fff;
  509. padding: 10px;
  510. position: relative;
  511. .right {
  512. background: #fff;
  513. }
  514. .search-header {
  515. overflow: hidden;
  516. padding: 0 10px 10px 10px;
  517. border-bottom: 1px solid #bcbcbc;
  518. }
  519. .tableBox {
  520. display: flex;
  521. height: calc(100% - 150px);
  522. margin-top: 10px;
  523. .tableLeft {
  524. flex: 1;
  525. }
  526. }
  527. }
  528. .el-pagination button,
  529. .el-pagination span:not([class*="suffix"]) {
  530. vertical-align: middle;
  531. }
  532. </style>