注意:本帖为公开技术贴,不得用做任何商业用途
使用版本为vue2版本,vue3版本同理,请注意写法变更
本table在dialog中使用,会存在一个open方法作为打开dialog时的数据传输
<template><el-dialog title="xxxx选择" width="1200px" :visible.sync="value.flag" :before-close="handleClose" @open="handleOpen"><el-table :data="tableData" ref="multiTable" style="width: 100%" max-height="450" highlight-current-row border@select="handleSelectionChange" @row-click="handleRowClick" :row-key="getRowKeys"><el-table-column type="selection" width="55" :reserve-selection="true"></el-table-column><el-table-column label="序号" type="index" width="50" align="center"></el-table-column><el-table-column label="ID" prop="pointId" width="80" align="center"></el-table-column><el-table-column label="名称" prop="name"></el-table-column><el-table-column label="类型" prop="type" align="center"></el-table-column></el-table><div class="th-pagination"><el-pagination @size-change="sizeChange" @current-change="pageChange" :current-page="paging.page":page-size="paging.size" :total="paging.total"layout="total, sizes, prev, pager, next, jumper"></el-pagination></div><span slot="footer" class="dialog-footer"><el-button @click="close" size="mini">取 消</el-button><el-button type="primary" @click="submit" size="mini">确 定</el-button></span></el-dialog>
</template><script>export default {name: '',data() {tableData: [],tableCheckedData: [],paging: {page: 1,size: 10,total: 0},selectedArray: [],}},mounted() {},methods: {init() {this.getData();},async getData(data) {this.tableData= []},sizeChange(val) {const selectedArr = this.$refs.multiTable.selection.map(v => { return v.pointId })this.selectedArray = Array.from(new Set(this.selectedArray.concat(selectedArr)))this.paging.size = val;this.handleOpen()},pageChange(val) {const selectedArr = this.$refs.multiTable.selection.map(v => { return v.pointId })this.selectedArray = Array.from(new Set(this.selectedArray.concat(selectedArr)))this.paging.page = val;this.handleOpen()},getRowKeys(row) {return row.pointId;},handleSelectionChange(list, item) {this.tableCheckedData = listif (this.selectedArray && this.selectedArray.length > 0) {for (let i = 0; i < this.selectedArray.length; i++) {if (this.selectedArray[i] === item.pointId) {this.selectedArray.splice(i, 1)}}}},handleRowClick(row, event, column) {this.$refs.multiTable.toggleRowSelection(row);},async handleOpen() {await this.getData(this.queryData);this.$nextTick(() => {this.$refs.multiTable.clearSelection()if (this.selectedArray) {for (let i = 0; i < this.selectedArray.length; i++) {for (let j = 0; j < this.tableData.length; j++) {if (this.selectedArray[i] === this.tableData[j].pointId) { this.$refs.multiTable.toggleRowSelection(this.tableData[j])}}}}})},handleClose() {this.close()},close() {const data = { flag: false, callback: null }this.paging.page = 1this.$emit('closeDialog', data)},submit() {const pointList = this.tableCheckedDatalet lastPageChecked = pointList.map(v => { return v.pointId })lastPageChecked = Array.from(new Set(lastPageChecked))const finalChecked = arrayDeDuplication(lastPageChecked.concat(this.selectedArray))const arrayCleaned = finalChecked.filter(item => item !== undefined);if (arrayCleaned.length <= 0) {return this.$message.warning('请选择点位!')}this.close()},},
}
</script>