
<template>
    <layout-form>
        <el-form :model="form" :loading="loading" :rules="rules" size='small' label-width='100px' ref="form">
            <el-row>
                <Field label="类目名称" v-model="category.name" disabled />
                <Field label="类目代码" prop="categoryAllCode" v-model="category.code" disabled />
                <Field label="类目ID" prop="categoryId" v-model="form.categoryId" hidden />
                <Field label="物料代码" prop="code" v-model="form.code" disabled :hidden="pageInfo.type == 'add'" />
                <Field label="物料名称" prop="name" v-model="form.name" />
                <Field label="规格/型号" prop="specModel" v-model="form.specModel" />
                <Field label="计量单位" prop="unitOfMeasure" v-model="form.unitOfMeasure" :enumData='dict.unitOfMeasure' type='select' />
                <Field label="默认用量" prop="useNum" v-model="form.useNum" />
                <Field label="默认损耗率" prop="lossRate" v-model="form.lossRate" />
                <Field label="默认补给" prop="supplyType" v-model="form.supplyType" :enumData='dict.supplyType' type='select' />
                <Field label="默认成本" prop="costPlan" v-model="form.costPlan" />
                <Field label="主图片url" prop="mainPicUrl" v-model="form.mainPicUrl" />
                <Field label="备注" prop="remark" v-model="form.remark" />
            </el-row>
            <form-buttons @submit='submitForm' @cancel='cancelForm' :noSaveBtn="pageInfo.type === 'view'" />
        </el-form>
    </layout-form>
</template>

<script>
import form from "@/assets/mixins/form";
export default {
    mixins: [form],
    methods: {
        beforeRender(data) {
            this.category = Object.assign({}, data.category);
            return data;
        },
    },
    data() {
        return {
            category: {},
            toString: ["unitOfMeasure", "supplyType"],
            rules: {
                name: [
                    {
                        required: true,
                        message: "请输入物料名称",
                        trigger: "blur",
                    },
                ],
                code: [
                    {
                        required: false,
                        message: "请输入物料代码",
                        trigger: "blur",
                    },
                ],
                categoryId: [
                    {
                        required: true,
                        message: "请输入类目ID",
                        trigger: "blur",
                    },
                ],
                specModel: [
                    {
                        required: true,
                        message: "请输入规格/型号",
                        trigger: "blur",
                    },
                ],
                unitOfMeasure: [
                    {
                        required: true,
                        message: "请输入计量单位",
                        trigger: "blur",
                    },
                ],
                costPlan: [
                    {
                        type: "integer",
                        required: false,
                        message: "请输入计划成本[1-~]",
                        trigger: "blur",
                    },
                ],
                useNum: [
                    {
                        type: "integer",
                        required: true,
                        message: "请输入默认用量[1-~]",
                        trigger: "blur",
                    },
                ],
                lossRate: [
                    {
                        type: "integer",
                        required: true,
                        message: "请输入默认损耗率[0-~]",
                        trigger: "blur",
                    },
                ],
                supplyType: [
                    {
                        required: true,
                        message: "请选择默认补给方式",
                        trigger: "blur",
                    },
                ],
            },
        };
    },
};
</script>
