<template>
    <!-- transport -->
    <div class="Transport">
        <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 { reqTransport, reqSetTransport } from "@/api/meatTransport.js";
export default {
    name: "Transport",
    data() {
        return {
            list: [{ status: "" , number: ""}]
        };
    },
    created() {
        this.getTransport();
    },
    methods: {
        onSubmit() {
            let status = [];
            let number = [];
            this.list.forEach(item => {
                status.push(item.status);
                number.push(item.number);
            });
            this.$confirm("确定更新信息？").then(() => {
                reqSetTransport({ status: status.join(","), number: number.join(",") })
                    .then(res => {
                        if (res.errCode) {
                            this.$message.error(res.errMsg);
                        } else {
                            this.getTransport();
                            this.$message.success("更新成功！");
                        }
                    })
                    .catch(err => {
                        console.log(err);
                        this.$message.error("更新失败！");
                    });
            });
        },
        getTransport() {
            reqTransport()
                .then(res => {
                    let arr2 = res.conf['number'].split(",")
                    this.list = [];
                    res.conf['status'].split(",").forEach((item, i) => {
                        this.list.push({ 'status': item , 'number': arr2[i]});
                    });
                })
                .catch(err => {
                    console.error(err);
                });
        }
    }
};
</script>

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