<template>
	<view class="settlement-pages">
		<!-- 授信结算 -->
		<view class="sxjs-box" v-if="settlementType == 'CREDIT'">
			<view class="sxjs-head flex flex_column align-center justify_center">
				<view>已用额度</view>
				<view class="edu">
					￥<text>{{info.usedAmount}}</text>
				</view>
				<view>
					<u-button :throttle-time="100" size="mini" @click="viewDetail" :custom-style="{background:'#066cff',color:'#fff'}" shape="circle" type="success">查看详情</u-button>
				</view>
			</view>
			<view class="sxjs-head-grid flex align-center justify_between">
				<view>
					<view>授信额度</view>
					<view class="edu">￥<text>{{info.creditLimit}}</text></view>
				</view>
				<view>
					<view>可用额度</view>
					<view class="edu">￥<text>{{info.usableAmount}}</text></view>
				</view>
			</view>
		</view>
		<!-- 按月结算 -->
		<view class="ayjs-box" v-if="settlementType == 'MONTH'">
			<view class="ayjs-head flex flex_column align-center justify_center">
				<view>累计待结算</view>
				<view class="edu">
					￥<text>{{info.waitSettleAmount}}</text>
				</view>
				<view v-if="info.waitSettleAmount">
					<u-button :throttle-time="100" size="mini" @click="viewDetail('-1')" :custom-style="{background:'#066cff',color:'#fff'}" shape="circle" type="success">查看详情</u-button>
				</view>
			</view>
			<view class="jsList">
				<view v-for="item in ayJsList" :key="item.month" class="flex align-center justify_between" @click="viewDetail(item.month)">
					<view>{{item.month}}月</view>
					<view>
						<text>￥{{item.settleAmount}}</text>
						<uniIcons color="#999" size="20" type="arrowright"></uniIcons>
					</view>
				</view>
				<view style="padding-top: 10%;border:0" v-if="ayJsList.length==0 && status!='loading'">
					<u-empty :src="`/static/nodata.png`" icon-size="120" text="暂无数据" img-width="120" mode="list"></u-empty>
				</view>
				<view style="padding: 20upx;border:0" v-if="(total>=ayJsList.length&&ayJsList.length)||status=='loading'">
					<u-loadmore :status="status" />
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import uniIcons from '@/components/uni-icons/uni-icons.vue';
	import {findStoreShelfSettleRule,waitSettleForMonth} from '@/api/shelf'
	export default {
		components: {
			uniIcons
		},
		data() {
			return {
				settlementType: '',
				info: null,
				ayJsList: [],
				status: '',
				total: 0
			}
		},
		onReady() {
		},
		onNavigationBarButtonTap(btns){
			// 结算记录
			if(btns.index == 0){
				uni.navigateTo({
					url: "/pagesA/digitalShelf/settlementRecord/settlementRecord"
				})
			}
		},
		onShow() {
			this.getDetail()
		},
		methods: {
			// 查询详情
			getDetail(){
				findStoreShelfSettleRule().then(res => {
					console.log(res)
					if(res.status == 200){
						this.info = res.data
						this.settlementType = res.data.settleType
						if(this.settlementType == "MONTH"){
							// 获取待结算列表
							this.getAyDjsList()
						}
					}
				})
			},
			// 获取待结算列表
			getAyDjsList(){
				this.status = 'loading'
				waitSettleForMonth().then(res => {
					console.log(res)
					this.ayJsList = res.data || []
					this.total = this.ayJsList.length
					this.status = ''
				})
			},
			// 已用额度详情
			viewDetail(month){
				if(this.settlementType == 'CREDIT'){
					uni.navigateTo({
						url: "/pagesA/digitalShelf/settlementManage/settlementSxDetail?data="+encodeURIComponent(JSON.stringify(this.info))
					})
				}else{
					uni.navigateTo({
						url: "/pagesA/digitalShelf/settlementManage/settlementAyDetail?month="+month+"&data="+encodeURIComponent(JSON.stringify(this.info))
					})
				}
			}
		}
	}
</script>

<style lang="less">
.settlement-pages{
	min-height: 100vh;
	> view{
		padding: 30rpx 50rpx;
	}
	.sxjs-box{
		> view{
			background-color: #fff;
			border-radius: 25rpx;
			margin-bottom: 20rpx;
			min-height: 100rpx;
			padding: 30rpx;
			color: #666;
		}
		.sxjs-head{
			width: 100%;
			text-align: center;
			font-size: 30rpx;
			.edu{
				color: #FA3534;
				padding: 10rpx 0;
				font-size: 36rpx;
				text{
					font-size: 46rpx;
					font-style: italic;
					font-weight: 900;
				}
			}
		}
		.sxjs-head-grid{
			> view{
				width: 50%;
				border-right: 2rpx solid #eee;
				text-align: center;
				.edu{
					text{
						font-size: 40rpx;
						color: #222;
					}
				}
				&:last-child{
					border: 0;
				}
			}
		}
	}
	.ayjs-box{
		> view{
			background-color: #fff;
			border-radius: 25rpx;
			margin-bottom: 20rpx;
			min-height: 100rpx;
			padding: 30rpx;
			color: #666;
		}
		.ayjs-head{
			width: 100%;
			text-align: center;
			font-size: 30rpx;
			.edu{
				color: #FA3534;
				padding: 10rpx 0;
				font-size: 36rpx;
				text{
					font-size: 46rpx;
					font-style: italic;
					font-weight: 900;
				}
			}
		}
		.jsList{
			> view{
				border-bottom: 2rpx solid #eee;
				padding: 20rpx 10rpx;
				text{
					margin-left: 10rpx;
				}
				&:last-child{
					border: 0;
				}
			}
		}
	}
}
</style>
