<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 emit = defineEmits(['handClick']);
  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;

        let res = [...Fxcolumns];
        if (param.value.scjdbm === 'S5') {
          res.splice(0, 1, {
            title: '修复标题',
            dataIndex: 'bt',
            resizable: true,
          });
        } else if (param.value.scjdbm === 'S4') {
          res.splice(0, 1, {
            title: '风险管控标题',
            dataIndex: 'bt',
            resizable: true,
          });
        } else if (param.value.scjdbm === 'S10') {
          res.splice(0, 1, {
            title: '风险管控及修复标题',
            dataIndex: 'bt',
            resizable: true,
          });
        } else if (param.value.scjdbm === 'S6') {
          res.splice(0, 1, {
            title: '效果评估标题',
            dataIndex: 'bt',
            resizable: true,
          });
        }
        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;
    }
    emit('handClick', selectedRows);
  }
</script>
<style scoped></style>
