<template>
  <div class="set_basics_box" v-loading="loading">
    <el-row>
      <el-col :span="8">
        <el-form :model="basics_info" ref="basics_info" :rules="basics_info_rules" label-width="120px">
          <div class="basics_title" style="font-size:20px;color:#303133;padding:0 0 0 32px; margin-bottom: 30px">基础设置</div>
          <el-form-item prop="base_point">
            <template slot="label">
              <span>基础分</span>
              <el-tooltip placement="top">
                <div slot="content" style="width: 300px;">设置分值后，系统将为全部员工自动加上此项基础分；此项基础分仅加一次，计入每个员工的累计总分。</div>
                <span class="tips">?</span>
              </el-tooltip>
            </template>
            <el-input v-model.number="basics_info.base_point" min="0" placeholder="请输入基础分分值"  type="Number"></el-input>
          </el-form-item>
          <el-form-item prop="service_point">
            <template slot="label">
              <span>工龄分</span>
              <el-tooltip placement="top">
                <div slot="content" style="width: 300px">首次加分=员工已在职的月份数*工龄分，未满一个月的不加分；后续加分按已设置的工龄分值每月自动累加</div>
                <span class="tips">?</span>
              </el-tooltip>
            </template>
            <el-input v-model.number="basics_info.service_point" min="0" placeholder="请输入基础分分值"  type="Number"></el-input>
          </el-form-item>
          <el-form-item prop="a2b">
            <template slot="label">
              <span>A分转B分</span>
              <el-tooltip placement="top">
                <div slot="content" style="width: 300px">设置后，每奖扣1条A分，额外产生一条分值按比例转换后的B分记录，如设置1A分=10B分时，因表现出色奖10A分的同时，额外奖100B分。</div>
                <span class="tips">?</span>
              </el-tooltip>
            </template>
            <el-col :span="6">1A分 = </el-col>
            <el-col :span="14">
              <el-input v-model.number="basics_info.a2b" min="0" placeholder="请输入基础分分值" type="Number" ></el-input>
            </el-col>
            <el-col :span="4">B分</el-col>
          </el-form-item>

          <el-form-item prop="rule_limit_check">
            <template slot="label">
              <span>积分审批</span>
              <el-tooltip placement="top">
                <div slot="content" style="width: 300px">勾选后开启。开启后，管理者奖扣积分、审批积分时只要按照公司已有的积分规则制度去打分，一律不受权限分的限制</div>
                <span class="tips">?</span>
              </el-tooltip>
            </template>
            <el-checkbox v-model="basics_info.rule_limit_check" >规则内打分免审</el-checkbox>
          </el-form-item>
          <el-form-item prop="task_review">
            <template slot="label">
              <span>管理者奖扣</span>
              <el-tooltip placement="top">
                <div slot="content" style="width: 300px">管理者除了要主动给员工奖扣积分，审批员工申请的积分和任务也记入Ta的奖扣分任务内</div>
                <span class="tips">?</span>
              </el-tooltip>
            </template>
            <el-checkbox v-model="basics_info.task_review" >审批打分记入管理者奖扣分任务</el-checkbox>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" :loading="save_loading" @click="save('basics_info')">保存</el-button>
          </el-form-item>
        </el-form>
      </el-col>
    </el-row>
  </div>
</template>
<script>
export default {
  data() {
    return {
      loading: false,
      save_loading: false,
      basics_info: {},
      basics_info_rules:{},
    }
  },
  watch:{
  },
  methods: {
    get_basics(){
      let self = this
      self.loading = true
      self.$http('get','/api/integral/site/config').then((res) => {
        if (res.data.code == 1) {
          const resData = JSON.parse(JSON.stringify(res.data.data))
          this.basics_info = resData
          resData.rule_limit_check?this.basics_info.rule_limit_check = false :this.basics_info.rule_limit_check = true
          resData.task_review?this.basics_info.task_review = true :this.basics_info.task_review = false
        }else{
          self.$message.error(res.data.msg)
        }
      }).finally(() => {
        self.loading = false
      })
    },
    save(formName) {
      let self = this
      this.$refs[formName].validate((valid) => {
        if (valid) {
          self.save_loading = true
          // const headers = {'Accept': 'application/vnd.test.v2+json'}
          let data = JSON.parse(JSON.stringify(this.basics_info))
          this.basics_info.rule_limit_check?data.rule_limit_check = 0: data.rule_limit_check = 1
          this.basics_info.task_review?data.task_review = 1: data.task_review = 0
          self.$http('post','/api/integral/site/config',data,'v2').then((res) => {
            if (res.data.code == 1) {
              self.$message.success(res.data.msg)
            } else{
              self.$message.error(res.data.msg)
            }
          }).catch((e) => {self.$message.error(e.data.msg)}).finally(()=>{
            self.save_loading = false
          })
        }
      });
    }
  },
  mounted(){
    this.get_basics()
  }
}
</script>
<style scoped lang="scss">
.set_basics_box{
  padding:20px 0;
  background:#fff;
}
/deep/ .el-message--info{
  font-size:20px;
}
.el-form-item__error{
  left: 50px;
}
.tips{
  background: #409EFF;
  border-radius: 50%;
  width: 14px;
  height: 14px;
  color: #fff;
  display: inline-block;
  font-size: 12px;
  line-height: 14px;
  text-align: center;
}
</style>