效果图如下:
代码如下:
<el-dialog title="下级选择"
:visible.sync="chooseUser"
width="60%"
center>
<div style="text-align: center;">
<el-transfer
ref="roleTransfer"
style="text-align: left; display: inline-block;height:500px"
v-model="Selected"
filterable
:titles="['可选人员', '已选人员']"
:format="{
noChecked: '${total}',
hasChecked: '${checked}/${total}'
}"
@change="handleChange"
:data="datalist">
<span slot-scope="{ option }">{{ option.label }}</span>
</el-transfer>
</div>
<span slot="footer" class="dialog-footer">
<el-button @click="reBack()" style="margin:0px 30px 0px 30px">返回</el-button>
<el-button type="success" @click="saveChoose()">保存</el-button>
</span>
</el-dialog>
获取穿梭框列表,渲染到页面:
choose(id){
this.chooseUser = true
this.chooseId = id
setTimeout(async () => {
let params = {
roleId:id
};
let res = await req.post("/accountLogin/select", params)
console.log("ress",res.t)
let data = [];
let allData = res.t;
this.Selected = JSON.parse(allData.Selected)
allData.Optional.forEach((member, index) => {
data.push({
label: member.name,
key: member.id,
id: member.id,
});
});
this.datalist = data
console.log("this.data",this.datalist)
}, 200);
},
Methods:
handleChange(val, direction, movedKeys) { //当前变化的值 , 穿梭框左右方向
console.log(val, direction, movedKeys)
console.log("val",val)
this.selectUser = val
if (direction === "right") {
movedKeys.forEach((key) => {
let index = this.leftvalue.findIndex((item) => item === key);
this.leftvalue.splice(index, 1);
});
movedKeys.forEach((key) => {
this.rightvalue.push(key);
});
} else {
movedKeys.forEach((key) => {
let index = this.rightvalue.findIndex((item) => item === key);
this.rightvalue.splice(index, 1);
});
movedKeys.forEach((key) => {
this.leftvalue.push(key);
});
}
console.log("this.leftvalue",this.leftvalue);
console.log("this.rightvalue",this.rightvalue);
},
将val的值用一个变量存起来,点击保存,将存放val的变量通过接口传过去