<template>
    <!-- breed_info -->
    <div class="Breed_info">
        <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.fodder"></el-input>
                </el-form-item>
                <el-form-item label="断奶存活率(单位 %)">
                    <el-input v-model="form.weaning"></el-input>
                </el-form-item>
                <el-form-item label="仓库使用率(单位 %)">
                    <el-input v-model="form.warehouse"></el-input>
                </el-form-item>
                <el-form-item label="配种分娩率(单位 %)">
                    <el-input v-model="form.breeding"></el-input>
                </el-form-item>
                <el-form-item label="多羔率(单位 %)">
                    <el-input v-model="form.kids"></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 { reqBreed_info, reqSetBreed_info } from "@/api/breed.js";
export default {
    name: "Breed_info",
    data() {
        return {
            form: {
                fodder: "",
                weaning: "",
                warehouse: "",
                breeding: "",
                kids: ""
            }
        };
    },
    created() {
        this.getBreed_info();
    },
    methods: {
        onSubmit() {
            this.$confirm("确定更新信息？").then(() => {
                reqSetBreed_info(this.form)
                    .then(res => {
                        if (res.errcode) {
                            this.$message.error("更新失败！");
                        } else {
                            this.$message.success("更新成功！");
                        }
                    })
                    .catch(err => {
                        console.log(err);
                        this.$message.error("更新失败！");
                    });
            });
        },
        getBreed_info() {
            reqBreed_info()
                .then(res => {
                    this.form = res.conf;
                })
                .catch(err => {
                    console.error(err);
                });
        }
    }
};
</script>

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