<template>
  <div class="m-container">
    <div class="infoWrap">
      <el-form :model="accompanyForm" :inline="true" label-position="left">
        <el-form-item  label="每周可预约课次" style="position: relative" label-width="130px">
              <el-tooltip placement="top" popper-class='mTooltip'>
                  <div slot="content"> 
                  不填时，默认不限制上课次数
                  </div>
                  <img :src="imageIcon" class='micon el-tooltip' style="width:8px height:8px" alt="">
                </el-tooltip>
          <el-input type="number" v-model.trim="accompanyForm.count"></el-input>
        </el-form-item>
        <el-form-item label="每周休息的周次">
          <el-select v-model="accompanyForm.week" clearable>
            <el-option label="星期一" value="1" />
            <el-option label="星期二" value="2" />
            <el-option label="星期三" value="3" />
            <el-option label="星期四" value="4" />
            <el-option label="星期五" value="5" />
            <el-option label="星期六" value="6" />
            <el-option label="星期日" value="7" />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitOk">确定</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
<script>
import { teacherFreeTime,resetTeacherFreeTime } from '@/api/teacherManager'  
export default {
     props: ['teacherId'],
  data() {
    return {
      accompanyForm: {
        count: null,
        week: null
      },
      accompanyId:null,
       imageIcon:require('@/assets/images/base/warning.png'),
    };
  },
  created(){
      this.init()
  },
  activated(){
      this.init()
  },
  methods:{
      init(){
        //  this.teacherId = this.$route.query.teacherId ;
            if (this.$route.query.search) {
        this.Fsearch = this.$route.query.search;
      }
      if (this.$route.query.rules) {
        this.Frules = this.$route.query.rules
      }
         if( this.teacherId){
             teacherFreeTime({id:this.teacherId}).then(res=>{
                 if(res.code == 200&&res.data){
                     this.accompanyId = res.data.id;
                     this.accompanyForm.count = res.data.totalTimes;
                     res.data.holiday?this.accompanyForm.week = res.data.holiday.toString():this.accompanyForm.week = null;
                 }
             })
         }
      },
      submitOk(){
           this.$confirm('确认保存设置?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
               resetTeacherFreeTime({holiday:this.accompanyForm.week,userId:this.teacherId,id:this.accompanyId,totalTimes:this.accompanyForm.count}).then(res=>{
              if(res.code == 200){
                  this.$message.success('保存成功')
                   this.$router.push({ path: '/business/teacherList', query: { rules: this.Frules, search: this.Fsearch } })
              }
          })
        })
       
      }
  }
};
</script>

<style lang="scss" scoped>
    .micon {
    position: absolute;
    top:12px;
    left:-26px;
    z-index: 100;
  }
</style>