<template>
	<view>
		<u-picker confirm-color="#EF9944" v-model="showTime" mode="time" :params="params"  @confirm="confirmTime">
		</u-picker>
		<view class="top">
			<view class="tixian">
				<view class="value" style="margin-bottom: 50rpx;">
					<text>总应收</text>
					<text class="text-price">{{shopData.charge}}</text>
				</view>
				<view class="flex justify-center align-center">
					<view class="cu-btn btn round" style="padding: 24rpx 50rpx;" hover-class="hoverClass1"
						@click="$jump('/pages/withdraw/withdraw')">
						提现
					</view>
				</view>
			</view>
			<view style="display: flex;justify-content: flex-start;">
				<view class="value">
					<text>余额</text>
					<text class="text-price">{{shopData.balance}}</text>
				</view>
			</view>

		</view>
		<view class="margin-top-20" style="margin-bottom: -10rpx;">
			<u-tabs active-color="#FC8D38" :active-item-style="activeItemStyle" :list="tabslist" bg-color="#f1f1f1"
				:current="current" @change="change"></u-tabs>
		</view>
		<view class="data">
			<view class="left">
				<view @click.stop="showTime = true">
					<text>{{defaultTime}}</text>
					<text class="cuIcon-unfold padding-left-10"></text>
				</view>
				<!-- <view>
					<text>支出 ￥ 165.00 收入 ￥ 463.00</text>
				</view> -->
			</view>
			<view class="right" @click="goStatistics">
				<text>统计</text>
				<text class="cuIcon-right"></text>
			</view>
		</view>

		<view class="card">
			<view v-if="current==0" style="display: flex;">
				<view class="area1 area-padding " style="padding-left: 40rpx;">
					<text>积分来源</text>
				</view>
				<view class="area2 area-padding">
					<text>折扣</text>
				</view>
				<view class="area3 area-padding  text-center">
					<text>价值</text>
				</view>
			</view>
			<view v-if="current==1" style="display: flex;">
				<view class="area1 area-padding " style="padding-left: 40rpx;">
					<text>积分来源</text>
				</view>
				<view class="area2 area-padding">
					<text>积分</text>
				</view>
				<view class="area3 area-padding  ">
					<text>价值</text>
				</view>
			</view>
			<mescroll-body :height="height" ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback"
				:down="downOption" :up="upOption">
				<view @click="$jump('/pages/bill/billDetail?billDetail='+JSON.stringify(item)+'&current='+current)"
					class="item" hover-class="hoverClass" v-for="(item,index) in list" :key="index">
					<block v-if="current==0">
						<view class="area1">
							<view class="item-padding">
								<image style="border-radius: 50%;"
									:src="item.avatar?item.avatar:'/static/icon/avatar.png'" mode="aspectFit">
								</image>
								<view class="margin-left-10">
									<text>{{item.nickName || '用户支付'}}</text>
									<text>{{item.createTime}}</text>
								</view>
							</view>
						</view>
						<view class="area2 text-area" style="width: 15%;">
							<view class="item-padding">
								<text>{{item.discount==-1 || item.discount==0?'无折扣':item.discount +'折'}}</text>
							</view>
						</view>
						<view class="area3 text-area u-p-r-20" style="width: 30%;">
							<view class="item-padding"
								style="flex:1;text-align: right;font-size: 34rpx;color: #F39248;">
								+￥{{item.cost || 0}}</view>
						</view>
					</block>
					
					<block v-if="current==1">
						<view class="area1">
							<view class="item-padding">
								<image :src="item.channelLogo" mode="aspectFit"></image>
								<view class="">
									<text>{{item.channelName}}</text>
									<text>{{item.createTime}}</text>
								</view>
							</view>
						</view>
						<view class="area2 text-area ">
							<view class="item-padding">
								<image style="width: 35rpx;height: 35rpx;margin-bottom: -5rpx;"
									src="@/static/icon/points-value.png"></image>
								<text style="font-size: 32rpx;margin-left: 10rpx;color: #F39248;">+{{item.price  || 0}}</text>
							</view>
						</view>
						<view class="area3 text-area ">
							<view class="item-padding" style="font-size: 34rpx;color: #000;">￥{{item.price  || 0}}</view>
						</view>
					</block>
				</view>
			</mescroll-body>


		</view>
	</view>
</template>

<script>
	import MescrollMixin from "@/components/mescroll-body/mescroll-mixins.js";
	export default {
		mixins: [MescrollMixin],
		data() {
			return {
				activeItemStyle: {
					fontWeight: 800,
					fontSize: '36rpx'
				},
				tabslist: [{
					name: '余额明细'
				}, {
					name: '应收明细'
				}],
				current: 0,
				list: [],
				downOption: {
					auto: false
				},
				upOption: {
					empty: {
						fixed: true,
						top: "-180rpx"
					}
				},

				showTime: false,
				params: {
					year: true,
					month: true,
				},
				defaultTime: '',
				
				shopData: {},
				height: '',
			}
		},
		onLoad() {
			this.defaultTime=this.$dateTime.format(new Date(),'YYYY-mm')
			this.shopDetail()
		},
		onReady() {
			this.getElInfo()
		},
		methods: {
			async getElInfo() {
				let rectInfo = await this.$u.getRect('.card');
				this.height = this.$u.sys().windowHeight - rectInfo.top + 'px'
			},
			async shopDetail() {
				let params = {
					shopId: this.vuex_shopId
				}
				let res = await this.$api.shop.shopBillsInfo(params)
				this.shopData = res.data
			},
			async shop() {
				let params = {}

				let res = await this.$api.shop.remainDetailPage(params)
			},
			confirmTime(e) {
				this.defaultTime = e.year + '-' + e.month
				this.downCallback()
			},
			upCallback(mescroll) {
				if (!this.vuex_shopId) {
					return
				}
				let params = {
					receiveId: this.vuex_shopId,
					current: mescroll.num,
					size: mescroll.size,
					payStatus:this.$global.PAY_STATUS.SUCCESS
				}
				if (this.defaultTime) {
					params.createTime = this.$dateTime.format(new Date(this.defaultTime))
				} else {
					params.createTime = this.$dateTime.format(new Date())
				}
				try {
					if (this.current == 0) {
						this.$api.bills.list(params).then(res => {
							let data = res.data.records
							let total = res.data.total
							mescroll.endBySize(data.length, total);
							if (mescroll.num == 1) this.list = []; //如果是第一页需手动制空列表
							this.list = this.list.concat(data); //追加新数据
						})
					} else if (this.current == 1) {
						this.$api.pointBills.list(params).then(res => {
							let data = res.data.records
							let total = res.data.total
							mescroll.endBySize(data.length, total);
							if (mescroll.num == 1) this.list = []; //如果是第一页需手动制空列表
							this.list = this.list.concat(data); //追加新数据
						})
					}

				} catch (e) {
					this.mescroll.endErr()
				}
			},
			downCallback() {
				setTimeout(() => {
					this.mescroll.resetUpScroll();
				}, 500)
			},
			change(index) {
				this.current = index;
				this.mescroll.resetUpScroll();
			},
			goStatistics(){
				let url='/pages/statistics/statistics'
				if (this.current==1) {
					url='/pages/statistics/pointBillStatistics'
				}
				uni.navigateTo({
					url
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.btn {
		background-color: #FC8D38;
		color: #FFFFFF;
		border-radius: 50rpx;
		border: 1rpx solid #FFFFFF;
	}

	.hoverClass1 {
		box-shadow: 0rpx 0rpx 10rpx #DDDDDD;
	}

	.top {
		padding: 36rpx 50rpx;
		background-image: linear-gradient(to right, #FBA33D, #FF8D32);
		display: flex;
		flex-direction: column;
		justify-content: center;

		.tixian {
			display: flex;
			justify-content: space-between;
		}

		.value {
			display: flex;
			flex-direction: column;
			text-align: center;

			text:first-child {
				text-align: left;
				color: #FCD7BD;
				font-size: 32rpx;
			}

			text:last-child {
				padding-top: 10rpx;
				font-size: 60rpx;
				color: #FFFFFF;
			}
		}
	}

	.data {
		padding: 50rpx 0 25rpx 40rpx;
		display: flex;
		justify-content: space-between;

		.left {
			display: flex;
			flex-direction: column;

			view:first-child {
				font-size: 34rpx;
				color: #000;
				padding-bottom: 10rpx;
			}

			view:last-child {
				font-size: 26rpx;
				color: #666666;
			}
		}

		.right {
			padding-right: 20rpx;
			color: #666666;
			display: flex;
			justify-content: center;
			align-items: center;
			text-align: center;
		}
	}

	.card {
		background-color: #FFFFFF;

		.area-padding {
			padding: 40rpx 0 20rpx;
		}

		.text-area {
			display: flex;
			justify-content: flex-start;
			align-items: center;
		}

		.area1 {
			padding-left: 30rpx;
			width: 50%;

			view:first-child {
				display: flex;

				image {
					width: 80rpx;
					height: 80rpx
				}

				view {
					padding-left: 15rpx;
					padding-bottom: 5rpx;
					display: flex;
					flex-direction: column;

					text:first-child {
						font-size: 32rpx;
						padding-bottom: 10rpx;
						color: #000;
					}

					text:last-child {
						font-size: 22rpx;
						color: #888888;
					}
				}
			}
		}

		.area2 {
			width: 30%;
		}

		.area3 {
			width: 20%;
		}

		.item-padding {
			padding: 20rpx 0;
		}

		.item {
			padding: 5rpx;
			display: flex;
			border-bottom: 1rpx solid #DDDDDD;
		}

		.item:last-child {
			border: none;
		}



	}
</style>
