<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>
					<input class="middle-date-des" type="text" v-model="condition.storeName" placeholder="" />
				</view>
			</view>

			<view class="planout-block">
				<button class="btn" type="default" @tap="search">
					<text class="btn-text">查询</text>
				</button>
			</view>

			<scroll-view class="scroll-area" :style='scrollHeight' scroll-y="true" lower-threshold='150'
				@scrolltolower='scrolltolower'>
				<view class="middle view planout-block-item" v-for="(item,index) in lists" :key='index'
					@click="handleClick($event,item, index)">
					<!-- <view class="text-block">
						<text class="middle-date middle-date-select">终端名称</text>
						<text class="middle-date-des middle-date-des-select">{{item.storeName}}</text>
					</view>
					<view class="text-block">
						<text class="middle-date middle-date-select">终端ID</text>
						<text class="middle-date-pro middle-date-des-select">{{item.storeId}}</text>
					</view> -->
					<view class="middle-title">
						<text class="middle-title__text flex1">终端名称：</text>
						<text class="middle-title__text flex6">{{ item.storeName }}</text>
					</view>
					<view class="middle-title">
						<view style="width: 130px;">
							<text class="middle-title__text flex1">联系人：</text>
							<text class="middle-title__text flex6">{{ item.consignee }}</text>
						</view>
						<view>
							<text class="middle-title__text flex1">联系电话：</text>
							<text class="middle-title__text flex6">{{ item.consigneePhone }}</text>
						</view>
					</view>
					<view class="middle-title justify-space">
						<view>
							<text class="middle-title__text flex1">省：</text>
							<text class="middle-title__text flex6">{{ item.provinceName }}</text>
						</view>
						<view>
							<text class="middle-title__text flex1">市：</text>
							<text class="middle-title__text flex6">{{ item.cityName }}</text>
						</view>
						<view>
							<text class="middle-title__text flex1">区：</text>
							<text class="middle-title__text flex6">{{ item.districtName }}</text>
						</view>
					</view>
					<view class="middle-title">
						<text class="middle-title__text flex1">详细地址：</text>
						<text class="middle-title__text flex6">{{ item.address }}</text>
					</view>
				</view>
				<view class="loading-more" v-if='lists.length>2'>
					<text class="loading-more-text">{{loadingText}}</text>
				</view>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex'

	import { queryDirectStore } from '@/servers/purchaseList.js'
	export default {
		data() {
			return {
				isOpened: 'none',
				loadingText: '加载中...',
				condition: {
					storeName: '',
				},
				lists: [],
				pageOption: {
					current: 1,
					size: 50
				},
				totalCount: 0,
				totalPage: 0,
				terminalQureyParams: {}
			}
		},
		computed: {
			...mapState(['sysinfo']),
			navHeight() {
				return {
					'height': `${this.sysinfo.safeArea.top + 44}px`
				}
			},
			scrollHeight() {
				return {
					'height': `${this.sysinfo.safeArea.height - 44 - 220}px`
				}
			},
			pagination(){
			  return{
				page: this.pageOption.current,
				pagesize: this.pageOption.size,
				totalCount: this.totalCount,
			  }
			}
		},
		onPullDownRefresh() {
			this.reset()
			this.getProduct(true)
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 600);
		},
		onLoad(option) {
			this.terminalQureyParams = {
				...JSON.parse(option.params)
			}
		},
		created() {
			this.reset()
			this.getProduct(true);
		},
		methods: {
			async getProduct(isRefresh) {
				const params = { page:this.pageOption, ...this.terminalQureyParams, ...this.condition }
				uni.showLoading({
					title: '加载中'
				});
				setTimeout(function() {
					uni.hideLoading();
				}, 2000);
				const res = await queryDirectStore(params)
				uni.hideLoading();
				const {
					records,
					total
				} = res.data.data
				this.totalCount = total
				this.totalPage = Math.ceil(total * 1 / this.pageOption.size * 1)

				if (isRefresh) {
					this.lists = records
				} else {
					this.lists = this.lists.concat(records)
				}
			},
			scrolltolower() {
				console.log('onReachBottom');
				if (this.pageOption.current < this.totalPage) {
					this.pageOption.current++
					this.getProduct()
				} else {
					this.loadingText = '-- 到底了 --'
				}
			},
			reset() {
				this.condition = {
					storeName: '',
				},
				this.pageOption = {
					current: 1,
					size: 50
				},
				this.lists = []
				this.loadingText = '加载中'
			},
			search() {
				this.pageOption = {
					current: 1,
					size: 50
				},
				this.lists = []
				this.getProduct(true)
			},
			handleClick(e, content, index) {
				console.log(e, content, index)
				uni.$emit('selectTerminal', {
					selectTerminal: content
				})
				uni.navigateBack()
			}
		}
	}
</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;
		height: 100vh;
	}

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

	.middle {
		background-color: #fff;
		border-radius: 16rpx;
		padding: 32rpx;
		padding-right: 60rpx;
		border-radius: 20rpx;
	}

	.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;
		white-space: nowrap;
		overflow: hidden;
		text-overflow: ellipsis;
		color: #888;
	}
	.middle-date-pro {
		flex: 3;
		font-size: 28rpx;
		height: 96rpx;
		color: #888;
		word-break: break-all;
		padding-right: 4px;
	}

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

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

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

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

	.scroll-area {
		overflow-y: scroll;
	}

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

	.uni-swipe {
		flex: 1;
		margin-bottom: 26rpx;
	}

	::v-deep  .uni-swipe_box {
		flex: 1;
	}

	.swipe-right-block {
		display: flex;
		width: 100rpx;
		justify-content: center;
		align-items: center;
	}

	.swipe-right-block__text {
		display: inline-block;
		width: 52rpx;
		height: 52rpx;
		border-radius: 50%;
		background-color: #fff;
	}

	.swipe-right-block__active {
		width: 52rpx;
		height: 52rpx;
		border-radius: 50%;
		background-color: $wly-primary-color;
	}

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

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

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

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

	.loading-more {
		flex: 1;
		align-items: center;
		justify-content: center;
		padding-top: 14px;
		padding-bottom: 14px;
		text-align: center;
	}

	.loading-more-text {
		font-size: 12px;
		color: #999;
	}
	.middle-title {
		display: flex;
		align-items: center;
		margin-bottom: 32rpx;
	}
	.justify-space{
		justify-content: space-between
	}
	.middle-title__text {
		font-weight: 500;
		font-size: 28rpx;
		color: $text-base-color;
		font-family: PingFangSC, PingFangSC-Medium;
	}
</style>
