This commit is contained in:
zhutianqi
2021-12-06 10:34:50 +08:00
parent 784c4187f2
commit a752a98808
2 changed files with 33 additions and 5 deletions
@@ -16,7 +16,9 @@
multiple
@change="handleChange"
>
<!-- <el-option value="全选" label="全选" @click.native="clickOption"></el-option>-->
<el-option value="全选" @click.native="clickOption" v-if="options.length > 0">
{{ checkAll ? '取消全选' : '全选' }}
</el-option>
<el-option
v-for="opt in options"
:key="opt.value"
@@ -53,7 +55,8 @@ export default {
},
data () {
return {
valueArr: []
valueArr: [],
checkAll: false,
}
},
computed: {
@@ -71,9 +74,32 @@ export default {
}
},
methods: {
clickOption () {
this.checkAll = !this.checkAll
if (this.checkAll) {
let list = []
this.config.options.map(item => {
this.valueArr.push(item.value)
list.push(item.value)
})
this.$emit('input', list)
} else {
this.valueArr = []
this.$emit('input', this.valueArr)
}
},
handleChange (event) {
// const value = event.target.value
this.$emit('input', event)
if (event.includes('全选')) {
return
} else {
if (event.length === this.config.options.length) {
this.checkAll = true
} else {
this.checkAll = false
}
this.$emit('input', event)
}
// const value = event.target.value
}
},
@@ -91,7 +117,7 @@ export default {
this.valueArr = []
}
}
}
},
},
mounted () {
if (this.value !== '' && this.value !== null && typeof (this.value) !== 'undefined') {