<template>
<!-- sheepLivestock -->
    <div class="SheepLivestock">
        <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.all"></el-input>
                </el-form-item>
                <el-form-item label="种母羊存栏">
                    <el-input v-model="form.ram"></el-input>
                </el-form-item>
                <el-form-item label="总公羊存栏">
                    <el-input v-model="form.ewe"></el-input>
                </el-form-item>
                <el-form-item label="羔羊存栏">
                    <el-input v-model="form.lamb"></el-input>
                </el-form-item>
                <el-form-item label="育肥羊存栏">
                    <el-input v-model="form.commercial"></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 { reqSheepLivestock, reqSetSheepLivestock } from "@/api/breed.js";
export default {
    name: "SheepLivestock",
    data() {
        return {
            form: {
                all: "",
                ram: "",
                ewe: "",
                lamb: "",
                commercial: ""
            }
        };
    },
    created() {
        this.getSheepLivestock();
    },
    methods: {
        onSubmit() {
            this.$confirm("确定更新信息？").then(() => {
                reqSetSheepLivestock(this.form)
                    .then(res => {
                        console.log(res)
                        if(res.errcode) {
                            this.$message.error("更新失败！");
                        }
                        this.$message.success("更新成功！");
                    })
                    .catch(err => {
                        console.log(err);
                        this.$message.error("更新失败！");
                    });
            });
        },
        getSheepLivestock() {
            reqSheepLivestock()
                .then(res => {
                    this.form = res.conf
                })
                .catch(err => {
                    console.error(err);
                });
        }
    }
};
</script>

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