<template>
	<el-dialog
		v-model="state.dialogVisible"
		draggable
		title="督办详情"
		ref="dialogRef"
		@mouseup="mouseup"
		:style="'transform: ' + state.transform + ';'"
		width="50%"
		destroy-on-close
		@close="close"
	>
		<div class="collapse-container">
			<el-form label-width="110px" ref="ruleFormRef" :model="state.ruleForm" class="show-info-form">
				<el-row :gutter="35">
					<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.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.superviseDetail.crUser }} </el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
						<el-form-item label="督办部门"> {{ state.superviseDetail.launchOrgName }} </el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
						<el-form-item label="督办时间"> {{ formatDate(state.superviseDetail.creationTime, 'YYYY-mm-dd HH:MM:SS') }} </el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
						<el-form-item label="督办回复时限"> {{ formatDate(state.superviseDetail.replyLimitTime, '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="被督办部门">{{ state.superviseDetail.orgName }}</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.superviseDetail.applyContent }}</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 classify="督办申请" v-model="state.superviseDetail.files" />
						</el-form-item>
					</el-col>
					<template v-if="state.superviseDetail.replyTime">
						<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="督办回复时间"> {{ formatDate(state.superviseDetail.replyTime, '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.superviseDetail.replyContent }} </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 classify="督办回复" v-model="state.superviseDetail.replyFiles" />
							</el-form-item>
						</el-col>
					</template>
				</el-row>
			</el-form>
		</div>
		<template #footer>
			<span class="dialog-footer">
				<el-button @click="closeDialog" class="default-button">关 闭</el-button>
			</span>
		</template>
	</el-dialog>
</template>
<script setup lang="ts" name="businessSuperviseDetailDialog">
import { defineAsyncComponent, reactive, ref } from 'vue';
import { formatDate } from '@/utils/formatTime';
import { superviseDetail, superviseReply } from '@/api/business/supervise';
import { ElMessage, FormInstance } from 'element-plus';

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

// 定义子组件向父组件传值/事件
const emit = defineEmits(['updateList']);
// 定义变量内容
const state = reactive<any>({
	dialogVisible: false, // 是否显示弹窗
	loading: false, // 是否显示加载
	ruleForm: {
		acceptSms: false, // 发送督办短信
		applyContent: '', // 督办内容
	},
	superviseDetail: {}, // 督办详情
	transform: 'translate(0px, 0px)', // 滚动条位置
	orderDetail: {}, // 工单详情
	orgData: [], // 被督办部门
});
const ruleFormRef = ref<RefType>();
const getDetail = async (id: string) => {
	try {
		const { result } = await superviseDetail(id);
		state.superviseDetail = result ?? {};
		state.orderDetail = result?.order ?? {};
		state.dialogVisible = true;
	} catch (e) {
		console.log(e);
	}
};
// 设置抽屉
const dialogRef = ref<RefType>();
const mouseup = () => {
	state.transform = dialogRef.value.dialogContentRef.$el.style.transform;
};
// 打开弹窗
const openDialog = (val: any) => {
	getDetail(val.id);
};
// 关闭弹窗
const closeDialog = () => {
	state.dialogVisible = false;
};
const close = () => {
	ruleFormRef.value.clearValidate();
	ruleFormRef.value.resetFields();
};
defineExpose({
	openDialog,
	closeDialog,
});
</script>
