<template>
  <a-modal title="确认预约" :visible="confirmShow" @ok="confirmOk " @cancel="confirmCancel"
  :width=500 :body-style="{width:200}">
    <a-row >
      <a-col :md="6" :xs="6" style="text-align:right;"><span style="color:#000; margin-right: 10px; ">试听时间:</span> </a-col>
      <a-col :md="36" :xs="36">
        {{addPara.curriculaDate + getWeek(addPara.curriculaDate) + addPara.curriculaTime}}  </a-col>
  </a-row>
  <a-row style="margin-top: 15px;">
     <a-col :md="6" :xs="6" style="text-align:right;"> <span style="color:#000; margin-right: 10px;">试听课程:</span> </a-col>
      <a-col :md="36" :xs="36"> {{addPara.courseText}} </a-col>
    </a-row>
    <a-row style="margin-top: 15px;">
      <a-col :md="6" :xs="6" style="text-align:right;"><span style="color:#000; margin-right: 10px;">老师:</span> </a-col>
      <a-col :md="36" :xs="36"> {{addPara.lecturerText}} </a-col>
    </a-row>
    <a-row style="margin-top: 15px;">
      <a-col :md="6" :xs="6" style="text-align:right;"><span style="color:#000; margin-right: 10px;">教室:</span></a-col>
      <a-col :md="36" :xs="36">  {{addPara.classRoomText}} </a-col>
    </a-row>
    <a-row style="margin-top: 15px;">
      <a-col :md="6" :xs="6" style="text-align:right;"><span style="color:tomato;">*</span><span style="color:#000; margin-right: 10px;">下次跟进时间:</span></a-col>
      <a-col :md="36" :xs="36"> 
        <j-date date-format="YYYY-MM-DD" v-model="addPara.nextFollowDate" :disabledDate="disabledDate" >
        </j-date>
      </a-col>
    </a-row>
  </a-modal>
</template>
<script>

import { postAction } from '@/api/manage'
import { initDictOptions } from '@/components/dict/JDictSelectUtil'
import store from '@/store'
import { message } from 'ant-design-vue';
import moment from 'moment'
export default {
  name: 'AuditionConfirm',
  data () {
    return {

    }
  },
  props: ['confirmShow','addPara','addStatus'],
  watch: {
    immediate: true,
    confirmShow: {
      handler() {
        this.selected = null;
        initDictOptions('education_schedule').then((res) => {
          if (res.success) {
            this.timeList = res.result;
          }
        });
      },
    }
  },
  methods: {
    disabledDate(current) {
      return current < moment().subtract(1,'day');// 当前时间之前的所有日期都禁用
    },
    confirmCancel() {
      this.$emit('confirm-event', true);
    },
    async confirmOk() {
      if(this.addPara.nextFollowDate === null || this.addPara.nextFollowDate === undefined){
        message.warning('请输入下次跟进日期');
        return;
      }
      if(this.addStatus ==='addNew'){
        //添加课表 返回课表id
        await postAction("/education/educationSchedule/add", this.addPara).then((res) => {
          this.addPara.schedule_id = res.result;
        });
      }
      let marString = "";
      if(this.addPara.classRoomId !== null && this.addPara.classRoomId !== undefined) {
        marString = marString + this.addPara.classRoomText
      }
      if(this.addPara.lecturerId !== null && this.addPara.lecturerId !== undefined) {
        marString = marString + this.addPara.lecturerText
      }
      let para = {
        schoolDistrictId: this.addPara.schoolDistrictId,
        courseId: this.addPara.courseId,
        courseText: this.addPara.courseText,
        curriculaDate: this.addPara.curriculaDate,
        curriculaTime: this.addPara.curriculaTime,
        time_text: this.addPara.curriculaDate + this.getWeek(this.addPara.curriculaDate) + this.addPara.curriculaTime,
        classroomId:this.addPara.classRoomId,
        period: this.addPara.period,
        lecturerId: this.addPara.lecturerId,
        assistantId: this.addPara.assistantId,
        themeId: this.addPara.themeId,
        remark: this.addPara.remark + marString,
        schedule_id: this.addPara.schedule_id,
        saleNo: store.getters.userInfo.id,
        createBy: store.getters.userInfo.id,
        auditionStatus: "1",
        cp_id: this.addPara.cpId,
        cpPhone: this.addPara.cpPhone,
        nextFollowDate: this.addPara.nextFollowDate,
        sqlType: this.addPara.sqlType,
        scheduleId_old: this.addPara.scheduleId_old,
      }
      //增加跟进信息，排课增加，操作日期，更新用户info上次跟进和下次跟进日期
      await postAction("/customer/customerAudition/auditionAdd", para).then((res) => {
        if(res.success) {
          message.success(res.message);
          this.$emit('confirm-event', 'success');
        } else {
          message.warning(res.message);
          this.$emit('confirm-event', 'warning');
        }
      });
    },
    getWeek(text) {
      if (text !== undefined) {
        var dateArray = text.split("-");
        let date = new Date(dateArray[0], parseInt(dateArray[1] - 1), dateArray[2]);
        return "【星期" + "日一二三四五六".charAt(date.getDay()) +"】" ;
      } else {
        return null;
      }
    }
  }
}
</script>
