<!-- 零件基础信息卡片包括:
零件号、名称、描述、数量和单位
箱码、批次、库位、状态
可以通过属性控制库位和状态是否显示 -->
<template>
	<view class="ljh_box">
		<view class="ljh_info">
			<view class="tit_ljh">{{ dataContent.itemCode }}</view>
			<view class="label_xm font_xs fr">{{ dataContent.packingCode }}</view>
		</view>
		<view class="uni-flex space-between desc_card">
			<view class="ljh_left">
				<view class="text_lightblue font_xs">{{dataContent.itemName }}</view>
				<view class="text_lightblue font_xs">{{dataContent.itemDesc1}}</view>
			</view>
			<view class="ljh_right uni-row uni-flex u-col-center" style="
			 align-items: center;">
				<text class="tnum" v-if="!isEditCount">{{dataContent.qty}}</text>
				<input v-if="isEditCount" type="digit" v-model="countValue" @input="inputClick" style="
				width: 180rpx;
				height: 70rpx;
				text-align: center;
				background-color:#DCDCDC" />
				<text class="tunit">{{dataContent.uom}}</text>

			</view>
		</view>
	</view>
</template>

<script>
	import {
		getInventoryTypeStyle,
		getInventoryStatusDesc,
	} from '@/common/basic.js';

	export default {
		name: 'comItemTop',
		components: {},
		props: {
			dataContent: {
				type: Object,
				default: {}
			},
			isEditCount: {
				type: Boolean,
				default: false
			}
		},
		watch: {
			dataContent: {
				handler(newval, oldval) {
					this.countValue = this.dataContent.qty
				},
				immediate: true,
				deep: true
			}

		},
		data() {
			return {
				countValue: 0
			}
		},
		filters: {
			statusStyle: function(val) {
				return getInventoryTypeStyle(val);
			},
			statusColor: function(val) {
				return getInventoryStatusDesc(val);
			},
		},
		created() {

		},
		methods: {
			inputClick(value) {
				this.$nextTick(() => {
					if(value.detail.value==""){
						uni.showToast({
							title: "输入数量不能为空"
						})
						this.dataContent.qty = this.countValue;
						return;
					}
					
					if (value.detail.value < 0) {
						uni.showToast({
							title: "输入数量不能小于0"
						})
						this.countValue = this.dataContent.qty;
						return;
					}

					if (value.detail.value > this.dataContent.recommendQty) {
						uni.showToast({
							title: "输入数量不能大于库存" + this.dataContent.recommendQty
						})
						this.countValue = this.dataContent.qty
						return;
					}
					
					this.dataContent.qty = this.countValue;
				})


			}
		}
	}
</script>

<style>
</style>
