<template>
    <!-- head -->
    <div class="Head">
        <h2 style="margin-bottom: 20px;padding-bottom:7px;border-bottom:2px solid #ddd">头部信息</h2>
        <div class="left">
            <el-form ref="form" :model="form" label-width="140px">
                <el-form-item label="总存栏待宰">
                    <el-input v-model="form.carcass"></el-input>
                </el-form-item>
                <el-form-item label="未检疫数量">
                    <el-input v-model="form.productInventory"></el-input>
                </el-form-item>
                <el-form-item label="胴体数量">
                    <el-input v-model="form.totalSlaughter"></el-input>
                </el-form-item>
                <el-form-item label="产品库存">
                    <el-input v-model="form.noQuarantined"></el-input>
                </el-form-item>
                <el-form-item label="出肉率">
                    <el-input v-model="form.meatRate"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button style="margin-left:60%" type="primary" @click="onSubmit">更新信息</el-button>
                </el-form-item>
            </el-form>
        </div>
    </div>
</template>

<script>
import { reqHead, reqSetHead } from "@/api/butcher.js";
export default {
    name: "Head",
    data() {
        return {
            form: {
                id: "-1",
                carcass: "",
                productInventory: "",
                totalSlaughter: "",
                noQuarantined: "",
                meatRate: ""
            }
        };
    },
    created() {
        this.getHead();
    },
    methods: {
        onSubmit() {
            this.$confirm("确定更新信息？").then(() => {
                console.log(this.form);
                reqSetHead(this.form)
                    .then(res => {
                        if (res.errCode) {
                            this.$message.error(res.errMsg);
                        } else {
                            this.getHead();
                            this.$message.success("更新成功！");
                        }
                    })
                    .catch(err => {
                        console.log(err);
                        this.$message.error("更新失败！");
                    });
            });
        },
        getHead() {
            reqHead()
                .then(res => {
                    this.form = res.conf;
                    this.form.id = res.id;
                })
                .catch(err => {
                    console.error(err);
                });
        }
    }
};
</script>

<style lang="scss" scoped>
.Head {
    .left {
        width: 400px;
        margin-left: 50px;
    }
}
</style>