<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>
|