<template>
    <div class="layout">
        <div class="page">
            <div class="form-box">
                <div>
                    <h2 style="text-align: center;padding-bottom: 40px;">累计权重：<span style="color: red;">100%</span></h2>
                    <el-form ref="form" :model="form" label-width="80px">
                        <el-form-item label="自评权重">
                            <el-input v-model.number="form.selfWeight">
                                <template slot="append">%</template>
                            </el-input>
                        </el-form-item>
                        <el-form-item label="考勤权重">
                            <el-input v-model.number="form.attendWeight">
                                <template slot="append">%</template>
                            </el-input>
                        </el-form-item>
                        <el-form-item label="效能权重">
                            <el-input v-model.number="form.effectWeight">
                                <template slot="append">%</template>
                            </el-input>
                        </el-form-item>
                        <el-form-item label="办件权重">
                            <el-input v-model.number="form.goworkWeight">
                                <template slot="append">%</template>
                            </el-input>
                        </el-form-item>
                        <el-form-item label="评价权重">
                            <el-input v-model.number="form.reviewWeight">
                                <template slot="append">%</template>
                            </el-input>
                        </el-form-item>
                        <el-form-item style="text-align: center;">
                            <el-button type="primary" @click="onSubmit">立即保存</el-button>
                        </el-form-item>
                    </el-form>
                </div>
            </div>
        </div>
    </div>
</template>
<style lang="less" scoped>
.form-box{
    width: 700px;
    margin: 0 auto;
    padding-top: 10vh;
    &>div{
        background-color: rgba(246, 246, 246, 1);
        padding: 20px;
    }
}
</style>
<script>
export default {
    data(){
        return {
            form:{
                selfWeight:0,
                attendWeight:0,
                effectWeight:0,
                goworkWeight:0,
                reviewWeight:0,
            }
        }
    },
    created() {
        this.onView()
    },
    methods: {
        //提交
        onSubmit(){
            const form = {...this.form}
            let num = 0
            for (const iterator in form) {
                num = form[iterator] + num
            }
            if(num != 100){
                this.$message.error(`权重比例${num}%，请检查是否正确`);
                return
            }
            this.$post("/param/save",{paramKey:'weight',paramValue:JSON.stringify(this.form)}).then(res=>{
                const {code,msg} = res
                if(code == 1){
                    this.$message.success('保存成功');
                }else{
                    this.$message.error(msg);
                }
            })
        },
        //查询
        onView(){
            this.$post("/param/key?key=weight").then(res=>{
                const {code,data} = res
                if(code == 1){
                    this.form = JSON.parse(data)
                }
                
            })
        }
    },
}
</script>