<template>
  <el-dialog
    :title="title"
    :visible.sync="oneDialogVisible"
    @close="closePop"
    :modal="false"
    width="66%"
    class="flex-aic vehicle-dialog"
  >
    <div id="chatRecord" style="margin-top: -30px; max-height: 540px; overflow: auto">
      <el-form
        ref="form"
        :model="form"
        :rules="rules"
        label-width="140px"
      >
        <p style="padding: 10px; background: #f5f5f5">基础信息</p>
        <el-row>
          <el-col :span="12">
            <el-form-item label="用途" prop="useType">
              <el-radio v-model="form.useType" :label="1">租赁</el-radio>
              <el-radio v-model="form.useType" :label="2">自用</el-radio>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="车牌号码" prop="numberPlate">
              <el-input
                v-model="form.numberPlate"
                placeholder="输入车牌"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="车辆编码" prop="code">
              <el-input
                v-model="form.code"
                placeholder="请输入车辆编码"
                type="number"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="出行状态" prop="status">
              <el-select
                class="filter-item"
                v-model="form.status"
                placeholder="请选择车辆状态"
                style="width: 100%"
              >
                <el-option
                  v-for="(val, index) in getAllVehicleStatus()"
                  :key="index"
                  :label="val.val"
                  :value="val.code"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="公里数" prop="mileageLastUpdate">
              <el-input
                type="number"
                v-model="form.mileageLastUpdate"
                placeholder="请输入公里数"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="停靠门店" prop="parkBranchCompanyId">
              <el-select
                class="filter-item"
                v-model="form.parkBranchCompanyId"
                placeholder="请选择停靠门店"
                filterable
              >
                <el-option
                  v-for="(val, index) in allVehicleBranchCompany"
                  :key="index"
                  :label="val.name"
                  :value="val.id"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="新旧程度" prop="vehicleStatus">
              <el-select
                style="width: 100%"
                class="filter-item"
                v-model="form.vehicleStatus"
                placeholder="请选择新旧程度"
              >
                <el-option key="1" label="全新" :value="1"></el-option>
                <el-option key="2" label="9成新" :value="2"></el-option>
                <el-option key="3" label="8成新" :value="3"></el-option>
                <el-option key="4" label="7成新" :value="4"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="车身状况" prop="vehicleBodyStatus">
              <el-select
                class="filter-item"
                v-model="form.vehicleBodyStatus"
                placeholder="请选择车身状况"
                style="width: 100%"
              >
                <el-option key="1" label="无剐蹭" :value="1"></el-option>
                <el-option key="2" label="微瑕疵" :value="2"></el-option>
                <el-option key="3" label="无瑕疵" :value="3"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="内饰" prop="vehicleInnerStatus">
              <el-select
                class="filter-item"
                v-model="form.vehicleInnerStatus"
                placeholder="请选择内饰"
                style="width: 100%"
              >
                <el-option key="1" label="全新" :value="1"></el-option>
                <el-option key="2" label="9成新" :value="2"></el-option>
                <el-option key="3" label="8成新" :value="3"></el-option>
                <el-option key="4" label="7成新" :value="4"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="备注">
          <el-input
            type="textarea"
            :rows="5"
            v-model="form.remark"
            placeholder="请输入备注信息"
          ></el-input>
        </el-form-item>
        <p style="padding: 10px; background: #f5f5f5">车辆归属</p>
        <el-row>
          <el-col :span="12">
            <el-form-item label="所属门店" prop="subordinateBranch">
              <el-select
                class="filter-item"
                v-model="form.subordinateBranch"
                placeholder="请选择所属门店"
                filterable
              >
                <el-option
                  v-for="(val, index) in allVehicleBranchCompany"
                  :key="index"
                  :label="val.name"
                  :value="val.id"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="托管人">
              <el-input
                v-model="form.belongToName"
                placeholder="请输入托管人"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <p style="padding: 10px; background: #f5f5f5">品牌、车型</p>
        <el-row>
          <el-col :span="12">
            <el-form-item label="车辆品牌" prop="brand">
              <el-select
                class="filter-item"
                v-model="form.brand"
                placeholder="请选择车辆品牌"
                style="width: 100%"
              >
                <el-option
                  :key="getUnkownBrandCode"
                  label="未知"
                  :value="getUnkownBrandCode"
                ></el-option>
                <el-option
                  v-for="item in getAllBranch()"
                  :key="item.code"
                  :label="item.val"
                  :value="item.code"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="车型" prop="modelId">
              <el-select
                class="filter-item"
                v-model="form.modelId"
                placeholder="请选择车型"
                filterable
              >
                <el-option
                  v-for="(val, index) in allVehicleList"
                  :key="index"
                  :label="val.name"
                  :value="val.id"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="生产商">
              <el-select
                class="filter-item"
                v-model="form.manufacturer"
                placeholder="请选择生产商"
                filterable
              >
                <el-option
                  v-for="(val, index) in allManufacturer"
                  :key="index"
                  :label="val"
                  :value="val"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <p style="padding: 10px; background: #f5f5f5">车辆信息</p>
        <el-row>
          <el-col :span="12">
            <el-form-item label="车架号">
              <el-input v-model="form.vin" placeholder="请输入车架号"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="发动机号">
              <el-input
                v-model="form.engineNum"
                placeholder="请输入发动机号"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="上牌日期">
              <el-date-picker
                v-model="form.vehicleRegisterDate"
                type="datetime"
                placeholder="上牌日期"
                value-format="yyyy-MM-dd hh:mm:ss"
                format="yyyy-MM-dd hh:mm:ss"
              ></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="年审日期">
              <el-date-picker
                v-model="form.annualVerificationDate"
                type="date"
                format="yyyy-MM-dd"
                value-format="yyyy-MM-dd hh:mm:ss"
                placeholder="选择日期"
                style="width: 100%"
              ></el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="行驶证" :style="{ display: 'block' }">
          <el-upload
            class="avatar-uploader"
            :action="BASE_API + '/api/universal/file/app/unauth/admin/upload'"
            :show-file-list="false"
            :headers="getHeaderWithToken"
            :on-success="handleAvatarSuccess"
            :before-upload="beforeAvatarUpload"
            :style="{ display: 'inline-block' }"
          >
            <img
              v-if="
              $utils.isString(form.drivingLicensePath) &&
              !$utils.isEmpty(form.drivingLicensePath)
            "
              :src="getDrivingLicenseUrl(form.drivingLicensePath)"
              class="avatar"
              :style="{ display: 'block' }"
            />
            <i
              v-else
              class="el-icon-plus avatar-uploader-icon"
              :style="{ lineHeight: '350px' }"
              style="position: relative"
            >
              <br />
              <span class="driving-title">行驶证正面</span>
            </i>
          </el-upload>

          <el-upload
            class="avatar-uploader"
            :action="BASE_API + '/api/universal/file/app/unauth/admin/upload'"
            :show-file-list="false"
            :headers="getHeaderWithToken"
            :on-success="handleAvatarSuccessF"
            :before-upload="beforeAvatarUpload"
            :style="{ display: 'inline-block' }"
          >
            <img
              v-if="
              $utils.isString(form.drivingLicenseDuplicatePath) &&
              !$utils.isEmpty(form.drivingLicenseDuplicatePath)
            "
              :src="getDrivingLicenseUrl(form.drivingLicenseDuplicatePath)"
              class="avatar"
              :style="{ display: 'block' }"
            />
            <i
              v-else
              class="el-icon-plus avatar-uploader-icon"
              :style="{ lineHeight: '350px' }"
              style="position: relative"
            >
              <br />
              <span class="driving-title">行驶证副本</span>
            </i>
          </el-upload>
        </el-form-item>
        <p style="padding: 10px; background: #f5f5f5">保险信息</p>
        <el-row>
          <el-col :span="12">
            <el-form-item label="商业险公司">
              <el-select
                class="filter-item"
                v-model="form.insuranceCompany"
                placeholder="请选择商业险公司"
                style="width: 100%"
              >
                <el-option
                  :key="undefined"
                  label="无"
                  :value="undefined"
                ></el-option>
                <el-option
                  v-for="(val, index) in getAllInsuranceCompany()"
                  :key="index"
                  :label="val.val"
                  :value="val.code"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="商业险单号">
              <el-input
                v-model="form.insuranceNo"
                placeholder="请输入商业险单号"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="商业险日期">
              <el-date-picker
                v-model="form.insuranceEndDate"
                type="date"
                value-format="yyyy-MM-dd hh:mm:ss"
                :editable="true"
                format="yyyy-MM-dd"
                placeholder="请选择商业险到期时间"
                style="width: 100%"
              ></el-date-picker>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="交强险公司">
              <el-select
                class="filter-item"
                v-model="form.strongInsuranceCompany"
                placeholder="请选择交强险公司"
                style="width: 100%"
              >
                <el-option
                  :key="undefined"
                  label="无"
                  :value="undefined"
                ></el-option>
                <el-option
                  v-for="(val, index) in getAllInsuranceCompany()"
                  :key="index"
                  :label="val.val"
                  :value="val.code"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="交强险单号">
              <el-input
                v-model.text="form.strongInsuranceNo"
                placeholder="请输入交强险单号"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="交强险日期">
              <el-date-picker
                v-model="form.strongInsuranceEndDate"
                value-format="yyyy-MM-dd hh:mm:ss"
                type="date"
                :editable="true"
                format="yyyy-MM-dd"
                placeholder="请选择交强险到期时间"
                style="width: 100%"
              ></el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col>
            <el-form-item label="保单pdf" :style="{ display: 'block' }">
              <el-upload
                ref="uploadPdf"
                :action="BASE_API + '/api/universal/file/app/unauth/admin/upload'"
                :show-file-list="false"
                :headers="getHeaderWithToken"
                :on-success="handleAvatarSuccessPDF"
                :style="{ display: 'inline-block' }"
                accept=".pdf"
              >
                <el-button size="small" plain>选择文件</el-button>
              </el-upload>
              <div v-for="(item, i) in pdfList" :key="i" @click="downloadPDF(i)">
                <span>{{ item.name }}</span>
              </div>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <div slot="footer" class="flex-aic-jcc" style="margin-top: 10px">
      <el-button plain @click="closePop">取消</el-button>
      <el-button
        type="primary"
        v-if="!isClick"
        class="handle-ok"
        @click="handleOk('form')"
        >确定</el-button
      >
      <el-button
        type="primary"
        v-if="isClick"
        class="handle-ok"
        style="opacity: 0.4"
        :disabled="true"
        >确定</el-button
      >
    </div>
  </el-dialog>
</template>

<style lang="scss">
.vehicle-dialog .el-dialog {
  margin-top: 0 !important;
}
</style>
<script type="javascript">
import { mapGetters } from "vuex";
import ElFormItem from "../../../../node_modules/element-ui/packages/form/src/form-item.vue";
import ElRow from "element-ui/packages/row/src/row";
import ElCol from "element-ui/packages/col/src/col";
import ElRadio from "../../../../node_modules/element-ui/packages/radio/src/radio.vue";
import ElButton from "../../../../node_modules/element-ui/packages/button/src/button.vue";
import {
  addObj,
  getObj,
  putObj,
  vehicleBranchCompanyAll,
  allManufacturer,
} from "../../../api/vehicle/vehicleInfo";
import { getToken } from "utils/auth";
import {
  VEHICLE_CONSTANT_VEHICLE_BRAND,
  VEHICLE_CONSTANT_BRAND_CODE_UNKOWN,
} from "../../../store/modules/baseInfo";
import {
  getConstantListByType,
  getAllInsuranceCompany,
  getInsuranceCompany,
} from "api/base_info/constant/";
import { getAllVehicleList } from "../../../api/vehicleType";
import { objDeepCopy } from "../../../utils";
export default {
  props: ["title", "oneRow"],
  components: {
    ElButton,
    ElRadio,
    ElFormItem,
    ElCol,
    ElRow,
  },
  data() {
    return {
      BASE_API: process.env.BASE_API,
      oneDialogVisible: false,
      allVehicleBranchCompany: [], // 全部所属门店列表
      allVehicleList: [], //全部车型
      allManufacturer: [], // 生产商列表
      isClick: false, // 添加、编辑-确定按钮  是否已点击
      form: {
        useType: 1, // 用途
        // state: 1, // 1、上架   2、下架
        id: undefined, // 车辆id
        numberPlate: undefined, // 车牌号码
        code: undefined, // 车辆编号
        status: undefined, // 出行状态
        mileageLastUpdate: undefined, // 公里数
        parkBranchCompanyId: undefined, // 停靠门店
        subordinateBranch: undefined, // 所属门店
        belongToName: undefined, // 托管人
        vehicleInnerStatus: undefined, // 内饰：1、全新，2、9成新，3、8成新，4、7成新
        vehicleStatus: undefined, // 新旧程度：1、全新，2、9成新，3、8成新，4、7成新
        vehicleBodyStatus: undefined, // 车身状况：1、无剐蹭，2、微瑕疵，3、无瑕疵
        remark: undefined, // 备注
        brand: undefined, // 车辆品牌
        modelId: undefined, // 车型id
        manufacturer: undefined, // 生产商
        vin: undefined, //车架号
        engineNum: undefined, //发动机号
        vehicleRegisterDate: undefined, // 上牌日期
        annualVerificationDate: undefined, // 年审日期
        drivingLicensePath: undefined, // 行驶证正面
        drivingLicenseDuplicatePath: undefined, // 行驶证副本
        insuranceCompany: undefined, // 商业险公司
        insuranceNo: undefined, // 商业险单号
        insuranceEndDate: undefined, // 商业险日期
        strongInsuranceCompany: undefined, // 交强险公司
        strongInsuranceNo: undefined, // 交强险单号
        strongInsuranceEndDate: undefined, // 交强险日期
      },
      rules: {
        numberPlate: {
          required: true,
          message: "请输入车牌号",
          trigger: "blur",
        },
        mileageLastUpdate: [this.integerValidator()],
        status: {
          required: true,
          message: "请选择出行状态",
          trigger: "change",
        },
        code: {
          required: true,
          message: "请输入车辆编码",
          trigger: "blur",
        },
        useType: {
          required: true,
          message: "请选择用途",
          trigger: "change",
        },
        parkBranchCompanyId: {
          required: true,
          message: "请选择停靠门店",
          trigger: "change",
        },
        vehicleStatus: {
          required: true,
          message: "请选择新旧程度",
          trigger: "change",
        },
        vehicleBodyStatus: {
          required: true,
          message: "请选择车身状况",
          trigger: "change",
        },
        vehicleInnerStatus: {
          required: true,
          message: "请选择内饰",
          trigger: "change",
        },
        subordinateBranch: {
          required: true,
          message: "请选择所属门店",
          trigger: "change",
        },
        brand: {
          required: true,
          message: "请选择车辆品牌",
          trigger: "change",
        },
        modelId: {
          required: true,
          message: "请选择车型",
          trigger: "change",
        },
      },
      pdfList: [], // 保单列表
    };
  },
  mounted() {
    this.oneDialogVisible = true;
    this.cleanForm(); // 清空表单数据
    if (this.title == "编辑车辆") {
      // 编辑
      this.getVehicleDetail(); // 获取车辆详情
    }
    this.getAllManufacturer(); // 获取全部生产商
    this.getAllVehicleType(); // 获取全部车型
    this.getVehicleBranchCompanyAll(); // 获取所有门店
  },
  computed: {
    ...mapGetters(["elements"]),
    getHeaderWithToken() {
      return { Authorization: getToken() };
    },
    getUnkownBrandCode: () => VEHICLE_CONSTANT_BRAND_CODE_UNKOWN, // 车辆品牌
  },
  methods: {
    /**
     * 获取全部供应商列表
     */
    getAllManufacturer() {
      allManufacturer().then((response) => {
        if (response.status == 200) {
          this.allManufacturer = response.data;
        } else {
          this.$notify({
            title: "失败",
            message: response.message,
            type: "error",
            duration: 2000,
          });
        }
      });
    },
    /**
     * 获取全部车型
     * */
    getAllVehicleType() {
      getAllVehicleList().then((response) => {
        if (response.status == 200) {
          let listRs = undefined;
          if (!this.$utils.isEmpty(response.data)) {
            listRs = response.data;
          }
          this.allVehicleList = listRs;
        } else {
          this.$notify({
            title: "失败",
            message: response.message,
            type: "error",
            duration: 2000,
          });
        }
      });
    },
    getAllInsuranceCompany,
    getInsuranceCompany,
    /**
     * 获取所有门店
     */
    getVehicleBranchCompanyAll() {
      vehicleBranchCompanyAll({ state: 1 }).then((response) => {
        if (response.status == 200) {
          this.allVehicleBranchCompany = response.data;
        } else {
          this.$notify({
            title: "失败",
            message: response.message,
            type: "error",
            duration: 2000,
          });
        }
      });
    },
    /**
     * 获取车辆全部品牌
     */
    getAllBranch: () => {
      return getConstantListByType(VEHICLE_CONSTANT_VEHICLE_BRAND);
    },
    /**
     * 获取车辆详情
     */
    getVehicleDetail() {
      getObj(this.oneRow.id).then((response) => {
        if (response.status == 200) {
          this.$utils.objectEach(response.data, (item, key) => {
            this.form[key] = item;
          });
          // this.form = {
          //   id: response.data.id, // 车辆id
          //   numberPlate: response.data.numberPlate, // 车牌号码
          //   code: response.data.code, // 车辆编号
          //   status: response.data.status, // 出行状态
          //   mileageLastUpdate: response.data.maintenanceMileage, // 公里数
          //   parkBranchCompanyId: response.data.parkBranchCompanyId, // 停靠门店
          //   subordinateBranch: response.data.subordinateBranch, // 所属门店
          //   belongToName: response.data.belongToName, // 托管人
          //   vehicleInnerStatus: response.data.vehicleInnerStatus, // 内饰：1、全新，2、9成新，3、8成新，4、7成新
          //   vehicleStatus: response.data.vehicleStatus, // 新旧程度：1、全新，2、9成新，3、8成新，4、7成新
          //   vehicleBodyStatus: response.data.vehicleBodyStatus, // 车身状况：1、无剐蹭，2、微瑕疵，3、无瑕疵
          //   remark: response.data.remark, // 备注
          // }
        } else {
          this.$notify({
            title: "失败",
            message: response.message,
            type: "error",
            duration: 2000,
          });
        }
      });
    },
    beforeAvatarUpload(file) {
      const isJPG = file.type === "image/jpeg" || file.type === "image/gif";
      file.type === "image/jpeg" ||
        file.type === "image/gif" ||
        file.type === "image/pdf";
      const isLt2M = file.size / 1024 / 1024 < 10;

      if (!isJPG) {
        this.$message.error("上传图片只能是 JPG/GIF 格式!");
      }
      if (!isLt2M) {
        this.$message.error("上传图片大小不能超过 10MB!");
      }
      // this.showLoadingBody = true
      return isJPG && isLt2M;
    },
    /**
     * 行驶证--正面
     */
    handleAvatarSuccess(res, file) {
      this.form.drivingLicensePath = res.data;
      this.showLoadingBody = false;
    },
    /**
     * 行驶证--副本
     */
    handleAvatarSuccessF(res, file) {
      this.form.drivingLicenseDuplicatePath = res.data;
      this.showLoadingBody = false;
    },
    /**
     * PDF保单上传
     */
    handleAvatarSuccessPDF(res, file) {
      if (res.data) {
        if (this.pdfList.length >= 0) {
          var data = {
            id: this.pdfList.length + 1,
            name: "车辆保单" + (this.pdfList.length + 1),
            url: res.data,
          };
          this.pdfList.push(data);
        }
      }
      this.showLoadingBody = false;
    },
    showImgDialog(drivingLicensePath) {
      this.licenceSrcUrl = this.getDrivingLicenseUrl(drivingLicensePath);
      this.dialogForm4LicenceVisible = true;
    },
    /**
     * 行驶证--src
     */
    getDrivingLicenseUrl(drivingLicensePath) {
      if (drivingLicensePath.indexOf("https") > -1) {
        return drivingLicensePath;
      } else {
        return (
          process.env.BASE_API +
          "/vehicle/vehicleInfo/download/drivingLicense?realFileRelPath=" +
          encodeURI(drivingLicensePath)
        );
      }
    },
    /**
     * 下载保单
     */
    downloadPDF(i) {
      var data = this.pdfList[i].url;
      if (data) {
        window.open(data, "_blank");
      } else {
        this.$notify({
          title: "失败",
          message: "车辆保单不存在",
          type: "error",
          duration: 2000,
        });
      }
    },
    /**
     * 公里数验证
     */
    integerValidator: function () {
      return {
        validator: (rule, value, callback) => {
          if (this.$utils.isUndefined(value) || this.$utils.isNull()) {
            return callback();
          }
          if (!this.$utils.isInteger(value)) {
            return callback(new Error("必须为整数"));
          }
          if (value < 1 || value > 9999999999) {
            return callback(new Error("编码合法范围：[1 - 9999999999]"));
          }
          callback();
        },
        trigger: "blur",
      };
    },
    /**
     * 清空表单数据
     */
    cleanForm() {
      this.form = {
        useType: 1, // 用途
        id: undefined, // 车辆id
        numberPlate: undefined, // 车牌号码
        code: undefined, // 车辆编号
        status: undefined, // 出行状态
        mileageLastUpdate: undefined, // 公里数
        parkBranchCompanyId: undefined, // 停靠门店
        subordinateBranch: undefined, // 所属门店
        belongToName: undefined, // 托管人
        vehicleInnerStatus: undefined, // 内饰：1、全新，2、9成新，3、8成新，4、7成新
        vehicleStatus: undefined, // 新旧程度：1、全新，2、9成新，3、8成新，4、7成新
        vehicleBodyStatus: undefined, // 车身状况：1、无剐蹭，2、微瑕疵，3、无瑕疵
        remark: undefined, // 备注
        brand: undefined, // 车辆品牌
        modelId: undefined, // 车型id
        manufacturer: undefined, // 生产商
        vin: undefined, //车架号
        engineNum: undefined, //发动机号
        vehicleRegisterDate: undefined, // 上牌日期
        annualVerificationDate: undefined, // 年审日期
        drivingLicensePath: undefined, // 行驶证正面
        drivingLicenseDuplicatePath: undefined, // 行驶证副本
        insuranceCompany: undefined, // 商业险公司
        insuranceNo: undefined, // 商业险单号
        insuranceEndDate: undefined, // 商业险日期
        strongInsuranceCompany: undefined, // 交强险公司
        strongInsuranceNo: undefined, // 交强险单号
        strongInsuranceEndDate: undefined, // 交强险日期
      };
    },
    /**
     * 关闭弹窗
     */
    closePop() {
      this.oneDialogVisible = false;
      this.$emit("oneDialogEvent", false);
    },
    /**
     * 确定
     */
    handleOk() {
      const set = this.$refs;
      if (this.isClick) {
        return;
      }
      this.isClick = true;
      if(!this.form.useType || !this.form.numberPlate || !this.form.code || !this.form.status ||
        !this.form.parkBranchCompanyId || !this.form.vehicleStatus || !this.form.vehicleBodyStatus || !this.form.vehicleInnerStatus){
        // 用途
        let ele = document.getElementById('chatRecord');
        ele.scrollTop = 0;
      } else if(!this.form.subordinateBranch || !this.form.brand || !this.form.modelId){
        // 所属门店/车辆品牌/车型
        let ele = document.getElementById('chatRecord');
        ele.scrollTop = 500;
      }
      console.log(this.form)
      set["form"].validate((valid) => {
        if (valid) {
          let params = objDeepCopy(this.form);
          params.registerDate = this.form.vehicleRegisterDate; // 上牌时间
          params.vehicleRegisterDate = undefined;
          if (this.form.id) {
            // 编辑
            putObj(params).then((response) => {
              if (response.code == 1) {
                this.$notify({
                  title: "成功",
                  message: "编辑成功",
                  type: "success",
                  duration: 2000,
                });
                this.$emit("oneDialogEvent", true);
              } else {
                this.isClick = false;
                this.$notify({
                  title: "失败",
                  message: response.message,
                  type: "error",
                  duration: 2000,
                });
              }
            });
          } else {
            // 添加
            addObj(params).then((response) => {
              if (response.code == 1) {
                this.$notify({
                  title: "成功",
                  message: "添加成功",
                  type: "success",
                  duration: 2000,
                });

                this.$emit("oneDialogEvent", true);
              } else {
                this.isClick = false;
                this.$notify({
                  title: "失败",
                  message: response.message,
                  type: "error",
                  duration: 2000,
                });
              }
            });
          }
        } else {
          this.isClick = false;
        }
      });
    },
    /**
     * 出行状态
     */
    getAllVehicleStatus: function () {
      return {
        1: {
          code: 1,
          val: "正常运行",
        },
        3: {
          code: 3,
          val: "报废",
        },
        4: {
          code: 4,
          val: "出车",
        },
        6: {
          code: 6,
          val: "维修中",
        },
        7: {
          code: 7,
          val: "保养中",
        },
        8: {
          code: 8,
          val: "上牌中",
        },
      };
    },
  },
};
</script>
