<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="12">
            <a-form-model-item label="校区ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="schoolDistrictId">
              <j-dict-select-tag type="list" v-model="model.schoolDistrictId" dictCode="school_organization,name,id" placeholder="请选择校区ID" disabled/>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="潜客姓名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="cpName">
              <a-input v-model="model.cpName" placeholder="请输入潜客姓名" disabled ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="潜客手机" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="cpPhone">
              <j-dict-select-tag type="list" v-model="model.cpPhone" dictCode="" placeholder="请选择潜客手机" disabled/>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="试听日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="auditionTime">
              <j-date placeholder="请选择试听日期"  v-model="model.auditionTime" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%" disabled/>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="顾问" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="salesCode">
              <a-input v-model="model.salesCode" placeholder="请输入顾问" disabled ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="试听状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="auditionStatus">
              <a-input v-model="model.auditionStatus" placeholder="请输入试听状态"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="到听日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="realAuditionTime">
              <j-date placeholder="请选择到听日期"  v-model="model.realAuditionTime" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="markString">
              <a-textarea v-model="model.markString" rows="4" placeholder="请输入备注" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="课表ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="scheduleId">
              <a-input v-model="model.scheduleId" placeholder="请输入课表ID"  ></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'CustomerAuditionForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/miliCustomer/customerAudition/add",
          edit: "/miliCustomer/customerAudition/edit",
          queryById: "/miliCustomer/customerAudition/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>