<template>
	<div class="g_flex_row_center">
		<div class="m-job-detail g_pt_24" style="width: 780px">
			<div class="g_flex_row_center flex_center g_mb_16">
				<div class="g_fs_14">标题：</div>
				<div class="g_mt_0 g_br_6 g_flex_1" style="border: 1px solid #d9d9d9">
					<a-input v-model:value="currentInfo.title"></a-input>
				</div>
			</div>
			<div class="g_flex_row_center">
				<div class="g_fs_14">内容：</div>
				<div class="g_mt_0 g_br_6 g_flex_1" style="border: 1px solid #d9d9d9">
					<iframe src="../../../public/static/editor.html" width="100%" height="500px" frameborder="0" ref="iframeDom" style="border-top-left-radius: 6px"></iframe>
				</div>
			</div>
			<div class="g_flex_row_start g_mt_24 g_ml_42">
				<a-button class="g_mr_16" @click="cancel">取消</a-button>
				<a-button type="primary">发布</a-button>
			</div>
		</div>
	</div>
</template>

<script setup>
import { ref, onMounted, getCurrentInstance, watch, onBeforeUnmount } from "vue";
const commonJS = getCurrentInstance().appContext.app.config.globalProperties.G;
import { useRouter, useRoute } from "vue-router";
const router = useRouter(); // 应用路由
const route = useRoute();
import { useStore } from "@/stores/counter";
const storeJS = useStore();
let currentInfo = ref({});
onMounted(() => {
	console.log(route);
	let newList = [{}, {}, {}];

	newList.forEach((item, index) => {
		item.rank = index + 1;
		item.title = "常用发票主体信息" + index;
		item.content = "默认主体：郑州伯才科技有限公司 单位名称：郑州伯才科技有限公司 纳税人识别号：91410100MA9L4HDT0L 地址：河南自贸试验区郑州" + index;
		item.time = "2024-03-11 13:04:24";
	});
	if (route.query.id) {
		currentInfo.value = newList[Number(route.query.id)];
	}
	initData();
});
const iframeDom = ref();
window.addEventListener("message", (val) => {
	// console.log(val.data);
	if (val.data.lake) {
		currentInfo.value.desc_yq = val.data.lake;
		currentInfo.value.desc = val.data.html;
	}
});
const initData = () => {
	// iframeDom.value.contentWindow.postMessage("");

	iframeDom.value.onload = function () {
		console.log(route);
		if (route.name == "messageEdit") {
			iframeDom.value.contentWindow.postMessage(currentInfo.value.content);
		} else {
			iframeDom.value.contentWindow.postMessage("");
		}
	};
};
const cancel = ()=>{
  router.back()
}
</script>

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