<template>
	<view class="installmentbox">
		<!-- 产品信息 -->
		<view class="mobile">
			<view class="ltpic">
				<image :src="cart[0].image" mode=""></image>
			</view>
			<view class="rtcan">
				<text class="title">{{cart[0].productName}}</text>
				<view class="combination">
					<text>套餐:</text> <text>{{cart[0].sku}}</text>
				</view>
				<view class="tenancy">
					<text>租期:</text> <text>{{num}}期</text>
				</view>
				<view class="tenancy">
					<text>间隔:</text> <text>30天</text>
				</view>
				<view class="tenancy">
					<text>数量:</text> <text>{{cart[0].payNum}}</text>
				</view>
			</view>
		</view>
		<!-- 租金 -->
		<view class="rent">
			<view class="shouqi">
				<text>￥{{hireshou}} (第1期)</text>
				<view class="wz">
					首期租金
				</view>
			</view>
		<!-- 	<view class="zongzu">
				<text>￥{{sum}}</text>
				<view class="wz">
					总租金
				</view>
			</view> -->
			<view class="edu">
				<text>￥{{sum}}</text>
				<view class="wz">
					总金额
				</view>
			</view>
		</view>
		<!-- 分期方式 -->
		<view class="repayment">
			<view class="gap">
				<text class="title">分期方式</text> <text class="gapwz">间隔：{{fenqiobj.cycle}}天</text>
			</view>
			<view class="qishu">
				<text>期数</text> <text>还款日期</text> <text>还款金额</text>
			</view>
			<view class="date" style="margin-top: 40rpx;" v-for="(item,index) in installmentlist" :key="index">
				<text>第{{item.installmentNumber}}/{{installmentlist.length}}期</text> <text>日期：{{item.repaymentDeadlineStr}}</text> <text>￥{{item.repaymentAmount}}</text>
			</view>
		</view>

		<!-- 返回 -->
		<view class="return">
			<a href="javascript:;" @click="back">返回</a>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				installmentlist: [],
				cart:[],
				hireshou: '', //首期租金
				sum:0,
				num:0, //总金额
				fenqiobj:{}
			}
		},
		onLoad(option) {
			this.fenqiobj = JSON.parse((option.fenqiobj))
			this.cart = JSON.parse(option.cart)
			this.installmentlist = JSON.parse(option.list)
			console.log(this.installmentlist)
			this.hireshou = this.installmentlist[0].repaymentAmount
			
		},
		methods: {
			// 返回上一页
			back() {
				uni.navigateBack({
					delta: 1,
				})
			}
		},
		mounted() {
			// 计算总金额
			this.installmentlist.forEach((item, index) => {
				   this.num++
			       this.sum += parseFloat(item.repaymentAmount)  					
			})
			this.sum = parseFloat(this.sum).toFixed(2)
		}
	}
</script>

<style lang="less">
	// 分期详情最大盒子
	.installmentbox {
		width: 100%;
		background: rgb(227, 227, 227);
		font-size: 11px !important;

		// 产品信息
		.mobile {
			width: 100%;
			background-color: #fff;
			display: flex;
			padding: 40rpx;
			box-sizing: border-box;

			// 左边图片
			.ltpic {
				margin-right: 80rpx;

				image {
					width: 220rpx;
					height: 165rpx;
					border-radius: 20rpx;
				}
			}

			.rtcan {
				.title {
					font-size: 12px;
					color: rgba(33, 37, 41, 1);
					text-align: left;
					vertical-align: top;
					font-weight: 400;
					margin-bottom: 12rpx;
					display: block;
				}

				text {
					color: rgba(166, 166, 166, 1);
					text-align: left;
					vertical-align: top;
					margin-right: 10rpx;
				}
			}
		}

		// 租金
		.rent {
			display: flex;
			width: 100%;
			background: rgba(255, 255, 255, 1);
			box-shadow: 0px 10px 40px rgba(0, 0, 0, 0.05);
			text-align: center;
			justify-content: space-between;
			padding: 36rpx 60rpx;
			box-sizing: border-box;

			text {
				color: rgba(56, 56, 56, 1);
				font-size: 14px;
				font-weight: 400;
				line-height: 56rpx;
			}

			.wz {
				font-size: 12px;
				color: rgba(166, 166, 166, 1);
				line-height: 56rpx;
			}
		}

		// 分期方式
		.repayment {
			width: 100%;
			background-color: #fff;
			margin-top: 20rpx;
			text-align: center;
			padding-top: 20rpx;
			box-sizing: border-box;
			padding-bottom: 60rpx;

			.gap {
				display: flex;
				justify-content: space-between;
				padding: 0 70rpx;
				box-sizing: border-box;
				font-size: 14px;

				.gapwz {
					color: rgba(33, 37, 41, 0.6);
				}
			}

			.qishu {
				width: 100%;
				text-align: center;
				margin-top: 50rpx;
				font-size: 13px;

				text {
					display: block;
					flex: 1;
				}

				display: flex;
			}

			.date {
				margin-top: 20rpx;
				width: 100%;
				text-align: center;
				color: rgba(33, 37, 41, 0.6);

				text {
					display: block;
					flex: 1;
				}

				display: flex;
			}
		}

		// 返回
		.return {
			width: 100%;
			border-radius: 10px 10px 0px 0px;
			background: rgba(255, 255, 255, 1);
			margin-top: 50rpx;
			height: 140rpx;
			padding-top: 36rpx;
			box-sizing: border-box;
            position: fixed;
			bottom: 0;
			left: 0;
			a {
				text-decoration: none;
				color: #fff;
				display: block;
				width: 454rpx;
				margin: auto;
				height: 70rpx;
				border-radius: 5px;
				background: rgba(255, 141, 26, 1);
				text-align: center;
				line-height: 70rpx;
				font-size: 13px;
			}
		}
	}
</style>