<template>
	<el-dialog v-model="state.dialogVisible" draggable title="催办详情" ref="dialogRef" width="50%" destroy-on-close :before-close="handleClose">
		<div class="collapse-container pb1">
			<el-form label-width="110px" ref="ruleFormRef" :model="state.ruleForm">
				<el-row :gutter="10">
					<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.urgeDetail.crUser }} </el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
						<el-form-item label="催办部门"> {{ state.urgeDetail.creatorOrgName }} </el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
						<el-form-item label="催办时间"> {{ formatDate(state.urgeDetail.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.urgeDetail.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.urgeDetail.orgName }}</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" v-auth="'file:list'">
						<el-form-item label="附件" prop="handleResult" :rules="[{ required: false, message: '请选择附件', trigger: 'change' }]">
							<annex-list name="查看附件" readonly :businessId="state.urgeDetail.id" classify="催办回复" />
						</el-form-item>
					</el-col>
				</el-row>
			</el-form>
		</div>
		<template #footer>
			<span class="dialog-footer">
				<el-button @click="onCancel" class="default-button">关 闭</el-button>
			</span>
		</template>
	</el-dialog>
</template>
<script setup lang="ts" name="businessUrgeDetailDialog">
import { defineAsyncComponent, reactive, ref } from 'vue';
import { formatDate } from '/@/utils/formatTime';
import {urgeDetail, urgeSign} from '/@/api/business/urge';
import {ElMessage} 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>({
	collapseArr: ['1', '2'], // 折叠面板
	dialogVisible: false, // 是否显示弹窗
	loading: false, // 是否显示加载
	ruleForm: {
		acceptSms: false, // 发送催办短信
		applyContent: '', // 催办内容
	},
	urgeDetail: {}, // 催办详情
	orderDetail: {}, // 工单详情
	orgData: [], // 被催办部门
});
const ruleFormRef = ref<RefType>();
const getDetail = async (id: string) => {
	let res = await urgeDetail(id);
	state.urgeDetail = res.result ?? {};
	state.orderDetail = res.result?.order ?? {};
	state.dialogVisible = true;
};
// 催办签收
const onSign = (id: string) => {
  urgeSign({ id }).then(() => {
    ElMessage.success('签收成功');
    emit('updateList');
  });
};
// 打开弹窗
const openDialog = (val: any) => {
	getDetail(val.id);
  if (!val.signTime) {
    // 如果没有签收时间签收
    onSign(val.id);
  }
};
// 关闭弹窗
const closeDialog = () => {
	state.dialogVisible = false;
	ruleFormRef.value.clearValidate();
	ruleFormRef.value.resetFields();
};
// 取消
const onCancel = () => {
	closeDialog();
};
const handleClose = (done: any) => {
	closeDialog();
	done();
};
defineExpose({
	openDialog,
	closeDialog,
});
</script>

<style lang="scss" scoped></style>
