index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  1. <template>
  2. <div id="deviceList">
  3. <div class="search-header">
  4. <cenote-type @change="changeFloor"></cenote-type>
  5. </div>
  6. <el-row class="left">
  7. <span style="float:right;">当前筛选条件下共{{page.total || '--'}}竖井</span>
  8. <el-select v-model="onlyRead" @change="getTableHeader" style="width:100px;margin-right:20px;vertical-align:bottom;">
  9. <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"></el-option>
  10. </el-select>
  11. <el-select v-model="showType" @change="initTable" style="width:100px;margin-right:10px;vertical-align:bottom;">
  12. <el-option v-for="item in showTypes" :key="item.value" :label="item.label" :value="item.value"></el-option>
  13. </el-select>
  14. <el-button @click="handleCreateTableData">添加竖井</el-button>
  15. <el-button @click="getTableHeader">刷新</el-button>
  16. <el-button v-show="!onlyRead" @click="undo">撤销</el-button>
  17. </el-row>
  18. <div class="tableBox">
  19. <div class="center middle_sty" style="flex:2;" v-show="tableData && !tableData.length">
  20. <p>
  21. <i class="icon-wushuju iconfont"></i>
  22. 暂无数据
  23. </p>
  24. </div>
  25. <div class="tableLeft" v-show="tableData && tableData.length">
  26. <handson-table ref="table"></handson-table>
  27. </div>
  28. <div class="tableRight">
  29. <div v-show="isTableRightShow">
  30. <div class="table_right_box"><span class="iconfont close_right" @click="handleCloseRight">&#xe66b;</span></div>
  31. <h5>管理需要关联的元空间</h5>
  32. <p style="margin-bottom: 10px;">以下为关联的元空间id</p>
  33. <el-input
  34. type="textarea"
  35. :autosize="{ minRows: 6, maxRows: 10}"
  36. :disabled="onlyRead"
  37. placeholder="请输入元空间id,以“,”分割"
  38. v-model="spaceList">
  39. </el-input>
  40. <el-row class="right" v-show="!onlyRead">
  41. <el-button @click="handleCloseRight">取消</el-button>
  42. <el-button @click="saveSpaceList" type="primary">保存</el-button>
  43. </el-row>
  44. </div>
  45. </div>
  46. </div>
  47. <el-pagination
  48. class="right"
  49. v-show="tableData && tableData.length"
  50. @size-change="handleSizeChange"
  51. @current-change="handleCurrentChange"
  52. :current-page="page.pageNumber"
  53. :page-sizes="page.pageSizes"
  54. :page-size="page.pageSize"
  55. layout="total, sizes, prev, pager, next, jumper"
  56. :total="page.total">
  57. </el-pagination>
  58. </div>
  59. </template>
  60. <script>
  61. import tools from "@/utils/scan/tools"
  62. import handsonUtils from "@/utils/hasontableUtils"
  63. import showTools from "@/utils/handsontable/notShow"
  64. import text from "@/utils/handsontable/mainText"
  65. import cenoteType from "@/components/ledger/lib/cenoteType";
  66. import handsonTable from "@/components/common/handsontable";
  67. import { getDataDictionary, getCenoteTableData, updataCenoteTableData, deleteCenoteTableData, saveCenoteRelateSpace, BeatchQueryParam } from "@/api/scan/request"
  68. import { mapGetters, mapActions } from "vuex";
  69. export default {
  70. components: {
  71. cenoteType,
  72. handsonTable
  73. },
  74. data() {
  75. return {
  76. cenoteId: "",//竖井类型id
  77. shaftId: "",//要操作的竖井id
  78. isTableRightShow: false,
  79. spaceList: "",
  80. options: [{
  81. value: true,
  82. label: '只读模式'
  83. }, {
  84. value: false,
  85. label: '编辑模式'
  86. }],
  87. onlyRead: true,
  88. showType: "",
  89. // allMess: true,
  90. tableHeader: [],
  91. page: {
  92. pageSize: 50,
  93. pageSizes: [10, 20, 50, 100],
  94. pageNumber: 1,
  95. total: 0
  96. },
  97. tableData: [],
  98. copyTableData: [],
  99. tableExample:null
  100. };
  101. },
  102. computed: {
  103. ...mapGetters("layout", [
  104. "projectId",
  105. "secret",
  106. "userId"
  107. ]),
  108. showTypes () {
  109. return this.onlyRead?
  110. [{value: "Visible", label: '只看采集信息'}, {value: "all", label: '全部'}]:
  111. [{value: "Visible", label: '只看采集信息'}, {value: "all", label: '全部'}]
  112. }
  113. },
  114. created() {
  115. this.getTableHeader()
  116. },
  117. watch: {
  118. showTypes: {
  119. handler(newName, oldName) {
  120. if (newName && newName[0] && newName[0].value) {
  121. this.showType = newName[0].value
  122. } else {
  123. this.showType = ""
  124. }
  125. },
  126. immediate: true,
  127. deep: true
  128. }
  129. },
  130. methods: {
  131. // 获取表头数据(初始化表格)
  132. async getTableHeader() {
  133. let param = {
  134. data: {
  135. Orders: "sort asc",
  136. PageNumber: 1,
  137. PageSize: 500
  138. },
  139. type: 'Shaft'
  140. }
  141. await getDataDictionary(param, res => {
  142. this.tableHeader = res.Content;
  143. this.getTableData()
  144. })
  145. },
  146. async getTableData() {//获取表格数据
  147. let params = {
  148. Filters: this.cenoteId? `ProjectId='${this.projectId}';structureInfo.ShaftFuncType='${this.cenoteId}'`: `ProjectId='${this.projectId}'`,
  149. Orders: "createTime desc, ShaftID asc",
  150. PageNumber: this.page.pageNumber,
  151. PageSize: this.page.pageSize
  152. }
  153. await getCenoteTableData(params, (res) => {
  154. this.tableData = res.Content
  155. this.copyTableData = tools.deepCopy(res.Content)
  156. this.page.pageNumber = res.PageNumber
  157. this.page.total = res.Total
  158. if(this.tableData && this.tableData.length){
  159. if (this.onlyRead) {
  160. this.getBatch(res.Content)
  161. }
  162. this.initTable()
  163. }
  164. })
  165. },
  166. // 修改表格内容
  167. async updateTableData(data, change) {
  168. let param = {
  169. Content: [],
  170. Projection: []
  171. }, keyList = [];
  172. //生成要修改字段列表
  173. change.map(item => {
  174. let key = item[1].split(".")[0]
  175. if (item[1] && keyList.indexOf(key) == -1) {
  176. keyList.push(key);
  177. }
  178. if (item[1] && item[3] == "" && param.Projection.indexOf(key) == -1) {
  179. param.Projection.push(key);
  180. }
  181. });
  182. //生成对应修改数据
  183. data.map((item, index) => {
  184. keyList.map(value => {
  185. let itemData = tools.dataForKey(item, value)
  186. tools.setDataForKey(item, value, itemData == "" ? null : itemData)
  187. })
  188. // let keyarr = change[index][1].split(".")
  189. // if (keyarr && keyarr.length > 1) {
  190. // item[keyarr[0]][keyarr[1]] = item[keyarr[0]][keyarr[1]] != ""? item[keyarr[0]][keyarr[1]]: null
  191. // } else {
  192. // item[keyarr[0]] = item[keyarr[0]] != ""? item[keyarr[0]]: null
  193. // }
  194. param.Content.push(item);
  195. })
  196. await updataCenoteTableData(param, (res) => {
  197. })
  198. },
  199. // 删除表格数据
  200. async deleteTableData(params) {
  201. await deleteCenoteTableData(params, (res) => {
  202. this.$message.success("删除成功!")
  203. this.getTableHeader()
  204. })
  205. },
  206. //保存元空间关联
  207. async saveSpaceList() {
  208. let params = {
  209. ShaftId: this.shaftId,
  210. SpaceId: this.spaceList
  211. }
  212. await saveCenoteRelateSpace(params, (res) => {
  213. this.$message.success("关联成功!")
  214. this.getTableHeader()
  215. })
  216. },
  217. // 添加竖井
  218. handleCreateTableData() {
  219. this.$router.push({ name: 'cenoteadd'})
  220. },
  221. // 删除表格行
  222. handleDeleteTableRow() {
  223. let params = tools.differenceArr(this.tableData, this.copyTableData)
  224. if (params.length < 1 || this.tableData > this.copyTableData) {
  225. return
  226. }
  227. let param = []
  228. params.map(item => {
  229. param.push({ShaftID: item.ShaftID})
  230. })
  231. this.$confirm("此操作将删除竖井,是否继续?", "提示", {
  232. confirmButtonText: '确定',
  233. cancelButtonText: '取消',
  234. type: 'warning'
  235. }).then(() => {
  236. this.deleteTableData(param)
  237. }).catch(() => {
  238. this.getTableHeader()
  239. this.$message("取消删除")
  240. })
  241. },
  242. //修改
  243. handleUpdataTable(changeData, source) {
  244. if (!this.onlyRead) {
  245. if (changeData) {
  246. let trimmedArr = this.trimmedRows();
  247. let param = handsonUtils.getParam(changeData, source, this.tableExample, trimmedArr);
  248. let data = [];
  249. for (let i = 0; i < param.length; i++) {
  250. data.push(param[i]);
  251. }
  252. //如果data中包含/且data长度为1,将其转换成.
  253. if (changeData.length == 1 && changeData[0][1].indexOf("/") > 0) {
  254. changeData[0][1] = changeData[0][1].split("/").join(".")
  255. }
  256. // 存在data进行修改请求
  257. if (data && data.length) {
  258. this.updateTableData(data, changeData);
  259. }
  260. }
  261. }
  262. },
  263. //撤回
  264. undo() {
  265. this.tableExample.undo();
  266. },
  267. //切换竖井类型
  268. changeFloor(value) {
  269. this.cenoteId = value.Id
  270. this.getTableHeader()
  271. },
  272. //关闭右侧关联元空间输入按钮
  273. handleCloseRight() {
  274. this.isTableRightShow = false
  275. this.spaceList = ""
  276. },
  277. //切换每页显示多少条数据
  278. handleSizeChange(val) {
  279. this.page.pageSize = val
  280. this.getTableHeader()
  281. },
  282. //切换页数
  283. handleCurrentChange(val) {
  284. this.page.pageNumber = val
  285. this.getTableHeader()
  286. },
  287. formatHeaderData(list) {//格式化表头显示的数据
  288. let arr = tools.copyArr(list)
  289. let data = showTools.headerTextFilter(arr, "shaft", this.onlyRead, this.showType)
  290. data.unshift("关联的元空间", "其他关系");
  291. return data;
  292. },
  293. formatHeaderType(list) {//格式化表头头映射的数据
  294. let arr = tools.copyArr(list);
  295. let data = showTools.headerTypeFilter(arr, "shaft", this.onlyRead, this.showType)
  296. data.unshift({
  297. data: "SpaceCount",
  298. renderer: tools.num,
  299. readOnly: true
  300. },{
  301. data: "OtheRelations",
  302. renderer: (instance, td, row, col, prop, value, cellProperties) => {
  303. td.style.color = "#409EFF";
  304. td.style.cursor = "pointer";
  305. td.innerHTML = "查看";
  306. return td;
  307. },
  308. readOnly: true
  309. })
  310. return data;
  311. },
  312. initTable() {//实例化表格
  313. let settings = {
  314. data: this.tableData,
  315. colHeaders: this.formatHeaderData(this.tableHeader),
  316. columns: this.formatHeaderType(this.tableHeader),
  317. rowHeights: 30,
  318. maxRows: this.tableData.length,
  319. contextMenu: {
  320. items: {
  321. remove_row: {
  322. name: "删除竖井"
  323. }
  324. }
  325. },
  326. // 事件
  327. afterChange: this.handleUpdataTable, //修改后
  328. afterFilter: this.trimmedRows, //排序前
  329. afterRemoveRow: this.handleDeleteTableRow, //右键删除
  330. afterOnCellMouseDown: this.handleTdClick //鼠标点击
  331. };
  332. this.$nextTick(() => {
  333. console.log(this.$refs.table)
  334. this.tableExample = this.$refs.table.init(settings)
  335. });
  336. },
  337. //获取到了正确的信息
  338. getInfors(infos, row) {
  339. //其他的开始判断
  340. let val = this.tableExample.colToProp(row.col)
  341. let name = infos.ShaftLocalName?infos.ShaftLocalName:infos.ShaftName
  342. this.shaftId = infos.ShaftID //要操作的数据id
  343. //点击关联的元空间
  344. if (val === "SpaceCount") {
  345. this.spaceList = infos.SpaceList
  346. this.isTableRightShow = true
  347. } else if (val === "OtheRelations") {
  348. this.$router.push({
  349. path: "/ledger/cenoteDetail",
  350. query: {
  351. id: this.shaftId,
  352. name: name
  353. }
  354. })
  355. }
  356. },
  357. //表格点击事件
  358. handleTdClick(el, rowArr) {
  359. //点击的是表头
  360. if (rowArr.row < 0) {
  361. return;
  362. }
  363. //被筛选过后的数组
  364. let trimmedArr = this.trimmedRows();
  365. //是否启用了排序
  366. let isSort = this.tableExample.getPlugin("columnSorting").isSorted();
  367. if (trimmedArr.length && isSort) {
  368. let sortArr = this.myHotArr.getPlugin("columnSorting").rowsMapper
  369. .__arrayMap;
  370. let infos = this.tableData[trimmedArr[sortArr[rowArr.row]]];
  371. this.getInfors(infos, { row: sortArr[rowArr.row], col: rowArr.col });
  372. } else if (isSort) {
  373. //排序后的数组
  374. let sortArr = this.tableExample.getPlugin("columnSorting").rowsMapper.__arrayMap;
  375. let infos = this.tableData[sortArr[rowArr.row]];
  376. this.getInfors(infos, { row: sortArr[rowArr.row], col: rowArr.col });
  377. } else if (trimmedArr.length) {
  378. let infos = this.tableData[trimmedArr[rowArr.row]];
  379. this.getInfors(infos, { row: trimmedArr[rowArr.row], col: rowArr.col });
  380. } else {
  381. let infos = this.tableData[rowArr.row];
  382. this.getInfors(infos, rowArr);
  383. }
  384. },
  385. //获取被筛选掉的行号
  386. trimmedRows() {
  387. // var plugin = hot.getPlugin('trimRows').trimmedRows;//获取被筛选掉的行号
  388. var plugin = this.tableExample.getPlugin("trimRows").trimmedRows;
  389. let dataLength = this.tableData.length;
  390. let dataArr = new Array();
  391. for (let i = 0; i < dataLength; i++) {
  392. dataArr.push(i);
  393. }
  394. if (plugin.length <= 0) {
  395. dataArr = undefined;
  396. } else {
  397. dataArr = this.array_diff(dataArr, plugin);
  398. }
  399. return dataArr || [];
  400. // var DataArray = new Array();
  401. // for (var i = 0; i < plugin.length; i++) {
  402. // // 通过行号获取数据
  403. // DataArray.push(this.tableExample.getSourceDataAtRow(plugin[i]));
  404. // }
  405. },
  406. //去除数组中相同的元素
  407. array_diff(a, b) {
  408. for (var i = 0; i < b.length; i++) {
  409. for (var j = 0; j < a.length; j++) {
  410. if (a[j] == b[i]) {
  411. a.splice(j, 1);
  412. j = j - 1;
  413. }
  414. }
  415. }
  416. return a;
  417. },
  418. //获取动态参数
  419. getBatch(data) {
  420. let param = {
  421. secret: this.secret,
  422. ProjId: this.projectId,
  423. data: {
  424. criterias: []
  425. }
  426. };
  427. this.tableHeader.map(head => {
  428. if (
  429. head.InputMode == "L" ||
  430. head.InputMode == "L1" ||
  431. head.InputMode == "L2" ||
  432. head.InputMode == "M"
  433. ) {
  434. data.map(item => {
  435. let cur = tools.dataForKey(item, head.Path);
  436. if (cur) {
  437. param.data.criterias.push({
  438. id: item.ShaftID,
  439. code: head.InfoPointCode
  440. });
  441. }
  442. });
  443. }
  444. });
  445. if (param.data.criterias.length) {
  446. BeatchQueryParam(param, res => {
  447. this.tableData = data.map(item => {
  448. res.Content.map(child => {
  449. if (item.ShaftID == child.id) {
  450. if (child.data || child.data == 0) {
  451. this.tableHeader.map(head => {
  452. if (head.InfoPointCode == child.code) {
  453. tools.setDataForKey(item, head.Path, child.data);
  454. }
  455. });
  456. } else {
  457. this.tableHeader.map(head => {
  458. if (head.InfoPointCode == child.code) {
  459. tools.setDataForKey(
  460. item,
  461. head.Path,
  462. child.error ? "表号功能号格式错误" : "表号功能号不存在"
  463. );
  464. }
  465. });
  466. }
  467. }
  468. });
  469. return item;
  470. });
  471. this.tableExample.loadData(this.tableData);
  472. });
  473. }
  474. }
  475. }
  476. };
  477. </script>
  478. <style lang="less" scoped>
  479. #deviceList {
  480. overflow: hidden;
  481. height: 100%;
  482. background-color: #fff;
  483. padding: 10px;
  484. position: relative;
  485. .right {
  486. background: #fff;
  487. }
  488. .search-header {
  489. overflow: hidden;
  490. padding-bottom: 10px;
  491. border-bottom: 1px solid #bcbcbc;
  492. }
  493. .tableBox {
  494. display: flex;
  495. height: calc(100% - 140px);
  496. margin-top: 10px;
  497. .tableLeft {
  498. flex: 2;
  499. margin-right: 20px;
  500. }
  501. .tableRight {
  502. flex: 1;
  503. // display: none;
  504. border-left: 1px solid #dadada;
  505. padding: 5px 15px;
  506. margin-right: 5px;
  507. box-shadow: 0px 1px 5px 0px rgba(59, 66, 84, 0.15);
  508. .table_right_box::after{
  509. display: block;
  510. content: "";
  511. clear: both;
  512. }
  513. .close_right {
  514. float: right;
  515. cursor: pointer;
  516. }
  517. }
  518. }
  519. }
  520. .el-pagination button, .el-pagination span:not([class*=suffix]) {
  521. vertical-align: middle;
  522. }
  523. </style>