<template>
	<view class="virtualGoods-detail">
		<view class="content">
			<!-- <view class="popup-title">会员充值</view> -->
			<view class="goods-box">
				<image class="icon" :src="chooseInfo.mainImg" mode=""></image>
				<view class="goods-info">
					<view class="goods-title">
						{{chooseInfo.item_name}}
					</view>
					<view class="goods-desc">
						{{chooseInfo.catalogName}}
					</view>
				</view>
				<view class="price">
					￥{{Number(chooseInfo.channel_price).toFixed(2)}}
				</view>
			</view>

			<view class="notice">
				暂不提供IOS用户进行充值业务
			</view>

			<u--form labelPosition="top" :model="form" ref="uForm" borderBottom labelWidth="180rpx" :labelStyle="{'color': '#222222',
		'font-weight': 'bold','line-height':'60rpx','font-size': '28rpx'}">
				<u-form-item label="账号类型" borderBottom ref="item1">
					<view class="type-box" @click="show = true">
						<view class="">
							{{type}}
						</view>
						<image class="icon" src="../../static/right.png" mode=""></image>
					</view>
				</u-form-item>
				<u-form-item label="充值账号" prop="account" borderBottom ref="item1">
					<u--input v-model.trim="form.account" placeholder="请输入充值账号" border="none"></u--input>
				</u-form-item>
			</u--form>
			<view class="goods-describe">

				<rich-text :nodes="chooseInfo.goodsDescribe"></rich-text>
			</view>
			<button class="btn" type="default" :loading="loading" @click="handleBuy">确认</button>
		</view>
		
		<u-modal :show="iosShow" content='暂不提供IOS用户进行充值业务' @confirm="iosShow = false"></u-modal>
		
		<!-- 选择账号类型 -->
		<u-picker :show="show" :value='shopIndex' keyName="label" :closeOnClickOverlay="false" :columns="list" @confirm="choose" @cancel="show = false"></u-picker>
		
	</view>
</template>

<script>
	import {SHOP_ID} from '@/utils/config.js'
	export default {
		data() {
			return {
				show:false,
				iosShow: false,
				chooseInfo: {channel_price:0},
				type:'手机号',
				form:{
					account:'',
					accountType:1,
					productId:''
				},
				list:[
					[
						{
							label:'手机号',
							value:1,
						},
						{
							label:'QQ号',
							value:2,
						},
						{
							label:'其他',
							value:0,
						},
					]
				]
			}
		},
		methods: {
			choose(val){
				console.log(val.value[0]);
				this.type = val.value[0].label
				this.form.accountType = val.value[0].value
				this.$nextTick(()=>{
					this.show = false
				})
			},
			// 创建订单
			handleBuy() {
				if (uni.getStorageSync('token')) {
					if(JSON.parse(uni.getStorageSync('userInfo')).setMealCode == 0){
						if(!this.form.account) return uni.showToast({
							title:'请输入充值账号',
							icon:'none'
						})
						let that = this
						uni.getSystemInfo({
							success(res){
								console.log(res.osName);
								if(res.osName == 'ios'){
									that.show = false
									that.iosShow = true
								}else{
									let info = {
										price:Number(that.chooseInfo.channel_price).toFixed(2),
										goodsName:that.chooseInfo.item_name,
										accountType:that.form.accountType,
										rechargeAccount:that.form.account,
										productId:that.chooseInfo.product_id
									}
									uni.navigateTo({
										url:`/detail/virtualGoods/pay`,
										  success: function(res) {
											// 通过eventChannel向被打开页面传送数据
											res.eventChannel.emit('pay', info)
										  }
									})
								}
							}
						})
					}else{
						uni.showModal({
							title:'此商品需要开通会员才能购买',
							cancelText:'下次再说',
							confirmText:'立即开通',
							success(res) {
								if(res.confirm){
									uni.navigateTo({
										url:'/my/memberCenter/index'
									})
								}
							}
						})
					}
					
					
				} else {
					uni.showModal({
						title:'请登录',
						confirmText:'去登录',
						success(res){
							console.log(res);
							if(res.confirm){
								uni.navigateTo({
									url:'/login/login/login?redirect=/detail/virtualGoods/index'
								})
							}
						}
					})
				}
			
			}
		},
		onLoad() {
			let that = this
			const eventChannel = this.getOpenerEventChannel();
			eventChannel.on('data', function(data) {
				console.log('da',data);
				that.chooseInfo = data
				
			})
		}
	}
</script>

<style lang="scss" scoped>
	.virtualGoods-detail {
		.content{
			padding: 24rpx;
			.popup-title{
				font-size: 32rpx;
				font-weight: bold;
				color: #222222;
			}
			.type-box{
				display: flex;
				justify-content: space-between;
				align-items: center;
				.icon{
					width: 40rpx;
					height: 40rpx;
				}
			}
			.goods-box{
				display: flex;
				margin-top: 28rpx;
				.icon{
					width: 160rpx;
					height: 160rpx;
					border-radius: 16rpx;
					background: #F0F0F0;
				}
				.goods-info{
					display: flex;
					flex-direction: column;
					justify-content: space-around;
					flex: 1;
					margin-left: 20rpx;
					.goods-title{
						color: #222222;
						font-weight: bold;
						font-size: 36rpx;
					}
					.goods-desc{
						font-size: 28rpx;
						color: #AAAAAA;
					}
				}
				.price{
					color: $uni-color-primary;
					font-size: 36rpx;
					font-weight: bold;
					align-self: center;
				}
			}
			.notice{
				font-size: 24rpx;
				color: #AAAAAA;
				padding: 26rpx 0;
				border-bottom: 2rpx solid #F0F0F0;
			}
			.goods-describe{
				color: #222222;
				font-size: 24rpx;
				max-height: 480rpx;
				padding-top: 28rpx;
				overflow: auto;
			}
			.btn{
				position: fixed;
				left: 30rpx;
				bottom: env(safe-area-inset-bottom);
				width: 690rpx;
				height: 80rpx;
				line-height: 80rpx;
				background: $uni-color-primary;
				border-radius: 46rpx;
				margin-top: 54rpx;
				font-size: 28rpx;
				color: #fff;
			}
		}
	}
</style>