<!--
 * @Author: zwq
 * @Date: 2023-08-01 13:52:10
 * @LastEditors: zwq
 * @LastEditTime: 2023-11-23 15:14:37
 * @Description:
-->
<template>
	<el-form
		:model="dataForm"
		:rules="dataRule"
		ref="dataForm"
		v-if="visible"
		@keyup.enter.native="dataFormSubmit()"
		label-width="90px"
    label-position="top">
		<el-row :gutter="20">
			<el-col :span="8">
				<el-form-item label="仓库编码" prop="warehouseCode">
					<el-input
						v-model="dataForm.warehouseCode"
						readonly
						placeholder="请输入仓库编码" />
				</el-form-item>
			</el-col>
			<el-col :span="8">
				<el-form-item label="仓库名称" prop="warehouseName">
					<el-input
						v-model="dataForm.warehouseName"
						readonly
						placeholder="请输入仓库名称" />
				</el-form-item>
			</el-col>
			<el-col :span="8">
				<el-form-item label="库位编码" prop="code">
					<el-input
						v-model="dataForm.code"
						clearable
						placeholder="请输入库位编码" />
				</el-form-item>
			</el-col>
			<el-col :span="8">
				<el-form-item label="库位名称" prop="name">
					<el-input
						v-model="dataForm.name"
						clearable
						placeholder="请输入库位名称" />
				</el-form-item>
			</el-col>
			<el-col :span="8">
				<el-form-item label="排" prop="arrange">
					<el-input
						v-model="dataForm.arrange"
						clearable
						placeholder="请输入排" />
				</el-form-item>
			</el-col>
			<el-col :span="8">
				<el-form-item label="列" prop="col">
					<el-input v-model="dataForm.col" clearable placeholder="请输入列" />
				</el-form-item>
			</el-col>
			<el-col :span="8">
				<el-form-item label="层" prop="layer">
					<el-input v-model="dataForm.layer" clearable placeholder="请输入层" />
				</el-form-item>
			</el-col>
			<el-col :span="8">
				<el-form-item prop="type" label="库位类型">
					<el-select
						v-model="dataForm.type"
						filterable
						clearable
            style="width: 100%;"
						placeholder="请选择库位类型">
						<el-option
							v-for="item in urlOptions.dictList.dict0"
							:key="item.id"
							:label="item.label"
							:value="parseInt(item.value)"></el-option>
					</el-select>
				</el-form-item>
			</el-col>
			<el-col :span="8">
				<el-form-item prop="enabled" label="是否可用">
					<el-select
						v-model="dataForm.enabled"
						filterable
						clearable
            style="width: 100%;"
						placeholder="请选择是否可用">
						<el-option
							v-for="item in isorno"
							:key="item.id"
							:label="item.name"
							:value="item.id"></el-option>
					</el-select>
				</el-form-item>
			</el-col>
			<el-col :span="8">
				<el-form-item label="备注" prop="remark">
					<el-input
						v-model="dataForm.remark"
						clearable
						placeholder="请输入备注" />
				</el-form-item>
			</el-col>
		</el-row>
	</el-form>
</template>

<script>
import basicAdd from '../mixins/basic-add';
import {
	createWarehouseLocation,
	updateWarehouseLocation,
	getWarehouseLocation,
	getCode,
} from '@/api/warehouse/warehouseLocation';

export default {
	mixins: [basicAdd],
	data() {
		return {
			urlOptions: {
				isGetCode: true,
				getDictList: true,
				codeURL: getCode,
				createURL: createWarehouseLocation,
				updateURL: updateWarehouseLocation,
				infoURL: getWarehouseLocation,
			},
			nameList: ['location_type'],
			dataForm: {
				id: undefined,
				name: undefined,
				code: undefined,
				arrange: undefined,
				col: undefined,
				layer: undefined,
				type: undefined,
				enabled: 1,
				remark: undefined,
				warehouseId: undefined,
				warehouseName: undefined,
				warehouseCode: undefined,
			},
			dataRule: {
				code: [
					{ required: true, message: '库位编码不能为空', trigger: 'blur' },
				],
				name: [
					{ required: true, message: '库位名称不能为空', trigger: 'blur' },
				],
				arrange: [{ required: true, message: '排不能为空', trigger: 'blur' }],
				col: [{ required: true, message: '列不能为空', trigger: 'blur' }],
				layer: [{ required: true, message: '层不能为空', trigger: 'blur' }],
			},
			isorno: [
				{
					id: 0,
					name: '不可用',
				},
				{
					id: 1,
					name: '可用',
				},
			],
		};
	},
	methods: {
		init(id, info) {
			this.dataForm.id = id || '';
			this.dataForm.warehouseName = info.warehouseName;
			this.dataForm.warehouseCode = info.warehouseCode;
			this.dataForm.warehouseId = info.warehouseId;
			this.visible = true;
			if (this.urlOptions.getOption) {
				this.getArr();
			}
			if (this.urlOptions.getDictList) {
				this.getDict();
			}
			this.$nextTick(() => {
				this.$refs['dataForm'].resetFields();
				if (this.dataForm.id) {
					this.urlOptions.infoURL(id).then((response) => {
						this.dataForm = response.data;
						if (this.setData) {
							this.setDataForm();
						}
					});
				} else {
					if (this.urlOptions.isGetCode) {
						this.getCode();
					}
				}
			});
		},
	},
};
</script>
