<template>
    <a-modal title="报名" :visible="registrationShow" @ok="confirmOk " @cancel="confirmCancel"
    :width=500 :body-style="{width:200}">
    报名报名报名报名报名报名报名报名报名
    </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: 'CustomerRegistration',
    data () {
      return {
  
      }
    },
    props: ['registrationShow','dataPara','addStatus'],
    watch: {
      immediate: true,
      registrationShow: {
        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('registration-event', 'registration');
      },
      async confirmOk() {
        if(this.dataPara.nextFollowDate === null || this.dataPara.nextFollowDate === undefined){
          message.warning('请输入下次跟进日期');
          return;
        }
        if(this.addStatus ==='addNew'){
          //添加课表 返回课表id
          await postAction("/education/educationSchedule/add", this.dataPara).then((res) => {
            this.dataPara.schedule_id = res.result;
          });
        }
        let marString = "";
        if(this.dataPara.classRoomId !== null && this.dataPara.classRoomId !== undefined) {
          marString = marString + this.dataPara.classRoomText
        }
        if(this.dataPara.lecturerId !== null && this.dataPara.lecturerId !== undefined) {
          marString = marString + this.dataPara.lecturerText
        }
        let para = {
          schoolDistrictId: this.dataPara.schoolDistrictId,
          courseId: this.dataPara.courseId,
          courseText: this.dataPara.courseText,
          curriculaDate: this.dataPara.curriculaDate,
          curriculaTime: this.dataPara.curriculaTime,
          time_text: this.dataPara.curriculaDate + this.getWeek(this.dataPara.curriculaDate) + this.dataPara.curriculaTime,
          classRoomId:this.dataPara.classRoomId,
          period: this.dataPara.period,
          lecturerId: this.dataPara.lecturerId,
          assistantId: this.dataPara.assistantId,
          themeId: this.dataPara.themeId,
          remark: this.dataPara.remark + marString,
          schedule_id: this.dataPara.schedule_id,
          saleNo: store.getters.userInfo.username,
          cp_id: this.dataPara.cpId,
          cpPhone: this.dataPara.cpPhone,
          nextFollowDate: this.dataPara.nextFollowDate
        }
        //增加跟进信息，排课增加，操作日期，更新用户info上次跟进和下次跟进日期
        await postAction("/customer/customerAudition/auditionAdd", para).then((res) => {
          if(res.success) {
            message.success(res.message);
            this.$emit('confirm-event', false);
          } else {
            message.warning(res.message);
            this.$emit('confirm-event', true);
          }
        });
      },
      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>
  