在table列表内写开关,下拉框操作

<template>
    <div>
      <a-table
        ref="table"
        size="middle"
        bordered="bordered"
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange"
     >

          
         <span slot="selectType" slot-scope="text, record, index">
           <a-select
             style="width: 65%"        
             :value="text"
             placeholder="请选择类型"
             @change="e => handleChange(e, index)"
           >
              <a-select-option value="">请选择类型</a-select-option>
              <a-select-option value="ZX">
                中性
              </a-select-option>
              <a-select-option value="XX">
              小型
              </a-select-option>
            </a-select>
          </span>


            <span slot="isKey" slot-scope="text, record">
          //一个点击事件 并传值
             <a-switch
                @click="handleIsKey(record)"
                 :checked="record.isKey=== 'Y' ?  true : false"/>
          </span>
        </a-table>
    </div>
</template>
<script>
export default {
 name: "Modal",
 data () {
    return {
//定义全局的值,方便传参
     type: '',
     isKey:'',
  columns: [
          {
              title: '状态',
              dataIndex: 'isKey',
              ellipsis: true,
              align:"center",
              customRender:function (t, r, index) {
                if (t === 'Y') {
                  return "打开";
                } else if (t === 'N') {
                  return "关闭";
                }
          },
          {
              title: '类型',
              ellipsis: true,
              dataIndex: 'type',
              align: 'center',
              scopedSlots: { customRender: 'selectType' }
        },
       ]
      },
    },
  methods: {
     handleChange(value, index) {
          this.dataSource[index].type = value
          this.$forceUpdate()
          this.type = this.dataSource[index].type
          console.log( this.type, '输出类型')
     },
     handleIsKey(record) {
          this.loading = true
          //判断传入的参数
          if(record.isKey === 'Y'){
            this.isKey = 'N'
          }else{
            this.isKey = 'Y'
     },
     if (!this.type) {
          this.$message.error('请选择类型')
          this.loadData(1)
          return false
      }
      let params = {
          isKey: this.isKey,
          type: this.type,
      };
      putAction("/modal/modal/edit" ,params).then((res) => {
        if (res.success) {
          if(res.success){
            this.$message.success(res.message)
          }else{
            this.$message.error(res.message)
          }
          this.loadData()
        }else{
          this.loading = false
          this.$message.error("开启失败,请稍后重试!")
        }
      })
    }
   }
  }
</script>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值