<template>
	<view class="page">
		<button style="padding: 0;margin-left: 0; text-align: left;" class="nullBtn"  v-if='taskid == 487'>
			<image class="posterImg" src="https://ckbapi.quwanzhi.com/upload/img/ckb.png" mode="widthFix"></image>
		</button>
		<button style="padding: 0;margin-left: 0; text-align: left;" class="nullBtn" open-type="getPhoneNumber" v-else
			@getphonenumber="getPhoneNumber">
			<image class="posterImg" :src="poster.sUrl" mode="widthFix"></image>
		</button>
	</view>
</template>

<script>
	import {
		request
	} from '@/utils/request';
	export default {
		data() {
			return {
				taskid: '',
				token: "test",
				task: null,
				poster: null
			}
		},
		onLoad(options) {
			let scene = options.scene;
			let taskId = options.id;

			if (scene != undefined) {
				this.taskid = scene;
			} else if (taskId != undefined) {
				this.taskid = taskId;
			} else {
				this.taskid = 487;
			}

			this.getPosterData()
		},
		methods: {
			getPosterData() {
				let that = this;
				uni.request({
					method: 'POST',
					header: {
						'content-type': 'application/x-www-form-urlencoded', //自定义请求头信息
						'token': that.token
					},
					url: that.$config.apiUrl2 + '/v1/frontend/business/poster/getone',
					data: {
						oldId: that.taskid,
					},
					success: (res) => {
						if (res.data.code == 200) {
							that.poster = res.data.data.poster
							that.task = res.data.data.task
							that.taskid = res.data.data.task.id
							//修改标题
							uni.setNavigationBarTitle({
								title: ""
							});
						} else {
							uni.showToast({
								title: res.data.message,
								icon: 'none',
								duration: 2000
							});
						}
					}
				});
			},
			onShareAppMessage() {
				return {
					title: '',
					path: '/pages/poster/index2?id=' + this.taskid,
					imageUrl: poster.sUrl // 可以省略不写，这样会默认截图当前页面作为分享图片
				};
			},
			// 获取用户手机号
			getPhoneNumber(res) {
				let that = this;
				if (res.detail.errMsg == "getPhoneNumber:ok") {
					uni.showLoading({
						title: '请求中...',
						mask: true
					})
					uni.request({
						method: 'POST',
						header: {
							'content-type': 'application/x-www-form-urlencoded', //自定义请求头信息
							'token': that.token
						},
						url: that.$config.apiUrl2 + '/v1/frontend/business/poster/decryptphone',
						data: {
							id: that.taskid,
							code: res.detail.code
						},
						success: (res) => {
							uni.hideLoading();
							if (res.data.code == 200) {
								uni.showModal({
									title: '提示',
									content: that.task.sTip,
									success: function(res) {
										console.log(res)
									}
								})
							} else {
								uni.showToast({
									title: res.data.message,
									icon: 'none',
									duration: 2000
								});
							}
						}
					});

				}
			},

		}
	}
</script>

<style>
	.page {
		width: 100vw;
		height: 100vh;
	}

	.posterImg {
		width: 100%;
	}
</style>