<template>
	<view class="query-wrap">
		<uni-easyinput prefixIcon="search" :value="value" placeholder="请输入或扫描SN码" :focus="true" @input="input">
		</uni-easyinput>
		<qs-scanlistener @scan="scan"></qs-scanlistener>
		<view class="inner-item">
			<view class="item-stats">
				{{formData.stas}}
			</view>
			<view class="inventory-item">
				<view class="shuo-item-name">
					<view class="shuo-label-podnme">
						{{formData.prodName}}
					</view>
					<view class="shuo-unit">
						<span>{{ formData.unt }} ({{ formData.pacCnt
							            }}{{ formData.prcUnt }}/{{ formData.unt }})</span>
					</view>
				</view>
			</view>
			<view class="inventory-item">
				<view class="shuo-item">
					<view class="shuo-label">
						规格:
					</view>
					<view class="shuo-cont">
						{{formData.spec}}
					</view>
				</view>
				<view class="shuo-item">
					<view class="shuo-label">
						型号:
					</view>
					<view class="shuo-cont">
						{{formData.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="formData.mcsType == '0'"> 普通耗材 </span>
						<span v-if="formData.mcsType == '1'"> 高值耗材 </span>
						<span v-if="formData.mcsType == '2'"> 试剂 </span>
						<span v-if="formData.mcsType == '3'"> 总务耗材 </span>
					</view>
				</view>
				<view class="shuo-item">
					<view class="shuo-label">
						生产来源:
					</view>
					<view class="shuo-cont-blue">
						<span v-if="formData.prodSouc == '1'" type="success"> 国产 </span>
						<span v-if="formData.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">
						{{formData.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">
						{{formData.cgoLocName}}
					</view>
				</view>
			</view>
			<view class="inventory-item">
				<view class="shuo-item">
					<view class="shuo-label">
						应在库:
					</view>
					<view class="shuo-cont">
						{{formData.invCnt}}
					</view>
				</view>
				<view class="shuo-item">
					<view class="shuo-label">
						盘点数:
					</view>
					<view class="shuo-cont" v-if="formData.type=='暗盘'">
						<uni-number-box @change.native.stop="changeValue" v-model="item.intrCnt" />
					</view>
					<view class="shuo-cont" v-else>
						{{InventoryNub(formData)}}
					</view>
				</view>
			</view>
		</view>
		<view class="inner-item" v-for="(item,idex) in listData" :key="idex">
			<view class="text-title">
				<checkbox-group @change="checkChange" :data-id="item.sn">
					<label>
						<checkbox :checked="item.intrType=='1'?true:false" :value="item.sn"/>
					</label>
				</checkbox-group>
			</view>
			<view class="inventory-item">
				<view class="shuo-item">
					<view class="shuo-label">
						sn编码:
					</view>
					<view class="shuo-cont">
						{{item.sn}}
					</view>
				</view>
				<view class="shuo-item">
					<view class="shuo-label">
						RFIF码:
					</view>
					<view class="shuo-cont">
						{{item.rfid}}
					</view>
				</view>
			</view>
			<view class="inventory-item">
				<view class="shuo-item">
					<view class="shuo-label">
						批次:
					</view>
					<view class="shuo-cont">
						{{item.lotNum}}
					</view>
				</view>
				<view class="shuo-item">
					<view class="shuo-label">
						有效期至:
					</view>
					<view class="shuo-cont">
						<span>{{item.prodExpy}}</span>
					</view>
				</view>
			</view>
		</view>
		<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 {
		debounced
	} from '@/utils/debounced.js';
	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: [],
				inputVal: "",
				codeVal: "",
				confirmVal: "",
				changeVal: "",
				classes: [],
				listData: [],
				tabList: ['待盘点', '已盘点'],
				valueList: 0,
				beforeClose: true,
				datetimesingle: [],
				stroomId: "",
				stromName: "",
				formData: {}
			}
		},
		computed: {
			// ...mapState(['groundData'])
		},
		onShow() {
			let that = this;
			uni.getStorage({
				key: 'darkintdetail',
				success: function(res) {
					that.formData = res.data;
					that.stroomId = res.data.stroomId;
					that.intrNo = res.data.intrNo;
					that.stromName = res.data.stroomName
				}
			});
		},
		mounted() {
			this.$nextTick(()=>{
				 this.getData();
			})
		},
		methods: {
			...mapActions(['getInvenDetailData']),
			getData() {
				this.$http('inventory.getBrightData', {
					stroomId: this.stroomId,
					intrNo: this.intrNo,
					prodCode: this.formData.prodCode,
					pacCnt:this.formData.pacCnt,
					pacunt:this.formData.unt
				}, '加载中', true).then((res) => {
					if (res.success == true) {
						this.listData = res.data;
					}
				})

			},
			//计算盘点数
			InventoryNub(item) {
				if (item.intrCnt) {
					return item.intrCnt;
				}
				let intNub = this.listData.filter((item) => {
					return item.intrType == "1"
				})
				return intNub.length;

			},
			//日期格式化
			forMatTime(time) {
				return moment(time).format("YYYY-MM-DD");
			},
			changeValue() {
				console.log(this.dataList, '234234');
			},
			//盘点提交按钮
			orderAcept(type) {
				this.$http('inventory.brightData', {
					intrNo: this.intrNo,
					intrDetls: this.listData,
					prodCode: this.formData.prodCode,
					unt: this.formData.unt,
					pacCnt: this.formData.pacCnt,
				}, '加载中', true).then((res) => {
					if (res.success == true) {
						uni.redirectTo({
							url: '/pages/Inventorydetails/index',
							success: function(res) {
								console.log(res, "res")
							}
						});
					}

				})
				console.log(this.listData, '234234');
			},
			input(e) {
				this.value = e;
				this.dataChecked(e);
			},
			dataChecked(e) {
				let newData = [...this.listData];
				newData.map((item) => {
					if (item.sn === e) {
						return item.intrType = '1'
					}
				})
				this.listData = newData;
			},
			scan(code) {
				this.value = code;
				this.dataChecked(code);
			},
			lossData(e) {
				let newData = [...this.listData];
				newData.map((item) => {
					if (item.sn === e) {
						return item.intrType = '3'
					}
				})
				this.listData = newData;
			},
			checkChange(e) {
				if (e.detail.value && e.detail.value.length > 0) {
					this.dataChecked(e.detail.value[0]);
				} else {
					this.lossData(e.currentTarget.dataset.id);
				}
			},
			changeTab(index) {
				this.index = index;
				this.$refs.paging.reload();
			},
		},
		watch: {

		}

	}
</script>

<style lang="scss" scoped>
	.query-wrap {
		width: 100%;
		height: 100%;
		padding: 20rpx;
		box-sizing: border-box;
		background-color: #F1F1F1;
		overflow-y: scroll;
		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: 200;
		}

		.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>