quanwei
18 hours ago c441dea81bd86bdfb12dff35821fed51f4cc91c2
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<template>
  <!--
      作者 lyzflash
      时间:2021-12-28
      描述:设置-清理数据
  -->
  <div class="product-add">
      <!--清理数据-->
      <div class="common-form">清理数据</div>
      <div class="datalist">
        <ul>
            <li v-for="(item, index) in list" :key="index" class="customlist">
                <el-checkbox :indeterminate="item.isIndeterminate" v-model="item.checked" @change="handleCheckAllChange(index, $event)">{{item.name}}</el-checkbox>
                <p>
                    <el-checkbox v-for="(items, i) in item.list" v-model="items.checked" :label="items.name" :key="i" @change="handleCheckedListChange(index, items.key, $event)">{{items.name}}</el-checkbox>
                </p>
            </li>
        </ul>
      </div>
 
 
      <!--提交-->
      <div class="common-button-wrapper">
        <el-button type="primary" @click="onSubmit">提交</el-button>
      </div>
 
 
 
 
  </div>
 
</template>
 
<script>
  import SettingApi from '@/api/setting.js';
 
  export default {
    data() {
      return {
        form: {
          keys: [],
        },
        list: [],
        selectlist: []
      };
    },
    created() {
      this.getData()
    },
    mounted() {
      //this.list = this.format(this.list);
    },
 
    methods: {
      getData() {
        let self = this;
        SettingApi.clearDataDetail({}, true)
          .then(data => {
            self.list = data.data.dataList;
          })
          .catch(error => {});
      },
      //提交表单
      onSubmit() {
        let self = this;
        if(self.selectlist.length <= 0) {
          self.$message({
            message: '请选择要清理的数据',
            type: 'error'
          });
          return;
        }
        self
        .$confirm('清理后不可恢复,确定要操作吗?', '提示', {
          type: 'warning'
        })
        .then(() => {
          SettingApi.editClearData(self.selectlist, true)
          .then(data => {
            self.$message({
              message: '恭喜你,数据已清理成功',
              type: 'success'
            });
            self.selectlist = [];
          })
          .catch(error => {
 
          });
        });
      },
      // 全选反选的多选框
      handleCheckAllChange(index, e) {
        this.list[index].checked = e
        if(e == false) this.list[index].isIndeterminate = false
        var childrenArray = this.list[index].list
        //  console.log(childrenArray)
        if(childrenArray) {
          for(var i=0,len=childrenArray.length; i<len; i++) {
            childrenArray[i].checked = e
            if(e == false) {
              if(this.selectlist.indexOf(childrenArray[i].key) >= 0) {
                this.selectlist.splice(this.selectlist.indexOf(childrenArray[i].key), 1);
              }
            } else {
              if(this.selectlist.indexOf(childrenArray[i].key) == -1) {
                this.selectlist.push(childrenArray[i].key);
              }
              
            }
          }
          this.list[index].list = childrenArray;
        }
      },
      handleCheckedListChange(index, key, e) {
        var childrenArray = this.list[index].list
        var tickCount = 0, unTickCount = 0, len = childrenArray.length
        for(var i = 0; i < len; i++){
            if(key == childrenArray[i].key) childrenArray[i].checked = e
            if(childrenArray[i].checked == true) {
              tickCount++;
            }
            if(childrenArray[i].checked == false) {
              unTickCount++;
            }
        }
        this.list[index].list = childrenArray;
        if(e == true) {
          this.selectlist.push(key);
        } else {
          this.selectlist.splice(this.selectlist.indexOf(key), 1);
        }
        if(tickCount == len) {//二级全勾选
          this.list[index].checked = true
          this.list[index].isIndeterminate = false
        } else if(unTickCount == len) {//二级全不勾选
          this.list[index].checked = false
          this.list[index].isIndeterminate = false
        } else {
          this.list[index].checked = false
          this.list[index].isIndeterminate = true //添加一级不确定状态
        }
      }
    }
  };
</script>
 
<style>
  .tips {
    color: #ccc;
  }
 
  .datalist li {
    margin-bottom: 20px;
  }
 
  .datalist li > .el-checkbox {
    font-weight: bold;
  }
</style>