<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="efType">
              <j-dict-select-tag type="list" v-model="model.efType" dictCode="ef_type" placeholder="请选择入厂类型" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="送货需求编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sgNo">
              <!-- <a-input v-model="model.sgNo" placeholder="请输入送货需求编号"  ></a-input> -->
              <j-dict-select-tag type="list" v-model="model.sgNo" dictCode="tms_delivery_plan,sg_no,sg_no" placeholder="请选择送货需求编号" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="采购单号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="po">
              <a-input v-model="model.po" placeholder="请输入采购单号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <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="logistics">
              <a-input v-model="model.logistics" placeholder="请输入物流公司"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="车牌号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="carNum">
              <a-input v-model="model.carNum" placeholder="请输入车牌号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="司机姓名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="driverName">
              <a-input v-model="model.driverName" placeholder="请输入司机姓名"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="司机电话" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="driverTel">
              <a-input v-model="model.driverTel" placeholder="请输入司机电话"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="当前状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="currentStatus">
              <a-input v-model="model.currentStatus" 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="etaTime">
              <j-date placeholder="请选择预计到达"  v-model="model.etaTime" :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="ataTime">
              <j-date placeholder="请选择实际到达"  v-model="model.ataTime" :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="atdTime">
              <j-date placeholder="请选择实际离开"  v-model="model.atdTime" :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="enterWeight">
              <a-input-number v-model="model.enterWeight" placeholder="请输入入厂地磅重量" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="出厂地磅重量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="exitWeight">
              <a-input-number v-model="model.exitWeight" placeholder="请输入出厂地磅重量" style="width: 100%" />
            </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: 'VehicleInOutForm',
    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: "/vehicleinout/vehicleInOut/add",
          edit: "/vehicleinout/vehicleInOut/edit",
          queryById: "/vehicleinout/vehicleInOut/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 () {
        if (this.model.efType == '0' && !this.model.po) {
          this.$message.warning('入厂类型为送货时，采购单号必填！');
          return;
        }
        if (this.model.efType == '1' && !this.model.vdNo) {
          this.$message.warning('入厂类型为提货时，用车需求编号必填！');
          return;
        }
        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>