<template>
	<view class="content">
		<image src="../../static/img/b-top.png" mode="" class="b-top"></image>
		<view class="wrap-wrap">
			<view class="u-wrap">
				<view class="top flex">
					<image :src="userInfo.avatar" mode="" class="uavt"></image>
					<view class="name">
						<view class="clamp">
							{{userInfo.nickname}}
						</view>
						<view class="val">
							{{info.is_signing == 0 ?'已开通自动续费':'已解约'}}
						</view>
					</view>
					<view class="btn" @click="qx" v-if="info.is_signing == 0">
						取消续费
					</view>
				</view>
				<view class="type">
					按月捐款
				</view>
				<view class="price">
					¥{{info.price}}/月  每月自动续费
				</view>
			</view>
		</view>
		
		<view class="xq">
			<view class="j-tit">
				<text>捐款详情</text>
			</view>
			<view class="line flex">
				<image src="../../static/icon/dk1.png" mode=""></image>
				<view class="name">
					捐款项目
				</view>
				<view class="val">
					{{info.order_name}}
				</view>
			</view>
			<view class="line flex">
				<image src="../../static/icon/dk2.png" mode=""></image>
				<view class="name">
					每月捐款金额
				</view>
				<view class="val">
					{{info.price}}元
				</view>
			</view>
			<!-- <view class="line flex">
				<image src="../../static/icon/dk3.png" mode=""></image>
				<view class="name">
					支付方式
				</view>
				<view class="val">
					微信支付
				</view>
			</view> -->
		</view>
		<view class="xq" v-if="list.length > 0">
			<view class="j-tit">
				<text>月捐记录</text>
			</view>
			<view class="box">
				<view class="box-item" v-for="item in list" :key="item.id" >
					<view class="main">
						<view class="main-left">
							<view class="project">
								{{item.order_name}}
							</view>
							<view class="time">
								{{item.paytime_text}}
							</view>
						</view>
						<view class="mian-right">
							{{item.amount}}元
						</view>
					</view>
			
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex';
	import { getInfo,qxyue } from '@/api/money.js'
	export default {
		data() {
			return {
				list: [],
				info: {},
				id: 0,
				plan_id:0
			}
		},
		computed: {
			...mapState('user', ['hasLogin', 'userInfo']),
		},
		onLoad(opt) {
			this.id = opt.id;
			this.plan_id = opt.plan_id;
			console.log(opt.id,opt.plan_id,this.id,this.plan_id);
			this.getInfo();
		},
		methods: {
			qx() {
				let that = this
				uni.showModal({
					title: '提示',
					content: '您确定要取消当前的公益月捐？',
					success(res) {
						if (res.confirm) {
							console.log('用户点击确定');
							qxyue({
								id:that.id,
								plan_id:that.plan_id,
							}).then(res => {
								// console.log();
								uni.showToast({
									title: '解约成功',
									duration: 2000
								});
								that.info.is_signing = 1
								// that.getInfo()
								setTimeout(()=> {
									uni.navigateTo({
										url:'/pages/user/user'
									})
								},1500)
								
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
						
					}
				})
			},
			getInfo() {
				getInfo({
					id:this.id,
					plan_id:this.plan_id,
					page:1,
					limit:100
				}).then(res => {
					this.info = res.data.data
					this.list = res.data.list
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.b-top {
		width: 750rpx;
		height: 312rpx;
	}
	.wrap-wrap {
		background-color: #fff;
		padding-bottom:45rpx;
	}
	.u-wrap {
		width: 655rpx;
		height: 324rpx;
		background: linear-gradient(225deg, #FFEED2 0%, #FED591 100%);
		border-radius: 24rpx;
		margin:-200rpx auto 0;
		position: relative;
		padding: 28rpx 36rpx;
		.top {
			align-items: center;
			* {
				flex-shrink: 0;
			}
			.uavt {
				width: 90rpx;
				height: 90rpx;
				border-radius: 50%;
				background-color: #eee;
			}
			.btn {
				width: 190rpx;
				height:70rpx;
				height: 70rpx;
				background: #3A3A3B;
				border-radius: 35rpx;
				font-size: 30rpx;
				color: #FFFFFF;
				text-align: center;
				display: flex;
				justify-content: center;
				align-items: center;
			}
			.name {
				padding-left: 10rpx;
				flex-grow: 1;
				font-weight: 500;
				font-size: 30rpx;
				color: #333333;
				.val {
					font-weight: 500;
					font-size: 20rpx;
					color: #af9c7c;
				}
			}
		}
		
		.type {
			font-weight: bold;
			font-size: 40rpx;
			color: #6B4216;
			position: absolute;
			bottom: 75rpx;
		}
		.price {
			font-weight: 500;
			font-size: 28rpx;
			color: #6B4216;
			position: absolute;
			bottom: 28rpx;
		}
	}
	.xq {
		margin: 20rpx 0;
		background-color: #fff;
		padding: 45rpx  0;
		.line {
			align-items: center;
			padding: 30rpx 27rpx 30rpx 33rpx;
			* {
				flex-shrink: 0;
			}
			image {
				width: 34rpx;
				height: 34rpx;
			}
			.name {
				font-weight: bold;
				font-size: 30rpx;
				color: #333333;
				padding-left: 12rpx;
			}
			.val {
				flex-grow: 1;
				font-size: 26rpx;
				color: #666666;
				text-align: right;
			}
		}
	}
	.j-tit {
		font-weight: bold;
		font-size: 32rpx;
		color: #1D2023;
		text-align: center;
		padding-bottom: 30rpx;
	}
	.box {
		padding: 0 24rpx;
	
		.box-item {
			padding: 24rpx 0;
			border-bottom: 1rpx solid #e0e0e0;
	
			.header {
				color: #999999;
				font-size: 24rpx;
			}
	
			.main {
				margin-top: 22rpx;
				display: flex;
				justify-content: space-between;
	
				.mian-right {
					display: flex;
					flex-direction: column;
					justify-content: flex-end;
				}
	
				.main-left {
					.project {
						color: #333;
						font-size: 28rpx;
					}
	
					.time {
						margin-top: 6rpx;
						color: #999999;
						font-size: 22rpx;
					}
				}
			}
		}
	
	}
</style>