<!--
 * @Author: zwq
 * @Date: 2023-08-01 13:52:10
 * @LastEditors: zwq
 * @LastEditTime: 2023-12-05 14:05:08
 * @Description:
-->
<template>
	<el-form
		:model="dataForm"
		:rules="dataRule"
		ref="dataForm"
		v-if="visible"
		@keyup.enter.native="dataFormSubmit()"
		label-width="90px">
		<el-row :gutter="20">
			<el-col :span="isdetail?24:12">
				<el-form-item label="仓库编码" prop="code">
					<el-input
						v-model="dataForm.code"
						clearable
						:disabled="isdetail"
            :style="{width: isdetail?'70%':'100%',}"
						placeholder="请输入仓库编码" />
				</el-form-item>
			</el-col>
			<el-col :span="isdetail?24:12">
				<el-form-item label="仓库名称" prop="name">
					<el-input
						v-model="dataForm.name"
						clearable
						:disabled="isdetail"
            :style="{width: isdetail?'70%':'100%',}"
						placeholder="请输入仓库名称" />
				</el-form-item>
			</el-col>
			<el-col :span="isdetail?24:12">
				<el-form-item prop="type" label="仓库类型">
					<el-select
						v-model="dataForm.type"
						:disabled="isdetail"
						filterable
						clearable
            :style="{width: isdetail?'70%':'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="isdetail?24:12">
				<el-form-item prop="storageType" v-if="!isdetail" label="物料类型">
					<el-select
						v-model="dataForm.storageType"
						filterable
						clearable
            style="width: 100%;"
						placeholder="请选择物料类型">
						<el-option
							v-for="item in urlOptions.dictList.dict1"
							:key="item.id"
							:label="item.label"
							:value="parseInt(item.value)"></el-option>
					</el-select>
				</el-form-item>
			</el-col>
		</el-row>
	</el-form>
</template>

<script>
import basicAdd from '../mixins/basic-add';
import {
	getCode,
	createWarehouse,
	updateWarehouse,
	getWarehouse,
} from '@/api/warehouse/warehouse-info';

export default {
	mixins: [basicAdd],
	data() {
		return {
			urlOptions: {
				isGetCode: true,
				getDictList: true,
				codeURL: getCode,
				createURL: createWarehouse,
				updateURL: updateWarehouse,
				infoURL: getWarehouse,
			},
			nameList: ['warehouse_type', 'material_type'],
			dataForm: {
				id: undefined,
				name: undefined,
				code: undefined,
				type: undefined,
				storageType: undefined,
			},
			dataRule: {
				code: [
					{ required: true, message: '仓库编码不能为空', trigger: 'blur' },
				],
				name: [
					{ required: true, message: '仓库名称不能为空', trigger: 'blur' },
				],
				storageType: [
					{ required: true, message: '物料类型不能为空', trigger: 'change' },
				],
				type: [
					{ required: true, message: '仓库类型不能为空', trigger: 'change' },
				],
			},
			isdetail: false,
		};
	},
	methods: {
		init(id, isdetail) {
			this.dataForm.id = id || '';
			this.isdetail = isdetail || false;
			this.visible = true;
			this.getDict();
			this.$nextTick(() => {
				this.$refs['dataForm'].resetFields();
				if (this.dataForm.id) {
					this.urlOptions.infoURL(id).then((response) => {
						this.dataForm = response.data;
					});
				} else {
					if (this.urlOptions.isGetCode) {
						this.getCode();
					}
				}
			});
		},
	},
};
</script>
