<template>
	<el-dialog v-model="state.dialogVisible" draggable title="特提审批明细" width="50%" append-to-body destroy-on-close>
		<div class="collapse-container">
			<el-form label-width="110px" :model="state.ruleForm" class="show-info-form">
				<el-row :gutter="35">
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
						<el-form-item label="工单编码"> {{ state.detail?.order?.no }} </el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
						<el-form-item label="工单标题"> {{ state.detail?.order?.title }} </el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
						<el-form-item label="申请人"> {{ state.detail?.creatorName }} </el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
						<el-form-item label="申请部门"> {{ state.detail?.creatorOrgName }} </el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
						<el-form-item label="申请时间"> {{ formatDate(state.detail?.creationTime, 'YYYY-mm-dd HH:MM:SS') }} </el-form-item>
					</el-col>
					<el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
						<el-form-item label="申请特提节点" class="mb5">
							{{ state.detail?.stepName }}
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
						<el-form-item label="审批通过后节点" class="mb5">
							{{ state.detail?.nextStepName }}
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
						<el-form-item label="特提原因">
							{{ state.detail?.cause }}
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
						<el-form-item label="特提理由"  class="formatted-text">
							{{ state.detail?.reason }}
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
						<el-form-item label="附件">
							<annex-list name="特提附件" readonly classify="特提附件" v-model="state.detail.files" />
						</el-form-item>
					</el-col>
					<el-divider content-position="left">
						<el-text tag="b" size="large"> 审批详情 </el-text>
					</el-divider>
					<el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
						<el-form-item label="审批结果">
							{{ state.detail?.stateText }}
						</el-form-item>
					</el-col>
					<!-- 审核通过才展示字段 -->
					<template v-if="state.detail?.state === '1'">
						<el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
							<el-form-item label="特提节点">
								{{ state.detail?.nextStepName }}
							</el-form-item>
						</el-col>
						<el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
							<el-form-item label="办理对象">
								{{ state.detail?.nextHandlers?.map((item) => item.value).join(',') }}
							</el-form-item>
						</el-col>
						<!--            <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
              <el-form-item label="办理时限"> {{ state.detail?.timeLimit }} {{ state.detail?.timeLimitUnitText }} </el-form-item>
            </el-col>-->
						<el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
							<el-form-item label="无需计算期满时间" label-width="130px">
								{{ state.detail?.alterTime ? '是' : '否' }}
							</el-form-item>
						</el-col>
					</template>
					<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" v-if="state.detail.opinion">
						<el-form-item label="审批意见" class="formatted-text">
							{{ state.detail?.opinion }}
						</el-form-item>
					</el-col>
				</el-row>
			</el-form>
		</div>
	</el-dialog>
</template>
<script setup lang="ts">
import { defineAsyncComponent, reactive } from 'vue';
import { formatDate } from '@/utils/formatTime';
import { specialDetail } from '@/api/business/special';
import { transformFile } from '@/utils/tools';

// 引入组件
const AnnexList = defineAsyncComponent(() => import('@/components/AnnexList/index.vue'));

// 定义变量内容
const state = reactive<any>({
	dialogVisible: false, // 是否显示弹窗
	loading: false, // 是否显示加载
	detail: {}, // 详情信息
});
// 打开弹窗
const openDialog = async (id: string) => {
	state.loading = true;
	state.dialogVisible = true;
	try {
		const { result } = await specialDetail(id);
		state.detail = result;
		state.detail.files = transformFile(result.files);
		state.loading = false;
	} catch (e) {
		console.log(e);
		state.loading = false;
	}
};
// 关闭弹窗
const closeDialog = () => {
	state.dialogVisible = false;
};
defineExpose({
	openDialog,
	closeDialog,
});
</script>
