点击按钮打开dialog嵌套表格checked数据关闭dialog回显checked数据
介绍:点击按钮打开dialog嵌套表格,勾选数据,点击确认关闭弹窗并且回显选中得数据,回显的数据被删除,dialog里面的数据也被取消勾选,废话不多说 上代码!!!
这里的勾选回显-外层
dialog嵌套表格-里层
<template>
<div class="award-page">
<el-button @click="handlerService" class="btn">选择服务</el-button>
<el-table
:data="tableData"
style="width: 100%">
<el-table-column
prop="date"
label="项目名称">
</el-table-column>
<el-table-column
prop="name"
label="服务分类">
</el-table-column>
<el-table-column
prop="address"
label="价值">
</el-table-column>
<el-table-column
prop="address"
label="描述">
</el-table-column>
<el-table-column
label="操作"
>
<template slot-scope="scope">
<el-button @click="deleteItem(scope.row)">删除</el-button>
</template>
</el-table-column>
</el-table>
<el-dialog
title="添加服务项目"
:visible.sync="dialogFlag"
width="50%"
>
<el-table
:data="addServiceData"
ref="table"
@selection-change="handleSelectionChange"
style="width: 100%">
<el-table-column
type="selection"
width="55">
</el-table-column>
<el-table-column
prop="date"
label="日期"
width="180">
</el-table-column>
<el-table-column
prop="name"
label="姓名"
width="180">
</el-table-column>
<el-table-column
prop="address"
label="地址">
</el-table-column>
</el-table>
<span slot="footer" class="dialog-footer">
<el-button @click="dialogFlag = false">取 消</el-button>
<el-button type="primary" @click="handleConfirm">确 定</el-button>
</span>
</el-dialog>
</div>
</template>
<script>
export default {
data () {
return {
dialogFlag: false,
tableData: [], // 外层数据
preStoredData: [], // 暂存数据
addServiceData: [{ // 里层数据
date: '2016-05-02',
name: '王小虎',
address: '上海市普陀区金沙江路 1518 弄'
}, {
date: '2016-05-04',
name: '王小虎',
address: '上海市普陀区金沙江路 1517 弄'
}, {
date: '2016-05-01',
name: '王小虎',
address: '上海市普陀区金沙江路 1519 弄'
}, {
date: '2016-05-03',
name: '王小虎',
address: '上海市普陀区金沙江路 1516 弄'
}]
}
},
methods: {
// 打开弹窗
handlerService () {
this.dialogFlag = true
},
// 里层-勾选
handleSelectionChange (data) {
this.preStoredData = data
},
// 里层-确认
handleConfirm () {
this.dialogFlag = false
this.tableData = this.preStoredData
},
// 外层-删除
deleteItem (row) {
this.tableData = this.tableData.filter(item => item !== row);
this.cancelSelection(row)
},
// 里层-取消勾选
cancelSelection(row) {
const table = this.$refs.table;
// 使用toggleRowSelection来取消选中
table.toggleRowSelection(row, false);
},
}
}
</script>
<style lang="scss" scoped>
</style>
原文地址:https://blog.csdn.net/m0_58361435/article/details/144407461
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!