<template>
    <!-- genealogy -->
    <div class="Genealogy">
        <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="100px">
                <el-form-item label="本体">
                    <el-input v-model="form.self"></el-input>
                </el-form-item>
                <el-form-item label="父">
                    <el-input v-model="form.father"></el-input>
                </el-form-item>
                <el-form-item label="母">
                    <el-input v-model="form.mother"></el-input>
                </el-form-item>
                <el-form-item label="父母">
                    <el-input v-model="form.fm"></el-input>
                </el-form-item>
                <el-form-item label="父父">
                    <el-input v-model="form.ff"></el-input>
                </el-form-item>
                <el-form-item label="母父">
                    <el-input v-model="form.mf"></el-input>
                </el-form-item>
                <el-form-item label="母母">
                    <el-input v-model="form.mm"></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 { reqGenealogy, reqSetGenealogy } from "@/api/breed.js";
export default {
    name: "Genealogy",
    data() {
        return {
            form: {
                self: "",
                father: "",
                mother: "",
                fm: "",
                ff: "",
                mf: "",
                mm: ""
            }
        };
    },
    created() {
        this.getGenealogy();
    },
    methods: {
        onSubmit() {
            this.$confirm("确定更新信息？").then(() => {
                reqSetGenealogy(this.form)
                    .then(res => {
                        if (res.errCode) {
                            this.$message.error(res.errMsg);
                        } else {
                            this.getGenealogy();
                            this.$message.success("更新成功！");
                        }
                    })
                    .catch(err => {
                        console.log(err);
                        this.$message.error("更新失败！");
                    });
            });
        },
        getGenealogy() {
            reqGenealogy()
                .then(res => {
                    this.form = res.conf;
                })
                .catch(err => {
                    console.error(err);
                });
        }
    }
};
</script>

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