jinlin
2024-08-15 a856b0db283f46b6b48086e371393d375eece1a3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<template>
  <div style="text-align: right;">
    <el-popover placement="bottom" title="列筛选" trigger="click" @hide="saveSelectedColumns">
      <el-checkbox-group class="country-group" v-model="checkResult">
        <div class="country-group-cloumn">
          <el-checkbox class="country-group-item" v-for="item of colSelect" :label="item.prop" :key="item.prop">{{item.label}}</el-checkbox>
        </div>
      </el-checkbox-group>
      <el-button type="button" size="small" slot="reference"
      ><i class="el-icon-arrow-down el-icon-menu"></i
      ></el-button>
    </el-popover>
  </div>
</template>
 
<script>
  export default {
    name: 'column-select',
    props: ['showColList','pageCode'],//从父组件传过来的值
    watch: {
      checkResult(val) {
        // console.log(val,'checkResult的 val')
        let arr=[]
        let arr1 = this.showColList.filter(i => !val.includes(i.prop)) // 未选中列
        arr1.forEach((item,index)=>{
          arr.push(item.prop)
        })
        this.notSelectedColumns=arr
        this.showColList.filter(item => {
          if (val.indexOf(item.prop) !== -1) {
            item.isShow = true
          } else {
            item.isShow = false
          }
        })
      }
    },
    data() {
      return {
        checkResult: [], //选中列集合 (含列表上未显示的)
        notSelectedColumns:[] //未选中列集合
      }
    },
    created() {
    },
    methods:{
      async saveSelectedColumns(){
        // alert(2345)
        let param={
          pageName:this.$route.path,
          pageCode:this.pageCode,
          columnList:this.notSelectedColumns,
          isShow:0,
        }
        console.log(param,'param param')
        let res = this.$http.post('/defaultShowConfig',param)
        // if (res) {
        //   await this.$alert('保存成功',{type: 'success'})
        // }
      }
    },
    computed:{
      colSelect(){
       return  this.showColList.filter(i =>i.solidShow == true)
      },
    },
    mounted() {
      setTimeout(() => {
 
        this.showColList.forEach((item, index) => {
          console.log(item.isShow,'item.isShow item.isShow')
          if(item.isShow)
            this.checkResult.push(item.prop)
        })
      }, 500)
    }
  }
</script>
 
<style>
.country-group {
  display: flex;
  justify-content: center;
}
 
.country-group-cloumn {
  display: flex;
  flex-direction: column;
  margin: 0 20px;
}
 
.country-group-item {
  margin: 4px 0;
}
 
 
</style>