<el-dialog
class="dialog"
:title="upLowTitle"
:visible.sync="upLowVisble"
width="40%"
:before-close="handleClose"
:close-on-click-modal="false"
>
<div class="tree-layout">
<el-input placeholder="输入关键字进行过滤" v-model="filterText"></el-input>
<div class="tree">
<el-tree
:data="channels"
ref="channelTree"
:props="channelProps"
@check-change="upper_lowerChange"
:default-expanded-keys="['']"
default-expand-all
:filter-node-method="filterNode"
show-checkbox
:indent="16"
v-loading="upLowLoading"
node-key="id"
></el-tree>
</div>
</div>
<span slot="footer" class="dialog-footer dialog-tools">
<el-button type="success" @click="checkAll">全选</el-button>
<el-button type="warning" @click="inverse">反选</el-button>
<el-button type="primary" @click="shelves">上架</el-button>
<el-button type="danger" @click="obtained">下架</el-button>
<el-button @click="upLowCancel">取消</el-button>
</span>
</el-dialog>
export default {
mixins: [listMixins],
data() {
return {
upLowVisble: false,
filterText: "",
channels: [],
channelProps: {
label: "name",
children: "children",
isLeaf: "isChild",
id: "id"
},
flag: false,
isCheck: false,
upLowLoading: true,
upLowTitle: ""
}
},
methods: {
add() {
this.upLowVisble = true;
this.upLowLoad();
},
upLowLoad() {
let that = this;
this.upLowLoading = true;
axios
.post(this.$api.allChannelList)
.then(res => {
this.upLowLoading = false;
that.channels = res.body;
})
.catch(err => {
this.upLowLoading = false;
});
},
upper_lowerChange(node, checkStatus, childStatus) {
if (checkStatus) {
this.currentCheckChannelId = node.id;
}
},
filterNode(value, data) {
if (!value) return true;
return data.name.indexOf(value) !== -1;
},
checkAll() {
this.flag = true;
this.$refs.channelTree.setCheckedNodes(this.channels);
},
batchSelect(nodes, refs, flag, seleteds) {
if (typeof nodes != "undefined") {
nodes.forEach(element => {
refs.setChecked(element, flag, true);
});
}
if (typeof seleteds != "undefined") {
seleteds.forEach(node => {
refs.setChecked(node, !flag, true);
});
}
},
inverse() {
let res = this.$refs.channelTree;
let nodes = res.getCheckedNodes(true, true);
this.batchSelect(this.channels, res, true, nodes);
},
shelves() {},
obtained() {},
upLowCancel() {
this.upLowVisble = false;
this.channels = [];
}
},
created() {
},
watch: {
filterText(val) {
this.$refs["channelTree"].filter(val);
}
}
}