<template>
  <section class="p_all_20">

    <div class="">
      <div class="warmNotice">
        <p>温馨提示：</p>
        <p>1、年假期间，为避免出现下单后工厂无法发货的情况，请已经彻底停止接单、发货的品牌在下方设置具体的工厂放假时间，以通知客户避免在此期间下单后无法完成收货安装的问题。</p>
        <p>2、设置好放假时间后，勾选“通知客户”即可在分销系统通知客户，<span style="color:red">假期结束后需要关闭通知客户功能</span>。</p>
      </div>
      <div class="vacationDate">
        <div class="block">
          <span class="demonstration">工厂放假时间：</span>
          <el-date-picker
            v-model="dateArray"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            value-format="yyyy-MM-dd HH:mm:ss"
          ></el-date-picker>
        </div>
        <div class="buttonWrapper">
          <el-checkbox v-model="checked" class="checkBox">通知客户</el-checkbox>
          <el-button type="primary" class="vacationSubmit" @click="handleBtnClick">提交</el-button>
        </div>
      </div>
    </div>
  </section>
</template>

<script>

export default {
  name: "holiday",
  data() {
    return {
      dateArray: [],
      checked:false
    };
  },
  components: {
    
  },
  mounted() {
    this.init()
  },
  methods: {
    init(){
      let e = this
      e.$axios.get('/sys/holiday')
      .then((res) => {
        // debugger
        let data = res.data.data
        if(res.data.code == 200){
          // debugger
          e.dateArray.push(data.start)
          e.dateArray.push(data.end)
          data.enable == 1?e.checked = true:e.checked = false

        }
      })
      .catch((err) => {
        console.log(err)
      })
    },
    handleBtnClick(){
      let params = {}
      let e = this

      params.enable = e.checked == true?1:0
      params.start = e.dateArray[0]
      params.end = e.dateArray[1]

      e.$axios.post('/sys/holiday',params)
      .then((res) => {
        let data = res.data
        if(data.code == 200){
          e.$message.success(data.message)
        }else{
          e.$message.error(data.message)
        }
        console.log(res)
      })
      .catch((err) => {
        console.log(err)
      })
    }
  }
};
</script>

<style lang = "scss"scoped>
.warmNotice {
  margin-top: 10px;
  p {
    font-size: 13px;
    margin-top: 8px;
    line-height: 20px;
  }
}

.vacationDate {
  margin-top: 58px;
  .demonstration {
    margin-right: 30px;
  }
  .buttonWrapper {
    margin-left: 148px;
    .checkBox {
      margin: 21px 0;
    }
    .vacationSubmit {
      display: block;
      width: 238px;
      height: 39px;
    }
  }
}
</style>
