<template>
	<view style="height: 100vh;display: flex;flex-direction: column; background: #F0F2FF;">
		<view class="header">
			<view :style="{height:styles.top+'px'}"></view>
			<uni-nav-bar @clickLeft='jump(-1)' :border="false" color='white' backgroundColor="rgba(0,0,0,0)"
				left-icon="back" title="油站账户管理" />
			<view class="seach">
				<uni-easyinput @confirm='seachFn' style="border-radius:12rpx; margin-bottom: 10rpx;" prefixIcon="search"
					placeholder-style="color:#bbb;font-weight: 100;" confirmType="搜索"
					v-model="paramter.params.accountName" placeholder="请输入油站账户名称">
				</uni-easyinput>
				<!-- <uni-easyinput class="input" style="border-radius:12rpx ;" prefixIcon="search"
					placeholder-style="color:#bbb;font-weight: 100;" placeholder="业务负责人姓名/手机号">
				</uni-easyinput> -->
				<view style="display: flex; align-items: center;margin-top: 10rpx;">

					<view class="input" @click="selectLeader">{{paramter.params.name || '运营负责人'}} </view>
					<uni-data-select class="select" v-model="paramter.params.accountState"
						:localdata="range" @change="changeSelect"></uni-data-select>
				</view>
			</view>

		</view>
		<view style="flex:1;overflow: hidden;">
			<view v-if="!tableList.length"
				style="width: 100vw; height: 100%; display: flex;align-items: center;justify-content: center;">
				<image src="@/static/qx.png" style="width: 500rpx; height: 355rpx;"></image>
			</view>
			<scroll-view style="height: 100%;" scroll-y="true" @scrolltolower='scrolltolower'>
				<view class="container">
					<view class="item" v-for="item,index in tableList" :key="index"
						@tap="jump(1,'/financialCenter/serviceStation/detail',item)">
						<image class="logo" src="@/static/serviceStation.png"></image>
						<view>{{item.accountName}}</view>
						<view>账户总余额：{{handlerNumber(item.balance)}}</view>
						<view>近3日平均销量：{{handlerNumber(item.nlyThreedaysAvgAmount)}}</view>
						<view>统计时间：{{item.nlyThreedaysAvgTime?item.nlyThreedaysAvgTime:'--'}}</view>
					</view>
				</view>
			</scroll-view>
		</view>
		<charge @chargeChange='chargeChange' v-model="controlWindows.charge" />
	</view>
</template>

<script>
	import serve from '@/api/financialCenter/serviceStation.js'

	import charge from './components/charge.vue'
	export default {
		components: {
			charge
		},
		data() {
			return {
				controlWindows: {
					charge: false
				},
				styles: {},
				paramter: {
					currentPage: 1,
					pageSize: 10,
					sorted: {
						// createTime: 'desc'
						balance:'asc'
					},
					params: {
						accountName: ''
					}
				},
				tableList: [],
				range: [{
						value: "0",
						text: "禁用"
					},
					{
						value: "1",
						text: "启用"
					},
					{
						value: "-1",
						text: "冻结"
					}, {
						value: "-5",
						text: "作废"
					},
				],
			}
		},
		onLoad() {
			this.styles = uni.getMenuButtonBoundingClientRect()
			this.getByPage()
		},
		// onShow() {
		// 	this.getByPage()
		// },
		methods: {
			chargeChange(item) {
				this.paramter.params.operateUser = item.id
				this.paramter.params.name = item.userName
				this.seachFn()
			},
			selectLeader() {
				this.controlWindows.charge = true
			},
			changeSelect() {
				this.seachFn()
			},
			seachFn() {
				this.tableList = []
				this.paramter.currentPage = 1
				this.getByPage()
				console.log('seachFn')
			},
			getByPage() {
				serve.getByPage(this.paramter).then(res => {
					if (!res.data.list.length) {
						uni.showToast({
							title: '没有数据了哦~',
							icon: 'none'
						})
						return
					}
					this.tableList = this.tableList.concat(res.data.list);
				})
			},
			// 触底加载
			scrolltolower() {
				this.paramter.currentPage += 1
				this.getByPage()
			},
			handlerNumber(number) {
				if (number == 0) return number
				if (!number) {
					return '--'
				}
				return +number.toFixed(2)
			},
			jump(e, path, item) {
				switch (e) {
					case -1:
						uni.navigateBack()
						break;
					case 1:
						uni.navigateTo({
							url: `${path}?item=${encodeURI(JSON.stringify(item))}`
						})
						break;
				}
			},
		}
	}
</script>

<style>
	.input {
		/* display: inline-block; */
		/* margin-top: 10rpx; */
		height: 70rpx;
		border-radius: 12rpx;
		width: 69%;
		background: #fff;
		line-height: 70rpx;
		padding-left: 30rpx;
		color: #999;
	}

	.select {
		/* margin-top: 10rpx; */
		margin-left: 2%;
		display: inline-block;
		width: 29%;
		background: #fff;
		border-radius: 12rpx;
	}

	.uni-easyinput__content {
		background-color: #fff;
	}

	.header {
		position: relative;
		width: 100%;
		min-height: 403rpx;
		background: url('https://xoi-support.oss-cn-hangzhou.aliyuncs.com/星油admin小程序/sjbj.png') center/100% no-repeat;
	}

	.header .seach {
		margin-top: 30rpx;
		padding: 0 50rpx;
	}

	.container {
		padding: 30rpx 55rpx;
	}

	.container .item {
		position: relative;
		margin-bottom: 25rpx;
		padding-top: 60rpx;
		height: 300rpx;
		width: 100%;
		background: #fff;
		border-radius: 10rpx;
	}

	.container .item .logo {
		position: absolute;
		left: 20rpx;
		top: 50%;
		transform: translateY(-50%);
		width: 100rpx;
		height: 100rpx;
		border-radius: 50%;
		/* border: 1px solid #333; */
	}

	.container .item view {
		padding-left: 150rpx;
	}

	.container .item view:nth-of-type(1) {
		color: #333;
		font-size: 30rpx;
		font-weight: 550;
	}

	.container .item view {
		margin-top: 10rpx;
		color: #778899;
		font-size: 24rpx;
	}
</style>