<template>
	<view class="phone-haibao-info-page">
		<view class="phone-navBar-box">
			<view @click="goUpPage" class="nav-bar-icon"></view>
			<text class="nav-bar-title">职业海报</text>
			<view @click="getHaibaoImg" class="text-btn">分享</view>
		</view>
		<view class="haibao-info-body-box">
			<view v-if="data.img" class="img-box">
				<img :src="data.img" class="haibao-image" />
				<view class="info-text-box">
					<view class="haibao-info-text">
						<icon class="jz-icon"></icon>{{data.jzName}}
					</view>
					<view class="haibao-info-text">
						<icon class="tel-icon"></icon>{{data.realName}}（{{data.tel}}）
					</view>
				</view>

			</view>
			<view v-else class="loading-text">暂无数据</view>
		</view>
	</view>
	<share-popup ref="sharePopupRef" title="海报" desc="请点击查看海报详情" :link=haibaoUrl type="0" @success="onShareSuccess" />
</template>

<script setup>
	import {
		reactive,
		ref
	} from "vue"
	import {
		onLoad
	} from "@dcloudio/uni-app";
	import * as httpApi from '@/api/haibao.js'
	import SharePopup from '@/components/sharePopUp/index.vue'
	import config from "../../../config"
	const data = reactive({
		img: '',
		id: '',
		menuId: '',
		jzName: '',
		realName: '',
		tel: '',
		uuid: ''
	})
	const haibaoUrl = ref('')
	const sharePopupRef = ref(null)

	function onShareSuccess(e) {
		console.log('分享成功', e.scene)
	}

	function goUpPage() {
		uni.redirectTo({
			url: `/pages/admin/haibao/index?menuId=${data.menuId}`
		})
	}

	function getHaibaoOpsZhiyeData(id) {
		httpApi.getHaibaoInfo({
			id
		}).then(res => {
			data.img = res.data.image;
			data.jzName = res.data.jzName;
			data.realName = res.data.realName;
			data.tel = res.data.tel;
		}).catch(err => {
			console.error('加载海报失败:', err)
			uni.showToast({
				title: '加载失败',
				icon: 'none'
			})
		})
	}

	function getHaibaoImg() {
		httpApi.haibaoShare({
			id: data.id
		}).then(res => {
			if (res.code == 0) {
				uni.share({
					provider: "weixin",
					scene: "WXSceneTimeline",
					type: 2,
					imageUrl: "https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/uni@2x.png",
					success: function(res) {
						console.log("success:" + JSON.stringify(res));
					},
					fail: function(err) {
						console.log("fail:" + JSON.stringify(err));
					}
				});
			}
		}).catch(err => {
			uni.showToast({
				title: '获得海报图片失败',
				icon: 'none'
			})
		})
	}



	onLoad((options) => {
		data.id = options.cardId || ''
		data.menuId = options.menuId || ''
		if (data.id) {
			getHaibaoOpsZhiyeData(data.id)
		}
	})
</script>