<vxe-table
ref="xTable"
:data="tableObj.data"
:loading="tableObj.loading"
border
resizable
auto-resize
height="100%"
size="small"
highlight-current-row
highlight-hover-row
show-overflow="tooltip"
show-header-overflow="tooltip"
row-id="id"
:row-config="{ keyField: 'id', isCurrent: true, isHover: true }"
:radio-config="{ reserve: true, trigger: 'row' }"
:checkbox-config="{ reserve: true, trigger: 'row' }"
@radio-change="handleRadioChange"
@checkbox-all="checkboxAll"
@checkbox-change="changeCheckBox"
>
<vxe-column type="radio" width="80" align="center" :visible="!multiple">
<template #header>
<vxe-button type="text" @click="clearRadioRow">取消选中</vxe-button>
</template>
</vxe-column>
<vxe-column type="checkbox" width="80" align="center" :visible="multiple"></vxe-column>
<vxe-table-column field="sname" title="姓名" min-width="150" align="left"></vxe-table-column>
</vxe-table>
open(data) {
if (!this.multiple) {
this.selectObj = this.$XEUtils.clone(data, true)
} else {
this.selectArr = this.$XEUtils.clone(data, true)
}
this.dialogObj.show = true
this.getTableData()
},
getTableData() {
this.tableObj.data = res.data
this.copyData = res.data
if (!this.multiple && this.selectObj.id) {
const find = this.tableObj.data.find((i) => i.id === this.selectObj.id)
this.$refs.xTable.setRadioRow(find)
}
if (this.multiple && this.selectArr.length > 0) {
this.$refs.xTable.setCheckboxRow(this.selectArr, true)
}
setTimeout(() => {
this.$refs.xTable && this.$refs.xTable.refreshColumn()
}, 200)
},
doSearch() {
const str = this.searchStr.trim()
if (!!str) {
this.tableObj.data = this.copyData.filter((i) => i.name.includes(str))
} else {
this.tableObj.data = this.copyData
}
setTimeout(() => {
this.$refs.checkTable.setCheckboxRow(this.selectArr, true)
}, 200)
},
handleRadioChange() {
this.selectObj = this.$refs.xTable.getRadioRecord()
},
clearRadioRow() {
this.$refs.xTable.clearRadioRow()
this.selectObj = {}
},
changeCheckBox({ checked, row }) {
const findIndex = this.selectArr.findIndex((i) => i.id === row.id)
if (findIndex > -1 && !checked) {
this.selectArr.splice(findIndex, 1)
}
if (findIndex <= -1 && checked) {
this.selectArr.push(row)
}
},
checkboxAll({ checked }) {
this.tableObj.data.map((item) => {
const findIndex = this.selectArr.findIndex((i) => i.id === item.id)
if (findIndex > -1 && !checked) {
this.selectArr.splice(findIndex, 1)
}
if (findIndex <= -1 && checked) {
this.selectArr.push(item)
}
})
},