ant design vue3 嵌套表格的用法

<a-table

      :dataSource="dataSource"

      :columns="columns"

      :pagination="pagination"

      @change="tableChange"

      rowKey="id"

      @expand="expandChange"

    >

      <template #bodyCell="{ record, column, index }">

        <div v-if="column.dataIndex === 'index'">{{ index + 1 }}</div>

        <template v-if="column.key === 'actions'">

         <a-button type="link" @click="addRentEvent(record.id)">添加合同</a-button>

          <a-popconfirm

           title="是否确认删除当前数据?"

           ok-text="确认"

           cancel-text="取消"

           @confirm="confirm(record.id)"

           @cancel="cancel"

           >

         <a href="#">删除</a>

         </a-popconfirm>

        </template>

      </template>

      <template #expandedRowRender>

        <a-table

        slot="expandedRowRender"

        slot-scope="record, index, indent, expanded"

        :columns="innerColumns"

        :data-source="innerData"

        :pagination="false"

      >

      <!-- 合同的租赁状态0待生效1生效中2已到期3已退租

生效中,只能续签一次,续签后,续签的合同退租后,才可以退租 -->

      <template #bodyCell="{ column, record }">

        <template v-if="column.key === 'operation'">

          <a-button type="link" @click="reletChange">续租</a-button>

        </template>

        <template v-if="column.key === 'rangeTimer'">

        <span>{{ record.startTime }}至{{ record.endTime }}</span>

        </template>

        <template v-if="column.key === 'status'">

          <a-button class="custom-btn1" size="small" v-if="record.status === 0" style="color:">待生效</a-button>

          <a-button class="custom-btn2" size="small" v-if="record.status === 1">生效中</a-button>

          <a-button class="custom-btn3" size="small" v-if="record.status === 2">已到期</a-button>

          <a-button class="custom-btn4" size="small" v-if="record.status === 3">已退租</a-button>

        </template>

      </template>

    </a-table>

      </template>

    </a-table>

// 放父表格数据的数组

const dataSource = ref<any[]>([]);

// 放子表格的数组

const innerData = ref<any>([]);

const columns = ref([

  {

    title: '序号',

    dataIndex: 'index',

    key: 'index',

  },

  {

    title: '企业名称',

    dataIndex: 'name',

    key: 'name',

  },

  {

    title: '联系人',

    dataIndex: 'contact',

    key: 'contact',

  },

  {

    title: '联系电话',

    dataIndex: 'contactNumber',

    key: 'contactNumber',

  },

  {

    title: '操作',

    // 操作这一列不需要dataIndex,因为dataIndex是去渲染dataSource这个数组里面的元素的键的值的

    // dataIndex: 'cardStatus',

    key: 'actions',

  },

]);

const innerColumns = [

  { title: '租赁楼宇', dataIndex: 'buildingName', key: 'buildingName' },

  { title: '租赁起止时间', dataIndex: 'rangeTimer', key: 'rangeTimer' },

  { title: '合同状态', dataIndex: 'status', key: 'status' },

  {

    title: '操作',

    key: 'operation',

    scopedSlots: { customRender: 'operation' },

  },

];

const pagination = computed(() => ({

  position: ['bottomRight'],

  total: total1.value,

  current: formState.page,

  pageSize: formState.pageSize,

  showQuickJumper: true, // 是否显示跳转的结构

  showSizeChanger: true, // 显示每页显示条数切换器,下拉框

  pageSizeOptions: ['2', '3', '5', '10'],

  showTotal: (total: number) => ` 共${total} 条`,

}));

// table内置的分页插件,触发事件change

const tableChange = (pagination: any) => {

  formState.page = pagination.current;

  formState.pageSize = pagination.pageSize;

  search();

};

// 企业列表

const search =  async() => {

  const res = await getEnterpriseRequest({

    page:formState.page,

    pageSize: formState.pageSize,

    name:formState.name

  });

  console.log(res, '企业列表');

  dataSource.value = res.data.rows;

  total1.value = res.data.total;

};

search()

// * 功能:点击某行加号,加载子表格数据  // 点开子级表格(就是点击那个加号)触发的函数

// * 参数:expanded:是否展开

// * 参数:record:点击行的数据

const expandChange = (expanded:any, record:any) => {

console.log(expanded, record.id, '得到的数据');

if(!expanded) return

rentEnterpriseList(record.id)

}

// 企业租赁信息列表-展开

const rentEnterpriseList = async(id:any) => {

  const res = await rentEnterpriseListRequest(id)

  console.log(res, '获取企业租赁信息列表');

  innerData.value = res.data

}

  • 29
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值