123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527 |
- <template>
- <div id="deviceList">
- <div class="search-header">
- <cenote-type @change="changeFloor"></cenote-type>
- </div>
- <el-row class="left">
- <span style="float:right;">当前筛选条件下共{{page.total || '--'}}竖井</span>
- <el-select v-model="onlyRead" @change="getTableHeader" style="width:100px;margin-right:20px;vertical-align:bottom;">
- <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"></el-option>
- </el-select>
- <el-select v-model="showType" @change="initTable" style="width:100px;margin-right:10px;vertical-align:bottom;">
- <el-option v-for="item in showTypes" :key="item.value" :label="item.label" :value="item.value"></el-option>
- </el-select>
- <el-button @click="handleCreateTableData">添加竖井</el-button>
- <el-button @click="getTableHeader">刷新</el-button>
- <el-button v-show="!onlyRead" @click="undo">撤销</el-button>
- </el-row>
- <div class="tableBox">
- <div class="center middle_sty" style="flex:2;" v-show="tableData && !tableData.length">
- <p>
- <i class="icon-wushuju iconfont"></i>
- 暂无数据
- </p>
- </div>
- <div class="tableLeft" v-show="tableData && tableData.length">
- <handson-table ref="table"></handson-table>
- </div>
- <div class="tableRight">
- <div v-show="isTableRightShow">
- <div class="table_right_box"><span class="iconfont close_right" @click="handleCloseRight"></span></div>
- <h5>管理需要关联的元空间</h5>
- <p style="margin-bottom: 10px;">以下为关联的元空间id</p>
- <el-input
- type="textarea"
- :autosize="{ minRows: 6, maxRows: 10}"
- :disabled="onlyRead"
- placeholder="请输入元空间id,以“,”分割"
- v-model="spaceList">
- </el-input>
- <el-row class="right" v-show="!onlyRead">
- <el-button @click="handleCloseRight">取消</el-button>
- <el-button @click="saveSpaceList" type="primary">保存</el-button>
- </el-row>
- </div>
- </div>
- </div>
- <el-pagination
- class="right"
- v-show="tableData && tableData.length"
- @size-change="handleSizeChange"
- @current-change="handleCurrentChange"
- :current-page="page.pageNumber"
- :page-sizes="page.pageSizes"
- :page-size="page.pageSize"
- layout="total, sizes, prev, pager, next, jumper"
- :total="page.total">
- </el-pagination>
- </div>
- </template>
- <script>
- import tools from "@/utils/scan/tools"
- import handsonUtils from "@/utils/hasontableUtils"
- import showTools from "@/utils/handsontable/notShow"
- import text from "@/utils/handsontable/mainText"
- import cenoteType from "@/components/ledger/lib/cenoteType";
- import handsonTable from "@/components/common/handsontable";
- import { getDataDictionary, getCenoteTableData, updataCenoteTableData, deleteCenoteTableData, saveCenoteRelateSpace, BeatchQueryParam } from "@/api/scan/request"
- import { mapGetters, mapActions } from "vuex";
- export default {
- components: {
- cenoteType,
- handsonTable
- },
- data() {
- return {
- cenoteId: "",//竖井类型id
- shaftId: "",//要操作的竖井id
- isTableRightShow: false,
- spaceList: "",
- options: [{
- value: true,
- label: '只读模式'
- }, {
- value: false,
- label: '编辑模式'
- }],
- onlyRead: true,
- showType: "",
- // allMess: true,
- tableHeader: [],
- page: {
- pageSize: 50,
- pageSizes: [10, 20, 50, 100],
- pageNumber: 1,
- total: 0
- },
- tableData: [],
- copyTableData: [],
- tableExample:null
- };
- },
- computed: {
- ...mapGetters("layout", [
- "projectId",
- "secret",
- "userId"
- ]),
- showTypes () {
- return this.onlyRead?
- [{value: "Visible", label: '只看采集信息'}, {value: "all", label: '全部'}]:
- [{value: "Visible", label: '只看采集信息'}, {value: "all", label: '全部'}]
- }
- },
- created() {
- this.getTableHeader()
- },
- watch: {
- showTypes: {
- handler(newName, oldName) {
- if (newName && newName[0] && newName[0].value) {
- this.showType = newName[0].value
- } else {
- this.showType = ""
- }
- },
- immediate: true,
- deep: true
- }
- },
- methods: {
- // 获取表头数据(初始化表格)
- async getTableHeader() {
- let param = {
- data: {
- Orders: "sort asc",
- PageNumber: 1,
- PageSize: 500
- },
- type: 'Shaft'
- }
- await getDataDictionary(param, res => {
- this.tableHeader = res.Content;
- this.getTableData()
- })
- },
- async getTableData() {//获取表格数据
- let params = {
- Filters: this.cenoteId? `ProjectId='${this.projectId}';structureInfo.ShaftFuncType='${this.cenoteId}'`: `ProjectId='${this.projectId}'`,
- Orders: "createTime desc, ShaftID asc",
- PageNumber: this.page.pageNumber,
- PageSize: this.page.pageSize
- }
- await getCenoteTableData(params, (res) => {
- this.tableData = res.Content
- this.copyTableData = tools.deepCopy(res.Content)
- this.page.pageNumber = res.PageNumber
- this.page.total = res.Total
- if(this.tableData && this.tableData.length){
- if (this.onlyRead) {
- this.getBatch(res.Content)
- }
- this.initTable()
- }
- })
- },
- // 修改表格内容
- async updateTableData(data, change) {
- let param = {
- Content: [],
- Projection: []
- }, keyList = [];
- //生成要修改字段列表
- change.map(item => {
- let key = item[1].split(".")[0]
- if (item[1] && keyList.indexOf(key) == -1) {
- keyList.push(key);
- }
- if (item[1] && item[3] == "" && param.Projection.indexOf(key) == -1) {
- param.Projection.push(key);
- }
- });
- //生成对应修改数据
- data.map((item, index) => {
- keyList.map(value => {
- let itemData = tools.dataForKey(item, value)
- tools.setDataForKey(item, value, itemData == "" ? null : itemData)
- })
- // let keyarr = change[index][1].split(".")
- // if (keyarr && keyarr.length > 1) {
- // item[keyarr[0]][keyarr[1]] = item[keyarr[0]][keyarr[1]] != ""? item[keyarr[0]][keyarr[1]]: null
- // } else {
- // item[keyarr[0]] = item[keyarr[0]] != ""? item[keyarr[0]]: null
- // }
- param.Content.push(item);
- })
- await updataCenoteTableData(param, (res) => {
-
- })
- },
- // 删除表格数据
- async deleteTableData(params) {
- await deleteCenoteTableData(params, (res) => {
- this.$message.success("删除成功!")
- this.getTableHeader()
- })
- },
- //保存元空间关联
- async saveSpaceList() {
- let params = {
- ShaftId: this.shaftId,
- SpaceId: this.spaceList
- }
- await saveCenoteRelateSpace(params, (res) => {
- this.$message.success("关联成功!")
- this.getTableHeader()
- })
- },
- // 添加竖井
- handleCreateTableData() {
- this.$router.push({ name: 'cenoteadd'})
- },
- // 删除表格行
- handleDeleteTableRow() {
- let params = tools.differenceArr(this.tableData, this.copyTableData)
- if (params.length < 1 || this.tableData > this.copyTableData) {
- return
- }
- let param = []
- params.map(item => {
- param.push({ShaftID: item.ShaftID})
- })
- this.$confirm("此操作将删除竖井,是否继续?", "提示", {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- type: 'warning'
- }).then(() => {
- this.deleteTableData(param)
- }).catch(() => {
- this.getTableHeader()
- this.$message("取消删除")
- })
- },
- //修改
- handleUpdataTable(changeData, source) {
- if (!this.onlyRead) {
- if (changeData) {
- let trimmedArr = this.trimmedRows();
- let param = handsonUtils.getParam(changeData, source, this.tableExample, trimmedArr);
- let data = [];
- for (let i = 0; i < param.length; i++) {
- data.push(param[i]);
- }
- //如果data中包含/且data长度为1,将其转换成.
- if (changeData.length == 1 && changeData[0][1].indexOf("/") > 0) {
- changeData[0][1] = changeData[0][1].split("/").join(".")
- }
- // 存在data进行修改请求
- if (data && data.length) {
- this.updateTableData(data, changeData);
- }
- }
- }
- },
- //撤回
- undo() {
- this.tableExample.undo();
- },
- //切换竖井类型
- changeFloor(value) {
- this.cenoteId = value.Id
- this.getTableHeader()
- },
- //关闭右侧关联元空间输入按钮
- handleCloseRight() {
- this.isTableRightShow = false
- this.spaceList = ""
- },
- //切换每页显示多少条数据
- handleSizeChange(val) {
- this.page.pageSize = val
- this.getTableHeader()
- },
- //切换页数
- handleCurrentChange(val) {
- this.page.pageNumber = val
- this.getTableHeader()
- },
- formatHeaderData(list) {//格式化表头显示的数据
- let arr = tools.copyArr(list)
- let data = showTools.headerTextFilter(arr, "shaft", this.onlyRead, this.showType)
- data.unshift("关联的元空间", "其他关系");
- return data;
- },
- formatHeaderType(list) {//格式化表头头映射的数据
- let arr = tools.copyArr(list);
- let data = showTools.headerTypeFilter(arr, "shaft", this.onlyRead, this.showType)
- data.unshift({
- data: "SpaceCount",
- renderer: tools.num,
- readOnly: true
- },{
- data: "OtheRelations",
- renderer: (instance, td, row, col, prop, value, cellProperties) => {
- td.style.color = "#409EFF";
- td.style.cursor = "pointer";
- td.innerHTML = "查看";
- return td;
- },
- readOnly: true
- })
- return data;
- },
- initTable() {//实例化表格
- let settings = {
- data: this.tableData,
- colHeaders: this.formatHeaderData(this.tableHeader),
- columns: this.formatHeaderType(this.tableHeader),
- rowHeights: 30,
- maxRows: this.tableData.length,
- contextMenu: {
- items: {
- remove_row: {
- name: "删除竖井"
- }
- }
- },
- // 事件
- afterChange: this.handleUpdataTable, //修改后
- afterFilter: this.trimmedRows, //排序前
- afterRemoveRow: this.handleDeleteTableRow, //右键删除
- afterOnCellMouseDown: this.handleTdClick //鼠标点击
- };
- this.$nextTick(() => {
- console.log(this.$refs.table)
- this.tableExample = this.$refs.table.init(settings)
- });
- },
- //获取到了正确的信息
- getInfors(infos, row) {
- //其他的开始判断
- let val = this.tableExample.colToProp(row.col)
- let name = infos.ShaftLocalName?infos.ShaftLocalName:infos.ShaftName
- this.shaftId = infos.ShaftID //要操作的数据id
- //点击关联的元空间
- if (val === "SpaceCount") {
- this.spaceList = infos.SpaceList
- this.isTableRightShow = true
- } else if (val === "OtheRelations") {
- this.$router.push({
- path: "/ledger/cenoteDetail",
- query: {
- id: this.shaftId,
- name: name
- }
- })
- }
- },
- //表格点击事件
- handleTdClick(el, rowArr) {
- //点击的是表头
- if (rowArr.row < 0) {
- return;
- }
- //被筛选过后的数组
- let trimmedArr = this.trimmedRows();
- //是否启用了排序
- let isSort = this.tableExample.getPlugin("columnSorting").isSorted();
- if (trimmedArr.length && isSort) {
- let sortArr = this.myHotArr.getPlugin("columnSorting").rowsMapper
- .__arrayMap;
- let infos = this.tableData[trimmedArr[sortArr[rowArr.row]]];
- this.getInfors(infos, { row: sortArr[rowArr.row], col: rowArr.col });
- } else if (isSort) {
- //排序后的数组
- let sortArr = this.tableExample.getPlugin("columnSorting").rowsMapper.__arrayMap;
- let infos = this.tableData[sortArr[rowArr.row]];
- this.getInfors(infos, { row: sortArr[rowArr.row], col: rowArr.col });
- } else if (trimmedArr.length) {
- let infos = this.tableData[trimmedArr[rowArr.row]];
- this.getInfors(infos, { row: trimmedArr[rowArr.row], col: rowArr.col });
- } else {
- let infos = this.tableData[rowArr.row];
- this.getInfors(infos, rowArr);
- }
- },
- //获取被筛选掉的行号
- trimmedRows() {
- // var plugin = hot.getPlugin('trimRows').trimmedRows;//获取被筛选掉的行号
- var plugin = this.tableExample.getPlugin("trimRows").trimmedRows;
- let dataLength = this.tableData.length;
- let dataArr = new Array();
- for (let i = 0; i < dataLength; i++) {
- dataArr.push(i);
- }
- if (plugin.length <= 0) {
- dataArr = undefined;
- } else {
- dataArr = this.array_diff(dataArr, plugin);
- }
- return dataArr || [];
- // var DataArray = new Array();
- // for (var i = 0; i < plugin.length; i++) {
- // // 通过行号获取数据
- // DataArray.push(this.tableExample.getSourceDataAtRow(plugin[i]));
- // }
- },
- //去除数组中相同的元素
- array_diff(a, b) {
- for (var i = 0; i < b.length; i++) {
- for (var j = 0; j < a.length; j++) {
- if (a[j] == b[i]) {
- a.splice(j, 1);
- j = j - 1;
- }
- }
- }
- return a;
- },
- //获取动态参数
- getBatch(data) {
- let param = {
- secret: this.secret,
- ProjId: this.projectId,
- data: {
- criterias: []
- }
- };
- this.tableHeader.map(head => {
- if (
- head.InputMode == "L" ||
- head.InputMode == "L1" ||
- head.InputMode == "L2" ||
- head.InputMode == "M"
- ) {
- data.map(item => {
- let cur = tools.dataForKey(item, head.Path);
- if (cur) {
- param.data.criterias.push({
- id: item.ShaftID,
- code: head.InfoPointCode
- });
- }
- });
- }
- });
- if (param.data.criterias.length) {
- BeatchQueryParam(param, res => {
- this.tableData = data.map(item => {
- res.Content.map(child => {
- if (item.ShaftID == child.id) {
- if (child.data || child.data == 0) {
- this.tableHeader.map(head => {
- if (head.InfoPointCode == child.code) {
- tools.setDataForKey(item, head.Path, child.data);
- }
- });
- } else {
- this.tableHeader.map(head => {
- if (head.InfoPointCode == child.code) {
- tools.setDataForKey(
- item,
- head.Path,
- child.error ? "表号功能号格式错误" : "表号功能号不存在"
- );
- }
- });
- }
- }
- });
- return item;
- });
- this.tableExample.loadData(this.tableData);
- });
- }
- }
- }
- };
- </script>
- <style lang="less" scoped>
- #deviceList {
- overflow: hidden;
- height: 100%;
- background-color: #fff;
- padding: 10px;
- position: relative;
- .right {
- background: #fff;
- }
- .search-header {
- overflow: hidden;
- padding-bottom: 10px;
- border-bottom: 1px solid #bcbcbc;
- }
- .tableBox {
- display: flex;
- height: calc(100% - 140px);
- margin-top: 10px;
- .tableLeft {
- flex: 2;
- margin-right: 20px;
- }
- .tableRight {
- flex: 1;
- // display: none;
- border-left: 1px solid #dadada;
- padding: 5px 15px;
- margin-right: 5px;
- box-shadow: 0px 1px 5px 0px rgba(59, 66, 84, 0.15);
- .table_right_box::after{
- display: block;
- content: "";
- clear: both;
- }
- .close_right {
- float: right;
- cursor: pointer;
- }
- }
- }
- }
- .el-pagination button, .el-pagination span:not([class*=suffix]) {
- vertical-align: middle;
- }
- </style>
|