<template>
	<el-dialog v-model="state.dialogVisible" draggable title="审批详情" ref="dialogRef" width="50%" append-to-body destroy-on-close>
		<div class="collapse-container">
			<el-form label-width="110px" ref="ruleFormRef" :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.orderDetail.no }} </el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
						<el-form-item label="工单标题"> {{ state.orderDetail.title }} </el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
						<el-form-item label="申请人"> {{ state.visitDetail.creatorName }} </el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
						<el-form-item label="申请部门"> {{ state.visitDetail.creatorOrgName }} </el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
						<el-form-item label="申请时间"> {{ formatDate(state.visitDetail.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="申请理由">
							{{ state.visitDetail.visitReason }}
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
						<el-form-item label="附件" prop="handleResult" :rules="[{ required: false, message: '请选择附件', trigger: 'change' }]">
              <annex-list name="二次回访附件" readonly :businessId="state.visitDetail.id" classify="二次回访附件" v-model="state.visitDetail.files"/>
						</el-form-item>
					</el-col>
					<el-divider />
					<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
						<el-form-item label="审批结果">
							{{ state.visitDetail.visitApplyStateText }}
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
						<el-form-item label="审批意见">
							{{ state.visitDetail.examinOpinion }}
						</el-form-item>
					</el-col>
				</el-row>
			</el-form>
		</div>
	</el-dialog>
</template>
<script setup lang="ts" name="secondVisitDialog">
import { defineAsyncComponent, reactive, ref } from 'vue';
import { storeToRefs } from 'pinia';
import { useUserInfo } from '@/stores/userInfo';
import { formatDate } from '@/utils/formatTime';
import {  secondVisitDetail } from '@/api/business/secondVisit';
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: '', // 申请理由
		examinOpinion: '', // 审批意见
	},
	visitDetail: {}, //回访详情
	orderDetail: {}, // 工单详情
});
const ruleFormRef = ref<RefType>();
const storesUserInfo = useUserInfo();
const { userInfos } = storeToRefs(storesUserInfo); // 用户信息
/**
 * @description 打开弹窗
 * @param {object} val 工单详情
 */
const openDialog = (val: any) => {
	secondVisitDetail(val.id).then((res) => {
		state.orderDetail = res.result?.order ?? {};
		state.visitDetail = res.result ?? {};
    state.visitDetail.files = transformFile(state.visitDetail.files);
	});
	state.dialogVisible = true;
};
// 关闭弹窗
const closeDialog = () => {
	state.dialogVisible = false;
};
defineExpose({
	openDialog,
	closeDialog,
});
</script>
