<template>
	<view class="">
		<uni-popup ref="popup">
			<view class="uni-flex uni-column pop_customer">
				<view class="" style="padding:10rpx">
					<view class="uni-flex u-col-center uni-row space-between" style="padding: 10rpx 10rpx 20rpx 10rpx">
						<view class="" style="font-size: 35rpx;">
							{{title}}
						</view>
						<image style="width: 35rpx;height: 35rpx;" src="/static/icons/icons_close.svg"
							@click="closeEditPopup"></image>
					</view>
					<u-line />
					<view class="uni-flex uni-column" style="background-color: white; height:60%;">
						<view class="uni-flex uni-column  ">

							<view class="uni-flex uni-row space-between padding title u-col-center">
								<text>数量 : </text>
								<view class="uni-flex uni-row uni-center" style="align-items: center;">
									<input class="qty_input" v-model="allQty" :focus="true" type="number"
										@confirm="confirm()" />
									<uom :uom="dataContent.uom"></uom>
								</view>
							</view>
							<u-line />
							<view class="uni-flex uni-row space-between padding title u-col-center">
								<text>不合格数量 : </text>
								<view class="uni-flex uni-row uni-center" style="align-items: center;">
									<input class="qty_input" v-model="FailedQty" :focus="true" type="number"
										@confirm="confirm()" />
									<uom :uom="dataContent.uom"></uom>
								</view>
							</view>
							<u-line />
							<view class="uni-flex uni-row u-col-center" style="width: 100%;">
								<view class=""
									style=" text-align: center;font-size: 32rpx;font-weight: 700;margin-left: 20rpx;">
									不合格原因 :
								</view>
								<uni-data-picker style="padding: 20rpx; background-color:#fff;" class='uni-data-picker'
									placeholder="请选择原因" popup-title="选择不合格原因" :localdata="reasonList" v-model="reason">
								</uni-data-picker>
							</view>
							<u-line />

						</view>
					</view>
				</view>
				<view class="uni-flex uni-row hide_border">
					<button class="btn_edit_big_cancle" hover-class="btn_edit_big_after" @click="cancel()">取消</button>
					<button class="btn_edit_big_confirm" hover-class="btn_edit_big_after" @click="confirm()">确认</button>
				</view>
			</view>
		</uni-popup>
		<com-message ref="comMessage"></com-message>
	</view>
</template>

<script>
	import uom from '@/mycomponents/qty/uom.vue'
	import StdUom from '@/mycomponents/qty/StdUom.vue'
	import balanceStatus from '@/mycomponents/status/balanceStatus.vue'
	import comMessage from '@/mycomponents/common/comMessage.vue'
	import {
		getInspectReasonList
	} from '@/common/directory.js';

	export default {
		components: {
			uom,
			StdUom,
			balanceStatus,
			comMessage
		},
		data() {
			return {
				allQty: 0,
				stdCount: 1,
				stateData: 0,
				balanceQty: 0,
				inventoryStatus: "",
				originalInventoryStatus: "",
				dataContent: {},
				handleQty: 0,
				FailedQty: 0,
				reasonList: [],
				reason: ""

			}
		},
		watch: {

		},
		created() {
			this.reasonList = getInspectReasonList();
		},

		props: {
			title: {
				type: String,
				default: "编辑数量"
			},
			settingParam: {
				type: Object,
				default: {}
			},
			isShowStatus: {
				type: Boolean,
				default: true
			},
			allowEditStatus: {
				type: Boolean,
				default: false
			}
		},
		methods: {
			openEditPopup(item, handleQty) {
				this.dataContent = item
				this.inventoryStatus = this.dataContent.inventoryStatus
				this.toInventoryStatus = this.dataContent.toInventoryStatus
				this.allQty = Number(handleQty)
				this.FailedQty = Number(item.FailedQty)
				this.$refs.popup.open('bottom')
			},
			closeEditPopup() {
				this.$refs.popup.close()
			},
			confirm() {
				this.setValue();
			},
			cancel() {
				this.dataContent.inventoryStatus = this.originalInventoryStatus;
				this.closeEditPopup();
			},
			calcQty(val) {
				this.allQty = val * Number(this.dataContent.stdPackQty);
			},
			setValue() {
				var balanceQty = Number(this.dataContent.qty);
				if (this.allQty == 0) {
					this.$refs.comMessage.showConfirmWarningModal('数量必须大于0',
						res => {
							this.allQty = balanceQty;
						})
				} else if (this.allQty > balanceQty) {
					this.$refs.comMessage.showConfirmWarningModal('数量[' + this.allQty + ']不允许大于库存数量[' + balanceQty + ']',
						res => {
							this.allQty = balanceQty;
						})
				} else {
					this.callback();
				}
			},
			callback() {
				var reasonInfo = this.reasonList.find(res => {
					if (res.value == this.reason) {
						return res
					}
				})

				if (reasonInfo == undefined) {
					reasonInfo = {
						text: "",
						value: ""
						}
			}
				this.dataContent.toInventoryStatus = this.inventoryStatus
				this.$emit("confirm", Number(this.allQty), Number(this.FailedQty), reasonInfo);
				this.closeEditPopup();
			},
			updateStatus(value) {
				this.inventoryStatus = value
				console.log(this.inventoryStatus)
			}
		}
	}
</script>

<style lang="scss">
	.uni-popup .uni-popup__wrapper {
		width: 100% !important;
		padding: 30rpx;
	}

	.hide_border {
		button {
			border: none;
		}

		button::after {
			border: none;
		}
	}

	.title {
		font-size: 30rpx;
	}
</style>
