<template>
	<el-dialog v-model="state.dialogVisible" draggable title="退回详情" width="50%" append-to-body destroy-on-close>
			<el-form label-width="110px" :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.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="24" :lg="24" :xl="24">
						<el-form-item label="申请理由" class="formatted-text"> {{ state.detail.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="退回附件" v-model="state.detail.files" readonly classify="退回附件" /> </el-form-item>
					</el-col>
				<template v-if="state.detail?.auditTime">
          <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.detail?.auditUser }}
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
            <el-form-item label="审批时间">
              {{ formatDate(state.detail?.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="审批结果">
              {{ state.detail.state === 1 ? '审批通过' : '审批拒绝' }}
            </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.auditContent }}
            </el-form-item>
          </el-col>
        </template>
				</el-row>
			</el-form>
	</el-dialog>
</template>
<script setup lang="ts" name="returnAuditDetailDialog">
import { defineAsyncComponent, reactive } from 'vue';
import { formatDate } from '@/utils/formatTime';
import { returnAuditDetail } from '@/api/business/return';
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 (val: any) => {
	state.loading = true;
	state.dialogVisible = true;
	try {
		const { result } = await returnAuditDetail(val.id);
    if(result) state.detail = result;
		else state.detail = val;
		state.detail.files = transformFile(state.detail.files);
		state.loading = false;
	} catch (e) {
		console.log(e);
		state.loading = false;
	}
};
// 关闭弹窗
const closeDialog = () => {
	state.dialogVisible = false;
};
defineExpose({
	openDialog,
	closeDialog,
});
</script>
