<template>
	<view class="query-wrap">
		<view class="title-cont">
			<view class="search-view">
				<uni-easyinput prefixIcon="search" :value="value" placeholder="请输入耗材名称" @input="input">
				</uni-easyinput>
			</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.stop="itemDetails(item)">
				<view class="item-stats">
					{{item.stas}}
				</view>
				<view class="inventory-item">
					<view class="shuo-item-name">
						<view class="shuo-label-podnme">
							{{item.prodName}}
						</view>
						<view class="shuo-unit">
							<span>{{ item.unt }} ({{ item.pacCnt
							            }}{{ item.prcUnt }}/{{ item.unt }})</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">
						<view class="shuo-label">
							所在库房:
						</view>
						<view class="shuo-cont">
							{{stromName}}
						</view>
					</view>
					<view class="shuo-item">
						<view class="shuo-label">
							所在货位:
						</view>
						<view class="shuo-cont">
							{{item.cgoLocName}}
						</view>
					</view>
				</view>
				<view class="inventory-item">
					<view class="shuo-item">
						<view class="shuo-label">
							应在库:
						</view>
						<view class="shuo-label-green">
							{{item.invCnt}}
						</view>
					</view>
					<view class="shuo-item">
						<view class="shuo-label">
							盘点数:
						</view>
						<view class="shuo-label-green" v-if="formData.type=='暗盘'">
							<view class="addInvent" @click.stop="adIenty(item,index)">
								{{item.intrCnt}}
							</view>
						</view>
						<view class="shuo-label-green" v-else>
							{{item.intrCnt}}
						</view>
					</view>
				</view>
			</view>
		</z-paging>
		<uni-popup ref="popup">
			<uni-popup-dialog type="warn" :before-close="true" cancelText="取消" confirmText="确定" content="你确定结束盘点吗？"
				@confirm="dialogConfirm" @close="dialogClose"></uni-popup-dialog>
		</uni-popup>
		<uni-popup ref="addInvent" type="dialog">
			<uni-popup-dialog :before-close="true" cancelText="取消" confirmText="确定" @confirm="inventConfirm"
				@close="inventClose" title="增加盘点数">
				<uni-number-box v-model="innub" />
			</uni-popup-dialog>
		</uni-popup>
		<view class="botm-btn">
			<button type="default" plain="true" style="width:240rpx;line-height: 70rpx;background: #01A992;color:#fff"
				@click.stop="orderAcept()"> 结束盘点</button>
		</view>
	</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,
				value: "",
				dataList: [],
				changeVal: "",
				listData: [],
				stroomId: "",
				stromName: "",
				formData: {},
				itemData: {},
				innub: 0, //弹窗盘点数
			}
		},
		computed: {
			...mapState(['inventData'])
		},
		onShow() {
			if (this.$refs.paging) {
				this.$refs.paging.reload();
			}
			let that = this;
			uni.getStorage({
				key: 'Inventorydetails',
				success: function(res) {
					that.formData = res.data;
					that.stroomId = res.data.stroomId;
					that.intrNo = res.data.intrNo;
					that.stromName = res.data.stroomName
				}
			});
		},
		mounted() {

		},
		methods: {
			...mapActions(['getInvenDetailData']),
			...mapMutations(['setInventData']),
			async queryList(pageNo, pageSize) {
				await this.getInvenDetailData({
					pam: {
						current: pageNo,
						size: pageSize,
						"stroomId": this.stroomId,
						"intrNo": this.intrNo,
						prodName: this.value
					},
					that: this
				});
			},
			//确认结束盘点
			dialogConfirm() {
				this.brightFinsh();
			},
			//盘点提交
			brightFinsh() {
				this.$http('inventory.brightFinish', {
					intrNo: this.intrNo,
				}, '加载中', true).then((res) => {
					if (res.success == true) {
						this.$refs.popup.close();
						uni.redirectTo({
							url: '/pages/Inventory/index',
							success: function(res) {
								console.log(res, "res")
							}
						});
					} else {
						this.$refs.popup.close();
					}
				})
			},
			//日期格式化
			forMatTime(time) {
				return moment(time).format("YYYY-MM-DD");
			},
			//明盘盘点数增加弹窗
			adIenty(int, index) {
				this.index = index;
				this.innub = int.intrCnt ? int.intrCnt : 0;
				this.itemData = int;
				this.$refs.addInvent.open();
			},
			//盘点提交按钮
			orderAcept(type) {
				this.$refs.popup.open();
			},
			dialogClose() {
				this.$refs.popup.close();
			},
			inventClose() {
				this.$refs.addInvent.close();
			},
			//明盘盘点数点击确认
			inventConfirm() {
				this.$http('inventory.subMitDarkData', {
					intrNo: this.intrNo,
					prodCode: this.itemData.prodCode,
					unt: this.itemData.unt,
					pacCnt: this.itemData.pacCnt,
					intrCnt: this.innub,
					invCnt: this.itemData.invCnt
				}, '加载中', true).then((res) => {
					if (res.success == true) {
						this.$refs.addInvent.close();
						this.dataList[this.index].intrCnt= this.innub;
						console.log(this.dataList,'3232323');
						// this.$refs.paging.reload();
					} else {
						this.$refs.addInvent.close();
					}
				})
			},
			//跳转配送详情	 
			itemDetails(item) {
				if (this.formData.type == '暗盘') {
					return;
				}
				this.setInventData(this.dataList);
				uni.setStorage({
					key: 'darkintdetail',
					data: {
						...item,
						intrNo: this.intrNo,
						stroomId: this.stroomId,
					}
				});
			
				uni.navigateTo({
					url: '/pages/inventbright/index',
					success: function(res) {
						
					}
				});
				console.log(item,this.intrNo,this.stroomId,'盘点')
			},
			input: debounce(function(e) {
				this.value = e;
				this.getInvenDetailData({
					pam: {
						prodName: this.value,
						"stroomId": this.stroomId,
						"intrNo": this.intrNo,
					},
					that: this
				});

			}, 500),
			changeTab(index) {
				this.index = index;
				this.$refs.paging.reload();
			},
		},
		watch: {

		}

	}
</script>

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

		.botm-btn {
			width: 100%;
			height: 120rpx;
			background-color: #fff;
			position: fixed;
			left: 0;
			bottom: 0;
			padding-top: 40rpx;
			z-index: 22;
		}

		.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%;
		background-color: #F1F1F1;

	}
</style>