vue Transfer 穿梭框
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 穿梭框的更多相关文章
- vue使用element Transfer 穿梭框实现ajax请求数据和自定义查询
vue使用element Transfer 穿梭框实现ajax请求数据和自定义查询 基于element Transfer http://element-cn.eleme.io/#/zh-CN/comp ...
- vue实现穿梭框效果
vue实现穿梭框效果 一.总结 一句话总结: 用两个数组分别记录左右框框里面的值,用两个数组绑定checkbox,用来记录选中的checkbox值,根据选中的checkbox的值实现删除增加即可 1. ...
- Ant Design Pro中Transfer穿梭框的实际用法(与后端交互)
Ant Design Pro中Transfer穿梭框的实际用法(与后端交互) 该控件的属性以及属性的作用在ADP的官方文档中都有介绍,但没有讲如何与后端交互,本文旨在讲解该控件与后端的交互. Ant ...
- 修改vue element Transfer 穿梭框里内容区的宽度
<template> <el-transfer v-model="value1" :data="data"></el-transf ...
- Transfer 穿梭框
基础用法 Transfer 的数据通过 data 属性传入.数据需要是一个对象数组,每个对象有以下属性:key 为数据的唯一性标识,label为显示文本,disabled 表示该项数据是否禁止转移.目 ...
- 如何在vue+element中实现选择框和穿梭框的根据拼音以及拼音首字母以及汉字的模糊搜索
1.汉字: 直接添加对应的 filterable 2.拼音: 穿梭框和选择器的实现方式有所不同 选择器: <1>下载pinyin-match: npm i --save ...
- Vue实现拖拽穿梭框功能四种方式
一.使用原生js实现拖拽 点击打开视频讲解更加详细 <html lang="en"> <head> <meta charset="UTF-8 ...
- 【vue系列】elementUI 穿梭框右侧获取当前选中项的值的思路
最近 做了一个需求 在查询结果的表格中,选取(可多选)一些值,获取到保单号后,打开一个elementUI的穿梭框,然后获取到所有业务员,选取一些业务员后,将上一步获取到的保单号传递给业务员. 画个示意 ...
- VUE+ElementUI实现左侧为树形结构、右侧无层级结构的穿梭框
工作中遇到一个需求,需要将一个数据选择做成穿梭框,但是要求穿梭框左侧为树形结构.右侧为无层级结构的数据展示,ElementUI自身无法在穿梭框中添加树形结构,网上搜到了大佬封装的插件但是对于右侧的无树 ...
随机推荐
- RGBColorspace 与 GRAYColorspace 图片混合后,生成的视频有点问题
最近有一个用户遇到一个情况: 有3张图片,其中前两张是 RGBColorspace,最后一张是 GrayColorspace: 生成的视频,在显示最后一张图片的时候,明显出现奇怪的色彩区域,看下图: ...
- 将本地html文件拖到IE8浏览器无法打开,直接弹出一个下载的对话框
查看一下注册表[HKEY_CLASSES_ROOT\.htm]和[HKEY_CLASSES_ROOT\.html]的ContentType值是否都为“text/html”
- 团体程序设计天梯赛(CCCC) L3012 水果忍者 上凸或下凹的证明
团体程序设计天梯赛代码.体现代码技巧,比赛技巧. https://github.com/congmingyige/cccc_code #include <cstdio> #include ...
- JQERY EasyUI Tabs 选项卡 自适应浏览器宽度高度 解决方案
<script type="text/javascript"> $(window).resize(function () { $('#tt').tabs({ width ...
- console控制台的小问题
第一个foo里面应该是123,但是当执行完下面的代码之后,console控制台会自动将里面的内容改成我们修改之后的
- 温故知新 —— Floyd算法
什么?Floyd?sb O(n ^ 3) 算法早不用了,右上角红叉吧.我之前虽然也认识过 Floyd 算法的重要性,不过多少也是这么想的.然而最近三天连续 rand 到了好几道有关的题目,让我彻底重新 ...
- 关于mac 系统如何通过终端 连接linux服务器 并传文件!
首先要打开终端 mac远程链接服务器 输入 : ssh root@xxx.xx.xxx.xx xxx.xx.xxx.xx是端口号 后面会要求你输入password 即可远程连接 mac通过终端给 ...
- go 定时器
go 定时器 package main import ( "fmt" "time" ) func main() { t := time.NewTicker(ti ...
- vue的一些小坑
1.$refs使用时机 尝试在watch的时候使用$refs,发现里面都是空的,然后google了一下,$refs需要在整个组件挂载完成后才能使用 解决方法:使用setTimeout setTImeo ...
- 剑指Offer_编程题_18
题目描述 操作给定的二叉树,将其变换为源二叉树的镜像. 输入描述: 二叉树的镜像定义:源二叉树 8 / \ 6 10 / \ / \ 5 7 9 11 镜像二叉树 8 / \ 10 6 / \ / \ ...