<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>
	 <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: "月度全勤，每月加分",
        //   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,
          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,
        //   initia_input: {
        //     age: "0",
        //   },
        // },
      ],
	  obj: {
		  // ding_enable:'',
		  enable:'',
		  // month_full_ad: "", //>=0
		  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
	  },
    };
  },
  mounted() {
    this.cheak_ax();
  },
  methods: {
    initia(ok) {
      var objs = {};
	  objs.enable = ok[0].sj; 
      objs.normal = ok[1].sj; //>=0
	  objs.no_sign = ok[2].sj>0? ok[2].sj:ok[2].sj; //<=0
	  objs.absent = ok[3].sj>0? ok[3].sj:ok[3].sj; //<=0
	  objs.on_duty_late = ok[4].sj>0? ok[4].sj:ok[4].sj; //<=0
	  objs.off_duty_early = ok[5].sj>0? ok[5].sj:ok[5].sj; //<=0
	  objs.ot_per_day =ok[6].sj; //>=0
	  
   //    objs.ot_per_hour = ok[7].sj; //>=0
   //    objs.leave_per_hour = ok[8].sj>0? -ok[8].sj:ok[8].sj; //<=0
	  // objs.month_full_ad = 0
      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;
		});
    },
    cheak_ax() {
      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;
		}
		// config.no_sign=config.no_sign-(config.no_sign+config.no_sign);
		// config.absent=config.absent-(config.absent+config.absent);
		// config.on_duty_late=config.on_duty_late-(config.on_duty_late+config.on_duty_late);
		// config.off_duty_early=config.off_duty_early-(config.off_duty_early+config.off_duty_early);
		// config.leave_per_hour=config.leave_per_hour-(config.leave_per_hour+config.leave_per_hour);
		
		this.initia_arr[0].initia_input.age =config.enable
		// this.initia_arr[1].initia_input.age =config.month_full_ad? config.month_full_ad:0  //月度全勤加分
		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.off_duty_early? config.off_duty_early:0 //早退扣分
		// this.initia_arr[7].initia_input.age =config.ot_per_hour? config.ot_per_hour:0 //每小时加班加分 
		this.initia_arr[6].initia_input.age =config.ot_per_day? config.ot_per_day:0 //每加班满一天加分 
		// this.initia_arr[8].initia_input.age =config.leave_per_hour? config.leave_per_hour:0 //每小时请假扣分
		
      }).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>