<template>
	<view class="query-wrap">
		<uni-easyinput prefixIcon="search" :value="value" placeholder="请输入采购单号" @iconClick="iconClick" @input="input">
		</uni-easyinput>
		<v-tabs v-model="index" :tabs="tabList" @change="changeTab" :scroll="false"></v-tabs>
		<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" v-if="index=='0'">
					{{item.stas}}
				</view>
				<view class="inventory-item" v-if="index=='1'">
					<view class="shuo-item-name">
						<view class="shuo-label-podnme">
							出库单号
						</view>
						<view class="shuo-unit">
							{{item.delvOrdId}}
						</view>
					</view>
				</view>
				<view class="inventory-item">
					<view class="shuo-item-name">
						<view class="shuo-label-podnme">
							{{index=="0"?'订单号':"关联采购单"}}
						</view>
						<view class="shuo-unit">
							<span v-if="index == '0'">{{ item.id }}</span>
							<span v-if="index == '1'">{{item.purcOrdId}}</span>
						</view>
					</view>
				</view>
				<view class="inventory-item">
					<view class="shuo-item">
						<view class="shuo-label">
							{{index=="0"?'订单品种数':"采购品种数"}}
						</view>
						<view class="shuo-cont">
							{{item.detlCnt||""}}
						</view>
					</view>
					<view class="shuo-item">
						<view class="shuo-label">
							{{index=="0"?'订单总数量':"采购总数量"}}
						</view>
						<view class="shuo-cont">
							{{item.qtySum||""}}
						</view>
					</view>
				</view>
				<view class="inventory-item" v-if="index=='1'">
					<view class="shuo-item">
						<view class="shuo-label">
							本次出库数:
						</view>
						<view class="shuo-cont">
							{{item.bcckl||""}}
						</view>
					</view>
					<view class="shuo-item">
						<view class="shuo-label">
							本次验收量:
						</view>
						<view class="shuo-cont">
							{{item.shppCnt||""}}
						</view>
					</view>
				</view>
				<view class="inventory-item" v-if="index=='1'">
					<view class="shuo-item">
						<view class="shuo-label">
							待出库量:
						</view>
						<view class="shuo-cont">
							{{item.toDelvCnt||""}}
						</view>
					</view>
					<view class="shuo-item">
						<view class="shuo-label">
							出库人:
						</view>
						<view class="shuo-cont">
							{{item.docmker||""}}
						</view>
					</view>
				</view>
				<view class="inventory-item" v-if="index=='0'">
					<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.delvCnt||""}}
						</view>
					</view>
				</view>
				<view class="inventory-item">
					<view class="shuo-item-name">
						<view class="shuo-label">
							来源机构:
						</view>
						<view class="shuo-cont">
							{{item.branchName}}
						</view>
					</view>
				</view>
				<view class="inventory-item" v-if="index=='0'">
					<view class="shuo-item-name">
						<view class="shuo-label">
							采购类型:
						</view>
						<view class="shuo-cont">
							<span v-if="item.purcType == '2'">{{ item.oprn }}</span>
							<span v-if="item.purcType == '1'">普通采购</span>
						</view>
					</view>
				</view>
				<view class="inventory-item" v-if="index=='0'">
					<view class="shuo-item">
						<view class="shuo-label">
							采购时间:
						</view>
						<view class="shuo-cont">
							{{forMatTime(item.docmkDate)}}
						</view>
					</view>
				</view>
				<view class="inventory-item" v-if="index=='1'">
					<view class="shuo-item">
						<view class="shuo-label">
							出库时间:
						</view>
						<view class="shuo-cont">
							{{forMatTime(item.docmkDate)}}
						</view>
					</view>
				</view>
			</view>
		</z-paging>
	</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';
	export default {
		mixins: [ZPMixin],
		data() {
			return {
				index: 0,
				value1: "",
				value: "",
				dataList: [],
				inputVal: "",
				codeVal: "",
				confirmVal: "",
				changeVal: "",
				tabList: ['待出库', '已出库'],
				valueList: 0,
				beforeClose: true,
				itemData: {}
			}
		},
		computed: {
			...mapState(['instData', 'userData']),
		},
		onShow() {
			uni.$once('update', function(data) {
				// uni.redirectTo({
				// 	url: '/pages/grounding/grounding' //写你的路径
				// });
			})
		},
		mounted() {

		},
		//订单出库
		methods: {
			...mapActions(['getOrderAwaitData', 'getOrderAreadyData']),
			async queryList(pageNo, pageSize) {
				if (this.index == "0") {
					await this.getOrderAwaitData({
						pam: {
							current: pageNo,
							size: pageSize,
							spdId: this.instData.spdId,
							id: this.value
						},
						that: this
					})
				} else {
					await this.getOrderAreadyData({
						pam: {
							current: pageNo,
							size: pageSize,
							spdId: this.instData.spdId,
							id: this.value
						},
						that: this
					})
				}

			},
			forMatTime(row) {
				return moment(row).format("YYYY-MM-DD");
			},
			//跳转订单详情	 
			itemDetails(item) {
				uni.setStorage({
					key: 'orderDetailsData',
					data: item
				});
				if (this.index == "0") {
					uni.navigateTo({
						url: '/subpkg/pages/order-outbond/details',
						success: function(res) {
							console.log(res, "res")
						}
					});
				} else {
					uni.navigateTo({
						url: '/subpkg/pages/order-outbond/ready',
						success: function(res) {
							console.log(res, "res")
						}
					});
				}

			},
			input: debounce(function(e) {
				this.value = e;
				if (this.index == "0") {
					this.getOrderAwaitData({
						pam: {
							spdId: this.instData.spdId,
							id: this.value
						},
						that: this
					})
				} else {
					this.getOrderAreadyData({
						pam: {
							spdId: this.instData.spdId,
							id: this.value
						},
						that: this
					})
				}

			}, 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%;
	}
</style>