<template>
    <!-- warehouseOutRecord -->
    <div class="WarehouseOutRecord">
        <h2 style="margin-bottom: 20px;padding-bottom:7px;border-bottom:2px solid #ddd">出库申请记录</h2>
        <formList v-model="list" :title="['记录信息']" type="textarea" inputWidth="500px"></formList>
        <el-button style="margin-left:510px" type="primary" @click="onSubmit">更新信息</el-button>
    </div>
</template>

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

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