123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- <template>
- <div id="mySelect" :class="isAll?'isAll':''">
- <el-select
- v-model="searchSelect"
- multiple
- filterable
- placeholder="请选择"
- popper-class="cheng"
- @change="selectChange"
- @visible-change="vselectChange"
- >
- <el-option v-for="item in selectOption" :key="item.value" :label="item.label" :value="item.value" />
- </el-select>
- </div>
- </template>
- <script>
- export default {
- name: 'MySelect',
- components: {},
- props: {
- option: {
- type: Array,
- default: []
- },
- label: {
- type: String,
- default: 'label'
- },
- value: {
- type: String,
- default: 'value'
- }
- },
- data() {
- return {
- searchSelect: [],
- oldSearchSelect: [],
- selectOption: [],
- isAll: true,
- checkedIds: []
- }
- },
- computed: {},
- watch: {
- option() {
- console.log(this.option, '===this.option')
- if (this.option.length != 0 && this.value in this.option[0] && this.label in this.option[0]) {
- this.selectOption = []
- this.selectOption.push({
- value: 'all',
- label: '全部'
- })
- this.option.map(item => {
- this.selectOption.push({
- value: item[this.value],
- label: item[this.label]
- })
- })
- console.log(this.selectOption, '========123')
- this.selectOption.map(item => {
- this.searchSelect.push(item.value)
- this.oldSearchSelect.push(item.value)
- })
- }
- }
- },
- mounted() {
-
- },
- methods: {
-
- selectChange() {
-
- const oldIndexOfValue = this.oldSearchSelect.indexOf('all')
- const indexOfValue = this.searchSelect.indexOf('all')
- if (oldIndexOfValue != -1 && indexOfValue != -1) {
- this.searchSelect.splice(indexOfValue, 1)
- this.isAll = false
- this.saveNewSearchSelect()
- } else if (oldIndexOfValue == -1 && indexOfValue != -1) {
- this.searchSelect.splice(0)
- this.oldSearchSelect.splice(0)
- this.isAll = true
- this.selectOption.map(item => {
- this.searchSelect.push(item.value)
- this.oldSearchSelect.push(item.value)
- })
- } else if (oldIndexOfValue != -1 && indexOfValue == -1) {
- this.searchSelect.splice(0)
- this.oldSearchSelect.splice(0)
- this.isAll = false
- } else if (oldIndexOfValue == -1 && indexOfValue == -1) {
- const isAllSelected = false
- const allOption = []
- this.selectOption.map(item => {
- if (item.value != 'all') {
- allOption.push(item.value)
- }
- })
- if (allOption.length == this.searchSelect.length) {
- this.isAll = true
-
- this.searchSelect.splice(0, 0, 'all')
- this.saveNewSearchSelect()
- }
- }
- },
-
- saveNewSearchSelect() {
- this.oldSearchSelect.splice(0)
- this.searchSelect.map(item => {
- this.oldSearchSelect.push(item)
- })
- },
- vselectChange() {
- console.log(this.searchSelect, '====777')
- this.$emit('searchSelect', this.searchSelect)
- }
- }
- }
- </script>
- <style lang="scss">
- #mySelect{
- .el-select__tags{
- height: 26px;
- overflow: hidden;
-
- &>span{
- white-space: nowrap;
- overflow: hidden;
- display: block;
- }
- }
- .el-select .el-select__tags>span{
- overflow: hidden;
- text-overflow: ellipsis;
- display: inline-block!important;
-
- max-width: 90%;
- }
- .el-tag.el-tag--info .el-tag__close{
- display: none;
- }
- }
- .isAll{
- .el-select .el-select__tags>span{
- span:nth-child(n+2){
- display: none;
- }
- }
- }
- </style>
|