<template>
  <div class="table-page-search-wrapper" style="padding: 5px 10px;">
  <h3 style="text-align: center;">车辆预约</h3>
  <a-form-model ref="form" :model="model" :rules="validatorRules" layout="inline">
    <a-row>
      <a-col>
        <a-form-model-item label="送货需求编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sgNo">
            <a-input v-model="model.sgNo" placeholder="请输入送货需求编号" disabled ></a-input>
        </a-form-model-item>
      </a-col>
      <a-col>
        <a-form-model-item label="预约人姓名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="artName">
          <a-input v-model.trim="model.artName" placeholder="请输入预约人姓名" disabled/>
        </a-form-model-item>
      </a-col>
      <a-col>
        <a-form-model-item label="预约人电话" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="artTel">
          <a-input v-model.trim="model.artTel" placeholder="请输入预约人电话" disabled/>
        </a-form-model-item>
      </a-col>
      <a-col>
        <a-form-model-item label="预约人邮箱" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="artEmail">
          <a-input v-model.trim="model.artEmail" placeholder="请输入预约人邮箱" disabled/>
        </a-form-model-item>
      </a-col>
      <a-col>
        <a-form-model-item label="PO" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ffectivePo">
          <a-input v-model.trim="model.ffectivePo" placeholder="请输入PO" disabled/>
        </a-form-model-item>
      </a-col>
      <a-col>
        <a-form-model-item label="物流公司" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="logistics">
          <a-input v-model.trim="model.logistics" placeholder="请输入物流公司"/>
        </a-form-model-item>
      </a-col>
      <a-col>
        <a-form-model-item label="车牌号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="carNum">
          <a-input v-model.trim="model.carNum" placeholder="请输入车牌号"  ></a-input>
        </a-form-model-item>
      </a-col>
      <a-col>
        <a-form-model-item label="姓名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="driverName">
          <a-input v-model.trim="model.driverName" placeholder="请输入姓名"  ></a-input>
        </a-form-model-item>
      </a-col>
      <a-col>
        <a-form-model-item label="身份证" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="driverIdCard">
          <a-input v-model.trim="model.driverIdCard" placeholder="请输入身份证"  ></a-input>
        </a-form-model-item>
      </a-col>
      <a-col>
        <a-form-model-item label="电话" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="driverTel">
          <a-input v-model.trim="model.driverTel" placeholder="请输入电话"  ></a-input>
        </a-form-model-item>
      </a-col>
      <a-col>
        <a-form-model-item label="预计到达" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="etaTime">
          <j-date v-model="model.etaTime" placeholder="请选择时间" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%;"></j-date>
        </a-form-model-item>
      </a-col>
      <a-col>
        <a-form-model-item label="进厂门" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="enterFactoryDoor">
          <a-input v-model.trim="model.enterFactoryDoor" placeholder="请输入进厂门"  ></a-input>
        </a-form-model-item>
      </a-col>
      <a-col>
        <a-form-model-item label="出厂门" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="exitFactoryDoor">
          <a-input v-model.trim="model.exitFactoryDoor" placeholder="请输入出厂门"  ></a-input>
        </a-form-model-item>
      </a-col>
      <a-col style="text-align: center;margin-bottom: 20px;">
        <a-button @click="handleConfirm" type="primary">确定</a-button>
      </a-col>
    </a-row>
  </a-form-model>
  </div>
</template>
  
  <script>
  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'
  import { validateCarNumber, validateTel } from '@/utils/validators';

  export default {
    data() {
      return {
        model:{
        },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 6 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        validatorRules: {
          vdNo :[{required: true, message: '请选择用车需求编号!'}],
          shipType :[{required: true, message: '请选择发货类型!'}],
          carType :[{required: true, message: '请选择车型!'}],
          carLong :[{required: true, message: '请选择车长!'}],
          pickUpHub :[{required: true, message: '请选择取货仓库!'}],
          deliveryAddress :[{required: true, message: '请选择送货地点!'}],
          supplierCode :[{required: true, message: '请选择供应商编码!'}],
          carNum :[{required: true, message: '请输入车牌号!'},
            { validator: validateCarNumber, trigger: 'blur' }
          ],
          logistics :[{required: true, message: '请输入物流公司!'}],
          driverName :[{required: true, message: '请输入司机姓名!'}],
          driverTel :[{required: true, message: '请输入电话!'},
            { validator: validateTel, trigger: 'blur' }
          ],
          etaTime :[{required: true, message: '请选择时间!'}],
        },
        url:{
          getVdCountById: '/deliveryplan/deliveryPlan/getVdCountById',
          take: "/vehicleinout/vehicleInOut/take",
        }
      };
    },
    created() {
      this.getVdCountById();
    },
    methods: {
      getVdCountById(){
        const queryParams = new URLSearchParams(window.location.search);
        const id =queryParams.get('id');
        console.log(queryParams);
        console.log(queryParams.get('id'));
        getAction(this.url.getVdCountById, {id:id}).then(res => {
          if(res.success){
            this.model = res.result.records[0];
          }else{
            this.$message.warning(res.message);
          }
        })
      },
      handleConfirm(){
        this.$refs.form.validate(valid => {
          if (valid) {
            // 入厂类型: 送货
            this.model.efType = '0';
            httpAction(this.url.take,this.model,'post').then((res)=>{
              if(res.success){
                this.$message.success(res.message);
                this.model = {}
              }else{
                this.$message.warning(res.message);
              }
            })
          }
        })
      },
    },
  };
  </script>