<template>
    <BasicModal v-bind="$attrs" @register="registerModal" destroyOnClose :title="'查看问题清单'" :width="800" @ok="handleSubmit">

    <BasicTable @register="registerTable" >
    <template #tableTitle>
        <a-button type="primary" preIcon="ant-design:export-outlined" @click="onDefHandlerExportXls">导出问题清单</a-button>
    </template>
          <template #bodyCell="{ column, record,index }">
          <template v-if="column.key === 'index'">{{ index+1 }}</template>
          </template>
    </BasicTable>
    </BasicModal>

</template>

<script setup>
import { ref,toRaw } from 'vue';
import {BasicModal, useModalInner,useModal} from '/@/components/Modal';
import { proList,getExportUrl } from '../StProjectExecFour.api';
import {BasicTable} from '/@/components/Table';
import { useListPage } from '/@/hooks/system/useListPage';
import { useMethods } from '/@/hooks/system/useMethods';
const { handleExportXls } = useMethods();
const proCreData = ref({})
const emit = defineEmits(['register','success']);
const showBt=ref(true)
const [registerModal, {setModalProps, closeModal}] = useModalInner(async (data) => {
    showBt.value=!!data?.showFooter;
    proCreData.value = Object.assign({},data.complianeInfoRecord);
});
const props = defineProps({
  projectCreId: '',
  projectName:''
});
const columns = [
    {
    title: '序号',
    align:"left",
    key: 'index',
    dataIndex: 'index',
  },
   {
    title: '控制活动',
    align:"left",
    dataIndex: 'caName'
   },
      {
    title: '问题项',
    align:"left",
    dataIndex: 'problemItem'
   },
         {
    title: '问题描述',
    align:"left",
    dataIndex: 'problemExample'
   },
   {
    title: '风险等级',
    align:"left",
    dataIndex: 'damageLevel'
   },
   {
    title: '风险评分',
    align:"left",
    dataIndex: 'damageScore'
   },
   {
    title: '提出人',
    align:"left",
    dataIndex: 'proUserName'
   },
];
const { prefixCls,tableContext,onExportXls,onImportXls } = useListPage({
      tableProps:{
           title: '查看问题清单',
           api: proList,
           columns,
         canResize:false,
         useSearchForm: false,
         showIndexColumn: false,
         scroll: { x: false },
          showTableSetting: false,
          actionColumn: {ifShow: false},
          beforeFetch(params) {

              params = Object.assign(params,{projectCreId:proCreData.value.projectCreId})
            },
      },
  })
  function onDefHandlerExportXls(){
    console.log(proCreData);
  return handleExportXls(proCreData.value.projectName+'项目问题清单', getExportUrl, {projectCreId:proCreData.value.projectCreId});
}
  const [registerTable, {setProps,reload},{ rowSelection, selectedRowKeys }] = tableContext
    async function handleSubmit(v) {
        try {
            setModalProps({confirmLoading: true});
            //提交表单
            //关闭弹窗
            closeModal();
            //刷新列表
            emit('success');
        } finally {
            setModalProps({confirmLoading: false});
        }
    }
      defineExpose({setProps,reload})

</script>