<template>
  <a-modal title="选择课程" ok-text="确认" cancel-text="取消" :width="1000" :visible="auditionVisible" @ok="auditionOk"
    @cancel="auditionCancel">
    <a-tabs @change="handleChangeTab" :tab-bar-style="{marginTop: '-20px', paddingLeft: '0px'}">
      <a-tab-pane tab="试听课" key="1">
        <!-- 查询条件Audition -->
        <a-range-picker v-model="auditionQuery.date" format="YYYY-MM-DD" :placeholder="['开始日期', '结束日期']"
          @change="handleQueryTimeChange" :style="{width: '222px'}" />
        <DropDownSearch menuName='选择课程' :QueryList='courseList' :QueryReset='reset'></DropDownSearch>
        <DropDownSearch menuName='选择老师' :QueryList='lecturerList' :QueryReset='reset'></DropDownSearch>
        <DropDownSearch menuName='星期' :QueryList='weekList' :QueryReset='reset'></DropDownSearch>
        <a style="margin-left: 10px;" href="javascript:;" @click="handleReset()">重置</a>
        <!-- 选择区域 -->
      </a-tab-pane>

      <a-tab-pane tab="正式课" key="2">
        34formal
      </a-tab-pane>
    </a-tabs>
    <!-- <a-form-item label="客户来访日期"  style="width: 400px">
        <j-date v-decorator="['dateStr',rules.date]" :show-time="false" date-format="YYYY-MM-DD" :disabledDate="disabledDate" v-model="dateStr">
        </j-date>
      </a-form-item> -->
  </a-modal>
</template>
<script>
import { getAction, postAction } from '@/api/manage'
import { getDictItemsFromCache} from '@/api/api'
import { initDictOptions } from '@/components/dict/JDictSelectUtil'
import DropDownSearch from '../components/DropDownSearch'
import moment from 'moment'
export default {
    name: 'CustomerAuditionAdd',
    components: {
      DropDownSearch
    },
    data() {
        return {
            auditionVisible: false,
            auditionQuery: {},
            courseList: undefined,
            lecturerList: undefined,
            weekList: undefined,
            dateStr: "",
            reset: "",
            rules: {
                date: [
                    { required: true, message: '请输入预约日期!', trigger: 'blur'},
                ],
            },
        }
    },
    props: ['auditioningAddVisible', 'addRow'],
    watch: {
        auditioningAddVisible: {
          handler() {
              this.auditionVisible = this.auditioningAddVisible
              initDictOptions('customer_follow_type').then((res) => {
                  if (res.success) {
                      this.followTypeList = res.result;
                  }
              });
              this.followDate = moment(new Date()).format("YYYY-MM-DD HH:mm:ss");
          },
        }
    },
    created () {
      //给子组件传递数据 课程信息
      getAction("/education/educationCourse/queryList").then((res) => {
        this.courseList = res;
      });
      //给子组件传递数据 老师信息
      getAction("/sys/user/getMultiUser").then((res) => {
        let listTemp = [];
        for(let item of res) {
          let temp = {
            "id": item.id,
            "name":item.realname
          }
          listTemp.push(temp)
        }
        this.lecturerList = listTemp;
      });
      //给子组件传递数据 星期
      this.weekList = [ {"id": 1 , "name": "星期一"}, {"id": 2 , "name": "星期二"}, 
      {"id": 3 , "name": "星期三"}, {"id": 4 , "name": "星期四"}, {"id": 5 , "name": "星期五"}, 
      {"id": 6 , "name": "星期六"}, {"id": 7 , "name": "星期日"} ];
    },
    methods: {
        handleChangeTab(key) {
            if (key == 1) {
                this.timer1 = new Date().getTime();
            } else if (key == 2) {
                this.timer2 = new Date().getTime();
            }
        },
        disabledDate(current) {
            return current < moment().endOf("day"); // 当前时间之前的所有日期都禁用
        },
        disabledFollowDate(current) {
            return current > moment().endOf("day"); // 当前时间之后的所有日期都禁用
        },
        auditionOk(){
        if (this.dateStr == "") {
          this.$message.warn('请输入客户预约日期！');
          return null;
        } else {
          this.visitingloading = true;
          let params = {
            schoolDistrictId: this.dataVisit.schoolDistrictId,
            cpId: this.dataVisit.id,
            cpName: this.dataVisit.name,
            cpPhone: this.dataVisit.contactPhone,
            visitingTime: this.dateStr,
            salesCode: this.dataVisit.saleCode
          }
          postAction("/customer/customerInfo/addVisit", params).then((res) => {
            if (res.success) {
              this.$emit('ok');
              this.$message.success(res.message);
            } else {
              this.$message.warn(res.message);
            }
            }).finally(() => {
                this.visitingloading = false;
                this.visitingVisible = false;
                this.dateStr = "";
                this.dataVisit = "";
                this.$emit('update:visitingAddVisible', false);
            });
          }
        },
        auditionCancel(){
            this.dateStr = "";
            this.dataVisit = "";
            this.auditionQuery = "";
            this.reset = true;
            this.$emit('update:auditioningAddVisible', false);
        },
        onAuditionTimeChange: function (value, dateString) {
            this.queryAudition.beginTime=dateString[0];
            this.queryAudition.endTime=dateString[1];
        },
        handleQueryTimeChange() {

        },
        handleCourseChange(){

        },
        handleReset() {
          this.auditionQuery = "";
          this.reset = new Date().getTime();
        }
    }
}
</script>
