<!--投资储备审批-->
<script setup lang="ts">
import {reactive, ref} from "vue";
import ApprovalAction from "/@/components/workbench/common/ApprovalAction.vue";
import ProjectBasicInfoView from '/@/components/investment/common/ProjectBasicInfoView.vue';
import {ProjectBasicInfoFormData} from "/@/components/investment/common/ProjectBasicInfoForm.vue";
import {
	getReserveInvestmentProjectDetailAPI,
	ReserveInvestmentProjectItem
} from "/@/api/investment/reserveRegistration";
import { useI18n } from 'vue-i18n';
import { useMessage } from '/@/hooks/message';
const { t } = useI18n();
const message = useMessage();
type ReserveProjectItem = ReserveInvestmentProjectItem & {
	projectMainUnit?: string;
	projectDirection?: string;
	projectStartDate?: string;
	projectEndDate?: string;
	investmentRegion?: string;
	lastUpdateTime?: string;
};
const createEmptyDetail = (): ProjectBasicInfoFormData => ({
	applicant: '',
	applicationUnit: '',
	projectName: '',
	projectMainUnit: '',
	projectStartDate: '',
	investmentCategory: '',
	projectManagerName: '',
	projectSource: '',
	keyProject: '',
	withinMainBusiness: '',
	mainBusinessType: '',
	projectDirection: '',
	strategicEmergingIndustry: '',
	isManufacturing: '',
	projectAddress: '',
	isControllingShareholder: '',
	totalInvestmentAmount: '',
	ourTotalInvestmentAmount: '',
	projectDesc: '',
	progressDesc: '',
	projectProposal: '',
	applicationDate: '',
	projectOwnerUnit: '',
	projectEndDate: '',
	projectNature: '',
	contactNumber: '',
	constructionNature: '',
	majorInvestmentProject: '',
	mainBusinessCode: '',
	directionSubdivision: '',
	urbanStrategy: '',
	investmentRegion: '',
	projectDetailedAddress: '',
	ourShareholdingRatio: '',
	cumulativeInvestmentLastYear: '',
	ourCumulativeInvestmentLastYear: '',
	enterpriseSelfFund: '',
	externalRaisedFund: '',
	governmentInvestmentFund: '',
	otherFunds: '',
	partnerInfos: [],
	decisionType: '',
	isCompleteEstablishmentProcedures: '',
	establishmentDocumentNumber: '',
	establishmentDocumentInfo: '',
	decisionProgramDocumentNumber: '',
	decisionDocumentInfo: '',
	isCompleteDecisionProcedures: '',
	processInstanceId: '',
	reviewOpinions: {
		submitUnitOpinion: '',
		groupInvestmentDeptOpinion: '',
		submitUnitLeadershipOpinion: '',
		submitUnitMainLeadershipOpinion: '',
	},
});
const detailFormData = reactive<ProjectBasicInfoFormData>(createEmptyDetail());
const normalizeDetailData = (detail: ReserveInvestmentProjectItem) => {
	const defaultValues = createEmptyDetail();
	const attachments = parseUploadValue(detail.attachmentUrl);
	Object.assign(detailFormData, defaultValues, {
		applicant: detail.createBy || '',
		applicationUnit: detail.projectOwnerUnit || '',
		applicationDate: detail.createTime ? detail.createTime.split(' ')[0] : '',
		projectName: detail.projectName || '',
		projectMainUnit: detail.projectMainEntity || '',
		projectOwnerUnit: detail.projectOwnerUnit || '',
		projectStartDate: detail.projectStartTime || '',
		projectEndDate: detail.projectEndTime || '',
		investmentCategory: detail.investmentCategory || '',
		projectNature: detail.projectNature || '',
		projectManagerName: detail.projectLeaderName || '',
		contactNumber: detail.projectLeaderPhone || '',
		projectSource: detail.projectSource || '',
		constructionNature: detail.constructionNature || '',
		keyProject: detail.keyProject || '',
		majorInvestmentProject: detail.majorInvestmentProjects || '',
		withinMainBusiness: detail.isMainBusiness || '',
		mainBusinessType: detail.mainBusinessTypes || '',
		mainBusinessCode: detail.mainBusinessCode || '',
		projectDirection: detail.projectInvestmentDirection || '',
		directionSubdivision: detail.investmentDirectionSegmentation || '',
		strategicEmergingIndustry: detail.isStrategicEmergingIndustries || '',
		urbanStrategy: detail.urbanStrategy || '',
		isManufacturing: detail.isManufacturingIndustry || '',
		investmentRegion: detail.investmentArea || '',
		projectAddress: detail.projectAddress || '',
		projectDetailedAddress: detail.projectAddressDetail || '',
		isControllingShareholder: detail.isControllingStake || '',
		ourShareholdingRatio: detail.shareholdingRatio ? String(detail.shareholdingRatio) : '',
		totalInvestmentAmount: detail.projectTotalAmount ? String(detail.projectTotalAmount) : '',
		cumulativeInvestmentLastYear: detail.lastYearCompleted ? String(detail.lastYearCompleted) : '',
		ourTotalInvestmentAmount: detail.ourInvestmentTotalAmount ? String(detail.ourInvestmentTotalAmount) : '',
		ourCumulativeInvestmentLastYear: detail.ourLastYearCompleted ? String(detail.ourLastYearCompleted) : '',
		projectDesc: detail.projectDesc || '',
		projectProposal: attachments,
		enterpriseSelfFund: detail.enterpriseOwnFunds ? String(detail.enterpriseOwnFunds) : '',
		externalRaisedFund: detail.externalRaisedFunds ? String(detail.externalRaisedFunds) : '',
		governmentInvestmentFund: detail.governmentInvestmentFunds ? String(detail.governmentInvestmentFunds) : '',
		otherFunds: detail.otherFunds ? String(detail.otherFunds) : '',
		decisionType: detail.decisionType || '',
		isCompleteEstablishmentProcedures: detail.isProjectApprovalCompleted || '',
		establishmentDocumentNumber: detail.projectApprovalFileNo || '',
		establishmentDocumentInfo: detail.projectApprovalFileInfo || '',
		isCompleteDecisionProcedures: detail.isDecisionProcedureCompleted || '',
		decisionProgramDocumentNumber: detail.decisionProcedureFileNo || '',
		decisionDocumentInfo: detail.decisionFileInfo || '',
		progressDesc: detail.progressDesc || '',
		cooperationUnits: detail.cooperationUnits || []
	});
	detailFormData.partnerInfos.splice(0, detailFormData.partnerInfos.length);
};
const parseUploadValue = (value: any) => {
	if (!value) return [];
	if (Array.isArray(value)) return value;
	try {
		return JSON.parse(value);
	} catch {
		return [];
	}
};
const handleView = async () => {
	const res = await getReserveInvestmentProjectDetailAPI('1995316851811131393');
	Object.assign(detailFormData, res.data);
	normalizeDetailData(res.data)
};
handleView();
const status = ref('pending');
</script>

<template>
	<el-card style="height: 100%">
		<el-row :gutter="20">
			<el-col :span="18">
				<el-scrollbar>
					<ProjectBasicInfoView :model-value="detailFormData"/>
				</el-scrollbar>
			</el-col>
			<el-col :span="6">
				<ApprovalAction :status="status" :approval-records="[]" :task-id="taskId"/>
			</el-col>
		</el-row>
	</el-card>
</template>

<style scoped lang="scss">

</style>