<template>
  <a-modal title="来访信息添加" ok-text="确认" cancel-text="取消" :visible="visitingShow" :confirm-loading="visitingloading"
    @ok="visitingOk" @cancel="visitingCancel" :width="600">
    <a-row>
      <a-col :md="24" :xs="24" style="display: flex;">
        <div style="color:#000; flex:16; text-align: right;"><span style="color:tomato;">*</span>预约来访日期:</div>
        <div style="flex: 75;">
          <j-date date-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择预约来访日期" :show-time="true" v-model="dateStr" style="margin-left: 6px;" >
          </j-date>
        </div>
      </a-col>
    </a-row>
    <a-row style="margin-top: 15px;">
      <a-col :md="24" :xs="24" style="display: flex;">
        <div style="color:#000; flex:16; text-align: right;">备注:</div>
        <div style="flex: 75;">
          <a-textarea v-model="addPara.remark" rows="4" placeholder="请输入备注" style="max-width: 86%; margin-left: 6px;" />
        </div>
      </a-col>
    </a-row>
    <a-row style="margin-top: 15px;">
      <a-col :md="24" :xs="24" style="display: flex;">
        <div style="color:#000; flex:16; text-align: right;">下次跟进日期:</div>
        <div style="flex: 75;">
          <j-date  date-format="YYYY-MM-DD" placeholder="请选择预下次跟进日期" v-model="addPara.nextFollowDate" 
          style="margin-left: 6px;" :disabledDate="disabledDate">
          </j-date>
        </div>
      </a-col>
    </a-row>
  </a-modal>
</template>
<script>

import { postAction } from '@/api/manage'
import { initDictOptions } from '@/components/dict/JDictSelectUtil'
import store from '@/store'
import moment from 'moment'
export default {
  name: 'CustomerVisitingAdd',
  data() {
    return {
      addPara:{},
      visitingloading: false,
      dateStr: undefined,
    }
  },
  props: ['visitingShow','dataPara'],
  watch: {
    immediate: true,
    visitingShow: {
      handler() {
        console.log(this.dataPara);
        this.dateStr = moment(new Date()).format("YYYY-MM-DD HH:mm:ss");
        initDictOptions('education_schedule').then((res) => {
          if (res.success) {
            this.timeList = res.result;
          }
        });
      },
    }
  },
  methods: {
    disabledDate(current) {
      return current < moment().subtract(1,'day');// 当前时间之前的所有日期都禁用
    },
    visitingOk() {
      if (this.dateStr == "") {
        this.$message.warn('请输入客户预约日期！');
        return null;
      } else {
        this.visitingloading = true;
        let params = {
          schoolDistrictId: this.dataPara.schoolDistrictId,
          cpId: this.dataPara.id,
          cpName: this.dataPara.name,
          cpPhone: this.dataPara.contactPhone,
          visitingTime: this.dateStr,
          salesCode: this.dataPara.saleCode,
          markString: this.addPara.remark,
          nextFollowDate: this.addPara.nextFollowDate,
          createBy:store.getters.userInfo.id,
          cpType: 1,
        }
        postAction("/customer/customerVisiting/addVisit", params).then((res) => {
          if (res.success) {
            this.$message.success(res.message);
          } else {
            this.$message.warn(res.message);
          }
        }).finally(() => {
          this.visitingloading = false;
          this.addPara = {};
          this.$emit('visiting-event','visiting');
        });
      }
    },
    visitingCancel() {
      this.addPara = {};
      this.$emit('visiting-event','visiting');
    },
  }
}
</script>
