system.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628
  1. <template>
  2. <div style="height: calc(100% - 44.5px);padding: 0px 10px 10px;box-sizing: border-box;">
  3. <div class="hanson-bar">
  4. <div style="float:right;overflow:hidden;">
  5. <span>当前筛选条件下共{{page.total || '--'}}系统</span>
  6. </div>
  7. <el-select v-model="onlyRead" @change="getHeaderData(mess)" style="width:100px;margin-right:20px;vertical-align:bottom;">
  8. <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"></el-option>
  9. </el-select>
  10. <el-select v-model="showType" @change="initTable" style="width:100px;margin-right:10px;vertical-align:bottom;">
  11. <el-option v-for="item in showTypes" :key="item.value" :label="item.label" :value="item.value"></el-option>
  12. </el-select>
  13. <el-button size="small" style="width: 80px" @click="addDevice" icon="iconfont icon-tianjia">添加系统</el-button>
  14. <el-button size="small" style="width: 80px" @click="reset" icon="iconfont icon-shuaxin">刷新</el-button>
  15. <el-button size="small" style="width: 80px" @click="undo" icon="iconfont icon-undo">撤销</el-button>
  16. </div>
  17. <qrcode :dialog="myDialog" :addBody="true" ref="qrcode"></qrcode>
  18. <upload-files-dialog ref="upload" @changeFile="fileChange" :keysArr="filesArr" :dialog="myDialog"></upload-files-dialog>
  19. <upload-img-dialog @changeFile="imgChange" :keysArr="imgsArr" :dialog="myDialog"></upload-img-dialog>
  20. <pic-dialog :dialog="myDialog" :keysArr="picsArr" @change="changePics"></pic-dialog>
  21. <div class="center middle_sty" style="height: 91%" v-show="!mess.deviceId && (!tableData || !tableData.length)">
  22. <p><i class="icon-wushuju iconfont"></i>请选择系统类型</p>
  23. </div>
  24. <div class="center middle_sty" style="height: 91%" v-show="mess.deviceId && (!tableData || !tableData.length)">
  25. <p><i class="icon-wushuju iconfont"></i>暂无数据</p>
  26. </div>
  27. <div v-show="mess.deviceId && tableData && tableData.length" v-loading="loading" id="handsontable" ref="handsontable"></div>
  28. <div v-show="mess.deviceId && tableData && tableData.length" class="right">
  29. <my-pagination @change="getTableData" :page="page"></my-pagination>
  30. </div>
  31. <!-- <dialog-assets :assetType="[this.mess.deviceId]" @close="getClose" v-if="myDialog.addDevice" ref="assets" :dialog="myDialog"></dialog-assets> -->
  32. <details-dialog :iframeSrc="iframeSrc" v-if="myDialog.details" :dialog="myDialog"></details-dialog>
  33. <system-relevance @close="reset" :id="systemId" :dialog="myDialog"></system-relevance>
  34. <!-- 新增系统 -->
  35. <el-dialog title="确定新增系统的类型" :visible.sync="myDialog.addDevice" width="30%">
  36. <el-row>
  37. <my-cascader ref="cascader" @change="changeAddType" :all="true"></my-cascader>
  38. </el-row>
  39. <span slot="footer" class="dialog-footer">
  40. <el-button type="primary" @click="toAddDevice">下 一 步</el-button>
  41. </span>
  42. </el-dialog>
  43. </div>
  44. </template>
  45. <script>
  46. import {
  47. getTableHeader,
  48. getBillSystemList,
  49. updateBusiness,
  50. BeatchQueryParam,
  51. delBatchList,
  52. getDataDictionary,
  53. queryLinkSys,
  54. updateGeneralSys,
  55. deleteGeneralSys
  56. } from "@/api/scan/request"
  57. import myCascader from "@/components/ledger/lib/system";
  58. import tools from "@/utils/scan/tools";
  59. import handsonUtils from "@/utils/scan/hasontableUtils"
  60. import showTools from "@/utils/handsontable/notShow"
  61. import qrcode from "@/components/business_space/lib/qrcode"
  62. import uploadFilesDialog from "@/components/business_space/dialogs/list/filesDialog"
  63. import uploadImgDialog from "@/components/business_space/dialogs/list/uploadImgDialog"
  64. import picDialog from "@/components/business_space/dialogs/list/picDialog"
  65. import myPagination from "@/components/common/myPagination"
  66. import dialogAssets from "@/components/ledger/addDialog/dialogSystem"
  67. import detailsDialog from "@/components/business_space/lib/detailsDia"
  68. import systemRelevance from "@/components/ledger/tableTransfers"
  69. import Handsontable from "handsontable-pro"
  70. import 'handsontable-pro/dist/handsontable.full.css'
  71. import zhCN from 'handsontable-pro/languages/zh-CN'
  72. import {
  73. mapGetters,
  74. mapActions
  75. } from "vuex";
  76. export default {
  77. components: {
  78. qrcode, //二维码页面
  79. uploadFilesDialog,
  80. uploadImgDialog,
  81. picDialog,
  82. myPagination,
  83. dialogAssets,
  84. detailsDialog,
  85. systemRelevance,
  86. myCascader
  87. },
  88. computed: {
  89. ...mapGetters("layout", ["projectId", "secret", "userId"]),
  90. showTypes() {
  91. return this.onlyRead ?
  92. [{ value: "Visible", label: '只看采集信息' }, { value: "all", label: '全部' }] :
  93. [{ value: "partInfo", label: '隐藏信息点' }, { value: "all", label: '全部' }, { value: "Visible", label: '只看采集信息' }]
  94. }
  95. },
  96. data() {
  97. return {
  98. options: [{
  99. value: true,
  100. label: '只读模式'
  101. }, {
  102. value: false,
  103. label: '编辑模式'
  104. }],
  105. tableData: [],
  106. mess: {},
  107. tableHeader: null,
  108. page: {
  109. size: 50,
  110. sizes: [10, 30, 50, 100, 150, 200],
  111. total: 0,
  112. currentPage: 1
  113. },
  114. myDialog: {
  115. qrcode: false, //二维码弹窗
  116. firm: false, //厂商弹窗
  117. supply: false, //选择供应合同
  118. supplier: false, //供应商选择
  119. guarantee: false, //选择保单
  120. maintainer: false, //选择维修商
  121. insurer: false, //选择保险公司
  122. uploadFiles: false,//上传文件
  123. uploadImgs: false,//上传单个图片
  124. pic: false, //多个图片
  125. addDevice: false,
  126. details: false,//详情页
  127. relevance: false,//关联设备
  128. },
  129. row: null,//被修改的row
  130. filesArr: [],//保存临时的文件key
  131. messKey: null,
  132. imgsArr: [],//临时保存的图片key数组
  133. picsArr: [],//临时设备图片keys数组
  134. noShowList: ["SysID", "SysName"],
  135. copyMain: null,
  136. iframeSrc: "",
  137. systemId: "",
  138. onlyRead: true,
  139. showType: 'all',
  140. linkNameFalg: false,
  141. qrcodeUrl: "",//二维码图片地址
  142. loading: false,
  143. addData: {}, //添加设备选择的设备类型
  144. };
  145. },
  146. created() {
  147. },
  148. mounted() { },
  149. methods: {
  150. //触发父组件change
  151. getClose(val) {
  152. this.$emit("close", val)
  153. },
  154. //获取表头
  155. getHeaderData(code) {
  156. this.mess = code
  157. if (this.mess.deviceId) {
  158. let params = {
  159. data: {
  160. Orders: "sort asc",
  161. PageNumber: 1,
  162. PageSize: 500
  163. },
  164. type: this.mess.deviceId
  165. }
  166. getDataDictionary(params, res => {
  167. this.tableHeader = res.Content;
  168. this.getTableData()
  169. });
  170. }
  171. },
  172. changeWatch() {
  173. this.reset()
  174. },
  175. //获取主体数据
  176. getTableData() {
  177. let _this = this
  178. this.loading = true
  179. if (!!this.mess.deviceId) {
  180. let param = {
  181. PageSize: this.page.size,
  182. Orders: "createTime desc, SysID desc",
  183. PageNumber: this.page.currentPage,
  184. Filters: `category='${this.mess.deviceId}'`
  185. }
  186. if (this.mess.buildId == "noKnow") {
  187. param.Filters += `;buildingId isNull`
  188. } else if (this.mess.buildId && this.mess.buildId != "all") {
  189. param.Filters += `;buildingId='${this.mess.buildId}'`
  190. }
  191. queryLinkSys(param, res => {
  192. this.loading = false;
  193. _this.tableData = res.Content;
  194. _this.copyMain = tools.deepCopy(res.Content);
  195. _this.page.total = res.Total;
  196. if (res.Content && res.Content.length) {
  197. if (this.onlyRead) {
  198. this.getBatch(res.Content)
  199. }
  200. _this.initTable();
  201. }
  202. })
  203. }
  204. },
  205. //撤回
  206. undo() {
  207. this.hot.undo();
  208. },
  209. //刷新
  210. reset() {
  211. if (this.mess.deviceId) {
  212. this.getTableData();
  213. } else {
  214. this.$message({
  215. message: '请选择系统类型',
  216. type: 'warning'
  217. });
  218. }
  219. },
  220. //添加设备
  221. addDevice() {
  222. this.myDialog.addDevice = true
  223. if (this.mess.deviceId) {
  224. this.$nextTick(() => {
  225. this.$refs.cascader.setValue(this.mess.deviceId)
  226. })
  227. }
  228. },
  229. //下一步
  230. toAddDevice() {
  231. if (this.addData.Category) {
  232. this.$router.push({
  233. path: "/ledger/systemadd",
  234. query: this.addData
  235. });
  236. }
  237. },
  238. //选择设备类型-添加设备
  239. changeAddType(val) {
  240. this.addData.Category = val.Category;
  241. this.addData.CategoryName = val.CategoryName;
  242. },
  243. //格式化表头
  244. formatHeaderData(list) {
  245. let arr = tools.copyArr(list)
  246. let data = showTools.headerTextFilter(arr, 'system', this.onlyRead, this.showType)
  247. data.unshift("操作", "关联设备数量");
  248. return data;
  249. },
  250. //格式化表内容
  251. formatHeaderType(list) {
  252. let arr = tools.copyArr(list)
  253. let data = showTools.headerTypeFilter(arr, 'system', this.onlyRead, this.showType)
  254. data.unshift(
  255. {
  256. data: "caozuo",
  257. renderer: tools.lookDetails,
  258. readOnly: true
  259. },
  260. {
  261. data: "Count",
  262. renderer: tools.num,
  263. readOnly: true
  264. }
  265. );
  266. if (this.onlyRead) {
  267. data.map(item => {
  268. item.readOnly = true
  269. })
  270. }
  271. return data;
  272. },
  273. //获取动态参数
  274. getBatch(data) {
  275. let param = {
  276. secret: this.secret,
  277. ProjId: this.projectId,
  278. data: {
  279. criterias: []
  280. }
  281. }
  282. //一级遍历list
  283. this.tableHeader.map(head => {
  284. //如果一级标签为动态参数或者设定参数放入数据等待请求
  285. if (
  286. head.InputMode == "L" ||
  287. head.InputMode == "L1" ||
  288. head.InputMode == "L2" ||
  289. head.InputMode == "M"
  290. ) {
  291. data.map(item => {
  292. let cur = tools.dataForKey(item, head.Path);
  293. if (cur) {
  294. param.data.criterias.push({
  295. id: item.SysID,
  296. code: head.InfoPointCode
  297. });
  298. }
  299. });
  300. }
  301. })
  302. if (param.data.criterias.length) {
  303. BeatchQueryParam(param, res => {
  304. if (!this.onlyRead) {
  305. return false
  306. }
  307. this.tableData = data.map(item => {
  308. res.Content.map(child => {
  309. if (item.SysID == child.id) {
  310. if (!!child.data || child.data == 0) {
  311. this.tableHeader.map(head => {
  312. if (head.InfoPointCode == child.code) {
  313. tools.setDataForKey(item, head.Path, child.data);
  314. }
  315. });
  316. } else {
  317. this.tableHeader.map(head => {
  318. if (head.InfoPointCode == child.code) {
  319. tools.setDataForKey(
  320. item,
  321. head.Path,
  322. // child.error ? "表号功能号格式错误" : "表号功能号不存在"
  323. child.error ? child.value? "表号功能号格式错误" : "表号功能号不存在" : "暂未采集到实时数据"
  324. );
  325. }
  326. });
  327. }
  328. }
  329. })
  330. return item
  331. })
  332. this.hot.loadData(this.tableData)
  333. })
  334. }
  335. },
  336. //初始化插件
  337. initTable() {
  338. var container = document.getElementById("handsontable");
  339. let winHeight = document.documentElement.clientHeight;
  340. if (this.hot) {
  341. this.hot.destroy();
  342. this.hot = null;
  343. }
  344. this.hot = new Handsontable(container, {
  345. data: this.tableData,
  346. fixedColumnsLeft: 4,
  347. colHeaders: this.formatHeaderData(this.tableHeader), //表头文案
  348. columns: this.formatHeaderType(this.tableHeader), //数据显示格式
  349. filters: true,
  350. maxRows: this.tableData.length,
  351. height: winHeight - 335,
  352. columnSorting: true, //添加排序
  353. sortIndicator: true, //添加排序
  354. renderAllRows: true,
  355. // colWidths: 200,
  356. autoColumnSize: true,
  357. language: "zh-CN",
  358. manualColumnResize: true,
  359. manualColumnMove: true,
  360. dropdownMenu: [
  361. "filter_by_condition",
  362. "filter_by_value",
  363. "filter_action_bar"
  364. ],
  365. contextMenu: {
  366. items: {
  367. remove_row: {
  368. name: "删除该系统"
  369. }
  370. }
  371. },
  372. // 事件
  373. afterChange: this.handleUpdataTable, //修改后
  374. afterFilter: this.trimmedRows, //排序前
  375. afterRemoveRow: this.handleDeleteTableRow, //右键删除
  376. afterOnCellMouseDown: this.eventClick //鼠标点击
  377. });
  378. let pro = document.getElementById("hot-display-license-info");
  379. if (!!pro) {
  380. pro.parentNode.removeChild(pro);
  381. }
  382. this.isLoading = false;
  383. },
  384. //表格中的点击
  385. eventClick(el, rowArr) {
  386. //点击的是表头
  387. if (rowArr.row < 0) {
  388. return;
  389. }
  390. //被筛选过后的数组
  391. let trimmedArr = this.trimmedRows();
  392. //是否启用了排序
  393. let isSort = this.hot.getPlugin("columnSorting").isSorted();
  394. if (trimmedArr.length && isSort) {
  395. let sortArr = this.myHotArr.getPlugin("columnSorting").rowsMapper
  396. .__arrayMap;
  397. let infos = this.tableData[trimmedArr[sortArr[rowArr.row]]];
  398. this.getInfors(infos, { row: sortArr[rowArr.row], col: rowArr.col });
  399. } else if (isSort) {
  400. //排序后的数组
  401. let sortArr = this.hot.getPlugin("columnSorting").rowsMapper.__arrayMap;
  402. let infos = this.tableData[sortArr[rowArr.row]];
  403. this.getInfors(infos, { row: sortArr[rowArr.row], col: rowArr.col });
  404. } else if (trimmedArr.length) {
  405. let infos = this.tableData[trimmedArr[rowArr.row]];
  406. this.getInfors(infos, { row: trimmedArr[rowArr.row], col: rowArr.col });
  407. } else {
  408. let infos = this.tableData[rowArr.row];
  409. this.getInfors(infos, rowArr);
  410. }
  411. },
  412. handleUpdataTable(changeData, source) {
  413. if (!this.onlyRead) {
  414. if (changeData) {
  415. let trimmedArr = this.trimmedRows();
  416. let param = handsonUtils.getParam(changeData, source, this.hot, trimmedArr);
  417. let data = [];
  418. for (let i = 0; i < param.length; i++) {
  419. data.push(param[i]);
  420. }
  421. //如果data中包含/且data长度为1,将其转换成.
  422. if (changeData.length == 1 && changeData[0][1].indexOf("/") > 0) {
  423. changeData[0][1] = changeData[0][1].split("/").join(".")
  424. }
  425. //存在data进行修改请求
  426. if (data && data.length) {
  427. this.updateBusiness(data, changeData);
  428. }
  429. }
  430. }
  431. },
  432. //删除资产
  433. async handleDeleteTableRow() {
  434. this.$confirm('此操作将删除该系统, 是否继续?', '提示', {
  435. confirmButtonText: '确定',
  436. cancelButtonText: '取消',
  437. type: 'warning'
  438. }).then(() => {
  439. let params = tools.differenceArr(this.tableData, this.copyMain)
  440. let param = []
  441. params.map(item => {
  442. param.push({ SysID: item.SysID })
  443. })
  444. this.removeSys(param)
  445. }).catch(() => {
  446. this.getTableData()
  447. this.$message('取消删除');
  448. });
  449. },
  450. async removeSys(param) {
  451. await deleteGeneralSys(param, res => {
  452. this.$message.success("删除成功")
  453. this.$emit('close','')
  454. this.getTableData()
  455. })
  456. },
  457. // 修改
  458. updateBusiness(data, change) {
  459. let param = {
  460. Content: [],
  461. Projection: []
  462. }, keyList = [];
  463. //生成要修改字段列表
  464. change.map(item => {
  465. let key = item[1].split(".")[0]
  466. if (item[1] && keyList.indexOf(key) == -1) {
  467. keyList.push(key);
  468. }
  469. if (item[1] && item[3] == "" && param.Projection.indexOf(key) == -1) {
  470. param.Projection.push(key);
  471. }
  472. });
  473. //生成对应修改数据
  474. data.map((item, index) => {
  475. keyList.map(value => {
  476. let itemData = tools.dataForKey(item, value);
  477. tools.setDataForKey(item, value, itemData == "" ? null : itemData);
  478. });
  479. param.Content.push(item);
  480. });
  481. updateGeneralSys(param, res => { });
  482. },
  483. //获取到了正确的信息
  484. getInfors(infos, row) {
  485. //其他的开始判断
  486. let val = this.hot.colToProp(row.col);
  487. this.systemId = infos.SysID
  488. this.row = row.row
  489. this.messKey = val
  490. switch (val) {
  491. //操作
  492. case 'caozuo':
  493. // window.open(`http://adm.sagacloud.cn:8058/system?id=${infos.id}&pid=${this.projectId}&secret=${this.secret}`,"_blank")
  494. this.$message("开发中...")
  495. break;
  496. //设备二维码图片
  497. case 'EquipQRCode':
  498. this.qrcodeUrl = this.tableData[row.row].EquipQRCode;
  499. if (!!this.qrcodeUrl) {
  500. this.myDialog.qrcode = true;
  501. } else {
  502. this.$message("此设备没有设备二维码");
  503. }
  504. break;
  505. //关联设备数量
  506. case 'Count':
  507. if (!this.onlyRead) {
  508. this.myDialog.relevance = true
  509. }
  510. break;
  511. default:
  512. break;
  513. }
  514. },
  515. //获取被筛选掉的行号
  516. trimmedRows() {
  517. // var plugin = hot.getPlugin('trimRows').trimmedRows;//获取被筛选掉的行号
  518. var plugin = this.hot.getPlugin("trimRows").trimmedRows;
  519. let dataLength = this.tableData.length;
  520. let dataArr = new Array();
  521. for (let i = 0; i < dataLength; i++) {
  522. dataArr.push(i);
  523. }
  524. if (plugin.length <= 0) {
  525. dataArr = undefined;
  526. } else {
  527. dataArr = this.array_diff(dataArr, plugin);
  528. }
  529. return dataArr || [];
  530. // var DataArray = new Array();
  531. // for (var i = 0; i < plugin.length; i++) {
  532. // // 通过行号获取数据
  533. // DataArray.push(this.hot.getSourceDataAtRow(plugin[i]));
  534. // }
  535. },
  536. //上传文件弹窗触发事件
  537. fileChange(keys) {
  538. this.setDataToMain(keys[0], this.messKey.split(".")[1], this.row)
  539. // tools.setItem(this.deviceType.code, this.tableData)
  540. },
  541. //上传图片弹窗触发事件
  542. imgChange(keys) {
  543. this.setDataToMain(keys[0], this.messKey.split(".")[1], this.row)
  544. // tools.setItem(this.deviceType.code, this.tableData)
  545. },
  546. //设备图片弹窗改变事件
  547. changePics(keys) {
  548. this.setDataToMain(keys, this.messKey.split(".")[1], this.row)
  549. // tools.setItem(this.deviceType.code, this.tableData)
  550. },
  551. //判断是否有值,有值赋值
  552. setDataToMain(data, key, row) {
  553. if (!!data && data != '--') {
  554. if (!!this.tableData[row].infos) {
  555. //falg确定每个的是否有值
  556. let falg = false
  557. if (!this.tableData[row].infos[key]) {
  558. falg = true
  559. }
  560. //铭牌照片特殊处理
  561. if (key == 'Nameplate') {
  562. this.tableData[row].infos[key] = {
  563. "systemId": "dataPlatform",
  564. "name": "铭牌照片",
  565. "type": "image",
  566. "key": data
  567. }
  568. } else {
  569. this.tableData[row].infos[key] = data
  570. }
  571. if (falg) {
  572. this.updateBusiness([this.tableData[row]], [[0, "infos." + key, null, data]])
  573. }
  574. } else {
  575. this.tableData[row].infos = {}
  576. if (key == 'Nameplate') {
  577. this.tableData[row].infos[key] = {
  578. "systemId": "dataPlatform",
  579. "name": "铭牌照片",
  580. "type": "image",
  581. "key": data
  582. }
  583. } else {
  584. this.tableData[row].infos[key] = data
  585. }
  586. }
  587. } else {
  588. this.tableData[row].infos[key] = ''
  589. }
  590. }
  591. },
  592. watch: {
  593. projectId() {
  594. this.tableData = []
  595. this.mess.deviceId = null
  596. this.page.total = 0
  597. },
  598. showTypes: {
  599. handler(newName, oldName) {
  600. if (newName && newName[0] && newName[0].value) {
  601. this.showType = newName[0].value
  602. } else {
  603. this.showType = ""
  604. }
  605. },
  606. immediate: true,
  607. deep: true
  608. }
  609. }
  610. };
  611. </script>
  612. <style lang="less">
  613. .hanson-bar {
  614. height: 40px;
  615. padding: 5px 0;
  616. font-size: 14px;
  617. overflow: hidden;
  618. margin-top: 0;
  619. line-height: 40px;
  620. .iconfont {
  621. font-size: 12px;
  622. }
  623. }
  624. </style>