<template>
	<view class="content">
		<image class="yearImg" src="https://cdn.douhuofalv.com/images/2023/04/17/80a076d77afdbe716e29f2ea56f9b103.png" mode="widthFix"></image>
		<view class="list">
			<view class="title">
				<view class="title-name"><text>企业法律咨询服务包</text></view>
				<view class="title-text">legal advice</view>
			</view>
			<view class="item" :class="{active : item.service_user != null}" v-for="(item, index) in synthesisArr" :key="index">
				<view class="endedAt" v-if="item.service_user">
					<view class="endedAt-time">到期时间：{{item.service_user.ended_at}}</view>
				</view>
				<view class="top">
					<view class="top-title">{{item.title}}</view>
					<view class="top-btn" :class="{'hide': item.button_status === 3}" @click="onBtn(index)">
						<text v-if="item.button_status === 0">立即购买</text>
						<text v-if="item.button_status === 1">立即续费</text>
						<text v-if="item.button_status === 2">等待支付</text>
						<text v-if="item.button_status === 3">打款审核中</text>
						<text v-if="item.button_status === 4">打款被驳回</text>
					</view>
				</view>
				<view class="range">
					<view class="range-label">
						<view class="range-label-title">针对群体：</view>
						<view class="range-label-text">
							{{item.audiences}}
						</view>
					</view>
					<view class="range-label">
						<view class="range-label-title">咨询收费：</view>
						<view class="range-label-text">
							{{item.price}}元/年
						</view>
					</view>
					<view class="range-label">
						<view class="range-label-title">服务期限：</view>
						<view class="range-label-text">
							{{item.day}}天
						</view>
					</view>
					<view class="range-label scope" v-if="index == 0">
						<view class="range-label-title">服务范围：</view>
						<view class="range-label-text">
							<text v-for="(items, scopeIndex) in item.scope" :key="scopeIndex">{{scopeIndex + 1}}、{{items}}</text>
						</view>
					</view>
				</view>
				<view class="shape" v-if="index >= 1">
					<view class="shapeBack"></view>
					<view class="shapeCont">
						<view class="shapeWhite">
							<view class="shapeWhite-title">
								服务范围
							</view>
							<view class="shapeWhite-label" v-for="(items, scopeIndex) in item.scope" :key="scopeIndex">
								{{scopeIndex + 1}}、{{items}}
							</view>
							<image class="shapeWhite-back" src="https://cdn.douhuofalv.com/images/2023/04/17/893b41e87c2bdfca62c4936a880c79cd.png" mode="widthFix"></image>
						</view>
					</view>
				</view>
			</view>
		</view>
		
		<image class="yearBttom" src="https://cdn.douhuofalv.com/images/2023/04/17/fc4cad00a630e3d69b3f486e9d2937e9.png" mode="widthFix"></image>
		
		<!-- 关注公众号 -->
		<view class="tipsBack" v-if="generalShow"></view>
		<view class="tipsCont" v-if="generalShow">
			<view class="tipsWhite">
				<image class="tipsCont-img" src="https://douhuo-storage.oss-cn-beijing.aliyuncs.com/images/2023/06/06/6b1485847b45273618f8d922ceee889c.png" mode="widthFix"></image>
				<view class="tipsWhite-top">
					<view class="tipsWhite-name">
						请您先关注抖火法律咨询公众号
					</view>
					<view class="tipsWhite-text">
						关注后，可立即下单
					</view>
				</view>
				<view class="tipsWhite-btn">
					<view class="tipsWhite-btn-go" @click="generalShow = false">
						稍后关注
					</view>
					<view class="tipsWhite-btn-go" @click="judgeGeneral">
						马上关注
					</view>
				</view>
			</view>
		</view>
		
		<!-- 打款凭证弹出 -->
		<view class="voucherBack" :class="{active : voucherState}"></view>
		<view class="voucherPop" :class="{active : voucherState}">
			<view class="tipsWhite">
				<image class="voucherPop-img" src="https://cdn.douhuofalv.com/images/2023/04/17/f4a3c45fe9aa7db143a362fc5b13b31d.png" mode="widthFix"></image>
				<view class="voucherPop-title">
					<view class="voucherPop-name">支付提示</view>
					<view class="voucherPop-text">抱歉，此订单不支持线上支付，请上传打款凭证</view>
					<view class="voucherPop-btn">
						<!-- @click="cancelPay" -->
						<view class="voucherPop-go" @click="voucherState = false">
							暂不支付
						</view>
						<view class="voucherPop-go voucherPop-up" @click="clickOpen">
							上传凭证
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import { judgeReal } from '@/apis/interfaces/user'
	import { authFollow } from '@/apis/interfaces/index'
	import { yearSynthList } from '@/apis/interfaces/synthesis'
	export default {
		data() {
			return {
				synthesisArr  : [],  //企业-年费服务包列表
				generalShow   : false ,// 公众号
				voucherState  : false,  // 上传凭证弹出
				orderId		  : '',     // 订单 ID
				orderType     : '',     // 订单类型
				orderPrice    : '',     // 订单金额
			}
		},
		
		created() {},
		
		
		onShow() {
			// 获取-个人-年费服务包列表
			this.yearServe();
		},
		
		methods: {
			// 个人-年费服务包列表
			yearServe(){
				yearSynthList({
					type: this.$Route.query.type
				}).then(res => {
					this.synthesisArr = res
				}).catch(err => {
					uni.showToast({
						title: err.message,
						icon : 'none'
					})
				})
			},
			
			// 点击开通按钮
			onBtn(index){
				let obj = this.synthesisArr[index]
				if(obj.service_order === null){
					this.onOpenPAY(obj.synthesis_service_id)
					return
				}
				switch (obj.button_status){
					case 1:
						this.onOpenPAY(obj.synthesis_service_id)
						break;
					case 2:
						this.expressSheet(obj.service_order.service_order_id, obj.service_order.order_type, obj.service_order.can, obj.service_order.price)
						break;
					case 3:
						uni.showToast({
							title: '打款凭证审核中，请耐心等待',
							icon : 'none'
						})
						break;
					case 4:
						uni.showModal({
							title		: '审核被驳回',
							content		: '驳回原因：' + obj.service_order.offline_pays.remark,
							showCancel	: false,
							success		: modalRes => {
								if(modalRes.confirm){
									this.$Router.push({
										name	: 'VoucherOpen',
										params	: {
											payId	 	: obj.service_order.offline_pays.offline_pay_id,
											type	 	: 'edit',
											orderId		: obj.service_order.order_id,
											orderType	: obj.service_order.order_type.replace(/\\/g, '-'),
											price		: obj.price
										}
									})
								}
							}
						})
					break;
				}
			},
			
			// 选择支付方式
			expressSheet(id, type, can, price) {
				this.orderId   = id
				this.orderType = type
				this.orderPrice = price
				uni.showActionSheet({
				    itemList: ['线上支付', '线下支付'],
				    success: sheetRes => {
						if(sheetRes.tapIndex == 0) {
							if(can.online) {
								this.$Router.push({name: 'FeePay', params: {id: id, orderType: type, price: price, payForm: 'service'}})
								return
							}
							this.voucherState = true
						} else if (sheetRes.tapIndex == 1) {
							this.$Router.push({name: 'VoucherOpen', params: {orderId: id, orderType: type, price: price}})
						}
				    },
				    fail: sheetFail => {}
				})
			},
			
			// 取消支付
			// cancelPay() {
			// 	this.voucherState = false
			// 	uni.showToast({
			// 		title: '取消支付',
			// 		icon : 'none'
			// 	})
			// 	setTimeout(()=>{
			// 		this.$Router.replace({name: 'YearOrder', params: {yearType: 2}})
			// 	},3000)
			// },
			
			// 上传凭证
			clickOpen() {
				this.voucherState = false
				this.$Router.push({name: 'VoucherOpen', params: {orderId: this.orderId, orderType: this.orderType, price: this.orderPrice}})
			},
			
			// 填写支付信息
			onOpenPAY(serveId){
				// 判断是否认证
				judgeReal().then(res => {
					if(res.has_sign) {
						if(!res.has_subscribe) {
							// 弹出公众号
							this.generalShow = true
						} else {
							// 跳到咨询表单页
							this.$Router.push({
								name: 'StandWrite',
								params: {
									serveId
								}
							})
						}
						return
					}
					// 跳到认证页面
					this.$Router.replace({name: 'sheetIdcard'})
				}).catch( err => {
					uni.showToast({
						title: err.message,
						icon: "none"
					})
				})
			},
			
			// 状态
			judgeGeneral(){
				// 获取微信授权信息
				authFollow({
					url: 'https://web.douhuofalv.com/webview/webCode'
				    // url: 'https://web.douhuotest.douhuofalv.com/webview/webCode'
				}).then(res => {
				    window.location.href = res
				}).catch(err => {
				    uni.showToast({
				        title: err.message,
				        icon: "none"
				    })
				})
				
				// 关闭公众号
				this.generalShow = false
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		width: 100vw;
		background-color: #121d4c;
	}
	
	.yearImg,
	.yearBttom{
		width: 100%;
		display: block;
	}
	
	.list {
		padding: 30rpx;
		box-sizing: border-box;
		background-color: #121d4c;
		.title {
			margin-bottom: 40rpx;
			display: flex;
			height: 80rpx;
			line-height: 80rpx;
			.title-name {
				flex: 1;
				text {
					padding: 0 70rpx 0 30rpx;
					font-size: 36rpx;
					background-image: -webkit-linear-gradient(40deg,#f1c593, #fef9f2);
					display: inline-block;
					color: #2c3c66;
					font-weight: 600;
					position: relative;
					&:after {
						position: absolute;
						content: '';
						right: 0;
						top: 0;
						width: 0;
						height: 0;
						border-width: 40rpx;
						border-style: solid;
						border-color: transparent #121d4c transparent transparent;
					}
				}
			}
			.title-text {
				font-size: 36rpx;
				text-transform: uppercase;
				background-image: -webkit-linear-gradient(top,#86716b, #8e8f9c);
				-webkit-background-clip:text; 
				-webkit-text-fill-color:transparent;
			}
		}
		.item {
			background-color: #002088;
			border-radius: 20rpx;
			padding: 30rpx;
			box-sizing: border-box;
			margin-bottom: 30rpx;
			position: relative;
			&.active {
				padding-top: 70rpx;
			}
			.endedAt {
				position: absolute;
				top: 0;
				left: 0;
				display: inline-block;
				color: #2c3c66;
				width: 100%;
				text-align: center;
				.endedAt-time {
					background-image: -webkit-linear-gradient(40deg,#f1c593, #fef9f2);
					margin: 0 auto;
					display: inline-block;
					padding: 0 20rpx;
					line-height: 52rpx;
					font-size: 26rpx;
					border-radius: 0 0 5rpx 5rpx;
					color: #582700;
				}
			}
			.top {
				display: flex;
				font-weight: 600;
				line-height: 54rpx;
				margin-bottom: 20rpx;
				.top-title {
					font-size:36rpx;
					background-image: -webkit-linear-gradient(top,#fdf6ca, #e29c68); 
					-webkit-background-clip:text; 
					-webkit-text-fill-color:transparent;
					flex: 1;
				}
				.top-btn {
					background-image: -webkit-linear-gradient(top,#fff8da,#f3c796);
					color: #582700;
					padding: 0 30rpx;
					border-radius: 50rpx;
					box-shadow: 0 8rpx 6rpx rgba(0, 0, 0, .3);
					&.hide{
						opacity: .7;
					}
				}
			}
			.range {
				color: #ffffff;
				font-size: 28rpx;
				.range-label {
					line-height: 40rpx;
					padding: 10rpx 0;
					display: flex;
					.range-label-title {
						width: 160rpx;
					}
					.range-label-text {
						width: calc(100% - 160rpx);
						text {
							display: block;
							margin-bottom: 20rpx;
							&:last-child {
								margin-bottom: 0;
							}
						}
					}
				}
			}
			
			.shape {
				position: relative;
				margin-top: 30rpx;
				font-size: 28rpx;
				.shapeBack {
					background-color: #0d245b;
					height: 20rpx;
					width: 100%;
					border: 4rpx solid #e8c595;
					border-radius: 80rpx;
				}
				.shapeCont {
					padding: 0 30rpx;
					box-sizing: border-box;
					margin-top: -18rpx;
					.shapeWhite {
						background-color: #ffffff;
						border-radius: 0 0 20rpx 20rpx;
						padding: 40rpx 30rpx 30rpx;
						box-sizing: border-box;
						color: #0e2660;
						position: relative;
						&::after {
							position: absolute;
							content: '';
							top: 0;
							left: 0;
							width: 100%;
							height: 20rpx;
							background-image: -webkit-linear-gradient(top, #a7a8ad, transparent);
						}
						.shapeWhite-title {
							font-size: 38rpx;
							margin-bottom: 20rpx;
						}
						.shapeWhite-label {
							padding: 10rpx 0;
							line-height: 44rpx;
						}
						.shapeWhite-back {
							width: 85%;
							position: absolute;
							right: 0;
							bottom: 0;
						}
					}
				}
			}
		}
		
	}
	
	// 关注
	.tipsBack {
		position: fixed;
		width: 100vw;
		height: 100vh;
		left: 0;
		top: 0;
		z-index: 9;
		background-color: rgba(0, 0, 0, .8);
	}
	.tipsCont {
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-box-pack: center;
		position: fixed;
		left: 0;
		right: 0;
		top: 0;
		bottom: 0;
		z-index: 10;
		padding: 0 10%;
		box-sizing: border-box;
	}
	
	.tipsWhite {
		background-color: #ffffff;
		border-radius: 20rpx;
		overflow: hidden;
	}
	
	.tipsWhite-top {
		padding: $padding;
		box-sizing: border-box;
		text-align: center;
	}
	
	.tipsCont-img {
		width: 100%;
	}
	
	.tipsWhite-name {
		text-align: center;
		color: #111111;
		font-size: 34rpx;
		font-weight: 600;
		margin-bottom: 15rpx;
	}
	
	.tipsWhite-text {
		font-size: 30rpx;
		color: #666666;
		line-height: 48rpx;
	}
	
	.tipsWhite-btn {
		display: flex;
		padding: $padding 10rpx;
		box-sizing: border-box;
		.tipsWhite-btn-go {
			flex: 2;
			color: #fff;
			margin: 0 15rpx;
			height: 80rpx;
			line-height: 80rpx;
			text-align: center;
			border: 2rpx solid #F6F6F6;
			background-color: #007df5;
			border-radius: $radius-m;
			&:first-child {
				color: #333333;
				background-color: #ffffff;
				border: 2rpx solid #cccccc;
			}
		}
	}
	
	// 打款凭证弹出
	.voucherBack {
		position: fixed;
		width: 100vw;
		height: 100vh;
		left: 0;
		top: 0;
		z-index: 99;
		background-color: rgba(0, 0, 0, .6);
		display: none;
		&.active {
			display: block;
		}
	}
	.voucherPop {
		-webkit-box-orient: vertical;
		-webkit-box-pack: center;
		position: fixed;
		left: 0;
		right: 0;
		top: 0;
		bottom: 0;
		z-index: 100;
		padding: 0 10%;
		box-sizing: border-box;
		display: none;
		&.active {
			display: -webkit-box;
		}
		.tipsWhite {
			background-color: #ffffff;
			border-radius: 20rpx;
			position: relative;
			.voucherPop-img {
				position: absolute !important;
				top: -80rpx;
				right: calc(50% - 100rpx);
				width: 200rpx;
			}
			.voucherPop-title {
				box-sizing: border-box;
				padding: 50rpx 70rpx;
				margin-top: 100rpx;
				text-align: center;
				.voucherPop-name {
					font-weight: 600;
					font-size: 38rpx;
				}
				.voucherPop-text {
					padding: 30rpx 0 35rpx;
					line-height: 44rpx;
				}
				.voucherPop-btn {
					display: flex;
					.voucherPop-go {
						flex: 2;
						text-align: center;
						border: 2rpx solid #da2b56;
						color: #da2b56;
						margin: 0 15rpx;
						line-height: 74rpx;
						border-radius: 10rpx;
						background-color: #ffffff;
						&.voucherPop-up {
							background-color: #da2b56;
							color: #ffffff;
						}
					}
				}
			}
		}
	}
</style>