vue 自定义el-table穿梭框功能

一、需求描述:前段时间接到一个需求是点击做一个类似穿梭框的表格点击选中功能,弹框的左边是全部数据展示,点击表格行数据可以选中自动增加到右边的已选框,并且可以手动删除、重置选中数据。点击确定后到展示到主页面,被选中的数据打开弹框不能再次选择。

二、界面展示:功能如下图所示:

  • 主页面没有选中的数据时,展示如下:

  •  弹框页面,展示如下:

  •  选中后主页面的数据显示如下:

  •  再次点击添加学生成绩按钮,之前选中数据不可再点击,如下图:

 三、代码实现:

  1. 首页面表格主键是orderId ,主页面代码:
    <div class="content-box"><div class="table-title flex-between"><span>学生成绩信息</span> <div style="text-align:end"><el-button plain type="primary" @click="delSomeMedic()">批量删除</el-button><el-button type="primary" @click="addMedic()">添加学生成绩</el-button></div></div><div class="single-table"><el-table ref="table" size="mini" height="100%" :data="tableData.adrDrugInfos" :header-cell-style="{background: '#fff',height:'40px'}" border@selection-change="handleSelectionChange"><el-table-column type="selection" width="40"> </el-table-column><el-table-column prop="dose" label="姓名" show-overflow-tooltip></el-table-column><el-table-column prop="suspectedConcomitant" label="是否住校" show-overflow-tooltip width="100"><template #default="scope"><span v-if="scope.row.suspectedConcomitant == '1'">住校生</span><span v-if="scope.row.suspectedConcomitant == '2'">非住校生</span></template></el-table-column><el-table-column prop="doseUnit" label="数学" show-overflow-tooltip></el-table-column><el-table-column prop="frequency" label="语文" show-overflow-tooltip></el-table-column><el-table-column prop="routeName" label="英语" show-overflow-tooltip></el-table-column><el-table-column prop="reasonForUse" label="备注" show-overflow-tooltip></el-table-column><el-table-column label="操作" header-align="center" width="200" align="center" fixed="right"><template slot-scope="scope"><el-button size="small" style="color: #409eff; padding: 0" type="text" @click="editMedic(false,scope.row)">成绩详情</el-button><el-button size="small" style="color: #409eff; padding: 0" type="text" @click="editMedic(true,scope.row)">编辑</el-button><el-button size="small" style="color: #409eff; padding: 0" type="text" @click="delMedic(scope.row)">删除</el-button></template></el-table-column></el-table></div>
    </div>//-----------------------------------------------------------------------------
    // 新增学生成绩信息addMedic() {if (this.tableData.healthEventId == '') {return this.$message.warning('请先选择学生')} else {this.$refs.addMedicDialog.open(this.tableData.adrDrugInfos,this.tableData.healthEventId,this.tableData.visitType)}},// 删除学生成绩信息delMedic(row) {this.$Confirm({ type: 'delete' }).then((e) => {this.tableData.adrDrugInfos.map((item, index) => {if (item.orderId == row.orderId) {this.tableData.adrDrugInfos.splice(index, 1)this.$message.success('删除成功!')}})}).catch((err) => {console.log(err)})},
    //选中学生成绩信息数据handleSelectionChange(val) {this.selectedMedicData = val},
    // 批量学生成绩信息delSomeMedic() {if (this.selectedMedicData.length <= 0) {return this.$message.warning('请先选择学生成绩信息')}this.$Confirm({ type: 'delete' }).then((e) => {this.selectedMedicData.forEach((val) => {this.tableData.adrDrugInfos.forEach((v, i) => {if (val.orderId == v.orderId) {this.tableData.adrDrugInfos.splice(i, 1)this.$message.success('删除成功!')}})})}).catch((err) => {console.log(err)})},
    // 选择学生成绩信息回显getMedicalData(data) {data.forEach((item) => {this.tableData.adrDrugInfos.push({orderId: item.orderId||'',suspectedConcomitant: item.suspectedConcomitant||'',dose: item.onceDosage||'',doseUnit: item.dosageunitName||'',frequency: item.freqDesc||'',routeName: item.defaultUsageCode||'',formName: item.drugForm||'',reasonForUse: item.reasonForUse||'',})})},
  2. 弹框页面数据主键是orderId,弹框页面代码:
    <template><el-dialogtitle="添加学生成绩":visible.sync="dialogVisible":close-on-click-modal="false"@close="close"append-to-bodytop="10vh !important"width="90%"><div class="box-wrapper"><div class="single-table-container left-table"><div class="search-form-wrapper"><div class="title">学生成绩列表</div><div class="seach_list"><el-inputprefix-icon="el-icon-search"placeholder="学生姓名"v-model="searchForm.onceDosage"size="mini"clearable></el-input><el-date-pickerv-model="dateTime"type="daterange"value-format="yyyy-MM-dd"format="yyyy-MM-dd"range-separator="—"@change="changeDateTime"start-placeholder="在校开始时间"end-placeholder="在校结束时间"></el-date-picker><el-button type="primary" size="mini" @click="searchTable">查询</el-button></div></div><div class="single-table"><el-tableref="leftTable"v-loading="tableLoading"size="mini"height="370px":data="tableData"striperow-key="orderId"tooltip-effect="dark":header-cell-style="{background: '#f5f7fa',fontWeight: 'bold',color: '#303133'}"border@selection-change="handleSelectionChange"@row-click="handleClickTableRow"><el-table-columntype="selection"width="40":reserve-selection="true":selectable="handleSelected"></el-table-column><el-table-columntype="index"header-align="center"align="center"label="序号"width="50"></el-table-column><el-table-columnprop="onceDosage"label="姓名"show-overflow-tooltipwidth="120":formatter="formartTableField"></el-table-column><el-table-columnprop="startDateTime"label="在校开始时间"show-overflow-tooltipwidth="100":formatter="formartTableField"></el-table-column><el-table-columnprop="stopDateTime"label="在校结束时间"show-overflow-tooltipwidth="100":formatter="formartTableField"></el-table-column><el-table-columnprop="dosageunitName"label="数学"show-overflow-tooltip:formatter="formartTableField"></el-table-column><el-table-columnprop="freqDesc"label="语文"show-overflow-tooltip:formatter="formartTableField"></el-table-column><el-table-columnprop="defaultUsageCode"label="英语"show-overflow-tooltip:formatter="formartTableField"></el-table-column></el-table></div><div class="table-pagination"><el-paginationclass="pagination"@current-change="handleCurrentChange":current-page="pages.pageIndex":page-size="pages.pageSize"layout="total,prev, pager, next":total="pages.total"></el-pagination></div></div><div class="single-table-container right-table"><div class="search-form-wrapper"><div class="title">已选学生</div></div><div class="single-table"><el-form:model="selectedForm"ref="selectedForm":rules="selectedForm.rules"><el-tableref="rightTable"size="mini"height="410px":data="selectedForm.selectedData"stripetooltip-effect="dark":header-cell-style="{background: '#f5f7fa',fontWeight: 'bold',color: '#303133'}"border><el-table-columntype="index"header-align="center"align="center"label="序号"width="50"></el-table-column><el-table-columnprop="onceDosage"label="姓名"width="120"show-overflow-tooltip></el-table-column><el-table-columnlabel="住校生/非住校生"show-overflow-tooltipwidth="188"><template #default="scope"><el-form-item:prop="'selectedData.' + scope.$index + '.suspectedConcomitant'"><el-radio-groupv-model="scope.row.suspectedConcomitant"size="mini"><el-radio label="1">住校生</el-radio><el-radio label="2">非住校生</el-radio></el-radio-group></el-form-item></template></el-table-column><el-table-column label="选择原因" show-overflow-tooltip><template #default="scope"><el-form-item:prop="'selectedData.' + scope.$index + '.reasonForUse'":rules="selectedForm.rules.reasonForUse"><el-inputplaceholder="请输入"v-model="scope.row.reasonForUse"clearable></el-input></el-form-item></template></el-table-column><el-table-columnlabel="操作"header-align="center"align="center"width="80"><template slot-scope="scope"><el-buttonsize="small"style="color: #409eff; padding: 0"type="text"@click="del(scope.row)">删除</el-button></template></el-table-column></el-table></el-form></div></div></div><span slot="footer" class="dialog-footer"><el-button @click="reset">重置</el-button><el-button :loading="btn_loading" type="primary" @click="submit">确认</el-button></span></el-dialog>
    </template>
    <script>
    import { getAdviceRec } from '@/api/adr/report-manage-service'export default {components: {},data() {return {dialogVisible: false,tableLoading: false,btn_loading: false,healthEventId: '',visitType: '',searchForm: {onceDosage: '',startDateTime: '',stopDateTime: ''},dateTime: [],selectedForm: {selectedData: [],rules: {reasonForUse: [{ required: true, message: '请输入选中学生的原因', trigger: 'blur' }]}},pages: {pageIndex: 1,pageSize: 10,total: 0},tableData: [{orderId: 1,onceDosage: '张三',startDateTime: '2020-01-01',stopDateTime: '2023-01-01',dosageunitName: '98',freqDesc: '95',defaultUsageCode: '99'},{orderId: 2,onceDosage: '李四',startDateTime: '2020-01-01',stopDateTime: '2023-05-01',dosageunitName: '100',freqDesc: '92',defaultUsageCode: '95'},{orderId: 3,onceDosage: '王五',startDateTime: '2021-01-01',stopDateTime: '2023-02-01',dosageunitName: '98',freqDesc: '95',defaultUsageCode: '100'},{orderId: 4,onceDosage: '赵六',startDateTime: '2021-06-01',stopDateTime: '2024-01-01',dosageunitName: '98',freqDesc: '100',defaultUsageCode: '90'}],pSelectedData: [] // 父级数据}},methods: {open(data, healthEventId, visitType) {this.healthEventId = healthEventId || ''this.visitType = visitType || ''this.dialogVisible = trueif (!!data && data.length > 0) {this.pSelectedData = data} else {this.pSelectedData = []}this.initTable()},initTable() {this.tableLoading = truelet params = {current: this.pages.pageIndex,size: this.pages.pageSize,visitType: this.visitType,healthEventId: this.healthEventId,startDateTime: this.searchForm.startDateTime,stopDateTime: this.searchForm.stopDateTime,onceDosage: this.searchForm.onceDosage}params = useKyyDelNullProperty(params)getAdviceRec(params).then((res) => {if (res.code == 200) {this.tableLoading = falsethis.tableData = res.result.recordsthis.pages.total = res.result.total// 默认在校this.tableData.forEach((item) => {this.$set(item, 'suspectedConcomitant', '1')})// 固定对齐表格this.$nextTick(() => {this.$refs.leftTable.doLayout()})} else {this.$message.error(`错误:${res.message}`)}}).catch((err) => {})setTimeout(() => {this.tableLoading = false}, 5000)},handleSelectionChange(val) {this.selectedForm.selectedData = val},close() {this.dialogVisible = falsethis.searchForm.onceDosage = ''this.searchForm.startDateTime = ''this.searchForm.stopDateTime = ''this.reset()},reset() {this.btn_loading = falsethis.$refs.leftTable.clearSelection()},// 删除del(row) {// 取消选中this.selectedForm.selectedData.map((item, index) => {if (item.orderId == row.orderId) {this.selectedForm.selectedData.splice(index, 1)this.$refs.leftTable.toggleRowSelection(row, false)}})},// 点击行勾选数据handleClickTableRow(row, event, column) {if (!this.handleSelected(row)) return falseif (this.selectedForm.selectedData.length > 0) {// 如果结果数组不为空,判断所选的这条是否在结果数组里if (JSON.stringify(this.selectedForm.selectedData).indexOf(JSON.stringify(row.orderId)) == -1) {this.selectedForm.selectedData.push(row)this.$refs.leftTable.toggleRowSelection(row, true)} else {// 取消选中this.selectedForm.selectedData.map((item, index) => {if (item.orderId == row.orderId) {this.selectedForm.selectedData.splice(index, 1)this.$refs.leftTable.toggleRowSelection(row, false)}})}} else {this.selectedForm.selectedData.push(row)this.$refs.leftTable.toggleRowSelection(row, true)}},// 已选数据不可再选,通过比较orderId 是否一致handleSelected(row, index) {if (this.pSelectedData?.length > 0) {if (this.pSelectedData.some((el) => {return el.orderId == row.orderId})) {return false} else {return true}} else {return true}},submit() {this.btn_loading = trueif (this.selectedForm.selectedData.length > 0) {this.$refs.selectedForm.validate(async (valid) => {if (valid) {this.$emit('getMedicalData', this.selectedForm.selectedData)this.close()this.$message.success('操作成功')} else {return this.$message.warning('请输入选择原因')}})} else {this.$message.warning('请选择要添加的学生成绩信息')}this.btn_loading = false},// 分页栏handleCurrentChange(val) {this.pages.pageIndex = valthis.initTable()},formartTableField(row, column, cellValue, index) {if (cellValue) {return cellValue}return '-'},changeDateTime(data) {if (data) {this.searchForm.startDateTime = data[0]this.searchForm.stopDateTime = data[1]} else {this.searchForm.startDateTime = ''this.searchForm.stopDateTime = ''}},// 查询searchTable() {if (!!this.dateTime && this.dateTime.length > 0) {this.searchForm.startDateTime = this.dateTime[0]this.searchForm.stopDateTime = this.dateTime[1]}this.pages.pageIndex = 1this.initTable()}}
    }
    </script>
    <style lang="scss" scoped>
    .box-wrapper {font-size: 14px;display: flex;justify-content: space-between;.left-table {width: 51%;padding: 0;}.right-table {width: 48%;padding: 0;.el-input {width: 100%;}.el-form-item {margin: 0;}.el-radio-group {:deep(.el-radio) {margin-right: 10px;.el-radio__label {font-size: 12px;padding-left: 10px;}}}}
    }
    </style>
    

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://xiahunao.cn/news/352298.html

如若内容造成侵权/违法违规/事实不符,请联系瞎胡闹网进行投诉反馈,一经查实,立即删除!

相关文章

Java核心知识点常考面试题(持续更新中)

Java核心知识点常考面试题&#xff08;持续更新中&#xff09; 线程与线程池Java锁机制轻量级锁重量级锁 线程与线程池 一、线程 1、线程的状态 2、线程的创建方式 &#xff08;1&#xff09;继承 Thread 类&#xff1b; &#xff08;2&#xff09;实现 Runnable 接口&#…

IDEA2023.1配置Git

一、前言 在使用新设备整理git项目时&#xff0c;报了以下问题&#xff0c;在整理项目的同时&#xff0c;做下记录。 二、下载git 2.1.官网下载git 官网下载地址&#xff1a; git官网&#xff0c;如下图所示&#xff1a; 如果选方法二&#xff0c; 接下来会让选择系统&#…

【cocos精品】《三国之刃》:腾讯首款三国炫技格斗手游

基于cocos引擎开发的《三国之刃》是腾讯独家代理的三国题材的动作格斗手游。独创的自由组合战技系统&#xff0c;配合特色的兵器和灵兽技能&#xff0c;可搭配出上万种格斗套路&#xff0c;让您的战斗酣畅淋漓又变幻莫测。清爽灵活的操作&#xff0c;无锁定技术PK&#xff0c;更…

java开发街机三国志_入坑必看《街机三国志》游戏初期重点讲解

《街机三国志》为了让新手更好的了解游戏&#xff0c;设立里相关的新手指引&#xff0c;引导新入门的玩家完成各种任务与基础的系统教学。只凭新手教学是没办法在初期阶段积累足够的资源的。本次小编特意整理了一些新手教程中没有提及的重点&#xff0c;希望帮助玩家们更好的开…

搜索引擎三国鼎立:百度 vs 360 vs 搜狗

理论上说&#xff0c;搜索市场不存在平分秋色的可能&#xff0c;不管份额如何接近&#xff0c;最终必然是东风压倒西风&#xff0c;这一点在全球市场都未见过反例。雅虎在日本和台湾独占鳌头&#xff0c;Naver在韩国有压倒性优势&#xff0c;Yandex称霸俄罗斯。谷歌在全球大部分…

街机三国志隐藏人物刘备_隐藏的人物

街机三国志隐藏人物刘备 最初的程序员的故事将永远不为人知 背后没有外套的男人是梅尔凯&#xff08;Mel Kaye&#xff09;&#xff0c;埃德纳瑟&#xff08;Ed Nather&#xff09;为他写了他永恒的程序员绝版经典著作《故事》 。 那一年是1960年&#xff0c;尽管存在有关他编…

Java霸王的大陆梦幻版_三国志霸王的大陆,喜欢三国的进

三国是中国历史上英雄辈出的时代&#xff0c;《霸王的大陆》这款移植自Fc的战棋游戏更是中国手游java游戏的No.1!该游戏内容极其丰富&#xff0c;对玩家的要求很高&#xff0c;因此这完全是一款符合游戏高手要求的大型单机游戏。以下是这款游戏的核心攻略&#xff0c;只要稍加留…

无可用下载链接_经典大全合集500个街机游戏大全下载

经典大全合集500个街机游戏大全下载 WinKawaks1.45模拟器 游戏链接 链接:https://pan.baidu.com/s/1MZ3_Gv825dtswcGXr006zQ 提取码:zhrk 一、游戏介绍

linux模拟器玩三国战记,三国战纪风云再起街机版

三国战纪风云再起街机版带你回忆最初玩三国街机游戏的乐趣,多种对战玩法轻松上手,在三国战纪风云再起街机版手机游戏里面玩家可以随便选择一个角色进入战斗,强烈的打击感绝对让你爱不释手,在指尖畅享超酷的格斗盛宴。 三国战纪风云再起街机版介绍 三国战纪风云再起街机版是…

智勇三国

视频: http://you.video.sina.com.cn/a/4806164-1488862174.html 8M的客户端下载地址: 一,http://yule.hedanwang.cn/sanguozhi/sanguozhi_864.htm 二,QQ群:100410266 的群共享下载 智勇三国是单机游戏三国群英传2的简单化、网络化、智能化。简单化指的是保留精华&#xff0c…

小时候玩的10款经典街机游戏,如今我们都在玩什么?

很多的人的童年&#xff0c;都是伴随着游戏度过的。尤其是8090后。今天就列举10款经典的大型街机游戏&#xff0c;跟大家一起回忆一下童年时光&#xff0c;不信没有你玩过的&#xff01; 1、《拳皇》 小时候小编最喜欢的大型对战格斗型街机游戏之一&#xff0c;一阵猛如虎的操…

toFixed精度丢失问题

bug说明&#xff1a; 10.3950 * 3935.00 用toFixed&#xff08;2&#xff09; 得到的是40904.32 实际应该是40904.33 解决的方法&#xff1a; 第一种&#xff1a; 在main.js中直接复制下面代码即可 Number.prototype.toFixed function (n) {n n || 0let resNum Math.ro…

深浅拷贝及赋值区别理解

浅拷贝&#xff1a; 对象浅拷贝Object.assign() 数组的浅拷贝Array.prototype.slice()与Array.prototype.concat() 解构赋值 1.对于数组/对象中基本数据类型[123,234]&#xff0c;拷贝的是数值&#xff0c;所以修改拷贝后的这个值&#xff0c;原数据不会改变&#xff1b;2.对…

谷歌浏览器手动设置Cookie

1、Chrome中访问地址chrome://flags 2、搜索Partitioned cookies将设置项改为Enabled即可&#xff0c; 3、重启浏览器&#xff0c;手动添加cookie将会保留&#xff0c;且不会标红

JavaScript网页cookie的“简单”设置

今天学习了“网页cookie”的简单设置&#xff0c; 这是一个&#xff0c;登录模型的简单设置&#xff0c;因为连接了"数据库"&#xff0c;刷新的时候会一直“重复”让输入&#xff0c;很繁琐&#xff0c;结果查找了&#xff0c;一些 网页Cookie的设置方法&#xff0c…

HTTP篇之cookie设置(前端和后台)

前台代码&#xff1a; var xhr new XMLHttpRequest(); xhr.open(GET,http://localhost:3000/list); xhr.withCredentials true; xhr.send(); XMLHttpRequest发送请求时需要设置withCredentials属性为true,来允许浏览器在自己的域设置cookie值。 如果withCredentials没有设…

职场已是00后的天下了,起薪20k,想都不敢想

2023年很卷吗&#xff1f;不&#xff0c;只能说你还得学&#xff01; 都说00后已经躺平了&#xff0c;但是有一说一&#xff0c;该卷的还是卷&#xff01; 这不&#xff0c;前段时间我们公司新招来了一个00后小伙&#xff0c;工作都没2年&#xff0c;跳槽到我们公司就起薪20K&…

cookie设置HttpOnly

1.什么是HttpOnly? 如果cookie中设置了HttpOnly属性&#xff0c;那么通过js脚本将无法读取到cookie信息&#xff0c;这样能有效的防止XSS攻击&#xff0c;窃取cookie内容&#xff0c;这样就增加了cookie的安全性&#xff0c;即便是这样&#xff0c;也不要将重要信息存入cookie…

如何为cookie设置HttpOnly

将cookie设置成HttpOnly是为了防止XSS攻击&#xff0c;窃取cookie内容&#xff0c;这样就增加了cookie的安全性&#xff0c;即便是这样&#xff0c;也不要将重要信息存入cookie。 如何在Java中设置cookie是HttpOnly呢&#xff1f; Servlet 2.5 API 不支持 cookie设置HttpOnly …

js登录设置cookie

COOKIE基础及应用 什么是COOKIE 1、记录用户信息&#xff0c; 通过 Cookie 来确定您是否已经登录过 2、比如你访问了购物网站&#xff0c;cookies记录了你的访问行为&#xff0c;广告主就能够根据你的访问行为&#xff0c;向你推送购物类的广告 COOKIE的特性 –同一个网站中,所…