<template>
	<el-dialog v-model="state.dialogVisible" draggable title="退回详情" width="50%" append-to-body destroy-on-close>
		<el-form label-width="110px" ref="ruleFormRef" :model="state.ruleForm" class="show-info-form" v-loading="state.loading">
			<el-row :gutter="35">
				<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
					<el-form-item label="工单编码"> {{ state.ruleForm.order?.no }} </el-form-item>
				</el-col>
				<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
					<el-form-item label="工单标题"> {{ state.ruleForm.order?.title }} </el-form-item>
				</el-col>
				<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
					<el-form-item label="申请人"> {{ state.ruleForm.creatorName }} </el-form-item>
				</el-col>
				<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
					<el-form-item label="申请部门"> {{ state.ruleForm.creatorOrgName }} </el-form-item>
				</el-col>
				<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
					<el-form-item label="退回申请时间"> {{ formatDate(Date(), 'YYYY-mm-dd HH:MM:SS') }} </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.ruleForm.content }}
					</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 :businessId="state.ruleForm.id" classify="退回附件" v-model="state.ruleForm.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="12" :md="12" :lg="12" :xl="12">
					<el-form-item label="审批结果">
						{{ state.ruleForm.state === 1 ? '审核通过' : state.ruleForm.state === 2 ? '审核驳回' : '' }}
					</el-form-item>
				</el-col>
				<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
					<el-form-item label="审核人">
						{{ state.ruleForm.auditName }}
					</el-form-item>
				</el-col>
				<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
					<el-form-item label="审核时间">
						{{ formatDate(state.ruleForm.auditTime, 'YYYY-mm-dd HH:MM:SS') }}
					</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.ruleForm.auditContent }}
					</el-form-item>
				</el-col>
			</el-row>
		</el-form>
	</el-dialog>
</template>
<script setup lang="ts" name="secondVisitDialog">
import { defineAsyncComponent, reactive, ref } from 'vue';
import { formatDate } from '@/utils/formatTime';
import { returnDetail } from '@/api/business/return';
import { transformFile } from '@/utils/tools';

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

// 定义子组件向父组件传值/事件
const emit = defineEmits(['updateList']);
// 定义变量内容
const state = reactive<any>({
	dialogVisible: false, // 是否显示弹窗
	loading: false, // 是否显示加载
	ruleForm: {
		content: '', // 退回申请理由
		auditOpinion: '', // 退回审批意见
	},
	orderDetail: {}, // 工单详情
});
const ruleFormRef = ref<RefType>();
/**
 * @description 打开弹窗
 * @param {object} val 工单详情
 */
const openDialog = (val: any) => {
	state.loading = true;
	returnDetail(val.id)
		.then((res) => {
			state.ruleForm = res.result;
			state.ruleForm.files = transformFile(state.ruleForm.files);
			state.loading = false;
			state.dialogVisible = true;
		})
		.catch(() => {
			state.loading = false;
		});
};
// 关闭弹窗
const closeDialog = () => {
	state.dialogVisible = false;
};
defineExpose({
	openDialog,
	closeDialog,
});
</script>
