<template>
	<view class="about">
		<view class="about-navbar" :style="{'height': (statusBarHeight+44)+'px'}">
			<u-navbar :bgColor="bgColor" :fixed="false" :autoBack="true" title="云股东中心">
				<view class="u-nav-slot" slot="content">
					<view class="nav"></view>
				</view>
			</u-navbar>
		</view>
		<view class="blank" :style="{'height': (statusBarHeight+44)+'px'}"></view>
		<view class="about-banner">
			<image mode="widthFix" src="https://zhengxin.njrenzhou.cn/static/yunbanner.png"></image>
		</view>
		<view class="about-gift" v-if="info.is_vip == 1">
			<image src="https://zhengxin.njrenzhou.cn/static/gift.png"></image>
			<view class="title">恭喜您成功已成为诚信点评云股东！</view>
		</view>
		<view class="about-gift" v-else>
			<view class="txt">
				<view class="title">成为诚信点评云股东</view>
				<view class="desc">{{info.yungudong.pay_money}}元/年<text>{{info.yungudong.pay_money}}元/年</text></view>
			</view>
			<view class="btn" @click="toCreate(2)">发起支付</view>
		</view>
		<view class="about-menu">
			<view class="title">云股东权益</view>
			<view class="desc" v-html="info.yungudong.content"></view>
		</view>
		<view class="about-menu">
			<view class="title">赞赏平台</view>
			<scroll-view scroll-x class="list" :show-scrollbar="true">
				<view class="item" :class="tabIndex == index?'item-on':''" v-for="(item,index) in info.zanshang" :key="index" @click="tabItem(index)">
					<view class="a">{{item.title}}</view>
					<view class="b"><text>{{item.money}}</text>元</view>
				</view>
			</scroll-view>
		</view>
		<view class="about-tip">所有的赞赏均被用于产品开发及援助他人！</view>
		<view class="btns" @click="toCreate(3)">支付赞赏</view>
	</view>
</template>

<script>
	const systemInfoSync = uni.getSystemInfoSync();
	export default {
		data() {
			return {
				statusBarHeight: 0,
				tabIndex: 0,
				list: [],
				info: {},
				bgColor: "transparent",
				isClick: true
			};
		},
		onLoad() {
			this.statusBarHeight = systemInfoSync.statusBarHeight
			this.getInfo();
		},
		methods: {
			tabItem(index) {
				this.tabIndex = index;
			},
			//获取信息
			async getInfo() {
				const { code, data, msg } = await this.$api.getyungudong({token: uni.getStorageSync("token")});
				if(code == 1){
					this.info = data;
				}
			},
			//去创建订单
			async toCreate(index) {
				if(this.isClick == false){
					return ;
				}
				this.isClick = false;
				if(index == 2){
					this.id = this.info.yungudong.id
				}else{
					this.id = this.info.zanshang[this.tabIndex].id
				}
				uni.showLoading({
					title: "支付中"
				})
				const { code, data, msg } = await this.$api.createOrder({type: index, token:uni.getStorageSync("token"),id: this.id})
				if(code == 1){
					this.toPay(data.money, data.order_no)
				}else {
					uni.showToast({
						icon: "none",
						title: msg
					})
				}
			},
			//去支付
			async toPay(pay_price,orderno) {
				const that = this;
				const { code, data, msg } = await that.$api.beforePay({pay_price, token:uni.getStorageSync("token"),orderno})
				if(code == 1){
					uni.requestPayment({
						timeStamp: data.timeStamp,
						nonceStr: data.nonceStr,
						package: data.package,
						signType: data.signType,
						paySign: data.paySign,
						success(res){
							that.isClick = true;
							uni.showToast({
								title: "支付成功",
								icon: "success"
							})
							setTimeout(()=>{
								that.getInfo();
							},2000)
						},
						fail(res){
							that.isClick = true;
							uni.showToast({
								title: "支付失败",
								icon: "error"
							})
							setTimeout(()=>{
								that.getInfo();
							},2000)
						}
					})
				}else {
					uni.showToast({
						icon: "none",
						title: msg
					})
				}
			},
		}
	}
</script>

<style scoped lang="scss">
	// https://zhengxin.njrenzhou.cn
.about{
	min-height: 100vh;
	background: url(https://zhengxin.njrenzhou.cn/static/bg3.png) center top no-repeat;
	background-size: 100% auto;
	overflow: hidden;
	padding: 0 25rpx;
	box-sizing: border-box;
	&-navbar{
		position: fixed;
		left: 0;
		right: 0;
		top: 0;
		z-index: 12;
		width: 100%;
		background: url(https://zhengxin.njrenzhou.cn/static/bg3.png) center top no-repeat;
		background-size: 100% auto;
	}
	&-banner{
		width: 100%;
		min-height: 280rpx;
		margin: 0 auto;
		margin-top: 10rpx;
		image{
			width: 100%;
			height: 100%;
		}
	}
	&-tip{
		font-weight: 500;
		font-size: 24rpx;
		color: #222222;
		margin-top: 30rpx;
		text-align: center;
	}
	.btns{
		width: 220rpx;
		line-height: 80rpx;
		background: #32303E;
		border-radius: 80rpx;
		font-weight: 500;
		font-size: 28rpx;
		color: #FFFFFF;
		margin: 30rpx auto;
		text-align: center;
	}
	&-gift{
		width: 100%;
		height: 314rpx;
		background: #FFFFFF;
		border-radius: 20rpx;
		padding: 30rpx;
		box-sizing: border-box;
		margin: 0 auto;
		margin-top: 20rpx;
		text-align: center;
		.txt{
			width: 100%;
			height: 150rpx;
			background: #FAF7F0;
			border-radius: 10rpx;
			border: 1px solid #32303E;
			padding: 20rpx;
			box-sizing: border-box;
			.desc{
				font-weight: 500;
				font-size: 28rpx;
				color: #D80C0C;
				margin-top: 20rpx;
				text{
					font-size: 24rpx;
					color: #999999;
					margin-left: 20rpx;
					text-decoration-line: line-through;
				}
			}
		}
		.btn{
			width: 220rpx;
			line-height: 80rpx;
			background: #32303E;
			border-radius: 80rpx;
			font-weight: 500;
			font-size: 28rpx;
			color: #FFFFFF;
			margin: 0 auto;
			margin-top: 25rpx;
		}
		image{
			width: 228rpx;
			height: 170rpx;
			margin-bottom: 20rpx;
		}
		.title{
			font-weight: 500;
			font-size: 36rpx;
			color: #222222;
		}
	}
	&-menu{
		width: 100%;
		min-height: 180rpx;
		background: #FFFFFF;
		border-radius: 20rpx;
		padding: 30rpx;
		box-sizing: border-box;
		margin: 0 auto;
		margin-top: 20rpx;
		.title{
			font-weight: 500;
			font-size: 36rpx;
			color: #222222;
		}
		.desc{
			font-weight: 500;
			font-size: 28rpx;
			color: #222222;
			line-height: 42rpx;
			overflow: hidden;
			margin-top: 20rpx;
		}
		.list{
			white-space: nowrap;
			overflow: hidden;
			margin-top: 30rpx;
			.item{
				width: 200rpx;
				height: 156rpx;
				background: #FAF7F0;
				border-radius: 10rpx;
				border: 1px solid #FAF7F0;
				text-align: center;
				display: inline-block;
				padding: 25rpx;
				box-sizing: border-box;
				margin-left: 20rpx;
				&:first-child{
					margin-left: 0;
				}
				.a{
					font-weight: 500;
					font-size: 24rpx;
					color: #222222;
					white-space: initial;
				}
				.b{
					font-weight: 500;
					font-size: 36rpx;
					color: #D80C0C;
					margin-top: 5rpx;
				}
				&-on{
					border: 1px solid #32303E;
				}
			}
		}
	}
}
</style>
