<el-table
ref="singleTable"
v-loading="tableLoading"
:data="tableData"
border
:height="tableHeight"
highlight-current-row
@row-click="rowClick"
@selection-change="selectionChange"
@select="onTableSelect"
@select-all="selectSingleTableAll"
>
<el-table-column type="selection" width="55px" align="center" />
<el-table-column label="序号" type="index" align="center" :index="(index) => { return (index+1) + (currentPage-1)*pageSize }" />
<el-table-column prop="policyNo" label="号码" :width="flexColumnWidth('policyNo', tableData, 200, 80)" align="center" />
</el-table>
<el-pagination
:current-page="currentPage"
:page-sizes="[10, 20, 30, 40, 50]"
:page-size="pageSize"
:total="total"
layout="total, sizes, prev, pager, next, jumper, slot"
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
>
<span style="padding-left:15px;color: #606266;font-weight: 400;">已选中<span style="padding: 0 5px;display: inline;">{{ tableAllSelectedId.length }}</span>条</span>
<el-button class="refresh-button" icon="el-icon-refresh" title="刷新" @click="refresh" />
</el-pagination>
data() {
return {
tableAllSelectedId: [], // 保存表格勾选的全部id
tableAllSelectedRow: [], // 保存表格勾选的行数据
tableData: [], // 当前所在页码的表格数据
tableData_all: [], // 表格的全部数据
currentPage: 1,
pageSize: 10,
tableLoading: false,
computed: {
tableData: {
get() {
return this.tableData // 多此一举是为了让tableData更响应式,目的在于显示勾选个数时更实时
},
set(val) { }
},
methods: {
// 查找对象在对象数组中的位置
findIndexInObejctArr: function(arr, obj) {
for (let i = 0, iLen = arr.length; i < iLen; i++) {
if (arr[i].deliverId === obj.deliverId) {
return i
}
}
return -1
},
// 点击表格勾选触发的事件
onTableSelect: function(rows, row) {
// 判断是点击了表格勾选还是取消勾选
// true就是选中,0或者false是取消选中
const selected = rows.length && rows.indexOf(row) !== -1
if (!selected) {
// 如果点击取消勾选
const index = this.tableAllSelectedId.indexOf(row.deliverId)
this.tableAllSelectedId.splice(index, 1) // 取消勾选,则删除id
this.tableAllSelectedRow.splice(index, 1) // 取消勾选,则删除数据
}
},
// 表格全选触发的事件
selectSingleTableAll: function(selection) {
// 获取当前页码所显示的数据
const a = this.tableData
// 获取当前页勾选的数据
const b = selection
let flag_inCurrentPage
selection.forEach((item) => {
if (item.deliverId === a[0].deliverId) {
flag_inCurrentPage = true
return
}
})
// 后端分页,点击全选框时,当前页的勾选数目等于当前页数据个数,判断为全选
const flag = a.length === b.length && flag_inCurrentPage
if (flag === true) { // 切换成了全选状态
this.tableData_all.forEach((item) => {
if (this.tableAllSelectedId.indexOf(item.deliverId) === -1) {
this.tableAllSelectedId.push(item.deliverId) // 如果点击全选就保存全部的id
this.tableAllSelectedRow.push(item) // 则保存表格全部的数据
}
})
// console.log(‘切换成了全选状态’, this.tableData_all)
} else { // 切换成了非全选状态
this.tableAllSelectedId = [] // 如果取消全选,则清空保存的id
this.tableAllSelectedRow = [] // // 如果取消全选,则清空保存的数据
// console.log(‘切换成了非全选状态’)
}
},
// 获取表格数据
getTableData: function(type) {
this.tableLoading= true
const params = {
cusCode: this.activeCustomer,
page: this.currentPage,
rows: this.pageSize,
address: this.queryForm.address
}
API.pageTableAPI(params).then(response => {
const res = response.data.data
if (response.data.flag === ‘success’) {
this.tableData = res.content // 该后端分页的数据用于显示(渲染)使用。(因数据量过大,于是使用后端分页)
this.total = res.total
// 当切换页码时
if (type === ‘ishandleCurrentChange’) {
this.KaTeX parse error: Expected '}', got 'EOF' at end of input: … this.refs.singleTable.toggleRowSelection(item, true)
} else {
this.KaTeX parse error: Expected 'EOF', got '}' at position 114: … }̲ …errorMsg(res)
}
this.tableLoading= false
}).catch(error => {
this.KaTeX parse error: Expected 'EOF', got '}' at position 61: …g= false }̲) // 请求表格…errorMsg(res)
}
this.tableLoading= false
}).catch(error => {
this.$errorMsg(‘’ + error)
this.tableLoading= false
})
},
query: function() {
this.currentPage = 1
this.tableAllSelectedId = [] // 点击查询按钮后,保存的勾选的id要清空
this.tableAllSelectedRow = [] // 点击查询按钮后,保存的勾选的数据要清空
this.getCenterList()
},
// 表格行点击事件
rowClick: function(row) {
// 只有同时高亮并选中的情况下才能取消选中
if (this.findIndexInObejctArr(JSON.parse(JSON.stringify(this.tableAllSelectedRow)), row) > -1) {
if (this.tableRadio === row) {
this.tableRadio = []
最后
资料过多,篇幅有限
自古成功在尝试。不尝试永远都不会成功。勇敢的尝试是成功的一半。
{
this.tableRadio = []
最后
[外链图片转存中…(img-BNY7hqKi-1718453074736)]
[外链图片转存中…(img-gkJ9gV2u-1718453074737)]
资料过多,篇幅有限
自古成功在尝试。不尝试永远都不会成功。勇敢的尝试是成功的一半。