<template>
    <!-- quarantinePass -->
    <div class="QuarantinePass">
        <h2 style="margin-bottom: 20px;padding-bottom:7px;border-bottom:2px solid #ddd">检疫合格率</h2>
        <formList v-model="list" :title="['批次','值(%)']" inputWidth="200px"></formList>
        <el-button style="margin-left:510px" type="primary" @click="onSubmit">更新信息</el-button>
    </div>
</template>

<script>
import { reqQuarantinePass, reqSetQuarantinePass } from "@/api/butcher.js";
export default {
    name: "QuarantinePass",
    data() {
        return {
            id: '-1',
            list: [{ keyList: "" , valueList: ""}]
        };
    },
    created() {
        this.getQuarantinePass();
    },
    methods: {
        onSubmit() {
            let keyList = [];
            let valueList = [];
            this.list.forEach(item => {
                keyList.push(item.keyList);
                valueList.push(item.valueList);
            });
            this.$confirm("确定更新信息？").then(() => {
                reqSetQuarantinePass({id: this.id, keyList: keyList.toString(), valueList: valueList.toString()})
                    .then(res => {
                        console.log(res);
                        if (res.errCode) {
                            this.$message.error(res.errMsg);
                        } else {
                            this.getQuarantinePass();
                            this.$message.success("更新成功！");
                        }
                    })
                    .catch(err => {
                        console.log(err);
                        this.$message.error("更新失败！");
                    });
            });
        },
        getQuarantinePass() {
            reqQuarantinePass()
                .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>
.QuarantinePass {
    .left {
        width: 400px;
        margin-left: 50px;
    }
}
</style>