<template>
    <a-modal title="预约来访" :visible="childShow" @ok="visitingOk " @cancel="visitingCancel" :width=500
        :body-style="{width:200}">
        <a-row>
            <a-col span="4"><span style="color: tomato;">*</span>选择校区:</a-col>
            <a-col span="20">
                <a-select style="width: 52%;" v-model="visitingParam.schoolDistrictId" placeholder="请选择校区" >
                <a-select-option v-for="(item, key)  in schoolOptions" :key="key" :value="item.value">
                    {{item.text}}
                </a-select-option>
                </a-select>
            </a-col>
        </a-row>
        <a-row style="margin-top:20px">
            <a-col span="4"><span style="color: tomato;">*</span>预约时间:</a-col>
            <a-col span="20">
                <a-date-picker showTime valueFormat="YYYY-MM-DD HH:mm:ss" :disabledDate="disabledDate"
                    v-model="visitingParam.visitingTime" />
            </a-col>
        </a-row>
        <a-row style="margin-top:20px">
            <a-col span="4">更新备注:</a-col>
            <a-col span="20">
                <a-textarea type="textarea" v-model="visitingParam.remarks" :rows="5" />
            </a-col>
        </a-row>
    </a-modal> 
</template>
<script>
import moment from 'dayjs'
import { postAction } from '@/api/manage'
import store from '@/store'
import {ajaxGetDictItems} from '@/api/api'
export default {
    name: 'CustomerBusinessVisiting',
    data() {
        return {
            visitingParam: {},
            schoolOptions:[],
        }
    },
    props: ['childShow', 'para'],
    watch: {
        immediate: true,
        childShow: {
            handler() {
                this.visitingParam = JSON.parse(JSON.stringify(this.para));
                ajaxGetDictItems('school_organization,name,id', null).then((res) => {
                    if (res.success) {
                        this.schoolOptions = res.result;
                    }
                });
            },
        }
    },
    methods: {
        disabledDate(current) {
            return current < moment().subtract(1,'day');// 当前时间之前的所有日期都禁用
        },
        visitingOk() {
            if(this.visitingParam.schoolDistrictId === null || this.visitingParam.schoolDistrictId === undefined || this.visitingParam.schoolDistrictId ==="") {
                this.$message.warn('请选择预约校区');
                return;
            }
            if(this.visitingParam.visitingTime ===null || this.visitingParam.visitingTime === undefined || this.visitingParam.visitingTime ==="") {
                this.$message.warn('请选择预约日期');
                return;
            }
            let params = {
                cp_id: this.visitingParam.id,
                schoolDistrictId: this.visitingParam.schoolDistrictId,
                status: '1',
                cpType: '2',
                createBy: store.getters.userInfo.id,
                cpName: this.visitingParam.name,
                cpPhone: this.visitingParam.phone,
                visitingTime: this.visitingParam.visitingTime,
                salesCode: this.visitingParam.salesCode,
                markString: this.visitingParam.remarks
            }
            postAction("/customer/customerVisiting/addVisit", params).then((res) => {
                if (res.success) {
                    this.$message.success('预约成功');
                    this.visitingParam.visitingTime = undefined;
                    this.visitingParam.schoolDistrictId = undefined;
                    this.visitingParam.remarks = this.para.remarks;
                    this.$emit('childReturn',false);
                } else {
                    this.$message.warn(res.message);
                }
            });
        },
        visitingCancel() {
            this.visitingParam.visitingTime = undefined;
            this.visitingParam.schoolDistrictId = undefined;
            this.visitingParam.remarks = this.para.remarks;
            this.$emit('childReturn',false);
        }
    }
}
</script>
  