<template>
  <div class="all" v-loading="loading">
    <el-tabs v-model="activeName" @tab-click="handleClick" class="tab-container" style="padding:20px 0 0 30px;">
        <el-tab-pane label="基本设置" name="first">
            <div class="integralApproval">
                <b>积分审批</b>
                <p>当前系统审批流程<a>查看图例</a></p>
                <div style="margin-top:10px;"><span>指定规则的审批或奖扣分，均可直接通过</span>
					<el-tooltip placement="top">
					  <div class="toolCont" slot="content">开启后，按照系统已有的积分规则制度提交的审批或者奖扣可即使审批人/录分人的权限分不足，也能审批通过</div>
					  <span class="initia_mark">?</span>
					</el-tooltip>
                    <el-switch style="margin-left:30px;" v-model="examine" active-color="#13ce66" inactive-color="rgb(202 202 202)"></el-switch></div>
            </div>
            <el-button type="primary" class="save" @click="saveFirst('first')">保存</el-button>
        </el-tab-pane>
        <el-tab-pane label="通知设置" name="second">
            <div class="integralApproval">
                <div v-for="(item,index) in informText" :key="index" style="margin-top:30px;">
                    <p><b style="font-size:16px;">{{item.title}}</b>
                    <el-switch v-if="item.switchs == 0" style="margin:-6px 0 0 30px;" v-model="individualPoints" active-color="#13ce66" inactive-color="rgb(202 202 202)"></el-switch>
                    <el-switch v-if="item.switchs == 1" style="margin:-6px 0 0 30px;" v-model="pointManagement" active-color="#13ce66" inactive-color="rgb(202 202 202)"></el-switch>
                    <el-switch v-if="item.switchs == 2" style="margin:-6px 0 0 30px;" v-model="taskToInform" active-color="#13ce66" inactive-color="rgb(202 202 202)"></el-switch>
                    <el-switch v-if="item.switchs == 3" style="margin:-6px 0 0 30px;" v-model="approvalNotice" active-color="#13ce66" inactive-color="rgb(202 202 202)"></el-switch>
                    </p>
                    <p>{{item.ram}}</p>
                    <p v-if="item.checkboxs && individualPoints"><el-checkbox v-model="checked">{{item.checkboxs}}</el-checkbox></p>
                </div>
            </div>
            <el-button type="primary" class="save" @click="saveFirst('second')">保存</el-button>
        </el-tab-pane>
    </el-tabs>
  </div>
</template>
<script>
export default {
  data() {
    return {
        loading: false,
        activeName: 'first',
        examine:false,

        
        checked:false,//积分日报展示A分数据
        individualPoints:false,//个人积分日报
        pointManagement:false,//积分管理周报
        taskToInform:false,//任务通知
        approvalNotice:false,//审批通知
        informText:[
            {title:'个人积分通知',switchs:0,ram:'每天推送个人积分的排名和奖扣分情况（不参与积分排名的除外）',checkboxs:'积分日报展示A分数据'},
            {title:'管理者奖扣分执行情况通知',switchs:1,ram:'每周给管理者推送当月的奖扣分执行情况'},
            {title:'任务通知',switchs:2,ram:'每天定时推送收到任务的通知'},
            {title:'审批通知',switchs:3,ram:'每天定时推送收到审批的通知'},
        ]
    };
  },
  components: {
      
  },
  watch:{
  },
  created() {},
  mounted() {
      this.cheakAx('first')
  },
  methods: {
    handleClick(tab, event) {
        this.cheakAx(this.activeName)
    },
    saveFirst(name){
        this.loading = true
        let data = {}
        if(name == 'first'){
            data.rule_limit_check = this.examine?0:1
        }else{
            console.log(this.individualPoints)
            console.log(this.pointManagement)
            console.log(this.taskToInform)
            console.log(this.approvalNotice)
            data.report_integral_daily = this.individualPoints?1:0
            this.individualPoints?data.report_integral_daily_a = this.checked?1:0:''
            data.report_integral_weekly = this.pointManagement?1:0
            data.report_work_daily = this.taskToInform?1:0
            data.report_review_daily = this.approvalNotice?1:0
        }
        this.$axios('post',"/api/integral/site/config",data).then((res) => {
            if(res.data.code == 1){
                this.$message({
                    message: res.data.msg,
                    type: 'success'
                });
            }
        }).finally(()=>{
            this.loading = false
        })
    },
    cheakAx(name){
      this.loading = true;
      this.$axios('get',"/api/integral/site/config").then((res) => {
        let data = res.data.data
        if(name == 'first'){
            this.examine = data.rule_limit_check == 0?true : false
        }else{
            this.individualPoints = data.report_integral_daily == 1?true : false
            this.checked = this.individualPoints?data.report_integral_daily_a == 1? true : false : false
            this.pointManagement = data.report_integral_weekly == 1?true : false
            this.taskToInform = data.report_work_daily == 1?true : false
            this.approvalNotice = data.report_review_daily == 1?true : false
        }
      }).finally(err=>{
        this.loading = false;
    });
    }
  },
};
</script>

<style  scoped lang="scss">
.integralApproval{
    margin-top: 20px;

    b{font-size:16px;}
    p{margin-top: 10px;
        a{color:#1795f9;padding-left:15px;cursor:pointer;}}
    .initia_mark {
        background: #191919;
        border-radius: 50%;
        width: 14px;
        height: 14px;
        color: #fff;
        display: inline-block;
        font-size: 12px;
        line-height: 14px;
        text-align: center;
        margin-left: 4px;
        cursor: default;
    }
}
.toolCont{
    max-width:280px;
}

.save{
    margin-top: 30px;
    width:100px;
    font-size:15px;
}
.tab-container ::v-deep .el-tabs__item{
    font-size: 16px;
}
.tab-container ::v-deep .el-tabs__nav-wrap::after {
    background: #fff
}
</style>