vue Transfer 穿梭框

Easter79
• 阅读 788

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

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

vue Transfer 穿梭框

实现思路:

  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>
点赞
收藏
评论区
推荐文章
blmius blmius
2年前
MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1
文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s
Jacquelyn38 Jacquelyn38
2年前
2020年前端实用代码段,为你的工作保驾护航
有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )
皕杰报表之UUID
​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为
Stella981 Stella981
2年前
Opencv中Mat矩阵相乘——点乘、dot、mul运算详解
Opencv中Mat矩阵相乘——点乘、dot、mul运算详解2016年09月02日00:00:36 \牧野(https://www.oschina.net/action/GoToLink?urlhttps%3A%2F%2Fme.csdn.net%2Fdcrmg) 阅读数:59593
Stella981 Stella981
2年前
KVM调整cpu和内存
一.修改kvm虚拟机的配置1、virsheditcentos7找到“memory”和“vcpu”标签,将<namecentos7</name<uuid2220a6d1a36a4fbb8523e078b3dfe795</uuid
Easter79 Easter79
2年前
Twitter的分布式自增ID算法snowflake (Java版)
概述分布式系统中,有一些需要使用全局唯一ID的场景,这种时候为了防止ID冲突可以使用36位的UUID,但是UUID有一些缺点,首先他相对比较长,另外UUID一般是无序的。有些时候我们希望能使用一种简单一些的ID,并且希望ID能够按照时间有序生成。而twitter的snowflake解决了这种需求,最初Twitter把存储系统从MySQL迁移
Wesley13 Wesley13
2年前
00:Java简单了解
浅谈Java之概述Java是SUN(StanfordUniversityNetwork),斯坦福大学网络公司)1995年推出的一门高级编程语言。Java是一种面向Internet的编程语言。随着Java技术在web方面的不断成熟,已经成为Web应用程序的首选开发语言。Java是简单易学,完全面向对象,安全可靠,与平台无关的编程语言。
Stella981 Stella981
2年前
Django中Admin中的一些参数配置
设置在列表中显示的字段,id为django模型默认的主键list_display('id','name','sex','profession','email','qq','phone','status','create_time')设置在列表可编辑字段list_editable
Wesley13 Wesley13
2年前
MySQL部分从库上面因为大量的临时表tmp_table造成慢查询
背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_
Python进阶者 Python进阶者
4个月前
Excel中这日期老是出来00:00:00,怎么用Pandas把这个去除
大家好,我是皮皮。一、前言前几天在Python白银交流群【上海新年人】问了一个Pandas数据筛选的问题。问题如下:这日期老是出来00:00:00,怎么把这个去除。二、实现过程后来【论草莓如何成为冻干莓】给了一个思路和代码如下:pd.toexcel之前把这
Easter79
Easter79
Lv1
今生可爱与温柔,每一样都不能少。
文章
2.8k
粉丝
5
获赞
1.2k