page

<div class="reportRight"> <div class="reportTitle"> <div class="title"> <el-button size="mini" @click="selectReport(1)"> </el-button> </el-button type="primary" size="mini" @click="selectReport(0)" > </div> </div> <div class="reportContent"> <div v-for="(item, index) in reportData" :key="index"> <div class="contentTitle"> <el-checkbox :label="item.id" v-model="item.isChecked" @change="selectAll($event, item)" >{{ item.name }}</el-checkbox > </div> <ul> <li v-for="(im, ins) in item.children" :key="ins"> <el-checkbox :label="im.id" v-model="im.isChecked" @change="selectOne($event, im)" >{{ im.name }}</el-checkbox > </li> </ul> </div> </div> </div>Copy the code

js

If (typeFlag == 1) {this.reportData.foreach (item => {if (typeFlag == 1) {this.reportData.foreach (item => { item.isChecked = true; item.children.forEach(im => { im.isChecked = true; }); }); } else { this.reportData.forEach(item => { item.isChecked = false; item.children.forEach(im => { im.isChecked = false; }); }); }}, // selectAll(val, item) {if (val == true) {item.children.foreach (im => {im.ischecked = true; // this.checkData.push(im.id); }); } else { item.children.forEach(im => { im.isChecked = false; // this.$set(im, 'isChecked', false) }); } item.isChecked = val; }, // select selectOne(val, im) {let data; if (val) { im.isChecked = true; } else { im.isChecked = false; } this.reportData.forEach(item => { if (im.pid == item.id) { data = item; item.isChecked = true; }}); let len = data.children.length; let checkedLen = 0; data.children.forEach(item => { if (item.isChecked == false) { checkedLen++; }}); if (len == checkedLen) { this.reportData.forEach(item => { if (im.pid == item.id) { item.isChecked = false; }}); }},Copy the code