<template>
    <BasicModal v-bind="$attrs" @register="registerModal" destroyOnClose :title="信息填报" :width="800" @ok="handleSubmit">
    <BasicTable @register="registerTable" >

          <template #bodyCell="{ column, record,index }">
          <template v-if="column.key === 'index'">{{ index+1 }}</template>
            <template v-if="column.key === 'fileUploadPath'&&record.fileUploadPath ">
              <JEllipsisFormat :isLink="true"  :value="record.fileUploadPath.substring(record.fileUploadPath.lastIndexOf('/')+1)" :length="60" @click="goToFile(record)"/>
            </template>
            <template v-if="column.key === 'fileUploadPathModel' &&record.fileUploadPathModel  ">
              <JEllipsisFormat :isLink="true"  :value="record.fileUploadPathModel.substring(record.fileUploadPathModel.lastIndexOf('/')+1)" :length="60" @click="goToFileM(record)"/>
            </template>
          </template>
    </BasicTable>
    </BasicModal>

</template>

<script setup>
import { ref,toRaw } from 'vue';
import {BasicModal, useModalInner,useModal} from '/@/components/Modal';
import { list } from '../StProjectExecOne.api';
import {BasicTable} from '/@/components/Table';
import { useListPage } from '/@/hooks/system/useListPage';
import { downloadFile } from '/@/utils/common/renderUtils';
import JEllipsisFormat from './JEllipsisFormat.vue';
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.record);
});
const props = defineProps({
  projectCreId: '',
  projectName:''
});
function goToFile(record){
  if(!!record.fileUploadPath){
    downloadFile(record.fileUploadPath);
  }else{
    message.warning("无附件");
  }
}
function goToFileM(record){
  if(!!record.fileUploadPathModel){
    downloadFile(record.fileUploadPathModel);
  }else{
    message.warning("无附件");
  }
}
const columns = [
    {
    title: '序号',
    align:"left",
    key: 'index',
    dataIndex: 'index',
  },
   {
    title: '资料检查',
    align:"left",
    dataIndex: 'checkReview'
   },
      {
    title: '部门',
    align:"left",
    dataIndex: 'fileUploadDep'
   },
         {
    title: '责任人',
    align:"left",
    dataIndex: 'fileUploadUser'
   },
   {
    title: '上传日期',
    align:"left",
    dataIndex: 'fileUploadDate',
    customRender:({text}) =>{
      return !text?"":(text.length>10?text.substr(0,10):text)
    },
   },
   {
    title: '上传文件',
    align:"left",
    dataIndex: 'fileUploadPath'
   },
];
const { prefixCls,tableContext,onExportXls,onImportXls } = useListPage({
      tableProps:{
           title: '查看相关文件',
           api: list,
           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})
            },
      },
  })
  const [registerTable, {setProps,reload},{ rowSelection, selectedRowKeys }] = tableContext
    async function handleSubmit(v) {
        try {
            setModalProps({confirmLoading: true});
            //提交表单
            //关闭弹窗
            closeModal();
            //刷新列表
            emit('success');
        } finally {
            setModalProps({confirmLoading: false});
        }
    }
  function handleSuccess(record){
    reload();
  }
      defineExpose({setProps,reload})

</script>