<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="用车需求编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="vdNo">
              <!-- <a-input v-model="model.vdNo" placeholder="请输入提货用车需求编号"  ></a-input> -->
              <j-search-select-tag type="list" v-model="model.vdNo" dict="tms_vehicle_demand,vd_no,vd_no" showSearch placeholder="请选择用车需求编号" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="实际预约人姓名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="artName">
              <a-input v-model="model.artName" placeholder="请输入实际预约人姓名"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="实际预约人电话" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="artTel">
              <a-input v-model="model.artTel" placeholder="请输入实际预约人电话"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="实际预约人邮箱" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="artEmail">
              <a-input v-model="model.artEmail" placeholder="请输入实际预约人邮箱"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="紧急情况" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="urgency">
              <!-- <a-input v-model="model.urgency" placeholder="请输入紧急"  ></a-input> -->
              <j-dict-select-tag type="list" v-model="model.urgency" dictCode="urgency" placeholder="请选择紧急情况" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="产品标签" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="productLabel">
              <a-input v-model="model.productLabel" placeholder="请输入产品标签"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="备注信息" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="notes">
              <a-input v-model="model.notes" placeholder="请输入备注信息"  ></a-input>
            </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="请输入入厂对接人姓名"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="入厂对接人电话" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="cpTel">
              <a-input v-model="model.cpTel" placeholder="请输入入厂对接人电话"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="入厂对接人邮箱" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="cpEmail">
              <a-input v-model="model.cpEmail" placeholder="请输入入厂对接人邮箱"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="提货单号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ladingBill">
              <a-input v-model="model.ladingBill" placeholder="请输入提货单号"  ></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: 'TakeDeliveryPlanForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 7 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/takedeliveryplan/takeDeliveryPlan/add",
          edit: "/takedeliveryplan/takeDeliveryPlan/edit",
          queryById: "/takedeliveryplan/takeDeliveryPlan/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>