<template>
	<view class="query-wrap">
		<view class="search-view">
			<uni-easyinput prefixIcon="search" :value="value" placeholder="请输入采购订单号" @iconClick="iconClick" @input="input">
			</uni-easyinput>
			<view class="filter-text" @click.stop="filterTime">
				筛选
			</view>
		</view>
		
		<z-paging ref="paging" @query="queryList" v-model="dataList" :use-page-scroll="true">
			<view class="inner-item" v-for="(item,indx) in dataList" :key="indx" @click="itemDetails(item)">
				<view class="item-stats">
					<span v-if="item.purcOrdStas == 'A'">待受理</span>
					<span v-if="item.purcOrdStas == 'B'">待出库</span>
					<span v-if="item.purcOrdStas == 'C'">待验收</span>
					<span v-if="item.purcOrdStas == 'D'">部分出库</span>
					<span v-if="item.purcOrdStas == 'Y'">已验收</span>
				</view>
				<view class="inventory-item">
					<view class="shuo-item-name">
						<view class="shuo-label">
							采购订单号:
						</view>
						<view class="shuo-unit">
							{{item.id}}
						</view>
					</view>
				</view>
				<view class="inventory-item">
					<view class="shuo-item">
						<view class="shuo-label">
							采购品种:
						</view>
						<view class="shuo-cont">
							{{item.detlCnt||""}}
						</view>
					</view>
					<view class="shuo-item">
						<view class="shuo-label">
							采购总数量:
						</view>
						<view class="shuo-cont">
							{{item.qtySum}}
						</view>
					</view>
				</view>
				<view class="inventory-item">
					<view class="shuo-item">
						<view class="shuo-label">
							采购总金额:
						</view>
						<view class="shuo-cont">
							{{item.purcAmt||""}}
						</view>
					</view>
					<view class="shuo-item">
						<view class="shuo-label">
							来源机构:
						</view>
						<view class="shuo-cont">
							{{item.branchName}}
						</view>
					</view>
				</view>
				<view class="inventory-item">
					<view class="shuo-item-name">
						<view class="shuo-label">
							采购员:
						</view>
						<view class="shuo-cont">
							{{item.deptName||""}}
						</view>
					</view>
				</view>
				<view class="inventory-item">
					<view class="shuo-item-name">
						<view class="shuo-label">
							采购时间:
						</view>
						<view class="shuo-cont">
							{{item.docmkDate}}
						</view>
					</view>
				</view>
			</view>
		</z-paging>
		<uni-popup ref="popup" :mask-click="false">
			<view class="time-view">
				<UnidatetimePicker type="datetimerange" 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,
				value1: "",
				value: "",
				dataList: [],
				inputVal: "",
				codeVal: "",
				confirmVal: "",
				changeVal: "",
				tabList: ['待受理', '已受理', '退回', '关闭'],
				tabIndex: ['A', 'B', 'C', 'D'],
				valueList: 0,
				beforeClose: true,
				itemData: {},
				datetimesingle:[]
			}
		},
		computed: {
			...mapState(['instData']),
		},
		onShow() {
			uni.$once('update', function(data) {
				// uni.redirectTo({
				// 	url: '/pages/grounding/grounding' //写你的路径
				// });
			})
		},
		mounted() {

		},
		methods: {
			...mapActions(['getMcsOrdeData']),
			async queryList(pageNo, pageSize) {
				let pamStas = this.tabIndex[this.index];
				await this.getMcsOrdeData({
					pam: {
						current: pageNo,
						size: pageSize,
						spdId: this.instData.spdId,
						purcOrdId: this.value.trim(),
						docmkDateStart: this.datetimesingle[0],
						docmkDateEnd: this.datetimesingle[1]
					},
					that: this
				})
			},
			// 日期重置
			reset() {
				this.datetimesingle = [];
			},
			//日期确定按钮
			btnConfirm() {
				this.$refs.popup.close();
				this.$refs.paging.reload();
			},
			filterTime() {
				this.$refs.popup.open('bottom')
			},
			forMatTime(row) {
				return moment(row).format("YYYY-MM-DD HH:mm");
			},
			//跳转订单详情	 
			itemDetails(item) {
				uni.setStorage({
					key: 'puderDelData',
					data: item
				});
				uni.navigateTo({
					url: '/subpkg/pages/mcs-puhse-order/details',
					success: function(res) {
						console.log(res, "res")
					}
				});
			},
			input: debounce(function(e) {
				this.value = e;
				let pamStas = this.tabIndex[this.index];
				this.getMcsOrdeData({
					pam: {
						spdId: this.instData.spdId,
						purcOrdId: e
					},
					that: this
				})
				this.$nextTick(() => {
					// this.value = e;
					// this.inputVal = e;
				})
			}, 500),
			iconClick(e) {
				console.log(e, '点击搜索拿到的数据');
			},
			blur(e) {
				this.$nextTick(() => {
					// this.value = e.target.value;
				})
			},
			changeTab(index) {
				this.index = index;
				this.$refs.paging.reload();
			},
			handleShelf(item) {

			},
			changeList(e) {
				// console.log(e)
			},
			onchange(e) {
				// console.log(e, 44)
			},
			onnodeclick(node) {
				console.log(node, "node");
			},
			onpopupclosed(e) {
				// console.log(e, 33)
			}
		},
		watch: {

		}

	}
</script>

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

	uni-page-body {
		width: 100%;
		height: 100%;
	}
	.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;
		}
	}
	.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;
		}
	}
</style>