<template>
	<view class="webview-page">
		<web-view :src="url  + '/html/index.html?url=' + src" v-if="src"></web-view>
		<cover-view class="cover-box">
			<button class="share-btn" @click="tokefu">
				<cover-image class="img-btn" src="../static/kefu.png" mode=""></cover-image>
			</button>
			<button class="share-btn" open-type="share">
				<cover-image class="img-btn" src="../static/share.png" mode=""></cover-image>
			</button>
		</cover-view>
	</view>
</template>

<script>
	import url from "../../common/url.js"
	export default {
		data() {
			return {
				src: '',
				url: url,
				id: '',
				type: '',
				worker_id: 0,
				worker_phone: '',
				worker_hx_username: ''
			}
		},
		onLoad(option) {
			// console.log(option)
			this.src = encodeURIComponent(option.url)
			this.id = option.id
			this.type = option.type
		},
		onShow() {
			this.getuser()
		},
		onShareAppMessage() {
			if (this.type == 1) {
				return {
					path: '/pagesA/index/rizhao?id=' + this.id
				}
			} else {
				return {
					path: '/pagesA/index/yifang?id=' + this.id
				}
			}
		},
		methods: {
			tokefu() {
				if (uni.getStorageSync("token")) {
					if (this.worker_id == 0) {
						uni.navigateTo({
							url: "/pagesA/index/kefu?id=" + this.id
						})
					} else {
						this.$u.post('/api/Member/consult_record', {
							type: 2
						})
						uni.navigateTo({
							url: "/pages/index/chat?hx_username=" + this.worker_hx_username + "&worker_id=" + this.worker_id
						})
					}
				} else {
					uni.navigateTo({
						url: "/pagesA/index/kefu?id=" + this.id
					})
				}
			},
			getuser() {
				this.$u.post('/api/Member/member_info').then(res => {
					this.worker_id = res.data.worker_id
					this.worker_phone = res.data.worker_phone
					this.worker_hx_username = res.data.worker_hx_username
				})
			},
		}
	}
</script>

<style lang="scss">
	.webview-page {
		height: 100vh;

		.cover-box {
			position: fixed;
			top: 240px;
			right: 10px;
			background-color: rgba(0, 0, 0, 0);
			z-index: 10;
			padding: 1px 5px;
			border-radius: 100px;
		}

		.share-btn {
			margin: 0;
			padding: 0;
			background-color: rgba(0, 0, 0, 0);
			border: none;
			line-height: 1;
			margin: 15px 0;
			width: 30px;
			height: 30px;

			.img-btn {
				width: 30px;
				height: 30px;
				opacity: 0;
			}
		}

		.share-btn::after {
			border: none;
		}
	}
</style>