<template>
	<view class="query-wrap">
		<view class="title-cont">
			<view class="search-view">
				<uni-easyinput prefixIcon="search" :value="value" placeholder="请输入或扫描单号" @input="input" @blur="blur"
					@confirm="confirm">
				</uni-easyinput>
				<view class="filter-text" @click.stop="filterTime" v-if="index=='1'">
					筛选
				</view>
			</view>
			<v-tabs v-model="index" :tabs="tabList" @change="changeTab" :scroll="false"></v-tabs>
		</view>
		<z-paging ref="paging" @query="queryList" v-model="dataList" :use-page-scroll="true">
			<view class="inner-item" v-for="(item,index) in dataList" :key="index" @click="itemDetails(item)">
				<view class="item-stats">
					{{item.stas=='C'?'已验收':"待验收"}}
				</view>
				<view class="inventory-item" v-if="item.stas=='C'">
					<view class="shuo-item-name">
						<view class="shuo-label">
							验收单号:
						</view>
						<view class="shuo-unit">
							{{item.id}}
						</view>
					</view>
				</view>
				<view class="inventory-item" v-if="item.stas=='C'">
					<view class="shuo-item-name">
						<view class="shuo-label">
							本次验收量:
						</view>
						<view class="shuo-unit">
							{{item.mcsCnt}}
						</view>
					</view>
				</view>
				<view class="inventory-item" v-if="item.stas=='B'">
					<view class="shuo-item-name">
						<view class="shuo-label">
							配送单号:
						</view>
						<view class="shuo-unit">
							{{item.stooutId}}
						</view>
					</view>
				</view>
				<view class="inventory-item">
					<view class="shuo-item">
						<view class="shuo-label">
							配送品种数:
						</view>
						<view class="shuo-cont">
							{{item.stoCnt}}
						</view>
					</view>
					<view class="shuo-item">
						<view class="shuo-label">
							配送总数量:
						</view>
						<view class="shuo-cont">
							{{item.devCnt}}
						</view>
					</view>
				</view>
				<view class="inventory-item">
					<view class="shuo-item">
						<view class="shuo-label">
							采购品种数:
						</view>
						<view class="shuo-cont">
							{{item.catCnt}}
						</view>
					</view>
					<view class="shuo-item">
						<view class="shuo-label">
							采购总数量:
						</view>
						<view class="shuo-cont">
							{{item.sumCnt}}
						</view>
					</view>
				</view>
				<view class="inventory-item">
					<view class="shuo-item">
						<view class="shuo-label">
							未配送数量:
						</view>
						<view class="shuo-cont">
							{{item.lstCnt}}
						</view>
					</view>
				</view>
				<view class="inventory-item" v-if="item.stas=='C'">
					<view class="shuo-item-name">
						<view class="shuo-label">
							配送单号:
						</view>
						<view class="shuo-cont">
							{{item.stooutId}}
						</view>
					</view>
				</view>
				<view class="inventory-item" v-if="item.stas=='B'">
					<view class="shuo-item">
						<view class="shuo-label">
							采购员:
						</view>
						<view class="shuo-cont">
							{{item.crteUsrName}}
						</view>
					</view>
					<view class="shuo-item">
						<view class="shuo-label">
							采购时间:
						</view>
						<view class="shuo-cont" style="font-size: 18rpx;">
							{{ forMatTimehs(item.crteTime) }}
						</view>
					</view>
				</view>
				<view class="inventory-item" v-if="item.stas=='C'">
					<view class="shuo-item">
						<view class="shuo-label">
							验收员:
						</view>
						<view class="shuo-cont">
							{{item.crteUsrName}}
						</view>
					</view>
					<view class="shuo-item">
						<view class="shuo-label">
							验收时间:
						</view>
						<view class="shuo-cont">
							{{ forMatTime(item.crteTime) }}
						</view>
					</view>
				</view>
				<view class="inventory-item">
					<view class="shuo-item">
						<view class="shuo-label">
							采购类型:
						</view>
						<view class="shuo-cont">
							<span v-if="item.purcType == 'A'">普通采购</span>
							<span v-if="item.purcType == 'B'">手术备货</span>
						</view>
					</view>
					<view class="shuo-item">
						<view class="shuo-label">
							采购订单号:
						</view>
						<view class="shuo-cont">
							{{item.soucId}}
						</view>
					</view>
				</view>
			</view>
		</z-paging>
		<uni-popup ref="popup" :mask-click="false">
			<view class="time-view">
				<UnidatetimePicker type="daterange" v-model="datetimesingle" />
				<view class="btn-view">
					<button type="primary" plain="true" style="height:70rpx;line-height: 70rpx;"
						@click.stop="reset()">重置</button>
					<button type="primary" plain="true" style="height:70rpx;line-height: 70rpx;"
						@click.stop="btnConfirm()">确定</button>
				</view>
			</view>
		</uni-popup>
	</view>
</template>
<script>
	import {
		mapState,
		mapMutations,
		mapActions
	} from 'vuex';
	import {
		debounce
	} from 'lodash';
	import moment from "moment";
	import ZPMixin from '@/uni_modules/z-paging/components/z-paging/js/z-paging-mixin.js';
	import UnidatetimePicker from '@/subpkg/uni_modules/uni-datetime-picker/components/uni-datetime-picker/uni-datetime-picker.vue';
	export default {
		mixins: [ZPMixin],
		components: {
			UnidatetimePicker
		},
		data() {
			return {
				index: 0,
				value: "",
				dataList: [],
				inputVal: "",
				codeVal: "",
				confirmVal: "",
				changeVal: "",
				classes: [],
				listData: [],
				tabList: ['待验收', '已验收'],
				valueList: 0,
				beforeClose: true,
				datetimesingle: [],
			}
		},
		computed: {
			 ...mapState(['houseSelectData'])
		},
		onShow() {
			uni.$once('update', function(data) {
				// uni.redirectTo({
				// 	url: '/pages/grounding/grounding' //写你的路径
				// });
			})
		},
		mounted() {

		},
		methods: {
			...mapActions(['getAceptData', 'getAreadyData']),
			...mapMutations(['setAcceptDetaData']),
			async queryList(pageNo, pageSize) {
				if (this.index == 0) {
					await this.getAceptData({
						pam: {
							current: pageNo,
							size: pageSize,
							id: this.value,
							pdaType: "pda",
							soucStroomId: this.houseSelectData.houseId
						},
						that: this
					});
				}
				if (this.index == 1) {
					await this.getAreadyData({
						pam: {
							current: pageNo,
							size: pageSize,
							id: this.value,
							ordDate: this.datetimesingle
						},
						that: this
					});
				}
			},
			//日期格式化
			forMatTime(time) {
				return moment(time).format("YYYY-MM-DD");
			},
			//时分秒
			forMatTimehs(time) {
				return moment(time).format("YYYY-MM-DD HH:mm");
			},
			//日期确定按钮
			btnConfirm() {
				this.$refs.popup.close();
				this.$refs.paging.reload();
			},
			input(e) {
				this.requsData(e);
			},
			//筛选时间
			filterTime() {
				this.$refs.popup.open('bottom')
			},
			//跳转验收详情	 
			itemDetails(item) {
				uni.setStorage({
					key: 'accept-storage-details',
					data: item
				});
				uni.navigateTo({
					url: '/subpkg/pages/acceptance/details',
					success: function(res) {}
				});
			},
			requsData: debounce(function(e) {
				this.value = e;
				if (this.index == 0) {
					this.getAceptData({
						pam: {
							id: e
						},
						that: this
					});
				}
				if (this.index == 1) {
					this.getAreadyData({
						pam: {
							id: e
						},
						that: this
					});
				}

			}, 500),
			iconClick(e) {
				console.log(e, '点击搜索拿到的数据');
			},
			// 日期重置
			reset() {
				this.datetimesingle = [];
			},
			blur(e) {
				this.$nextTick(() => {
					// this.value = e.target.value;
				})
			},

			confirm(e) {
				this.$nextTick(() => {
					// this.value = e;
					// this.confirmVal = e;
				})
			},
			changeTab(index) {
				this.index = index;
				this.$refs.paging.reload();
			},
			oncloseList() {
				this.$refs.inputDialog.close()
			},
			changeList(e) {
				// console.log(e)
			},
			onchange(e) {
				// console.log(e, 44)
			},
			onnodeclick(node) {
				console.log(node, "node");
			},
			onpopupclosed(e) {
				// console.log(e, 33)
			}
		},
		watch: {
			groundData(newData, flodData) {
				this.$refs.paging.complete(newData);
			},
		}

	}
</script>

<style lang="scss">
	.query-wrap {
		width: 100%;
		padding: 20rpx;
		box-sizing: border-box;
		background-color: #F1F1F1;
		overflow-y: scroll;
		overflow-x: hidden;

		.time-view {
			height: 350rpx;
			background-color: #fff;
			padding: 50rpx 50rpx 0 50rpx;
			box-sizing: border-box;

			.btn-view {
				width: 100%;
				height: 100rpx;
				margin-top: 100rpx;
				display: flex;
				justify-content: space-around;
			}
		}

		.title-cont {
			padding-top: 10rpx;
			width: 100%;
			background-color: #fff;

			.search-view {
				width: 100%;
				height: 100rpx;
				display: flex;
				align-items: center;
				padding: 0rpx 20rpx 0rpx 20rpx;
				box-sizing: border-box;

				.filter-text {
					width: 72rpx;
					height: 50rpx;
					line-height: 50rpx;
					color: rgba(1, 169, 146, 1);
					font-size: 36rpx;
					font-family: PingFangSC-bold;
					padding-left: 20rpx;
				}
			}
		}
	}

	uni-page-body {
		width: 100%;
		height: 100%;
	}
</style>