<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>

			<view class="planout-block-lists" :style="scrollHeight">
				<list class="lists-wrapper" scrollable loadmoreoffset='1' show-scrollbar='false'>
					<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.CUSTOMER}}</text>
							</view>
							<view class="text-block">
								<text class="middle-date middle-date-select">客户名称</text>
								<text class="middle-date-des middle-date-des-select">{{item.CUSTOMER_NAME}}</text>
							</view>
							<view class="text-block">
								<text class="middle-date middle-date-select">上账日期</text>
								<text class="middle-date-des middle-date-des-select">{{item.POSTING_DATE}}</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.GOODS_AMOUNT}}</text>
							</view>
						</view>
						<view class="empty-block"></view>
						<!-- </scroll-view> -->
					</cell>
				</list>
			</view>

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

<script>
	import {
		mapState
	} from 'vuex'

	import {
		apiGetMarketSupportFee
	} from '@/servers/billingInvoice.js'

	import timeFormat from '@/uview-ui/libs/function/timeFormat.js'

	export default {
		data() {
			return {
				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 - 237- 44 - 20}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() {
				let CUSTOMER = []
				let POSTING_DATE = []
				if (this.condition.start) {
					POSTING_DATE = [{
						SIGN: 'I',
						OPTION: 'BT',
						LOW: '20220401' || this.condition.start.replaceAll('-', ''),
						// LOW: '20220401' || this.condition.start.replaceAll('-', ''),
						HIGH: '20220530' || this.condition.end.replaceAll('-', '')
						// HIGH: '20220530' || this.condition.end.replaceAll('-', '')
					}]
				}
				if (this.userInfo.role !== 'WLY001') {
					CUSTOMER = [{
						SIGN: 'I',
						OPTION: 'EQ',
						// LOW: '4000000105' || this.userInfo.code,
						LOW: this.userInfo.code,
						HIGH: ''
					}]
				}
				const params = {
					'USER_BP': this.userInfo.code || '4000000105',
					ROLE: 'WLY001',
					CUSTOMER,
					POSTING_DATE,
				}
				const res = await apiGetMarketSupportFee(params)

				this.lists = res.DATA.concat(res.DATA).concat(res.DATA)
			},
			reset() {
				this.loadParams = {
					total: 0,
					totalPage: 1,
					isDone: false,
					isRefresh: false
				}
				this.page.PAGE = 1
				this.lists = []
				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 {
		position: relative;
		width: 750rpx;
	}

	.lists {
		position: relative;
		flex-direction: column;
		background: #f0f4f5;
		// height: 100vh;
	}

	.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: 84rpx;
		margin-top: 64rpx;
		margin-bottom: 48rpx;
		padding: 0 24rpx;
	}

	.planout-block-item {
		flex: 1;
		// width: 750rpx;
		// margin-bottom: 26rpx;
	}

	.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;
	}
</style>
