<template>
    <BasicModal v-bind="$attrs" @register="registerModal" destroyOnClose :title="信息填报" :width="800" @ok="handleSubmit">
    <BasicTable @register="registerTable" >
          <template #action="{ record }">
        <TableAction v-show="showBt"  :actions="getTableAction(record)" :dropDownActions="getDropDownAction(record)"/>
      </template>
          <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>
        <StProjectExecOneConfig @register="registerModalUpFile" @success="handleSuccess" />

</template>

<script setup>
import { ref,toRaw } from 'vue';
import {BasicModal, useModalInner,useModal} from '/@/components/Modal';
import { list } from '../StProjectExecOne.api';
import {BasicTable, TableAction} from '/@/components/Table';
import { useListPage } from '/@/hooks/system/useListPage';
import { downloadFile } from '/@/utils/common/renderUtils';
import JEllipsisFormat from './JEllipsisFormat.vue';
import StProjectExecOneConfig from './StProjectExecOneConfig.vue';
const [registerModalUpFile, {openModal:openModalUpFile}] = useModal();
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: 'des'
   },
   {
    title: '模板',
    align:"left",
    dataIndex: 'fileUploadPathModel'
   },
   {
    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 },
         actionColumn: {
             width: 160,
             ifShow: showBt
          },

          showTableSetting: false,
          beforeFetch(params) {
                        console.log('参数打印');

            console.log(proCreData.value);
              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();
  }
  function handleUpFile(record){
  openModalUpFile(true, {
       record:{id:record.id,projectCheckId:record.projectCheckId},
       uploadFiles: true,
       isUpdate: true,
       showFooter: true,
     });
}
  function getTableAction(record){
       return [
         {
           label: '上传',
           onClick: handleUpFile.bind(null, record),
         },
      ]
}
function getDropDownAction(record){
       return [
         
       ]
   }
      defineExpose({setProps,reload})

</script>