<template>
	<view class="staff">
		<view class="search">
			<input class="uni-input" v-model="keyword" placeholder="请输入" />
			<view class="btn" @click="searchHistory()">搜索</view>
		</view>
		<scroll-view scroll-y="true" class="main" @scrolltolower="more()">
			<view class="list" v-for="(v,i) in aList" :key="i">
				<view class="li">
					<view class="left">
						产品名称
					</view>
					<view class="right">
						{{v.name}}
					</view>
				</view>
				<view class="li">
					<view class="left">
						瓶码
					</view>
					<view class="right">
						{{v.bottleId}}
					</view>
				</view>
				<view class="li">
					<view class="left">
						箱码
					</view>
					<view class="right">
						{{v.boxId}}
					</view>
				</view>
				<view class="li">
					<view class="left">
						配送单
					</view>
					<view class="right">
						{{v.sendId}}
					</view>
				</view>
				<view class="li">
					<view class="left">
						配送日期
					</view>
					<view class="right">
						{{getTime(v.sendTime)}}
					</view>
				</view>
				<view class="li">
					<view class="left">
						经销商
					</view>
					<view class="right">
						{{v.agencyName}}
					</view>
				</view>
				<view class="li">
					<view class="left">
						经销商所在地
					</view>
					<view class="right">
						{{v.agencyRegion}}
					</view>
				</view>
				<view class="li">
					<view class="left">
						上报地点
					</view>
					<view class="right">
						{{v.region}}
					</view>
				</view>
				<view class="li">
					<view class="left">
						窜货说明
					</view>
					<view class="right">
						{{v.remark}}
					</view>
				</view>
				<view class="li">
					<view class="left">
						上报时间
					</view>
					<view class="right">
						{{getTime(v.submitTime)}}
					</view>
				</view>
				<view class="li">
					<view class="left">
						上报人
					</view>
					<view class="right button" @click="getPerson(v.submit)">
						{{v.submit}}
					</view>
				</view>
			</view>
			<uni-load-more :status="status" :content-text="contentText" />
		</scroll-view>
		<view class="sum">
			总计: {{sum}}个上报记录
		</view>
		<uni-popup ref="popup" background-color="#fff">
			<view class="popup-content" type="center">
				<view class="th">
					上报人信息
				</view>
				<view class="td">
					<view class="">
						姓名
					</view>
					<view class="right">
						{{Person.name}}
					</view>
				</view>
				<view class="td">
					<view class="">
						性别
					</view>
					<view class="right">
						{{Person.sex}}
					</view>
				</view>
				<view class="td">
					<view class="">
						所属公司
					</view>
					<view class="right">
						{{Person.factory}}
					</view>
				</view>
				<view class="td">
					<view class="">
						所属部门
					</view>
					<view class="right">
						{{Person.department}}
					</view>
				</view>
				<view class="td">
					<view class="">
						职务
					</view>
					<view class="right">
						{{Person.duties}}
					</view>
				</view>
				<view class="td">
					<view class="">
						岗位
					</view>
					<view class="right">
						{{Person.duties}}
					</view>
				</view>
				<view class="td">
					<view class="">
						账号类型
					</view>
					<view class="right">
						{{Person.post}}
					</view>
				</view>
				<view class="td">
					<view class="">
						手机号
					</view>
					<view class="right">
						{{Person.phone}}
					</view>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import {
		search,
		checkBy
	} from '../../api/fleeing.js'
	import {
		mapState
	} from 'vuex'
	export default {
		props: ['date'],
		data() {
			return {
				keyword: '',
				aList: [], //展示的数据
				sum: '',
				Person: '',
				contentText: {
					contentdown: '上拉加载更多',
					contentrefresh: '加载中',
					contentnomore: '没有更多'
				},
				pages: 1,
				status: 'more',
			};
		},
		watch: {
			date(v1, v2) {
				this.getData()
			}
		},
		computed: {
			...mapState({
				submit: store => store.user.name
			})
		},
		mounted() {
			this.getData()
		},
		methods: {
			async getData() {
				uni.showLoading({
					title: '加载中'
				});
				let res = await search({
					conditions: this.keyword,
					submit: this.submit || '',
					submitTime: this.date,
					type: 1,
					num: 10,
					page: this.pages,
					accessToken:  uni.getStorageSync('tokenInfo'),
					account: uni.getStorageSync('account')
				})
				uni.hideLoading();
				this.aList = [...this.aList, ...res.data.list]
				if (res.data.count === this.aList.length) {
					this.status = 'noMore'
				}
				this.sum = res.data.count
			},
			//人员信息
			async getPerson(data) {
				const res = await checkBy({
					submit: data
				})
				console.log(res);
				this.Person = res.data.data
				this.$refs.popup.open()
			},
			// 获取时间
			getTime(time = new Date()) {
				let date = new Date(time);
				let year = date.getFullYear();
				let month = date.getMonth() + 1;
				let day = date.getDate();
				month >= 1 && month <= 9 ? (month = "0" + month) : "";
				day >= 0 && day <= 9 ? (day = "0" + day) : "";
				let timer = year + '年' + month + '月' + day + '日';
				return timer;
			},
			// 搜索
			searchHistory() {
				this.getData()
			},
			// 上拉加载更多
			more() {
				if (this.status != 'noMore') {
					this.status = 'loading'
					this.pages++;
					this.getData()
				}
			}
		}
	}
</script>

<style lang="scss">
	.staff {
		height: 100%;
		display: flex;
		flex-direction: column;
		justify-content: space-between;

		.search {
			height: 80rpx;
			display: flex;
			padding: 10rpx;
			border-bottom: 1rpx solid #dfdfdf;

			.uni-input {
				flex: 1;
				height: 100%;
				padding-left: 20rpx;
			}

			.btn {
				width: 20%;
				height: 100%;
				line-height: 80rpx;
				text-align: center;
				font-size: 30rpx;
				background-color: #f4f4f4;
			}
		}

		.main {
			height: calc(100% - 210rpx);
			padding: 0 20rpx;
			box-sizing: border-box;
			.wu {
				text-align: center;
				margin-top: 30rpx;
			}

			.list {
				border-bottom: 10rpx solid #dfdfdf;

				.li {
					display: flex;
					border-bottom: 1rpx solid #c5c5c5;
					padding: 20rpx 0;

					&:last-child {
						border-bottom: 0;
					}

					.left {
						width: 180rpx;
					}

					.right {
						flex: 1;
						color: #707070;
						text-align: right;
					}

					.button {
						color: #61aae0;
					}
				}
			}
		}

		.sum {
			height: 120rpx;
			line-height: 120rpx;
			text-align: center;
			color: #e40315;
			border-top: 10rpx solid #dfdfdf;
		}

		.popup-content {
			width: 600rpx;
			border-radius: 14rpx;
			padding-bottom: 100rpx;

			.th {
				height: 60rpx;
				line-height: 60rpx;
				text-align: center;
				background-color: #eaeaeb;
			}

			.td {
				padding: 15rpx;
				border-top: 1rpx solid #e3e3e3;
				display: flex;
				justify-content: space-between;
			}

		}

	}
</style>