<!--
 * @Author: zwq
 * @Date: 2023-08-01 13:52:10
 * @LastEditors: zwq
 * @LastEditTime: 2024-08-07 16:39:08
 * @Description:
-->
<template>
	<el-form
		:model="dataForm"
		:rules="dataRule"
		ref="dataForm"
		v-if="visible"
		@keyup.enter.native="dataFormSubmit()"
		label-width="100px"
    label-position="top">
		<el-row :gutter="20">
			<el-col :span="12">
				<el-form-item label="仓库名称" prop="name">
					<el-input
						v-model="dataForm.name"
						clearable
						placeholder="请输入仓库名称" />
				</el-form-item>
			</el-col>
			<el-col :span="12">
				<el-form-item label="仓库编码" prop="code">
					<el-input
						v-model="dataForm.code"
						clearable
						placeholder="请输入仓库编码" />
				</el-form-item>
			</el-col>
			<el-col :span="12">
				<el-form-item prop="enabled" label="是否启用">
					<el-select
						v-model="dataForm.enabled"
						filterable
						: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="12">
				<el-form-item prop="type" label="仓库类型">
					<el-select
						v-model="dataForm.type"
						filterable
						: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-row>
	</el-form>
</template>

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

export default {
	mixins: [basicAdd],
	data() {
		return {
			urlOptions: {
				isGetCode: true,
				codeURL: getCode,
				getDictList: true,
				createURL: createWarehouse,
				updateURL: updateWarehouse,
				infoURL: getWarehouse,
			},
			nameList: ['warehouse_type'],
			dataForm: {
				id: undefined,
				name: '',
        code: '',
				enabled: 1,
        type: 2,
        creator: ''
			},
			dataRule: {
				code: [
					{ required: true, message: '仓库编码不能为空', trigger: 'blur' },
				],
				name: [
					{ required: true, message: '仓库名称不能为空', trigger: 'blur' },
				],
			},
			isorno: [
				{
					id: 0,
					name: '停用',
				},
				{
					id: 1,
					name: '启用',
				},
			],
		};
	},
  created() {
      getUserProfile().then(response => {
        this.dataForm.creator = response.data.username;
      });
  },
	methods: {},
};
</script>
