<template>
  <div>
    <!--引用表格-->
    <BasicTable @register="registerTable" :rowSelection="rowSelection">
      <!--插槽:table标题-->
      <template #tableTitle>
        <!-- 每一个页面都有，无需配置权限 -->
        <a-button type="primary" @click="router.go(-1)">返回</a-button>
        <a-button type="primary" @click="view">查看基本信息</a-button>
      </template>
    </BasicTable>
  </div>
</template>

<script lang="ts" name="dkgl-gkpg-DetailList" setup>
  import { ref } from 'vue';
  import { BasicTable } from '/@/components/Table';

  import { useRouter } from 'vue-router';
  import { useMessage } from '/@/hooks/web/useMessage';
  import { useListPage } from '/@/hooks/system/useListPage';

  import { Fxcolumns } from '@/views/dkgl/fxpg/data';
  import { faList } from '/@/api/common/api';

  const router = useRouter();
  const { createMessage } = useMessage();

  const param = ref(router.currentRoute.value.query);

  //注册table数据
  const { tableContext } = useListPage({
    tableProps: {
      title: '基本信息列表',
      api: faList,
      beforeFetch(params) {
        params.wrdkid = param.value.wrdkid;
        params.scjdbm = param.value.scjdbm;
        params.jdnzt = param.value.jdnzt;
        params.pgtype = param.value.pgtype;

        let res = [...Fxcolumns];
        res.splice(4, 0, {
          title: '地块是否超标',
          dataIndex: 'sfcb',
          resizable: true,
          customRender: ({ record }: any) => {
            return record?.sfcb==='1'?'是':record?.sfcb==='0'?'否':'未调查';
          },
        });
        res.splice(5, 0, {
          title: '地块锁定状态',
          dataIndex: 'dksdztText',
          resizable: true,
        });
        setColumns(res);
      },
      columns: Fxcolumns,
      canResize: false,
      useSearchForm: false,
      rowKey: 'id',
      rowSelection: { type: 'radio' },
      clickToRowSelect: true,
      showActionColumn: false,
      actionColumn: {
        width: 120,
      },
    },
  });
  const [registerTable, { setColumns }, { rowSelection, selectedRowKeys, selectedRows }] = tableContext;

  // 查看基本信息
  function view() {
    if (selectedRowKeys.value.length == 0) {
      createMessage.info('请选择需要处理的内容，每次只能选中一条');
      return;
    }
    router.push(
      `/zjgl/expert/ViewDetail?wrdkid=${selectedRows.value[0].wrdkid}&id=${selectedRows.value[0].id}&pgtype=${selectedRows.value[0].pgtype}&scjdbm=${selectedRows.value[0].scjdbm}&dksdzt=1`
    );
  }
</script>
<style scoped></style>
