<template>
	<el-drawer v-model="state.dialogVisible" title="明细信息" destroy-on-close size="50%" append-to-body>
		<el-form label-width="110px" ref="ruleFormRef" :model="oldInfo" class="show-info-form" v-loading="state.loading">
			<el-row>
				<el-col><p class="border-title mb10">修改前</p></el-col>
				<el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
					<el-form-item label="来源渠道">
						{{ oldInfo.sourceChannel }}
					</el-form-item>
				</el-col>
				<el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
					<el-form-item label="受理人">
						{{ oldInfo.acceptorName }}
					</el-form-item>
				</el-col>
				<el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
					<el-form-item label="受理类型">
						{{ oldInfo.acceptType }}
					</el-form-item>
				</el-col>
				<el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
					<el-form-item label="来电人姓名">
						{{ oldInfo.fromName }} <el-text type="danger" tag="b" v-if="oldInfo.isSecret" class="ml15">保密</el-text>
					</el-form-item>
				</el-col>
				<el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
					<el-form-item label="工单编码">
						{{ oldInfo.no }}
					</el-form-item>
				</el-col>
				<el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
					<el-form-item label="来电主体">
						{{ oldInfo.identityTypeText }}
					</el-form-item>
				</el-col>
				<el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
					<el-form-item label="联系电话">
						{{ oldInfo.contact }}
					</el-form-item>
				</el-col>
				<template v-if="['YiBin'].includes(themeConfig.appScope)">
					<el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12" v-if="oldInfo.licenceType">
						<el-form-item label="证件类型">
							{{ oldInfo.licenceType }}
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12" v-if="oldInfo.licenceNo">
						<el-form-item label="证件号码">
							{{ oldInfo.licenceNo }}
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12" v-if="oldInfo.enterpriseName">
						<el-form-item label="企业名称">
							{{ oldInfo.enterpriseName }}
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12" v-if="oldInfo.zhuanBanMingCheng">
						<el-form-item label="专班名称">
							{{ oldInfo.zhuanBanMingCheng }}
						</el-form-item>
					</el-col>
				</template>
				<template v-if="['ZiGong', 'LuZhou'].includes(themeConfig.appScope)">
					<el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12" v-if="oldInfo.orderTag">
						<el-form-item label="工单标签">
							{{ oldInfo.orderTag }}
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
						<el-form-item label="重点标签">
							{{ oldInfo.orderTag }}
						</el-form-item>
					</el-col>
				</template>
				<el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
					<el-form-item label="热点分类">
						{{ oldInfo.hotspotSpliceName }}
					</el-form-item>
				</el-col>
				<el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12" v-if="oldInfo.fullAddress">
					<el-form-item label="事发地址">
						{{ oldInfo.fullAddress }}
					</el-form-item>
				</el-col>
				<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
					<el-form-item label="工单标题">
						{{ oldInfo.title }}
					</el-form-item>
				</el-col>
				<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
					<el-form-item label="受理内容">
						<div v-html="showKeyWord(oldInfo.content, oldInfo.sensitive)" class="formatted-text"></div>
					</el-form-item>
				</el-col>
				<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" v-if="oldInfo.centerOpinion">
					<el-form-item label="中心意见">
						<div class="formatted-text">{{ oldInfo.centerOpinion }}</div>
					</el-form-item>
				</el-col>
				<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" v-if="oldInfo.fileOpinion">
					<el-form-item label="承办意见">
						<div class="formatted-text">{{ oldInfo.fileOpinion }}</div>
					</el-form-item>
				</el-col>
				<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" v-if="oldInfo.sendBackOpinion">
					<el-form-item label="退回意见">
						<div class="formatted-text">{{ oldInfo.sendBackOpinion }}</div>
					</el-form-item>
				</el-col>
				<el-col><p class="border-title mb10 mt20">修改后</p></el-col>
				<el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
					<el-form-item label="来源渠道">
						{{ newInfo.sourceChannel }}
					</el-form-item>
				</el-col>
				<el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
					<el-form-item label="受理人">
						{{ newInfo.acceptorName }}
					</el-form-item>
				</el-col>
				<el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
					<el-form-item label="受理类型">
						{{ newInfo.acceptType }}
					</el-form-item>
				</el-col>
				<el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
					<el-form-item label="来电人姓名">
						{{ newInfo.fromName }} <el-text type="danger" tag="b" v-if="newInfo.isSecret" class="ml15">保密</el-text>
					</el-form-item>
				</el-col>
				<el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
					<el-form-item label="工单编码">
						{{ newInfo.no }}
					</el-form-item>
				</el-col>
				<el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
					<el-form-item label="来电主体">
						{{ newInfo.identityTypeText }}
					</el-form-item>
				</el-col>
				<el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
					<el-form-item label="联系电话">
						{{ newInfo.contact }}
					</el-form-item>
				</el-col>
				<template v-if="['YiBin'].includes(themeConfig.appScope)">
					<el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12" v-if="newInfo.licenceType">
						<el-form-item label="证件类型">
							{{ newInfo.licenceType }}
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12" v-if="newInfo.licenceNo">
						<el-form-item label="证件号码">
							{{ newInfo.licenceNo }}
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12" v-if="newInfo.enterpriseName">
						<el-form-item label="企业名称">
							{{ newInfo.enterpriseName }}
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12" v-if="newInfo.zhuanBanMingCheng">
						<el-form-item label="专班名称">
							{{ newInfo.zhuanBanMingCheng }}
						</el-form-item>
					</el-col>
				</template>
				<template v-if="['ZiGong', 'LuZhou'].includes(themeConfig.appScope)">
					<el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12" v-if="newInfo.orderTag">
						<el-form-item label="工单标签">
							{{ newInfo.orderTag }}
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
						<el-form-item label="重点标签">
							{{ newInfo.orderTag }}
						</el-form-item>
					</el-col>
				</template>
				<el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
					<el-form-item label="热点分类">
						{{ newInfo.hotspotSpliceName }}
					</el-form-item>
				</el-col>
				<el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12" v-if="newInfo.fullAddress">
					<el-form-item label="事发地址">
						{{ newInfo.fullAddress }}
					</el-form-item>
				</el-col>
				<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
					<el-form-item label="工单标题">
						{{ newInfo.title }}
					</el-form-item>
				</el-col>
				<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
					<el-form-item label="受理内容">
						<div v-html="showKeyWord(newInfo.content, newInfo.sensitive)" class="formatted-text"></div>
					</el-form-item>
				</el-col>
				<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" v-if="newInfo.centerOpinion">
					<el-form-item label="中心意见">
						<div class="formatted-text">{{ newInfo.centerOpinion }}</div>
					</el-form-item>
				</el-col>
				<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" v-if="newInfo.fileOpinion">
					<el-form-item label="承办意见">
						<div class="formatted-text">{{ newInfo.fileOpinion }}</div>
					</el-form-item>
				</el-col>
				<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" v-if="newInfo.sendBackOpinion">
					<el-form-item label="退回意见">
						<div class="formatted-text">{{ newInfo.sendBackOpinion }}</div>
					</el-form-item>
				</el-col>
			</el-row>
		</el-form>
		<template #footer>
			<span class="dialog-footer">
				<el-button @click="closeDrawer" class="default-button">关闭</el-button>
			</span>
		</template>
	</el-drawer>
</template>
<script setup lang="ts" name="businessUrgeDetailDialog">
import { reactive, ref } from 'vue';
import { getOrderModifyRecordDetail } from '@/api/todo/center';
import { useThemeConfig } from '@/stores/themeConfig';
import { storeToRefs } from 'pinia';

// 定义子组件向父组件传值/事件
// 定义变量内容
const state = reactive<any>({
	dialogVisible: false, // 是否显示弹窗
	loading: false, // 是否显示加载
});
const storesThemeConfig = useThemeConfig();
const { themeConfig } = storeToRefs(storesThemeConfig);
// 打开弹窗
const newInfo = ref<EmptyObjectType>({});
const oldInfo = ref<EmptyObjectType>({});
const openDrawer = async (id: string) => {
	state.loading = true;
	state.dialogVisible = true;
	try {
		const { result } = await getOrderModifyRecordDetail(id);
		newInfo.value = result.newInfo;
		oldInfo.value = result.oldInfo;
		state.loading = false;
	} catch (e) {
		console.log(e);
		state.loading = false;
		state.dialogVisible = false;
	}
};
// 高亮关键词
const showKeyWord = (val: string[], keywordArr: string[]) => {
	let str: any = val;
	if (keywordArr && keywordArr.length) {
		// 2.定制关键词对应正则
		keywordArr.forEach((e) => {
			let regStr = '' + `(${e})`;
			let reg = new RegExp(regStr, 'g');
			// 3.正则替换，关键词飘红
			str = str.replace(reg, '<span class="color-danger font-bold"">' + e + '</span>');
		});
	}
	return str;
};
// 关闭弹窗
const closeDrawer = () => {
	state.dialogVisible = false;
};
defineExpose({
	openDrawer,
	closeDrawer,
});
</script>
