<template>
	<view class="postDetail">
		<navbar leftClick @leftClick="leftClick" />

		<view class="swipe">
			<uv-swiper 
			:list="vedioList" 
			indicator 
			height="420rpx"></uv-swiper>
			
			<!-- <video :src="item.details.isImage[0]"
			style="width: 750rpx;height: 420rpx;"
			/> -->
		</view>

		<view class="box">

			<view class="topInfo">
				<view class="title">
					{{ item.details.name }}
				</view>
				<view class="price">
					￥{{ item.details.money }}/天
				</view>
				<view class="right">
					<view class="money30">
						近30天收益：￥{{ item.dayMoney }}
					</view>
					<view class="phone" v-if="isVedio">
						<view class=""
						v-if="item.details.phonePay != 'Y' || item.isPayPhone">
							联系方式：{{ item.details.phone }}
						</view>
						<view class=""
						v-else>
							联系方式<text @click="submit">付费查看</text>
						</view>
					</view>
				</view>
			</view>

			<view class="createBy">
				<view class="">
					发布人：{{ item.details.userId }}
				</view>
				<view class="">
					发布时间：{{ $dayjs(item.details.createTime).format('YYYY-MM-DD') }}
				</view>
			</view>


			<view class="content">
				<uv-parse :content="item.details.photographerContent"></uv-parse>
			</view>

			<view class="controls">
				<contentControls
				:type="1"
				:up="item.isThumbs_up"
				:down="item.isThumbs_down"
				@loadData="getData"
				:detail="item.details"/>
			</view>
			
			<view class="works"
			v-if="isVedio">
				<view class="item" 
				v-for="(t, index) in item.details.isImage"
				:key="index">
					<view class="item-title">
						{{ item.details.workName[index] || '' }}
					</view>
					<view class="item-image">
						<video :src="t" />
					</view>
				</view>
			</view>
		</view>

		<confirmationPopup
		ref="confirmationPopup"
		title="提示"
		@confirm="getContact"
		confirmText="确认支付">
			<view class="confirmationPopup">
				<image src="/static/image/publish/pay.png" 
				style="width: 150rpx;height: 150rpx;"
				mode=""></image>
				<view class="info">
					请支付{{ item.details.price }}元，10小时内可查看任意联系方式
				</view>
			</view>
		</confirmationPopup>

	</view>
</template>

<script>
	import contentControls from '@/components/content/contentControls.vue'
	import confirmationPopup from '@/components/toast/confirmationPopup.vue'
	import { mapGetters } from 'vuex'
	export default {
		components : {
			contentControls,
			confirmationPopup,
		},
		data() {
			return {
				item: {
					details : {}
				},
				list : [],
				queryParams: {
					pageNo: 1,
					pageSize: 10
				},
				total : 0,
				id : 0,
			}
		},
		onLoad(options) {
			// this.$route.query的参数
			console.log(options)
			this.id = options.id
		},
		computed : {
			...mapGetters(['isVedio']),
			vedioList(){
				return this.isVedio ? 
				this.item.details.isImage :
				this.item.details.image
			},
		},
		onShareAppMessage(res) {
		    return {
				title: this.item.details.name,
				path: '/pages/publish/actorDetail?id=' + this.id
		    }
		},
		//2.分享到朋友圈
		onShareTimeline(res) {
		    return {
				title: this.item.details.name,
				path: '/pages/publish/actorDetail?id=' + this.id
		    }
		},
		onShow() {
			this.getData()
		},
		//滚动到屏幕底部
		onReachBottom() {
			
		},
		onPullDownRefresh(){
			this.getData()
		},
		methods: {
			leftClick(){
				uni.navigateBack(-1)
			},
			getData(){
				this.$api('indexGetActorDetail', {
					id : this.id
				}, res => {
					uni.stopPullDownRefresh()
					if(res.code == 200){
						
						res.result.details.isImage = 
						res.result.details.isImage ?
						res.result.details.isImage.split(',') : [],
						
						res.result.details.workName = 
						res.result.details.workName ?
						res.result.details.workName.split(',') : []
						
						res.result.details.image = 
						res.result.details.image ?
						res.result.details.image.split(',') : []
						
						this.item = res.result
					}
				})
			},
			submit(){
				this.$refs.confirmationPopup.open()
			},
			// 付费查看联系方式
			getContact(){
				
				let self = this
				
				this.$api('getContact', {
					id : this.item.details.id
				} , res => {
					if(res.code == 200){
						uni.requestPayment({
							provider: 'wxpay', // 服务提提供商
							timeStamp: res.result.timeStamp, // 时间戳
							nonceStr: res.result.nonceStr, // 随机字符串
							package: res.result.packageValue,
							signType: res.result.signType, // 签名算法
							paySign: res.result.paySign, // 签名
							success: function (res) {
								console.log('支付成功',res);
								self.getData()
								self.$refs.confirmationPopup.close()
							},
							fail: function (err) {
								console.log('支付失败',err);
								self.$refs.confirmationPopup.close()
								uni.showToast({
									icon:'none',
									title:"支付失败"
								})
							}
						});
					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.postDetail {
		.box {
			padding: 20rpx;
			.topInfo{
				position: relative;
				.price{
					font-size: 34rpx;
					font-weight: 900;
					margin: 10rpx 0;
				}
				.right{
					position: absolute;
					right: 20rpx;
					top: 0rpx;
					line-height: 50rpx;
					text-align: right;
					.money30{
						font-size: 26rpx;
						color: #D43030;
					}
					.phone{
						text{
							color: #3A6BF1;
							margin-left: 10rpx;
						}
					}
				}
			}
			.title {
				font-size: 34rpx;
				font-weight: 600;
				color: #000;
			}

			.createBy {
				display: flex;
				margin-top: auto;
				margin-bottom: 10rpx;
				font-size: 24rpx;
				margin-top: 20rpx;
				color: #555;

				&>view {
					display: flex;
					align-items: center;
					justify-content: center;
					padding-right: 20rpx;
				}
			}

			.controls {
				margin-top: 30rpx;
			}

			.content {
				margin-top: 30rpx;
				color: #777;
			}
			
			.works{
				display: flex;
				flex-wrap: wrap;
				margin-top: 20rpx;
				.item{
					width: 320rpx;
					margin: 15rpx;
					.item-title{
						padding-bottom: 10rpx;
						color: #000;
					}
					.item-image{
						background-color: #999;
						width: 100%;
						height: 180rpx;
						video{
							width: 100%;
							height: 100%;
						}
					}
				}
			}
		}
	}
	.confirmationPopup{
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		width: 100%;
		height: 300rpx;
		image{
			margin-top: 40rpx;
		}
		.info{
			margin-top: 40rpx;
			font-size: 26rpx;
			padding: 0 30rpx;
		}
	}
</style>