iView+Vue+SpringBoot多选

通过给 columns 数据设置一项,指定 type: 'selection',即可自动开启多选功能。

给 data 项设置特殊 key _checked: true 可以默认选中当前项。

给 data 项设置特殊 key _disabled: true 可以禁止选择当前项。

正确使用好以下事件,可以达到需要的效果:

  • @on-select,选中某一项触发,返回值为 selection 和 row,分别为已选项和刚选择的项。
  • @on-select-all,点击全选时触发,返回值为 selection,已选项。
  • @on-selection-change,只要选中项发生变化时就会触发,返回值为 selection,已选项。

前端: 

<template>
    <div class="base-wrap" style="overflow:auto;margin-bottom: 80px;"> 
 <Table ref="selection" :columns="columnsList" :data="dataList" :loading="isLoading"
                   @on-selection-change="tableSelectChange"
            >
            </Table>
    </div>
</template>


<script>


    export default {
        data() {
            return {
                columnsList: [
                    {
                        type: 'selection',
                        width: 60,
                        align: 'center'
                    },
                    {
                        title: '序号',
                        type: "index",
                    },
              ]
           }
     },
  
  methods: {
     tableSelectChange(selection,row){
                this.tableSelectIds = [];
                for(let i=0;i<selection.length;i++){
                    this.tableSelectIds.push(selection[i].orderId);
                }
                console.log("选中项:"+this.tableSelectIds);
            },
     batchAddAffiliation(){
                let self = this;
                if(this.tableSelectIds.length<=0){
                    self.$Message.error("请先选择!");
                }else{
                    let params = {
                  
                        'ids': JSON.stringify(this.tableSelectIds)
                    };
                    this.$http.put("/order/pay", params).then(res => {
                        if (res.code === 200) {
                            self.$Message.success("添加成功!");
                            this.getData();
                        } else {
                            self.$Message.error("添加失败!" + res.code+res.data);
                        }
                    });
                }
            }
}

后端:

  接收参数:

 

 @PutMapping("/pay")
    @Transactional
    public Result batchAddAffiliation(@RequestBody Map<String, Object> paramsMap) {
 JSONArray json = JSONObject.parseArray((String) paramsMap.get("ids"));
        String[] ids = new String[json.size()];
        ids = json.toArray(ids);
   ...


}

 mapper:

battachPay(@Param("ids")String[] ids);
 <if test="ids!=null and ids.length>0">
            AND order_id IN
            <foreach collection="ids" item="id" index="index" open="(" close=")" separator=",">
                #{id}
            </foreach>
</if>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值