<template>
	<view>
		<view class="backcorf06 width100 height60 fcorfff fotct font24 fontspec10">流水明细</view>
		<view class="width90 mart20 height60">
			<picker class="flleft" mode="date" :value="date" :start="startDate" :end="endDate" @change="bindDateChange">
				<view class="uni-input datetim">{{date}}<i class="down"></i></view>
			</picker>
			<view class="rigMart flright">
				<view class="width100 font14 fcor999 fontspec" v-if="agentNum">
					订单数量: {{agentNum}}
				</view>
				<view class="width100 font14 fcor999 fontspec" v-else>
					订单数量: 0
				</view>
				<view class="width100 font14 fcor999 fontspec" v-if="agentToatalPrice">
					支出: {{agentToatalPrice}}元
				</view>
				<view class="width100 font14 fcor999 fontspec" v-else>
					支出:0 元
				</view>
			</view>
		</view>

		<view v-if="agentSalesCodeList == '' " class="mart60 fotct font14 fcor666">
			<image mode="widthFix" style="width: 70vw;" src="../../../static/img/noorder.png"></image>
		</view>

		<view class="width100 height90 backcorfff" style="margin-top: 1px;" v-for="agenL in agentSalesCodeList"
			:key="agenL.id">
			<view class="width70 flleft">
				<view class="font16 fcor333 fontwig6 width100 paddleft10 mart10">
					{{agenL.highCouponCode.consumeTime | formatDate('-')}}</view>
				<view class="font13 fcor999 width100 paddleft10 mart10">{{agenL.highCouponCode.storeName}}</view>
			</view>
			<view class="width30 flright">
				<view class="fotct pricew fcoreb5 fontwig6 font14">{{agenL.highCoupon.salesPrice}}.00元</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getAgentSalesCodeList,
		getAgentSalesPriceCount
	} from "../../../Utils/Api.js";
	export default {
		data() {
			const currentDate = this.getDate({
				format: true
			})
			return {
				date: currentDate,
				pageNum: 1,
				pageSize: 10,
				isNoMoreData: false,
				agentSalesCodeList: [],
				agentNum: '',
				agentToatalPrice: ''
			}
		},
		filters: {
			//过滤器 用于格式化时间
			formatDate: function(value, spe = '/') {
				let data = new Date(value);
				let year = data.getFullYear();
				let month = data.getMonth() + 1;
				let day = data.getDate();
				let h = data.getHours();
				let mm = data.getMinutes();
				let s = data.getSeconds();
				month = month >= 10 ? month : "0" + month;
				day = day >= 10 ? day : "0" + day;
				h = h >= 10 ? h : "0" + h;
				mm = mm >= 10 ? mm : "0" + mm;
				s = s >= 10 ? s : "0" + s;
				return `${year}${spe}${month}${spe}${day} ${h}:${mm}:${s}`;
			}
		},
		onReachBottom() {
			this.getAgentSalesCodeList();
		},
		computed: {
			startDate() {
				return this.getDate('start');
			},
			endDate() {
				return this.getDate('end');
			}
		},
		onLoad() {
			this.getAgentSalesCodeList();
			this.getAgentSalesPriceCount();
		},
		methods: {
			//赠券卡券列表
			getAgentSalesCodeList() {
				uni.showLoading({
					title: '加载中...'
				})
				if (this.isNoMoreData) {
					uni.hideLoading()
					return false;
				}
				let pagenum = this.pageNum;
				let Time = new Date(this.date).getTime();
				let params = {
					pageNum: pagenum,
					consumeTimeS: Time,
					consumeTimeE: Time,
					pageSize: this.pageSize
				}

				getAgentSalesCodeList(params).then(res => {
					if (res.return_code == '000000' && res.return_data.list != '') {
						uni.hideLoading();
						this.agentNum = res.return_data.total;
						this.isNoMoreData = res.return_data.list.length == this.pageSize ? false : true;
						this.agentSalesCodeList = this.agentSalesCodeList.concat(res.return_data.list);
						if (res.return_data.total == (this.pageNum * this.pageSize)) {
							this.isNoMoreData = true;
						}
						this.pageNum = res.return_data.list.length == this.pageSize ? ++pagenum : pagenum;
					} else {
						this.agentSalesCodeList = [];
						this.agentNum = '';
						uni.hideLoading()
					}
				})
			},
			getAgentSalesPriceCount() {
				uni.showLoading({
					title: '加载中...'
				})
				let Time = new Date(this.date).getTime();
				let params = {
					consumeTimeS: Time,
					consumeTimeE: Time
				}
				getAgentSalesPriceCount(params).then(res => {
					uni.hideLoading()
					if (res.return_code == '000000' && res.return_data.list != '') {
						uni.hideLoading();
						this.agentToatalPrice = res.return_data;
					}else{
						this.agentToatalPrice = '';
					}
				})
			},
			bindDateChange: function(e) {
				this.date = e.target.value;
				this.pageNum = 1;
				this.pageSize = 10;
				this.isNoMoreData = false;
				this.agentSalesCodeList = [];
				this.getAgentSalesCodeList();
				this.getAgentSalesPriceCount();
			},
			getDate(type) {
				const date = new Date();
				let year = date.getFullYear();
				let month = date.getMonth() + 1;
				let day = date.getDate();

				if (type === 'start') {
					year = year - 60;
				} else if (type === 'end') {
					year = year + 2;
				}
				month = month > 9 ? month : '0' + month;;
				day = day > 9 ? day : '0' + day;
				return `${year}-${month}-${day}`;
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #f6f6f6;
	}


	.datetim {
		width: 130px;
		height: 30px;
		line-height: 30px;
		background-color: #ffffff;
		text-align: center;
		border-radius: 15px;
	}

	i {
		border: solid #666666;
		border-width: 0 2px 2px 0;
		display: inline-block;
		padding: 4px;
		margin-left: 10px;
		vertical-align: 3px;
	}

	.down {
		-webkit-transform: rotate(45deg);
	}

	.pricew {
		line-height: 90px;
	}

	.rigMart {
		width: 250rpx;
	}
</style>
