<template>
 <div>
	 <div v-loading="loading" v-if="ding_enable">
	   <workpoints :initia_arr="initia_arr" v-if="!loading" :initia_head="initia_head" :obj="obj" @initia="initia" />
  	   <div class="all" v-else><workpoints :initia_arr="initia_arr" :initia_head="initia_head" :obj="obj" @initia="initia" /></div>
	 </div>
	 <div v-else class="all">
		 <div class="nullD">请到钉钉考勤管理后台-<span class="blue"> 工作台 </span>-<span class="blue"> 考勤打卡 </span>-<span class="blue"> 考勤报表 </span>-<span class="blue">切换新版 </span>-开启新版考勤报表功能</div>
		 <div class="text">如下图：</div>
		 <div class="img1">
			 <img src="@/assets/image/kq1.png">
		 </div>
		 <div class="img1">
		 	<img src="@/assets/image/kq2.png">
		 </div>
	 </div>
 </div>	
</template>

<script>
import workpoints from "@/components/publics/workpoints";
export default {
  components: {workpoints},	
  data() {
    return {
      loading: false,
	  ding_enable:true,
      initia_head: {
        initial_suername: "考勤积分",
        initial_suertext: "以下考勤加扣分，均为B分",
        initial_left: "167px",
        initial_width: "165px",
      },
      initia_arr: [
		  {
			initialName: "是否启用考勤设置",
			initia_mark: false,
			type:'switch',
			initia_input: {
			  age: "0",
			},
		  },
        {
          initialName: "正常打卡，每次加分",
          message:'只包含打上班卡',
          initia_mark: false,
          initia_input: {
            age: "0",
          },
        },
        {
          initialName: "上下班缺卡，每次扣分",
          initia_mark: false,
          initia_input: {
            age: "0",
          },
        },
		{
		  initialName: "旷工缺席，每次扣分",
		  initia_mark: false,
		  initia_input: {
		    age: "0",
		  },
		},
        {
          initialName: "上班迟到，每次扣分",
		  message:'不包含严重迟到、旷工迟到',
          initia_mark: false,
          initia_input: {
            age: "0",
          },
        },
		
		{
		  initialName: "严重迟到，每次扣分",
		  initia_mark: false,
		  initia_input: {
		    age: "0",
		  },
		},
		{
		  initialName: "旷工迟到，每次扣分",
		  initia_mark: false,
		  initia_input: {
		    age: "0",
		  },
		},

        {
          initialName: "下班早退，每次扣分",
          initia_mark: false,
          initia_input: {
            age: "0",
          },
        },
		{
		  initialName: "加班加分",
		  initia_mark: false,
		  message:'当天最终加班得分=【加班加分】*【加班-审批单统计】，必须是提交通过的审批单，加班才有加分 ',
		  initia_input: {
		    age: "0",
		  },
		},
		{
		  initialName: "月度全勤加分",
		  initia_mark: false,
		  initia_input: {
		    age: "0",
		  },
		},
		{//全勤配置
		  type:'object',
		  absent_holiday:{
			enable:0,
			list:[],
			val1:'',
			val2:'',
			val3:'',
		  },
		  absent_late:{
			enable:0,
			count:1,
			serious_late_count:1,
			absent_late_count:1,
		  },
		},
      ],
	  obj: {
		  // ding_enable:'',
		  enable:'',
		  normal: "", //>=0
		  no_sign: "", //<=0
		  absent: "", //<=0
		  on_duty_late: "", //<=0
		  off_duty_early: "", //<=0
		  // ot_per_hour: "", //>=0
		  ot_per_day:'',
		  // leave_per_hour: "", //<=0
		  month_full_ad: "", //>=0
	  },
    };
  },
  mounted() {
    this.getData();
  },
  methods: {
    initia(obj) {
	  console.log(obj);
	  // return false
		
	  let ok=obj.arr;
      var objs = {};
	  objs.enable = ok[0].sj; //是否启用考勤设置

      objs.normal = ok[1].sj; //正常打卡加分
	  objs.no_sign = ok[2].sj; //缺卡扣分
	  objs.absent = ok[3].sj; //旷工扣分
	  objs.on_duty_late = ok[4].sj; //迟到扣分
	  
	  objs.serious_late = ok[5].sj; //严重迟到，每次扣分
	  objs.absenteeism_late = ok[6].sj; //矿工迟到，每次扣分
	  
	  objs.off_duty_early = ok[7].sj;//早退扣分
	  objs.ot_per_day =ok[8].sj; //每加班满一天加分 
	  objs.month_full_ad = ok[9].sj //月度全勤加分
	  
	  
	  //全勤加分需同时满足以下条件
	  let {absent_late,absent_holiday}=obj.checkAllData;
	  objs.absent_late=absent_late;
	  
	  objs.absent_holiday=absent_holiday;
	  if(absent_late.enable==1
		&&(absent_late.count==0||!absent_late.count)
		&&(absent_late.serious_late_count==0||!absent_late.serious_late_count)
		&&(absent_late.absent_late_count==0||!absent_late.absent_late_count)){
		  this.$message.error("月度全勤加分的三种“迟到少于次数”至少要有一个值不能为0或空")
		  return
	  }
      this.$axios('post',"/api/ad/update",objs).then((res) => {
          if (res.data.code == 1) {
            this.$message({
              message: res.data.msg,
              type: "success",
            });
          }
        }).finally(err=>{
			this.loading = false;
		});
    },
    getData() {
      this.loading = true;
      this.$axios('get',"/api/ad/info").then((res) => {
        var arr = [],config=res.data.data;
		this.ding_enable=config.ding_enable==0? false:true;
		if(!this.ding_enable){
			return false;
		}
		this.initia_arr[0].initia_input.age =config.enable
		this.initia_arr[1].initia_input.age =config.normal? config.normal:0   //正常打卡加分
		this.initia_arr[2].initia_input.age =config.no_sign? config.no_sign:0 //缺卡扣分
		this.initia_arr[3].initia_input.age =config.absent? config.absent:0 //旷工扣分
		this.initia_arr[4].initia_input.age =config.on_duty_late? config.on_duty_late:0 //迟到扣分
		
		
		this.initia_arr[5].initia_input.age =config.serious_late? config.serious_late:0 //严重迟到，每次扣分
		this.initia_arr[6].initia_input.age =config.absenteeism_late? config.absenteeism_late:0 //矿工迟到，每次扣分
		
		
		this.initia_arr[7].initia_input.age =config.off_duty_early? config.off_duty_early:0 //早退扣分
		this.initia_arr[8].initia_input.age =config.ot_per_day? config.ot_per_day:0 //每加班满一天加分 
		this.initia_arr[9].initia_input.age =config.month_full_ad? config.month_full_ad:0  //月度全勤加分
		
		// 全勤配置
		this.initia_arr[10].absent_holiday =config.absent_holiday
		this.initia_arr[10].absent_late = config.absent_late 
		
		
		// this.initia_arr[5].initia_input.age =config.off_duty_early? config.off_duty_early:0 //早退扣分
		// this.initia_arr[6].initia_input.age =config.ot_per_day? config.ot_per_day:0 //每加班满一天加分 
		// this.initia_arr[7].initia_input.age =config.month_full_ad? config.month_full_ad:0  //月度全勤加分
		
		// // 全勤配置
		// this.initia_arr[8].absent_holiday =config.absent_holiday
		// this.initia_arr[8].absent_late = config.absent_late 
      }).finally(err=>{
			this.loading = false;
	  });
    },
  },
};
</script>

<style scoped lang="scss">
	.nullD{
		text-align: center;
		padding: 20px;
		font-size: 18px;
	}
	.text{
		padding: 30px;
		font-size: 18px;
		font-weight: 600;
	}
	.img1{
		text-align: center;
		margin-bottom: 20px;
	}
</style>