<template>
	<view class="query-wrap">
		<uni-easyinput prefixIcon="search" :value="value" placeholder="请输入或扫描SN码" @iconClick="iconClick" @input="input"
			@blur="blur" @confirm="confirm">
		</uni-easyinput>
		<qs-scanlistener @scan="scan"></qs-scanlistener>
		<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="inventory-item">
					<view class="shuo-item-name">
						<view class="shuo-label-podnme">
							{{item.prodName}}
						</view>
						<view class="shuo-unit">
							<span>{{ item.pacunt }} ({{ item.pacCnt
							            }}{{ item.prcUnt }}/{{ item.pacunt }})</span>
						</view>
					</view>
				</view>
				<view class="inventory-item">
					<view class="shuo-item">
						<view class="shuo-label">
							规格:
						</view>
						<view class="shuo-cont">
							{{item.spec}}
						</view>
					</view>
					<view class="shuo-item">
						<view class="shuo-label">
							型号:
						</view>
						<view class="shuo-cont">
							{{item.mol}}
						</view>
					</view>
				</view>
				<view class="inventory-item">
					<view class="shuo-item">
						<view class="shuo-label">
							耗材类别:
						</view>
						<view class="shuo-cont-blue">
							<span v-if="item.mcsType == '0'"> 普通耗材 </span>
							<span v-if="item.mcsType == '1'"> 高值耗材 </span>
							<span v-if="item.mcsType == '2'"> 试剂 </span>
							<span v-if="item.mcsType == '3'"> 总务耗材 </span>
						</view>
					</view>
					<view class="shuo-item">
						<view class="shuo-label">
							生产来源:
						</view>
						<view class="shuo-cont-blue">
							<span v-if="item.prodSouc == '1'" type="success"> 国产 </span>
							<span v-if="item.prodSouc == '2'" type="danger"> 进口 </span>
						</view>
					</view>
				</view>
				<view class="inventory-item">
					<view class="shuo-item-name">
						<view class="shuo-label">
							生产企业:
						</view>
						<view class="shuo-cont">
							{{item.prodEntp}}
						</view>
					</view>
				</view>
				<view class="inventory-item">
					<view class="shuo-item-name">
						<view class="shuo-label">
							供应商:
						</view>
						<view class="shuo-cont">
							{{item.splerName}}
						</view>
					</view>
				</view>
				<view class="inventory-item">
					<view class="shuo-item">
						<view class="shuo-label">
							RFID码:
						</view>
						<view class="shuo-cont-blue">
							{{item.rfid}}
						</view>
					</view>
					<view class="shuo-item">
						<view class="shuo-label">
							SN编码:
						</view>
						<view class="shuo-cont">
							{{item.id}}
						</view>
					</view>
				</view>
				<view class="inventory-item">
					<view class="shuo-item">
						<view class="shuo-label">
							上架货位:
						</view>
						<view class="shuo-label-green">
							{{item.cgoLocName}}
						</view>
					</view>
					<!-- <view class="shuo-item">
						<view class="shuo-label">
							状态:
						</view>
						<view class="shuo-cont-blue">
							{{}}
						</view>
					</view> -->
				</view>
				<view class="inventory-item">
					<view class="shuo-item">
						<view class="shuo-label">
							上架人员:
						</view>
						<view class="shuo-cont-blue">
							{{item.groundName}}
						</view>
					</view>
					<view class="shuo-item">
						<view class="shuo-label">
							上架时间:
						</view>
						<view class="shuo-cont" style="font-size: 18rpx;">
							{{item.groundDate}}
						</view>
					</view>
				</view>
				<uv-button text="上架" plain size="normal" type="primary" style="margin-top:20rpx;"
					@click.native.stop="handleShelf(item)" v-if="index=='0'"></uv-button>
			</view>
		</z-paging>
		<uni-popup ref="inputDialog" type="dialog">
			<uni-popup-dialog ref="inputClose" mode="input" title="上架" @confirm="dialogInputConfirm"
				:beforeClose="beforeClose" @close="oncloseList">
				<uni-data-picker :localdata="storageData" popup-title="货位" @change="onchange" v-model="classes"
					@popupclosed="onpopupclosed" @nodeclick="onnodeclick"></uni-data-picker>
			</uni-popup-dialog>
		</uni-popup>
	</view>
</template>

<script>
	import {
		mapState,
		mapMutations,
		mapActions
	} from 'vuex';
	import {
		debounce
	} from 'lodash';
	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: "",
				classes: [],
				tabList: ['待上架', '已上架'],
				valueList: 0,
				beforeClose: true,
				itemData: {}
			}
		},
		computed: {
			...mapState(['storageData'])
		},
		onShow() {
			uni.$once('update', function(data) {
				// uni.redirectTo({
				// 	url: '/pages/grounding/grounding' //写你的路径
				// });
			})
		},
		mounted() {
			this.getStorageData();
		},
		methods: {
			...mapActions(['getGroundData', 'getStorageData', 'listIngData']),
			...mapMutations(['setMentItemData']),
			async queryList(pageNo, pageSize) {
				await this.getGroundData({
					pam: {
						current: pageNo,
						size: pageSize,
						groundStas: this.index,
						id: this.value.trim()
					},
					that: this
				})
			},
			//跳转上架详情	 
			itemDetails(item) {
				uni.setStorage({
					key: 'ListingData',
					data: item
				});
				uni.navigateTo({
					url: '/pages/groundetials/groundetials',
					success: function(res) {
						console.log(res, "res")
					}
				});
			},
			scan(code) {
				this.value = code;
				let codeVal = code.trim();
				this.getGroundData({
					pam: {
						id: codeVal,
						groundStas: this.index,
					},
					that: this
				})
			},
			input: debounce(function(e) {
				this.value = e;
				this.getGroundData({
					pam: {
						id: e,
						groundStas: this.index,
					},
					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;
				})
			},

			confirm(e) {

				this.$nextTick(() => {
					// this.value = e;
					// this.confirmVal = e;
				})
			},
			changeTab(index) {
				this.index = index;
				this.$refs.paging.reload();
			},
			oncloseList() {
				this.$refs.inputDialog.close()
			},
			handleShelf(item) {
				this.itemData = item;
				this.$refs.inputDialog.open();
			},
			dialogInputConfirm() {
				if (this.classes.length === 0) {
					uni.showToast({
						title: '请选择货位',
						icon: 'none',
					});
					this.beforeClose = true;
					return;
				}
				let pamdata = [{
					sn: this.itemData.id,
					clibId: this.classes,
				}]
				this.listIngData(pamdata).then((res) => {
					this.$refs.paging.reload();
					this.classes = "";
					this.beforeClose = false;
					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" 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>