<template>
    <!-- HeadSum -->
    <div class="HeadSum">
        <h2 style="margin-bottom: 20px;padding-bottom:7px;border-bottom:2px solid #ddd">仓库使用率</h2>
        <div class="left">
            <el-form ref="form" :model="form" label-width="140px">
                <el-form-item label="产品总数">
                    <el-input v-model="form.totalProduct"></el-input>
                </el-form-item>
                <el-form-item label="今日出库数">
                    <el-input v-model="form.stockOut"></el-input>
                </el-form-item>
                <el-form-item label="今日入库数">
                    <el-input v-model="form.stockIn"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button style="margin-left:60%" type="primary" @click="onSubmit">更新信息</el-button>
                </el-form-item>
            </el-form>
        </div>
    </div>
</template>

<script>
import {
    reqHeadSum,
    reqSetHeadSum
} from "@/api/product.js";
export default {
    name: "HeadSum",
    data() {
        return {
            form: {
                id: "-1",
                totalProduct: "",
                stockOut: "",
                stockIn: ""
            }
        };
    },
    created() {
        this.getHeadSum();
    },
    methods: {
        onSubmit() {
            this.$confirm("确定更新信息？").then(() => {
                console.log(this.form);
                reqSetHeadSum(this.form)
                    .then(res => {
                        if (res.errCode) {
                            this.$message.error(res.errMsg);
                        } else {
                            this.getHeadSum();
                            this.$message.success("更新成功！");
                        }
                    })
                    .catch(err => {
                        console.log(err);
                        this.$message.error("更新失败！");
                    });
            });
        },
        getHeadSum() {
            console.log("99999999")
            reqHeadSum()
                .then(res => {
                    this.form = res.conf;
                    this.form.id = res.id;
                })
                .catch(err => {
                    console.error(err);
                });
        }
    }
};
</script>

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