<template>
	<view class="content">
		<image class="yearImg" src="https://cdn.douhuofalv.com/images/2023/04/17/85db0728f2bae879ecbe561eed100549.png" mode="widthFix"></image>
		<view class="list">
			<view class="title">
				<view class="title-name"><text>个人法律咨询365服务包</text></view>
				<image class="title-img" src="https://cdn.douhuofalv.com/images/2023/04/17/79426f8fe9395c1c1f5be41d0a6f2eb8.png" mode="widthFix"></image>
			</view>
			<view class="item" v-for="(item, index) in synthesisArr" :key="index">
				<view class="item-back">
					<view class="item-title">{{item.title}}</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>
					<image class="shapeWhite-back" src="https://cdn.douhuofalv.com/images/2023/04/17/705af638ddaed151ce5bc5ead85f604d.png" mode="widthFix"></image>
				</view>
				<view class="btn">
					<view class="btn-go" :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 class="order-at" v-if="item.is_open">到期时间：{{item.service_user.ended_at}}</view>
				</view>
			</view>	
		</view>
		<image class="yearBttom" src="https://cdn.douhuofalv.com/images/2023/04/17/fc4cad00a630e3d69b3f486e9d2937e9.png" mode="widthFix"></image>
	</view>
</template>

<script>
	import { yearSynthList } from '@/apis/interfaces/synthesis'
	import { certified } from '@/apis/interfaces/user'
	export default {
		data() {
			return {
				synthesisArr: [], // 服务单信息
				price		: ''  // 支付价格
			}
		},
		onShow() {
			this.yearServe();
		},
		methods: {
			// 年费服务包列表
			yearServe(){
				yearSynthList({
					type: 1
				}).then(res => {
					this.synthesisArr = res
				}).catch(err => {
					uni.showToast({
						title: err.message,
						icon : 'none'
					})
				})
			},
			// 点击开通按钮
			onBtn(index){
				let obj  = this.synthesisArr[index]
				switch (obj.button_status){
					case 2:
						let { order_id, order_type, can, price } = obj.service_order
						this.price = price
						this.expressSheet(order_id, order_type, can)
						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	: 'BankPay',
										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;
					default:
						this.$Router.push({
							name: 'PersonWrite',
							params: {
								serveId: obj.synthesis_service_id
							}
						})
						break;
				}
			},
			// 选择支付方式
			expressSheet(id, type, can) {
				this.orderId   = id
				this.orderType = type
				// 仅支持线下打款
				if(!can.online){
					this.onToBankPay()
					return
				}
				// 选择线上、下支付方式
				uni.showActionSheet({
					itemList: ['线上支付', '线下支付'],
					success: sheetRes => {
						if(sheetRes.tapIndex == 0){
							this.$Router.push({
								name: 'Pay',
								params: {
									paytype		: 'synthesize',
									orderId		: id,
									orderType	: type.replace(/\\/g, '-')
								},
							})
							return
						}
						this.onToBankPay()
				    }
				})
			},
			// 去线下打款
			onToBankPay(){
				this.$Router.push({
					name: 'BankPay',
					params: {
						orderId		: this.orderId,
						orderType	: this.orderType.replace(/\\/g, '-'),
						price		: this.price
					},
				})
			}
		}
	}
</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: #032e9e;
		border-radius: 0 0 60rpx 60rpx;
		.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 #03339e transparent transparent;
					}
				}
			}
			.title-img {
				width: 110rpx;
			}
		}
		.item {
			margin-bottom: 30rpx;
			.item-back {
				background-color: #002088;
				border-radius: 20rpx;
				padding: 30rpx;
				box-sizing: border-box;
				position: relative;
				.item-title {
					font-weight: 600;
					font-size:36rpx;
					background-image: -webkit-linear-gradient(top,#fdf6ca, #e29c68); 
					-webkit-background-clip:text; 
					-webkit-text-fill-color:transparent;
					flex: 1;
					margin-bottom: 30rpx;
				}
				.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;
								}
							}
						}
					}
				}
				.shapeWhite-back {
					width: 50%;
					position: absolute;
					left: 0;
					bottom: 0;
				}
			}
			.btn {
				padding: 40rpx;
				box-sizing: border-box;
				text-align: center;
				.btn-go {
					display: inline-block;
					background-image: -webkit-linear-gradient(top,#fff8da,#f3c796);
					color: #582700;
					width: 50%;
					font-weight: 600;
					font-size: 36rpx;
					line-height: 88rpx;
					border-radius: 50rpx;
					box-shadow: 0 8rpx 6rpx rgba(0, 0, 0, .3);
					&.hide{
						opacity: .7;
					}
				}
				.order-at{ text-align: center; color: white; font-size: 30rpx; padding-top: 30rpx; }
			}
		}
		
	}
</style>