<template>
	<view class="bill-list">
		<uni-collapse class="bill-box">
			<uni-collapse-item class="bill-item" v-for="(item,index) in list" :key="item.id" title-border="none"
				:border="false">
				<template v-slot:title>
					<view class="collapse-title">
						<view class="label">{{'第' + item.phase + '期'}}</view>
						<view>
							<view class="hui-tag info" v-if="!item.status">待付款</view>
							<view class="hui-tag warning" v-if="item.status === 1">付款中</view>
							<view class="hui-tag success" v-if="item.status === 2">已付款</view>
						</view>
					</view>
				</template>
				<view class="contract-bill-box">
					<view class="contract-bill-item">
						<view class="name">账单期数</view>
						<view class="label">{{'第' + item.phase + '期'}}</view>
					</view>
					<view class="contract-bill-item">
						<view class="name">账单日期</view>
						<view class="label">{{item.startDate}}至{{item.endDate}}</view>
					</view>
					<view class="contract-bill-item">
						<view class="name">金额</view>
						<view class="label">{{item.amount}}元</view>
					</view>
					<view class="contract-bill-item">
						<view class="name">收款方</view>
						<view class="label">{{item.organizationName}}</view>
					</view>
					<view class="contract-bill-item">
						<view class="name">付款方</view>
						<view class="label">{{item.payMerchantName || item.payClientName}}</view>
					</view>
					<view class="contract-bill-item">
						<view class="name">账单组成</view>
						<view class="label">{{returnLabel(item.data)}}</view>
					</view>
				</view>
			</uni-collapse-item>
		</uni-collapse>
	</view>
</template>

<script>
	import {
		getPaymentListByPage
	} from '@/request/api/contract.js'
	export default {
		props: ['detailId'],
		data() {
			return {
				list: []
			}
		},
		created() {
			this.init();
		},
		methods: {
			init() {
				getPaymentListByPage({
					currPage: 1,
					pageSize: 100,
					contractId: this.detailId
				}).then(res => {
					if (res.code === 200) {
						this.list = res.data.dataList;
					}
				})
			},
			returnLabel(data) {
				if (!data) return '';
				let list = JSON.parse(data);
				let str = [];
				for (var i = 0; i < list.length; i++) {
					if (list[i].unitPrice) {
						str.push(list[i].payCycle + '个月租金' + list[i].unitPrice + '元')
					} else if (list[i].earnestMoney) {
						str.push(this.$field.findTypeName('earnestMoneyType', list[i].earnestMoneyType) + list[i]
							.earnestMoney + '元')
					}
				}
				return str.join('+')
			}
		},
	}
</script>

<style lang="scss">
	.bill-list {

		.bill-box,
		.uni-collapse {
			background: transparent;
		}

		.collapse-title {
			display: flex;
			align-items: center;
			height: 84rpx;
			padding-left: 30rpx;

			.label {
				margin-right: 20rpx;
			}
		}

		.bill-item {
			margin-bottom: 20rpx;
			background: #fff;
			border-radius: 8rpx;
		}

		.contract-bill-box {
			padding: 30rpx;
			border-top: 1px solid $uni-border-1;

			.contract-bill-item {
				margin-top: 16rpx;
			}

			.name {
				color: $uni-secondary-color;
				font-size: 24rpx;
			}

			.label {
				margin-top: 10rpx;
				font-weight: 400;
			}
		}
	}
</style>