<template>
	<view class="lists">
		<view class="status_bar" :style="navHeight"></view>
		<view class="header-bg">
			<image class="header-bg-img" src="@/static/image/nav_bg@3x.png" mode="scaleToFill"></image>
		</view>
		<view class="main">
			<view class="middle view">
				<view class="text-block">
					<text class="middle-date">开始日期</text>
					<view class="middle-date-des uni-list picker-year">
						<view class="uni-list-cell">
							<view class="uni-list-cell-db">
								<picker class="picker-block" @change="bindPickerYearStartChange" mode="date"
									:value="condition.start" fields='day'>
									<text class="uni-input">{{condition.start}}</text>
								</picker>
							</view>
						</view>
						<image class="icon-arrow" src="@/static/image/arrow_r@3x.png" mode="aspectFit"></image>
					</view>
				</view>
				<view class="text-block text-block-last">
					<text class="middle-date">截止日期</text>
					<view class="middle-date-des uni-list picker-year">
						<view class="uni-list-cell">
							<view class="uni-list-cell-db">
								<picker class="picker-block" @change="bindPickerYearEndChange" mode="date"
									:value="condition.end" fields='day'>
									<text class="uni-input">{{condition.end}}</text>
								</picker>
							</view>
						</view>
						<image class="icon-arrow" src="@/static/image/arrow_r@3x.png" mode="aspectFit"></image>
					</view>
				</view>
			</view>

			<view class="planout-block">
				<button class="btn" type="default" @tap="search">
					<text class="btn-text">查询</text>
				</button>
			</view>
			<scroll-view :style='scrollHeight' class="scroll-area" scroll-y="true" lower-threshold='150'
				@scrolltolower='scrolltolower'>
				<list class="scroll-area view"  loadmoreoffset='100' show-scrollbar='false' @loadmore="scrolltolower">
					<cell class="list-cell" v-for="(item,index) in lists" :key='index'>
						<!-- <scroll-view class="scroll-area" :style='scrollHeight' scroll-y="true" lower-threshold='150'
				@scrolltolower='scrolltolower'> -->
						<view class="middle view planout-block-item">
							<view class="text-block">
								<text class="middle-date middle-date-select">入库量</text>
								<text class="middle-date-des middle-date-des-select">{{item.in}}件</text>
							</view>
							<view class="text-block">
								<text class="middle-date middle-date-select">出库量</text>
								<text class="middle-date-des middle-date-des-select">{{item.out}}件</text>
							</view>
							<view class="text-block text-block-last">
								<text class="middle-date middle-date-select">违约出库量</text>
								<text class="middle-date-des middle-date-des-select">{{item.outviolation}}件</text>
							</view>
						</view>
						<view class="empty-block"></view>
						<!-- </scroll-view> -->
					</cell>
				</list>
				<no-data class="no-data" v-if="lists.length===0"></no-data>
			</scroll-view>

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

<script>
	import {
		mapState
	} from 'vuex'

	import {
		queryScanDistributer
	} from '@/servers/breakwords.js'
	import timeFormat from '@/uview-ui/libs/function/timeFormat.js'
	import noData from '@/components/nodata.nvue';
	export default {
		components: {
			noData
		},
		data() {
			return {
				loadingText: '加载中...',
				refreshing: false,
				isOpened: 'none',
				condition: {
					start: '',
					end: ''
				},
				lists: [],
				page: {
					"PAGE": "1",
					"PAGESIZE": "10",
				},
				toPageParams: {
					page: '',
					mode: '',
					index: 0,
					head: {}
				}
			}
		},
		computed: {
			...mapState(['sysinfo', 'userInfo']),
			navHeight() {
				return {
					'height': `${this.sysinfo.safeArea.top + 44}px`
				}
			},
			mainHeight() {
				return {
					'height': `${this.sysinfo.safeArea.height}px`,
				}
			},
			scrollHeight() {
				return {
					'height': `${this.sysinfo.safeArea.height - 265 - 44}px`
				}
			}
		},
		onPullDownRefresh() {
			console.log('refresh');
			this.reset()
			this.getMarketSupportFee(true)
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 600);
		},
		created() {
			this.condition.start = timeFormat(new Date(), 'yyyy-mm-dd')
			this.condition.end = timeFormat(new Date(), 'yyyy-mm-dd')
			this.reset()
			this.getMarketSupportFee(true);
		},
		methods: {
			async getMarketSupportFee() {
				const params = {
					distributerId: '4000651200' || this.userInfo.code,
					from: this.condition.start,
					to: this.condition.end,
				}
				const res = await queryScanDistributer(params)

				this.lists = res.data
			},
			reset() {
				this.loadParams = {
					total: 0,
					totalPage: 1,
					isDone: false,
					isRefresh: false
				}
				this.page.PAGE = 1
				this.lists = []
				this.loadingText = '加载中'
			},
			scrolltolower() {
				console.log('onReachBottom');
				if (this.page.PAGE < this.loadParams.totalPage) {
					this.page.PAGE++
					this.getMarketSupportFee()
				} else {
					this.loadParams.isDone = true
					this.loadingText = '-- 到底了 --'
				}
			},
			search() {
				this.reset()
				this.getMarketSupportFee(true)
			},
			bindPickerYearStartChange(e) {
				console.log('picker发送选择改变，携带值为', e.detail.value)
				this.condition.start = e.detail.value
			},
			bindPickerYearEndChange(e) {
				console.log('picker发送选择改变，携带值为', e.detail.value)
				this.condition.end = e.detail.value
			},
		}
	}
</script>

<style lang="scss" scoped>
	.view {
		flex-direction: column;
	}

	.header-bg {
		height: 284rpx;
		margin-top: -88rpx;
	}

	.header-bg-img {
		width: 750rpx;
	}

	.lists {
		position: relative;
		flex-direction: column;
		overflow-y: scroll;
		background: #f0f4f5;
		overflow-x: hidden;
	}

	.main {
		position: relative;
		flex-direction: column;
		margin-top: -164rpx;
		padding: 0 16rpx;
	}

	.middle {
		background-color: #fff;
		border-radius: 16rpx;
		padding: 32rpx 64rpx 32rpx 48rpx;
	}

	.text-block {
		display: flex;
		overflow: hidden;
		height: 96rpx;
		margin-bottom: 14rpx;
		border-bottom: 1px solid #f4f5f6;
	}

	.text-block-last {
		margin-bottom: 0;
		border-bottom: 0;
	}

	.middle-date {
		flex: 2;
		font-size: 28rpx;
		line-height: 96rpx;
		color: #333;
		margin-bottom: 8rpx;
	}

	.middle-date-des {
		flex: 3;
		font-size: 28rpx;
		line-height: 96rpx;
		height: 96rpx;
		overflow: hidden;
		text-overflow: ellipsis;
		color: #888;
	}

	.middle-date-select {
		color: #888;
	}

	.middle-date-des-select {
		color: #333;
	}

	.picker-year {
		position: relative;
		border-radius: 4px;
		align-items: center;
	}

	.uni-input {
		font-size: 12px;
		color: #888;
	}

	.uni-list-cell {
		flex: 1;
	}

	.uni-list-cell-db {
		flex: 1;
	}

	.picker-block {
		flex: 1;
	}

	.icon-arrow {
		position: absolute;
		right: 0;
		top: 16px;
		width: 12rpx;
		height: 20rpx;
		z-index: 10;
	}

	.planout-block-lists {
		display: flex;
		flex-direction: column;
		background: #f0f4f5;
	}

	.list-cell {
		padding-bottom: 26rpx;
	}

	.lists-wrapper {
		display: flex;
		flex-direction: column;
	}

	.planout-block {
		display: flex;
		justify-content: space-between;
		height: 92rpx;
		margin-top: 64rpx;
		margin-bottom: 48rpx;
		padding: 0 24rpx;
	}

	.planout-block-item {
		flex: 1;
	}

	.btn {
		flex: 1;
		height: 92rpx;
		background: $wly-primary-color;
		border-radius: 46rpx;
	}

	.btn-text {
		color: #fff;
		font-size: 34rpx;
	}

	.empty-block {
		height: 26rpx;
		background: #f0f4f5;
	}
	.scroll-area {
		overflow-y: scroll;
	}
	.no-data {
		flex: 1;
		position: absolute;
		left: 0;
		top: 0;
		right: 0;
		bottom: 0;
		z-index: 10;
	}
</style>
