<template>
	<view class="content">
		<image class="expandImg" src="https://cdn.douhuofalv.com/images/2023/04/19/df2ecf6ece3e59de1d51c4ad09aa68f3.jpg" mode="widthFix"></image>
		<view class="list">
			<view class="list-title">
				<view class="list-title-number">expand</view>
				<view class="list-title-name">法律服务拓展包</view>
				<view class="list-title-trim"></view>
			</view>
			<view class="list-item">
				 <!-- @click="seekClick(item.expand_id)" -->
				<view class="list-label" v-for="(item, index) in entrustArr" :key="index">
					<view class="list-label-name">
						{{item.title}}
					</view>
					<view class="list-label-price"><rich-text :nodes="item.content"></rich-text></view>
					<!-- <view class="list-label-go">购买</view> -->
					<!-- data[0].order.status -->
					
					<view class="list-label-go" :class="{'hide': item.button_status === 2}" @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>
					</view>
				</view>
			</view>
		</view>
		<image class="expandBttom" 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 { expandsList } from '@/apis/interfaces/synthesis'
	export default {
		data() {
			return {
				entrustArr  	: [],     //案件委托列表
				generalShow 	: false,
				voucherState    : false,  // 上传凭证弹出// 公众号
				orderId			: '',     // 订单 ID
				orderType       : '',     // 订单类型
				orderPrice      : '',     // 订单金额
			}
		},
		
		created() {},
		
		onShow() {
			// 获取-案件委托-列表
			this.yearServe();
		},
		
		
		methods: {
			// 案件委托-列表
			yearServe(){
				expandsList().then(res => {
					this.entrustArr = res
				}).catch(err => {
					uni.showToast({
						title: err.message,
						icon : 'none'
					})
				})
			},
			
			// 点击开通按钮
			onBtn(index){
				let obj = this.entrustArr[index]
				if(obj.order === null){
					this.seekClick(obj.expand_id)
					return
				}
				// 0 购买 1 待支付 2 待审核 3 驳回
				switch (obj.button_status){
					case 0:
						this.seekClick(obj.expand_id)
						break;
					case 1:
						this.expressSheet(obj.order.expand_order_id, obj.order.order_type, obj.order.can, obj.order.price)
						break;
					case 2:
						uni.showToast({
							title: '打款凭证审核中，请耐心等待',
							icon : 'none'
						})
						break;
					case 3:
						this.$Router.push({
							name	: 'VoucherOpen',
							params	: {
								payId	 	: obj.order.offline_pays.offline_pay_id,
								type	 	: 'edit',
								orderId		: obj.order.order_id,
								orderType	: obj.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 => {}
				})
			},
			
			// 上传凭证
			clickOpen() {
				this.voucherState = false
				this.$Router.push({name: 'VoucherOpen', params: {orderId: this.orderId, orderType: this.orderType, price: this.orderPrice}})
			},
			
			// 立即咨询
			seekClick(entrustId) {
				// 判断是否认证
				judgeReal().then(res => {
					if(res.has_sign) {
						if(!res.has_subscribe) {
							// 弹出公众号
							this.generalShow = true
						} else {
							// 跳到咨询表单页
							this.$Router.push({
								name: 'ExpandWrite',
								params: {
									entrustId
								}
							})
						}
						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 {
		background-color: #121d4c;
	}
	
	.expandImg,
	.expandBttom{
		width: 100%;
		display: block;
	}
	
	.list {
		padding: 0 30rpx 30rpx;
		box-sizing: border-box;
		background-color: #121d4c;
		.list-title {
			font-size: 36rpx;
			margin-bottom: 40rpx;
			color: #ffffff;
			.list-title-trim {
				position: relative;
				left: 390rpx;
				bottom: 28rpx;
				background-color: #2f3aae;
				width: 35%;
				height: 4rpx;
				padding-left: 40rpx;
				box-sizing: border-box;
				&::after {
					position: absolute;
					content: '';
					left: -50rpx;
					top: -10rpx;
					width: 20rpx;
					height: 20rpx;
					transform:rotate(45deg);
					background-color: #2f3aae;
				}
			}
			.list-title-number {
				font-weight: 600;
				font-size: 58rpx;
				background-image: -webkit-linear-gradient(top,#ffffff 40%, transparent 70%);
				-webkit-background-clip:text; 
				-webkit-text-fill-color:transparent;
				text-transform: uppercase;
			}
			.list-title-name {
				font-size: 44rpx;
				margin-top: -20rpx;
				width: 390rpx;
			}
		}
		.list-item {
			position: relative;
			padding-left: 100rpx;
			box-sizing: border-box;
			&::after {
				position: absolute;
				content: '';
				left: 10rpx;
				top: 0;
				border-left: 4rpx dashed #3b46d6;
				width: 0;
				height: calc(100% - 64rpx);
			}
			.list-label {
				background-image: linear-gradient(to right,#3d48dd, #1f2a6f);
				padding: 15rpx 40rpx 15rpx 90rpx;
				box-sizing: border-box;
				border-radius: 80rpx 15rpx 15rpx 80rpx;
				margin-bottom: 30rpx;
				color: #ffffff;
				position: relative;
				&::before {
					position: absolute;
					content: '';
					left: -88rpx;
					top: calc(50% - 1rpx);
					border-bottom: 4rpx dashed #3b46d6;
					width: 60rpx;
					height: 0;
				}
				&::after {
					position: absolute;
					content: '';
					left: 40rpx;
					top: calc(50% - 9rpx);
					background-color: #091443;
					width: 18rpx;
					height: 18rpx;
					border-radius: 50%;
				}
				.list-label-name {
					margin-bottom: 5rpx;
				}
				.list-label-price {
					line-height: 48rpx;
				}
				.list-label-go {
					position: absolute;
					right: 30rpx;
					top: 35rpx;
					background-image: -webkit-linear-gradient(40deg,#f1c593, #fef9f2);
					color: #12053d;
					display: inline-block;
					line-height: 54rpx;
					padding: 0 30rpx;
					border-radius: 54rpx;
					font-size: 26rpx;
					font-weight: 600;
					&.hide{
						opacity: .7;
					}
				}
			}
		}
	}
	
	
	// 关注
	.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>