<template>
    <!-- lambDistribute -->
    <div class="LambDistribute">
        <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="120px">
                <el-form-item label="健仔">
                    <el-input v-model="form.healthy"></el-input>
                </el-form-item>
                <el-form-item label="木乃伊">
                    <el-input v-model="form.mummy"></el-input>
                </el-form-item>
                <el-form-item label="死仔">
                    <el-input v-model="form.death"></el-input>
                </el-form-item>
                <el-form-item label="弱仔">
                    <el-input v-model="form.weak"></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 { reqLambDistribute, reqSetLambDistribute } from "@/api/breed.js";
export default {
    name: "LambDistribute",
    data() {
        return {
            form: {
                healthy: "",
                mummy: "",
                death: "",
                lamb: "",
                weak: ""
            }
        };
    },
    created() {
        this.getLambDistribute();
    },
    methods: {
        onSubmit() {
            this.$confirm("确定更新信息？").then(() => {
                reqSetLambDistribute(this.form)
                    .then(res => {
                        if (res.errCode) {
                            this.$message.error(res.errMsg);
                        } else {
                            this.getLambDistribute();
                            this.$message.success("更新成功！");
                        }
                    })
                    .catch(err => {
                        console.log(err);
                        this.$message.error("更新失败！");
                    });
            });
        },
        getLambDistribute() {
            reqLambDistribute()
                .then(res => {
                    this.form = res.conf;
                })
                .catch(err => {
                    console.error(err);
                });
        }
    }
};
</script>

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