<template>
    <!-- warn -->
    <div class="Warn">
        <h2 style="margin-bottom: 20px;padding-bottom:7px;border-bottom:2px solid #ddd">消息提醒</h2>
        <formList v-model="list" :title="['消息']" type="textarea" inputWidth="600px"></formList>
        <el-button style="margin-left:610px" type="primary" @click="onSubmit">更新信息</el-button>
    </div>
</template>

<script>
import { reqWarn, reqSetWarn } from "@/api/breed.js";
export default {
    name: "Warn",
    data() {
        return {
            list: [{ msg: "" }]
        };
    },
    created() {
        this.getWarn();
    },
    methods: {
        /* 
        content[0]: 14587号母羊已到达断奶时间请及时断奶99
content[1]: 阿莫西林药品已经低于安全库存请补充
content[2]: 无害化仓库已满请及时清理
content[3]: 阿莫西林药品已经低于安全库存请补充
content[4]: 14587号母羊已到达断奶时间请及时断奶
content[5]: 无害化仓库已满请及时清理
content[6]: 14587号母羊已到达断奶时间请及时断奶
        
        */
        onSubmit() {
            let data = [];
            this.list.forEach(item => {
                data.push(item.msg);
            });
            console.log({ content: data.toString() })
            this.$confirm("确定更新信息？").then(() => {
                reqSetWarn({ content: data.toString() })
                    .then(res => {
                        if (res.errCode) {
                            this.$message.error(res.errMsg);
                        } else {
                            this.getWarn();
                            this.$message.success("更新成功！");
                        }
                    })
                    .catch(err => {
                        console.log(err);
                        this.$message.error("更新失败！");
                    });
            });
        },
        getWarn() {
            reqWarn()
                .then(res => {
                    this.list = [];
                    res.conf.content.forEach(item => {
                        this.list.push({ msg: item });
                    });
                })
                .catch(err => {
                    console.error(err);
                });
        }
    }
};
</script>

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