定制方案小程序完成

This commit is contained in:
aixianling
2022-07-14 10:11:17 +08:00
parent 7ee49a5367
commit baccd4505b
2 changed files with 75 additions and 11 deletions

View File

@@ -48,7 +48,8 @@ export default {
searchKey: {default: "name"},
multiple: Boolean,
disabled: Boolean,
meta: {default: () => []}
meta: {default: () => []},
choose: {default: null}
},
data() {
return {
@@ -65,7 +66,9 @@ export default {
]
},
selected() {
return [this.value].flat().filter(e => !!e) || []
const {choose, value, nodeKey} = this,
list = [choose].flat().map(e => e?.[nodeKey])
return [...new Set([value, list].flat())].filter(Boolean) || []
}
},
watch: {
@@ -103,15 +106,21 @@ export default {
handleCheck(row) {
const {nodeKey} = this
if (this.multiple) {
let selected = this.$copy(this.selected)
let selected = this.$copy(this.selected),
choose = this.$copy(this.choose)
if (row.checked) {
selected.push(row[nodeKey])
choose.push(row)
} else {
selected = selected.filter(e => e != row[nodeKey])
choose = choose.filter(e => e[nodeKey] != row[nodeKey])
}
this.$emit("change", selected)
this.$emit("update:choose", choose)
} else {
this.tableData.map(e => e.checked = e[nodeKey] == row.id && row.checked)
this.$emit("change", row.checked ? row[nodeKey] : '')
this.$emit("update:choose", row.checked ? row : null)
}
},
handleCheckAll(v) {
@@ -119,8 +128,9 @@ export default {
let selected = this.tableData.map(e => {
e.checked = v
return e
}).filter(e => e.checked)?.map(e => e[nodeKey]) || []
this.$emit("change", selected)
}).filter(e => e.checked) || []
this.$emit("change", selected?.map(e => e[nodeKey]))
this.$emit("update:choose", selected)
}
},
created() {