<template>
    <!-- sheepMixed -->
    <div class="SheepMixed">
        <h2 style="margin-bottom: 20px;padding-bottom:7px;border-bottom:2px solid #ddd">羊杂销售额</h2>
        <formList v-model="list" :title="['时间','销售额(元)']" inputWidth="200px" titleWidth="120px"></formList>
        <el-button style="margin-left:510px" type="primary" @click="onSubmit">更新信息</el-button>
    </div>
</template>

<script>
import { reqSheepMixed, reqSetSheepMixed } from "@/api/product.js";
export default {
    name: "SheepMixed",
    data() {
        return {
            id: '-1',
            list: [{ keyList: "" , valueList: ""}]
        };
    },
    created() {
        this.getSheepMixed();
    },
    methods: {
        onSubmit() {
            let keyList = [];
            let valueList = [];
            this.list.forEach(item => {
                keyList.push(item.keyList);
                valueList.push(item.valueList);
            });
            this.$confirm("确定更新信息？").then(() => {
                reqSetSheepMixed({id: this.id, keyList: keyList.toString(), valueList: valueList.toString()})
                    .then(res => {
                        console.log(res);
                        if (res.errCode) {
                            this.$message.error(res.errMsg);
                        } else {
                            this.getSheepMixed();
                            this.$message.success("更新成功！");
                        }
                    })
                    .catch(err => {
                        console.log(err);
                        this.$message.error("更新失败！");
                    });
            });
        },
        getSheepMixed() {
            reqSheepMixed()
                .then(res => {
                    this.id = res.id
                    let arr2 = res.conf['valueList']
                    this.list = [];
                    res.conf['keyList'].forEach((item, i) => {
                        this.list.push({ 'keyList': item , 'valueList': arr2[i]});
                    });
                })
                .catch(err => {
                    console.error(err);
                });
        }
    }
};
</script>

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