<!--
 * @Author: zwq
 * @Date: 2023-08-01 13:52:10
 * @LastEditors: zwq
 * @LastEditTime: 2024-04-10 09:30:06
 * @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="level">
					<el-input v-model="dataForm.level" clearable
						placeholder="请输入原料等级" />
				</el-form-item>
			</el-col>
			<el-col :span="12">
				<el-form-item label="原料编码" prop="code">
					<el-input v-model="dataForm.code" readonly />
				</el-form-item>
			</el-col>
			<el-col :span="12">
				<el-form-item label="单位" prop="unit">
					<el-select
						v-model="dataForm.unit"
						filterable
						clearable
						:style="{ width: '100%' }"
						placeholder="请选择单位">
						<el-option
							v-for="item in urlOptions.dictArr.dict0"
							:key="item.id"
							:label="item.label"
							:value="item.value"></el-option>
					</el-select>
				</el-form-item>
			</el-col>
		</el-row>
	</el-form>
</template>

<script>
import basicAdd from '@/mixins/basic-add';
import {
	createMaterial,
	updateMaterial,
	getMaterial,
  getCode
} from '@/api/base/material';

export default {
	mixins: [basicAdd],
	data() {
		return {
			urlOptions: {
				createURL: createMaterial,
				updateURL: updateMaterial,
				infoURL: getMaterial,
        codeURL: getCode, //获取code接口（返回结果为dataForm.code字段）
        dictNameList: ['unit_dict'], //数据字典name数组
			},
			dataForm: {
				id: undefined,
				code: '',
				name: '',
				unit: '',
				level: '',
			},
			dataRule: {
				name: [
					{ required: true, message: '原料不能为空', trigger: 'blur' },
				],
				code: [{ required: true, message: '编码不能为空', trigger: 'blur' }],
			},
		};
	},
	created() {},
	methods: {
	},
};
</script>
