<template>
    <!-- breedingTurnover -->
    <div class="BreedingTurnover">
        <h2 style="margin-bottom: 20px;padding-bottom:7px;border-bottom:2px solid #ddd">种羊销售金额</h2>
        <formList v-model="list" :title="['时间','金额']" inputWidth="300px" titleWidth="150px"></formList>
        <el-button style="margin-left:810px" type="primary" @click="onSubmit">更新信息</el-button>
    </div>
</template>

<script>

import { reqBreedingTurnover, reqSetBreedingTurnover } from "@/api/meatTransport.js";
export default {
    name: "BreedingTurnover",
    data() {
        return {
            list: [{ time: "" , turnover: ""}]
        };
    },
    created() {
        this.getBreedingTurnover();
    },
    methods: {
        onSubmit() {
            let time = [];
            let turnover = [];
            this.list.forEach(item => {
                time.push(item.time);
                turnover.push(item.turnover);
            });
            this.$confirm("确定更新信息？").then(() => {
                reqSetBreedingTurnover({ time: time.toString(), turnover: turnover.toString() })
                    .then(res => {
                        if (res.errCode) {
                            this.$message.error(res.errMsg);
                        } else {
                            this.getBreedingTurnover();
                            this.$message.success("更新成功！");
                        }
                    })
                    .catch(err => {
                        console.log(err);
                        this.$message.error("更新失败！");
                    });
            });
        },
        getBreedingTurnover() {
            reqBreedingTurnover()
                .then(res => {
                    let arr2 = res.conf['turnover']
                    this.list = [];
                    res.conf['time'].forEach((item, i) => {
                        this.list.push({ 'time': item , 'turnover': arr2[i]});
                    });
                })
                .catch(err => {
                    console.error(err);
                });
        }
    }
};
</script>

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