<template>
	<div>
		<el-dialog title="入库明细" :visible.sync="inDialogVisible" width="1000px">
			<el-form :model="store" label-position="right" label-width="80px" :rules="rules" ref="store">
				<el-row>
					<el-col :span="inDialogSpan" :offset="inDialogOffset">
						<el-form-item label="仓库">
							<el-select v-model="store.ware.id" clearable placeholder="请选择" style="width: 100%;">
								<el-option v-for="item in wares" :key="item.id" :label="item.name" :value="item.id">
								</el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="inDialogSpan">
						<el-form-item label="垛位">
							<el-input v-model="store.stack.name" disabled></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row>
					<el-col :span="inDialogSpan" :offset="inDialogOffset">
						<el-form-item label="层数" prop="layer">
							<el-input v-model.number="store.layer" :disabled="stack.isLayer!='2'"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="inDialogSpan">
						<el-form-item label="客户">
							<el-input v-model="store.customer.name" disabled>
								<el-button slot="append" icon="el-icon-search" @click="showCustomer"></el-button>
							</el-input>
						</el-form-item>
					</el-col>

				</el-row>
				<el-row>
					<el-col :span="inDialogSpan" :offset="inDialogOffset">
						<el-form-item label="发货地址">
							<el-input v-model="store.receiveAddress" >
									<el-button slot="append" icon="el-icon-search" @click="showAddress"></el-button>
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="inDialogSpan">
						<el-form-item label="车号">
							<el-input v-model="store.carNo"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row>
					<el-col :span="inDialogSpan" :offset="inDialogOffset">
						<el-form-item label="物料名称">
							<el-input v-model="store.material.name" disabled>
								<el-button slot="append" icon="el-icon-search" @click="showMaterial"></el-button>
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="inDialogSpan">
						<el-form-item label="钢种">
							<el-input v-model="store.material.standard" disabled>
								<el-button slot="append" icon="el-icon-search" @click="showMaterial"></el-button>
							</el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row>
					<el-col :span="inDialogSpan" :offset="inDialogOffset">
						<el-form-item label="钢板号">
							<el-input v-model="store.plateNo"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="inDialogSpan">
						<el-form-item label="规格型号">
							<el-input v-model="store.model"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row>
					<el-col :span="inDialogSpan" :offset="inDialogOffset">
						<el-form-item label="数量" prop="count">
							<el-input v-model.number="store.count"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="inDialogSpan">
						<el-form-item label="重量" prop="weight">
							<el-input v-model="store.weight" oninput = "value=value.replace(/[^\d.]/g,'')"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row>
					<el-col :span="inDialogSpan" :offset="inDialogOffset">
						<el-form-item label="计量方式" prop="wgtDcnMtcCd">
							<el-input v-model="store.wgtDcnMtcCd"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="inDialogSpan">
						<el-form-item label="切边类型" prop="edgeTy">
							<el-input v-model="store.edgeTy"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row>
					<el-col :span="inDialogSpan" :offset="inDialogOffset">
						<el-form-item label="产地">
							<el-input v-model="store.productionPlace"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="inDialogSpan">
						<el-form-item label="订单号">
							<el-input v-model="store.ordNo"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row>

					<el-col :span="inDialogSpan" :offset="inDialogOffset">
						<el-form-item label="理货人员">
							<el-select v-model="store.tallyPeople" size="small" style="margin-left: 10px" clearable placeholder="理货人员">
								<el-option v-for="item in tallyPeopleOption" :key="item.id" :label="item.dicName" :value="item.dicCode">
								</el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="inDialogSpan">
						<el-form-item label="付款单位">
							<el-input v-model="store.customer2.name" disabled>
								<el-button slot="append" icon="el-icon-search" @click="showCustomer2"></el-button>
							</el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row>
					<el-col :span="inDialogSpan*2" :offset="inDialogOffset">
						<el-form-item label="备注">
							<el-input v-model="store.remark" type="textarea"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row>
					<el-button size="medium" type="success" @click="handleConfirmIn('store')" :disabled="confAble">确定</el-button>
					<el-button size="medium" type="danger" @click="handleCancelIn">取消</el-button>
				</el-row>


			</el-form>
		</el-dialog>


		<popup-material ref="PopupMaterial" @receviceFromChild="receviceFromMaterial"></popup-material>
		<popup-customer ref="PopupCustomer" @receviceFromChild="receviceFromCustomer"></popup-customer>
		<popup-customer ref="PopupCustomer2" @receviceFromChild="receviceFromCustomer2"></popup-customer>
		<popup-address ref="PopupAddress" @receviceFromChild="receviceFromAddress" ></popup-address>
	</div>

</template>

<script>
	import axios from '@/axios'
	import PopupMaterial from '@/components/PopupMaterial.vue'
	import PopupCustomer from '@/components/PopupCustomer.vue'
	import PopupAddress from '@/components/PopupAddress.vue'
	import {
		mapState
	} from 'vuex'
	export default {
		props: {
			wareId: '',
			stack: {},
			wares: {
				type: Array
			},
		},
		components: {
			PopupMaterial,
			PopupCustomer,
			PopupAddress
		},
		mounted() {
			this.getSearchItem();
		},
		data() {
			return {
				moveFromStack: {},
				inDialogVisible: false,
				inDialogSpan: 8,
				inDialogSpanA: 7,
				inDialogSpanB: 1,
				inDialogOffset: 4,
				confAble:false,
				store: {
					id: '',
					ware: {
						id: '',
						name: ''
					},
					stack: {
						id: '',
						name: ''
					},
					layer: 0,
					material: {
						id: '',
						name: '',
						standard: ''
					},
					model: '',
					customer: {
						id: '',
						name: ''
					},
					customer2: {
						id: '',
						name: ''
					},
					count: '',
					weight: '',
					remark: '',
					plateNo: '',
					receiveAddress: '',
					wgtDcnMtcCd:'',
					edgeTy:'',
					productionPlace:'',
					ordNo:'',
					carNo:'',
					tallyPeople:'',
					fkComponyId:''
					
				},
				rules: {

					layer: [{
							required: true,
							message: '请输入层数',

						},
						{
							type: 'number',
							message: '层数必须为数字值'
						}
					],
					count: [{
							required: true,
							message: '请输入数量',

						},
						{
							type: 'number',
							message: '数量必须为数字值'
						}
					],

					weight: [{
							required: true,
							message: '请输入重量',

						}
					],
				},
				tallyPeopleOption:[],

			}
		},
		
		methods: {
			getSearchItem(){
				var url = 'Common/querySelector.do'
				var param = {
					type: 'TALLY_PEOPLE',
				}
				axios.get(url, param).then(response => {
					this.tallyPeopleOption = response.data.data;
				});

			},
			showMaterial() {
				this.$refs.PopupMaterial.show()
			},
			receviceFromMaterial(material) {
				this.store.material = material
			},

			showCustomer() {
				this.$refs.PopupCustomer.show()
			},
			showCustomer2() {
				this.$refs.PopupCustomer2.show()
			},
			receviceFromCustomer(customer) {
				this.store.customer = customer
				this.store.receiveAddress = customer.address
			},
			receviceFromCustomer2(customer) {
				this.store.customer2 = customer
				this.store.fkComponyId = customer.id;
			},
			
			showAddress() {
				this.$refs.PopupAddress.show(this.store.customer.id)
			},
			receviceFromAddress(address) {
				this.store.receiveAddress = address.address
			},
			
			show() {
				this.inDialogVisible = true
				this.store.ware.id = this.wareId
				this.store.stack = this.stack
				this.getLayerByStackId()
			},
			getLayerByStackId() {
				var url = 'WareStore/queryLayerByStackId.do'
				var param = {
					stackId: this.store.stack.id
				}
				axios.get(url, param).then(response => {
					this.store.layer = response.data.data
				});
			},
			handleConfirmIn(formName) {
				this.$refs[formName].validate((valid) => {
					if (valid) {
						
						this.confAble = true;
						var url = 'WareIn/in.do'
						var json = JSON.stringify(this.store)
						var param = {
							json: json
						}
						axios.post(url, param).then(response => {
							if (response.data.code == '0') {
								this.$message({
									type: 'success',
									message: '入库成功!',
								});
								this.inDialogVisible = false
								this.$emit('receviceFromChild');
							} else {
								this.$message({
									type: 'error',
									message: '入库失败!' + response.data.msg
								});
							}
							this.confAble = false;
						});
					} else {
						console.log('error submit!!');
						return false;
					}
				});
			},
			handleCancelIn() {
				this.inDialogVisible = false
			},
		}
	}
</script>

<style>
</style>
