表格穿梭框
第一版样式
1673663036640
引入
<!-- 调试增加 -->
<shuttleFrame
@routersPerson="routersPerson"
:rightPerson="rightPerson"
:formType="formType"
></shuttleFrame>
代码:
<template>
<div class="general">
<div class="topLeft">
<el-card class="box-card">
<span class="changeWords">可选用户</span>
<el-row>
<el-form ref="searchform" :model="searchForm">
<el-col :span="10">
<el-form-item prop="userName">
<el-input
:placeholder="'请输入人员姓名'"
clearable
v-model="searchForm.userName"
style="width: 95%"
>
</el-input>
</el-form-item>
</el-col>
<el-col :span="10">
<el-form-item prop="teamId">
<el-select
v-model="searchForm.teamId"
placeholder="请选择队伍"
@change="handleRanks"
style="width: 95%"
filterable
>
<el-option
v-for="item in ranksList"
:key="item.id"
:label="item.teamName"
:value="item.id"
>
</el-option>
</el-select>
</el-form-item>
</el-col>
<el-col :span="10">
<el-form-item prop="teamClassId">
<el-select
v-model="searchForm.teamClassId"
placeholder="请选择班组"
style="width: 95%"
filterable
>
<el-option
v-for="item in teamList"
:key="item.id"
:label="item.tGroupName"
:value="item.id"
>
</el-option>
</el-select>
</el-form-item>
</el-col>
<el-col :span="14">
<div class="rightbtn">
<el-button
type="primary"
icon="el-icon-search"
@click="searchlist"
class="marginL"
>查询
</el-button>
<el-button icon="el-icon-refresh-left" @click="resetform"
>重置</el-button
>
</div>
</el-col>
</el-form>
</el-row>
<el-row>
<el-table
ref="leftTableData"
:data="leftTableData"
style="width: 100%"
max-height="250"
@selection-change="changeCheckBoxValue"
>
<template slot="empty">
<el-empty :image-size="100" description="暂无数据"></el-empty>
</template>
<el-table-column
type="selection"
width="55"
:selectable="
(row) => {
return !rightTableData.find((v) => v.ciId == row.ciId);
}
"
></el-table-column>
<el-table-column
prop="name"
label="姓名"
fixed
show-overflow-tooltip
></el-table-column>
<el-table-column prop="ciGender" label="性别" show-overflow-tooltip>
</el-table-column>
<el-table-column
prop="ciTel"
label="联系电话"
show-overflow-tooltip
>
</el-table-column>
<el-table-column
prop="teamName"
label="所属队伍"
show-overflow-tooltip
>
</el-table-column>
<el-table-column
prop="tGroupName"
label="所属班组"
show-overflow-tooltip
>
</el-table-column>
</el-table>
</el-row>
</el-card>
</div>
<div class="topCenter">
<el-button type="primary" :disabled="add" @click="handleAdd"
>添加<i class="el-icon-arrow-right el-icon--right"></i
></el-button>
</div>
<div class="topRight">
<el-card class="box-card">
<span class="changeWords">已选用户</span>
<el-row>
<el-table
ref="rightTableData"
:data="rightTableData"
style="width: 100%"
max-height="373"
>
<template slot="empty">
<el-empty :image-size="100" description="暂无数据"></el-empty>
</template>
<el-table-column
prop="name"
label="姓名"
fixed
show-overflow-tooltip
></el-table-column>
<el-table-column label="操作" width="80">
<template slot-scope="scope">
<el-button
size="mini"
type="text"
@click="handleDelete(scope.$index, scope.row, rightTableData)"
>删除</el-button
>
</template>
</el-table-column>
</el-table>
</el-row>
</el-card>
</div>
</div>
</template>
<script type="text/javascript">
import { attendClassFindCiUser, ciUserFindOther } from "@/api/personnel";
export default {
data() {
return {
searchForm: {
userName: "",
teamId: "",
teamClassId: "",
},
add: true,
del: true,
leftTableData: [],
rightTableData: [],
transfer: [], //数据转移
ranksList: [], //队伍
teamList: [], //班组
};
},
props: {
//编辑传过来的人员
rightPerson: {
type: Array,
},
},
created() {
this.queryRoster();
this.getoptions();
},
watch: {
rightTableData: function (val) {
if (val && val.length) {
this.$emit("routersPerson", val);
}
console.log("我是最终的数据", val);
},
rightPerson: function (val) {
if (val.length) {
let leftTableData = [];
val.forEach((item) => {
this.leftTableData.forEach((i) => {
item.id == i.ciId && leftTableData.push(i);
});
// this.$refs.leftTableData.toggleRowSelection(item,true);
});
leftTableData.forEach((i) => {
console.log(11111);
this.$refs.leftTableData.toggleRowSelection(i);
});
this.rightTableData = leftTableData;
console.log("我是编辑人员", leftTableData);
}
},
},
methods: {
//获取下拉内容
async getoptions() {
const data = await ciUserFindOther({
pId: JSON.parse(localStorage.getItem("pId")),
});
this.ranksList = data.data;
console.log("我是下拉队伍", this.ranksList);
},
//选择队伍添加班组
handleRanks(id) {
this.searchForm.teamClassId = "";
this.ranksList.forEach((item) => {
if (item.id == id) {
this.teamList = item.teamGroupList;
}
});
console.log("我是班组", this.teamList);
},
//查询
searchlist() {
(this.page = 1), this.queryRoster();
},
//重置
resetform() {
this.$refs["searchform"].resetFields();
this.queryRoster();
},
//删除
handleDelete(index, rows, data) {
this.$refs.leftTableData &&
this.$refs.leftTableData.toggleRowSelection(rows, false);
data.splice(index, 1);
},
//选中
handleAdd() {
this.rightTableData = this.transfer;
console.log("我是选中的人员苏剧", this.rightTableData);
},
//查询花名册人员
async queryRoster() {
let params = {
pId: localStorage.getItem("pId"),
};
if (this.searchForm.userName) {
params.userName = this.searchForm.userName;
}
if (this.searchForm.teamId) {
params.teamId = this.searchForm.teamId;
}
if (this.searchForm.teamClassId) {
params.teamClassId = this.searchForm.teamClassId;
}
let data = await attendClassFindCiUser(params);
this.leftTableData = data.data;
},
//数据
changeCheckBoxValue(val) {
console.log("我是可选用户", val);
if (val.length) {
this.add = false;
this.transfer = val;
} else {
this.add = true;
}
},
},
};
</script>
<style lang="scss" scoped>
::v-deep {
.el-button + .el-button {
margin-left: 10px;
}
}
.changeWords {
display: inline-block;
margin: 10px 0;
font-size: 16px;
font-weight: bold;
}
.general {
display: flex;
align-items: center;
}
.topLeft {
width: 60%;
// background: rgb(240, 239, 239);
}
.topCenter {
width: 15%;
display: flex;
align-items: center;
justify-content: center;
}
.topRight {
width: 25%;
// height: 410px;
// background: rgb(240, 239, 239);
}
.box-card {
height: 433px;
}
</style>
优化后
取消了添加这一步,直接对左边数据的复选框进行点击取消的数据同步在右边的数据,可以直接使用
代码
<template>
<div class="general">
<div class="topLeft">
<el-card class="box-card">
<span class="changeWords">可选用户</span>
<el-row>
<el-form ref="searchform" :model="searchForm">
<el-col :span="10">
<el-form-item prop="userName">
<el-input
:placeholder="'请输入人员姓名'"
clearable
v-model="searchForm.userName"
style="width: 95%"
>
</el-input>
</el-form-item>
</el-col>
<el-col :span="10">
<el-form-item prop="teamId">
<el-select
v-model="searchForm.teamId"
placeholder="请选择队伍"
@change="handleRanks"
style="width: 95%"
filterable
>
<el-option
v-for="item in ranksList"
:key="item.id"
:label="item.teamName"
:value="item.id"
>
</el-option>
</el-select>
</el-form-item>
</el-col>
<el-col :span="10">
<el-form-item prop="teamClassId">
<el-select
v-model="searchForm.teamClassId"
placeholder="请选择班组"
style="width: 95%"
filterable
>
<el-option
v-for="item in teamList"
:key="item.id"
:label="item.tGroupName"
:value="item.id"
>
</el-option>
</el-select>
</el-form-item>
</el-col>
<el-col :span="14">
<div class="rightbtn">
<el-button
type="primary"
icon="el-icon-search"
@click="searchlist"
class="marginL"
>查询
</el-button>
<el-button icon="el-icon-refresh-left" @click="resetform"
>重置</el-button
>
</div>
</el-col>
</el-form>
</el-row>
<el-row>
<el-table
ref="leftTableData"
:data="leftTableData"
style="width: 100%"
max-height="250"
@selection-change="changeCheckBoxValue"
>
<template slot="empty">
<el-empty :image-size="100" description="暂无数据"></el-empty>
</template>
<el-table-column type="selection" width="55"></el-table-column>
<el-table-column
prop="name"
label="姓名"
fixed
show-overflow-tooltip
></el-table-column>
<el-table-column prop="ciGender" label="性别" show-overflow-tooltip>
</el-table-column>
<el-table-column
prop="ciTel"
label="联系电话"
show-overflow-tooltip
>
</el-table-column>
<el-table-column
prop="teamName"
label="所属队伍"
show-overflow-tooltip
>
</el-table-column>
<el-table-column
prop="tGroupName"
label="所属班组"
show-overflow-tooltip
>
</el-table-column>
</el-table>
</el-row>
</el-card>
</div>
<div class="topCenter">
<!-- <el-button type="primary" :disabled="add" @click="handleAdd"
>添加<i class="el-icon-arrow-right el-icon--right"></i
></el-button> -->
-->
</div>
<div class="topRight">
<el-card class="box-card">
<span class="changeWords">已选用户</span>
<el-row>
<el-table
ref="rightTableData"
:data="rightTableData"
style="width: 100%"
max-height="373"
>
<template slot="empty">
<el-empty :image-size="100" description="暂无数据"></el-empty>
</template>
<el-table-column
prop="name"
label="姓名"
fixed
show-overflow-tooltip
></el-table-column>
<el-table-column label="操作" width="80">
<template slot-scope="scope">
<el-button
size="mini"
type="text"
@click="handleDelete(scope.$index, scope.row, rightTableData)"
>删除</el-button
>
</template>
</el-table-column>
</el-table>
</el-row>
</el-card>
</div>
</div>
</template>
<script type="text/javascript">
import { attendClassFindCiUser, ciUserFindOther } from "@/api/personnel";
export default {
data() {
return {
searchForm: {
userName: "",
teamId: "",
teamClassId: "",
},
add: true,
del: true,
leftTableData: [],
rightTableData: [],
// transfer: [], //数据转移
ranksList: [], //队伍
teamList: [], //班组
};
},
props: {
//编辑传过来的人员
rightPerson: {
type: Array,
},
//判断是新增还是编辑
formType: {
type: Number,
default: 0,
},
},
created() {
if (this.formType == 0) {
this.queryRoster();
}
this.getoptions();
},
computed: {
},
watch: {
rightPerson: function (val) {
console.log(val);
this.rightTableData = val.concat([]);
if (this.rightTableData.length&&this.formType == 1) {
this.queryRoster();
}
},
rightTableData:function(val){
if(val.length){
this.$emit('routersPerson',val)
}
},
},
methods: {
//获取下拉内容
async getoptions() {
const data = await ciUserFindOther({
pId: JSON.parse(localStorage.getItem("pId")),
});
this.ranksList = data.data;
},
//选择队伍添加班组
handleRanks(id) {
this.searchForm.teamClassId = "";
this.ranksList.forEach((item) => {
if (item.id == id) {
this.teamList = item.teamGroupList;
}
});
},
//查询
searchlist() {
(this.page = 1), this.queryRoster();
},
//重置
resetform() {
this.$refs["searchform"].resetFields();
this.queryRoster();
},
//删除
handleDelete(index, rows, data) {
console.log("index, rows, data", index, rows, data);
this.$refs.leftTableData &&
this.$refs.leftTableData.toggleRowSelection(rows, false);
// this.rightTableData.splice(index, 1);
},
//查询花名册人员
async queryRoster() {
let params = {
pId: localStorage.getItem("pId"),
};
if (this.searchForm.userName) {
params.userName = this.searchForm.userName;
}
if (this.searchForm.teamId) {
params.teamId = this.searchForm.teamId;
}
if (this.searchForm.teamClassId) {
params.teamClassId = this.searchForm.teamClassId;
}
let data = await attendClassFindCiUser(params);
this.leftTableData = data.data;
this.rightTableData.forEach((i) => {
this.leftTableData.forEach((item) => {
if (i.ciId == item.ciId) {
this.$nextTick(() => {
this.$refs.leftTableData.toggleRowSelection(item, true);
});
}
});
});
},
//数据
changeCheckBoxValue(val) {
this.rightTableData = val;
},
},
};
</script>
<style lang="scss" scoped>
::v-deep {
.el-button + .el-button {
margin-left: 10px;
}
}
.changeWords {
display: inline-block;
margin: 10px 0;
font-size: 16px;
font-weight: bold;
}
.general {
display: flex;
align-items: center;
}
.topLeft {
width: 60%;
// background: rgb(240, 239, 239);
}
.topCenter {
width: 15%;
display: flex;
align-items: center;
justify-content: center;
}
.topRight {
width: 25%;
// height: 410px;
// background: rgb(240, 239, 239);
}
.box-card {
height: 433px;
}
</style>