Element Transfer组件默认支持单个list的穿梭

现业务需要支持两个list,效果如下

实现思路:

  1、有选中才可穿梭

  2、已穿梭源数据减少、目标增加(双向)

  边界条件:

    存储旧List((用于已穿梭后切换下拉框重置list等)

  切下拉框时重置另一个list为旧list

    左边下拉框选项同右边时   清空右边下拉的选项

代码

<template>
<div class="page custom-MS custom-MS-ED">
<el-button class="right-top" type="primary" @click="updateBdCompany('qryForm')">保存</el-button>
<v-pageSection title="企业分配">
<el-row>
<el-form :inline="true" :model="qryInput" :rules="newRules" ref="qryForm" label-position="top">
<el-col :span="8" :offset="2">
<el-form-item label="源销售人员" prop="sourceAccount">
<el-select v-model="qryInput.sourceAccount" filterable placeholder="请选择" clearable @change="handleSourceChange">
<el-option v-for="item in bdList" :key="item.account" :label="item.name" :value="item.account">
<span style="float: left">{{ item.name }}</span>
<span style="float: right; color: #8492a6; font-size: 13px">{{ item.account }}</span>
</el-option>
</el-select>
</el-form-item>
</el-col>
<el-col :span="8" :offset="4">
<el-form-item label="目标销售人员" prop="targetAccount">
<el-select v-model="qryInput.targetAccount" filterable placeholder="请选择" clearable @change="handleTargetChange">
<el-option v-for="item in otherBdList" :key="item.account" :label="item.name" :value="item.account">
<span style="float: left">{{ item.name }}</span>
<span style="float: right; color: #8492a6; font-size: 13px">{{ item.account }}</span>
</el-option>
</el-select>
</el-form-item>
</el-col>
</el-form>
</el-row>
<el-row>
<el-col :span="8" :offset="2">
<el-table border height="450"
ref="multipleSourceTable"
:data="sourceCL"
tooltip-effect="dark"
style="width: 100%"
@selection-change="handleSourceSelectionChange">
       <!-- 使用Element表格的单选多选功能 -->
<el-table-column
type="selection"
width="55">
</el-table-column>
<el-table-column label="操作">
<template slot-scope="scope">{{scope.row.shortName}} -- {{scope.row.poi}}</template>
</el-table-column>
</el-table>
</el-col>
<el-col :span="2" :offset="1">
<div style="height: 260px">
<el-button type="primary" style="margin-top: 150px" :disabled="multipleSourceSelection.length == 0" @click="addToTarget">到右边<i class="el-icon-arrow-right el-icon--right"></i></el-button>
</div>
<div>
<el-button type="primary" icon="el-icon-arrow-left" :disabled="multipleTargetSelection.length == 0" @click="addToSource">到左边</el-button>
</div>
</el-col>
<el-col :span="8" :offset="1">
<el-table border height="450"
ref="multipleTargetTable"
:data="targetCL"
tooltip-effect="dark"
style="width: 100%"
@selection-change="handleTargetSelectionChange">
<el-table-column
type="selection"
width="55">
</el-table-column>
<el-table-column label="操作">
<template slot-scope="scope">{{scope.row.shortName}}-{{scope.row.poi}}</template>
</el-table-column>
</el-table>
</el-col>
</el-row>
</v-pageSection>
</div>
</template>
<script>
  //发ajax请求的服务
import CMService from '@/services/companyManagement-service'
export default {
data() {
return {
qryInput: {
sourceAccount: ''
},
updateParams: {},
companyIds: [],
bdList: [],
sourceCL: [],
targetCL: [],
oldSourceCL: [],
oldTargetCL: [],
multipleSourceSelection: [],
multipleTargetSelection: [],
     //Element 数据校验
newRules: {
sourceAccount: {
required: true,
message: '请选择源销售人员'
},
targetAccount: {
required: true,
message: '请选择目标销售人员'
}
},
}
},
methods: {
qry() {
let vm = this
CMService.qryUnderlingUser(this.qryInput, function(response) {
vm.bdList = response.data.bdList
})
},
// 封装的方法 start
// 是否穿梭过
isTransfer(curList, oldList) {
if(curList.length != oldList.length){
return true
}else{
return curList.every(function(item){
return oldList.includes(item)
})
}
},
// 删除已选
deleteSelected(curList, multipleSelection) {
let resultList = []
curList.forEach(function(itemC, indexC){
let resultFlag = multipleSelection.every(function(itemM, indexM){
return itemM.id != itemC.id
})
if(resultFlag) resultList.push(itemC)
})
return resultList
},
// 获取id组成的数组
getIdList(curList) {
let idList = []
curList.forEach(function(item, index){
idList.push(item.id)
})
return idList
},
// 封装的方法 end qrySourceCL(account) {
if(!account){
this.sourceCL = []
return
}
let vm = this
if(this.isTransfer){
this.targetCL = this.oldTargetCL
}
CMService.getBdCompanyList({account: account}, function(response) {
debugger
vm.sourceCL = response.data.companyList
vm.oldSourceCL = vm._.clone(response.data.companyList) })
},
qryTargetCL(account) {
if(!account){
this.targetCL = []
return
}
let vm = this
if(this.isTransfer){
this.sourceCL = this.oldSourceCL
}
CMService.getBdCompanyList({account: account}, function(response) {
vm.targetCL = response.data.companyList
vm.oldTargetCL = vm._.clone(response.data.companyList)
})
},
addToTarget() {
if(!this.qryInput.targetAccount){
this.$alert('请先选择目标销售人员')
return
}
this.sourceCL = this.deleteSelected(this.sourceCL, this.multipleSourceSelection)
this.targetCL = this.targetCL.concat(this.multipleSourceSelection)
},
addToSource() {
if(!this.qryInput.sourceAccount){
this.$alert('请先选择目标销售人员')
return
}
this.targetCL = this.deleteSelected(this.targetCL, this.multipleTargetSelection)
this.sourceCL = this.sourceCL.concat(this.multipleTargetSelection)
},
updateBdCompany(formName) {
let vm = this
this.$refs[formName].validate((valid) => {
if (valid) {
this.updateParams.companyIds = this.getIdList(this.targetCL)
CMService.updateBdCompany(this.updateParams, function(response) {
vm.$alert('修改成功').then(() => {
vm.dialogModifyFormVisible = false
vm.qry()
})
})
} else {
console.log('error submit!!')
return false
}
})
},
handleSourceChange(account) {
this.qrySourceCL(account)
},
handleTargetChange(account) {
this.qryTargetCL(account)
this.updateParams.account = account
},
toggleSelection(rows) {
if (rows) {
rows.forEach(row => {
this.$refs.multipleTable.toggleRowSelection(row);
});
} else {
this.$refs.multipleTable.clearSelection();
}
},
handleSourceSelectionChange(val) {
this.multipleSourceSelection = val;
},
handleTargetSelectionChange(val) {
this.multipleTargetSelection = val;
}
},
mounted() {
this.qry()
},
computed: {
    //目标销售人员由源销售人员过滤得到
otherBdList: function(){
let vm = this
return this.bdList.filter(function(item, index){
return item.account !== vm.qryInput.sourceAccount
})
}
},
}
</script>

vue Transfer 穿梭框的更多相关文章

  1. vue使用element Transfer 穿梭框实现ajax请求数据和自定义查询

    vue使用element Transfer 穿梭框实现ajax请求数据和自定义查询 基于element Transfer http://element-cn.eleme.io/#/zh-CN/comp ...

  2. vue实现穿梭框效果

    vue实现穿梭框效果 一.总结 一句话总结: 用两个数组分别记录左右框框里面的值,用两个数组绑定checkbox,用来记录选中的checkbox值,根据选中的checkbox的值实现删除增加即可 1. ...

  3. Ant Design Pro中Transfer穿梭框的实际用法(与后端交互)

    Ant Design Pro中Transfer穿梭框的实际用法(与后端交互) 该控件的属性以及属性的作用在ADP的官方文档中都有介绍,但没有讲如何与后端交互,本文旨在讲解该控件与后端的交互. Ant ...

  4. 修改vue element Transfer 穿梭框里内容区的宽度

    <template> <el-transfer v-model="value1" :data="data"></el-transf ...

  5. Transfer 穿梭框

    基础用法 Transfer 的数据通过 data 属性传入.数据需要是一个对象数组,每个对象有以下属性:key 为数据的唯一性标识,label为显示文本,disabled 表示该项数据是否禁止转移.目 ...

  6. 如何在vue+element中实现选择框和穿梭框的根据拼音以及拼音首字母以及汉字的模糊搜索

    1.汉字: 直接添加对应的 filterable     2.拼音: 穿梭框和选择器的实现方式有所不同   选择器:   <1>下载pinyin-match:   npm i --save ...

  7. Vue实现拖拽穿梭框功能四种方式

    一.使用原生js实现拖拽 点击打开视频讲解更加详细 <html lang="en"> <head> <meta charset="UTF-8 ...

  8. 【vue系列】elementUI 穿梭框右侧获取当前选中项的值的思路

    最近 做了一个需求 在查询结果的表格中,选取(可多选)一些值,获取到保单号后,打开一个elementUI的穿梭框,然后获取到所有业务员,选取一些业务员后,将上一步获取到的保单号传递给业务员. 画个示意 ...

  9. VUE+ElementUI实现左侧为树形结构、右侧无层级结构的穿梭框

    工作中遇到一个需求,需要将一个数据选择做成穿梭框,但是要求穿梭框左侧为树形结构.右侧为无层级结构的数据展示,ElementUI自身无法在穿梭框中添加树形结构,网上搜到了大佬封装的插件但是对于右侧的无树 ...

随机推荐

  1. JavaScript ES6 核心功能一览

    JavaScript 在过去几年里发生了很大的变化.这里介绍 12 个你马上就能用的新功能. JavaScript 历史 新的语言规范被称作 ECMAScript 6.也称为 ES6 或 ES2015 ...

  2. JavaScript FormData的详细介绍及使用

    本文转自:https://blog.csdn.net/liupeifeng3514/article/details/78988001 FormData的详细介绍及使用请点击此处,那里对FormData ...

  3. 将本地html文件拖到IE8浏览器无法打开,直接弹出一个下载的对话框

    查看一下注册表[HKEY_CLASSES_ROOT\.htm]和[HKEY_CLASSES_ROOT\.html]的ContentType值是否都为“text/html”

  4. JavaScript(JS)之Javascript对象DOM(五)

    https://www.cnblogs.com/haiyan123/p/7653032.html 一.JS中for循环遍历测试 for循环遍历有两种 第一种:是有条件的那种,例如    for(var ...

  5. C实现读写文件

    https://www.cnblogs.com/zhanghongfeng/p/7726199.html https://www.cnblogs.com/xudong-bupt/p/3478297.h ...

  6. 【NOI2013模拟】坑带的树(仙人球的同构+圆方树乱搞+计数+HASH)

    [NOI2013模拟]坑带的树 题意: 求\(n\)个点,\(m\)条边的同构仙人球个数. \(n\le 1000\) 这是一道怎么看怎么不可做的题. 这种题,肯定是圆方树啦~ 好,那么首先转为广义圆 ...

  7. POJ 2987 Firing (最大权闭合图)

    Firing Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 12108   Accepted: 3666 Descript ...

  8. 高级组件——选项卡面板JTabbedPane

    选项卡面板:JTabbedPane(标签位置,布局方式) 标签位置:JTabbedPane.TOP,JTabbedPane.BOTTOM,JTabbedPane.LEFT,JTabbedPane.RI ...

  9. Tensorflow做阅读理解与完形填空

    catalogue . 前言 . 使用的数据集 . 数据预处理 . 训练 . 测试模型运行结果: 进行实际完形填空 0. 前言 开始写这篇文章的时候是晚上12点,突然想到几点新的理解,赶紧记下来.我们 ...

  10. 【MSSQL】SQL Server的日期和时间类型

    参考:SQL Server的日期和时间类型 SQL Server使用 Date 表示日期,time表示时间,使用datetime和datetime2表示日期和时间. 1.秒的精度 秒的精度是指TSQL ...