<template>
	<wd-collapse v-model="value">
	  <wd-collapse-item title="表单数据" name="item1">
		  	<wd-cell title="申请人" :value="info.sqr" />
		  	<wd-cell title="业务类别" :value="info.ywlb" />
		  	<wd-cell title="申请事由" :value="info.sqsy" />
		  	<wd-cell title="部门审批领导" :value="info.bmspld_dictText" />
		  	<wd-cell title="申请部门" :value="info.sqbm" />
		  	<wd-cell title="申请时间" :value="info.sqsj" />
		  	<wd-cell title="申请盖章领导" :value="info.gzld" />
		  	<wd-cell title="申请盖章厂领导" :value="info.gzcld" />
		  	<wd-cell title="盖章位置" :value="info.gzwz" />
	  </wd-collapse-item>
	  <wd-collapse-item custom-body-style="padding:0;"  title="盖章文件" name="item2">
		  <SinopecEsignPage :valiData="valiData" ref="sign" :procInsId="props.formData.procInsId"  :path="props.formData.path" :fileName="info.wjdict" @stampSuccess="getStampSuccess" ></SinopecEsignPage>
	  </wd-collapse-item>
	</wd-collapse>
</template>

<script setup>
	import {
		queryUnData
	} from '@/api/integrated/unconventional'
	import {
		processHistoryList
	} from '@/api/bpm/sign'
	import {
		imgUrl
	} from '@/utils/index'
	import SinopecEsignPage from '@/components/Esign/SinopecEsignPage.vue'
	import { useUserStore } from '@/store/user'
	const userStore = useUserStore()
	
	const emit = defineEmits(['getStampSuc'])

	const sign = ref(null);
	const value = ref([]);
	const info = ref({});
	const valiData = ref({});
	const ifEsign = ref(true);
	const props = defineProps({
		formData: {
			type: Object,
			default: () => {},
		},
		fileName: {
			type: String,
			default: ""
		}
	})

	const queryData = ()=>{
		queryUnData({id:props.formData.dataId}).then(res=>{
			info.value  = res.result.records[0]
			initValiData(info.value); //处理验证data by 闵
			let lj = info.value.wj.split("/");
			let ljurl = lj[2] + '/' + lj[3];
			info.value.wjdict = ljurl;
		})
	}
	
	const  initValiData = (data)=>{
		//处理验证data by 闵
		let name = userStore.userInfo.realname;
		let num = null;
		if(data.lds){
		  let ldsMap = JSON.parse(data.lds);
		  if(ldsMap[name]) num = ldsMap[name]
		}
		if(data.clds){
		  let cldsMap = JSON.parse(data.clds);
		  if(cldsMap[name]) num = cldsMap[name]
		}
		if(num){
		  valiData.value.flag = true;
		  valiData.value.num = num;
		  valiData.value.name = name;
		}
	}

	const initValtime = ()=>{
		processHistoryList(props.formData.procInsId).then(res=>{
			if (res.success) {
			  valiData.value.time = res.result.records[0].startTime
			} else {
				console.log("加载失败")
			}
		})
	}

	  //获取印章成功事件，并将信号传给确认提交按钮。
	 const getStampSuccess=(val)=> {
		emit('getStampSuc', val)
	  }

	const signValidator = (procInsId,path)=>{
	 	//这里进行电子签章验证
		return sign.value.signValidator();
	 }

	onMounted(() => {
		queryData();
		initValtime();
	})
	
	
	defineExpose({ //暴露方法
	  signValidator,
	  ifEsign
	})
</script>
<style lang="scss" scoped>

	
</style>