<template>
  <div class="app-container">
    <!--    搜索栏-->
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch"
             :label-width=" locale ? '110px':'170px'">
      <el-form-item :label="t('baseCar.car.companyCode')" prop="companyCode">
        <el-input
            v-model="queryParams.companyCode"
            :placeholder=" t('common.pleaseEnter') + t('baseCar.car.companyCode')"
            style="width: 200px"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item :label="t('baseCar.car.carQueueId')" prop="carQueueId">
        <el-input
            v-model="queryParams.carQueueId"
            :placeholder="t('common.pleaseEnter') + t('baseCar.car.carQueueId')"
            style="width: 200px"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item :label="t('baseCar.car.carTypeId')" prop="carTypeId">
        <el-input
            v-model="queryParams.carTypeId"
            :placeholder="t('common.pleaseEnter') + t('baseCar.car.carTypeId')"
            style="width: 200px"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item :label="t('baseCar.car.carLicense')" prop="carLicense">
        <el-input
            v-model="queryParams.carLicense"
            :placeholder="t('common.pleaseEnter') + t('baseCar.car.carLicense')"
            style="width: 200px"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item :label="t('baseCar.car.carLicenseIn')" prop="carLicenseIn">
        <el-input
            v-model="queryParams.carLicenseIn"
            :placeholder="t('common.pleaseEnter') +t('baseCar.car.carLicenseIn')"
            style="width: 200px"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item :label="t('baseCar.car.carLicenseParent')" prop="carLicenseParent">
        <el-input
            v-model="queryParams.carLicenseParent"
            :placeholder="t('common.pleaseEnter') + t('baseCar.car.carLicenseParent')"
            style="width: 200px"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item :label="t('baseCar.car.carIdParent')" prop="carIdParent">
        <el-input
            v-model="queryParams.carIdParent"
            :placeholder="t('common.pleaseEnter') + t('baseCar.car.carIdParent')"
            style="width: 200px"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item :label="t('baseCar.car.userId')" prop="userId">
        <el-input
            v-model="queryParams.userId"
            :placeholder="t('common.pleaseEnter') + t('baseCar.car.userId')"
            style="width: 200px"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item :label="t('baseCar.car.userName')" prop="userName">
        <el-input
            v-model="queryParams.userName"
            :placeholder="t('common.pleaseEnter') + t('baseCar.car.userName')"
            style="width: 200px"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item :label="t('baseCar.car.deviceId')" prop="deviceId">
        <el-input
            v-model="queryParams.deviceId"
            :placeholder="t('common.pleaseEnter') + t('baseCar.car.deviceId')"
            style="width: 200px"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item :label="t('baseCar.car.deviceBindTime')" prop="deviceBindTime">
        <el-date-picker
            clearable
            style="width: 200px"
            v-model="queryParams.deviceBindTime"
            type="date"
            format="YYYY/MM/DD"
            value-format="YYYY-MM-DD"
            :placeholder="t('common.PleaseSelect') + t('baseCar.car.deviceBindTime')"
        />
      </el-form-item>
      <el-form-item :label="t('baseCar.car.firstChangeDate')" prop="firstChangeDate">
        <el-date-picker
            clearable
            style="width: 200px"
            v-model="queryParams.firstChangeDate"
            type="date"
            format="YYYY/MM/DD"
            value-format="YYYY-MM-DD"
            :placeholder="t('common.PleaseSelect') + t('baseCar.car.firstChangeDate')"
        />
      </el-form-item>
      <el-form-item :label="t('baseCar.car.trailerNum')" prop="trailerNum">
        <el-input
            v-model="queryParams.trailerNum"
            :placeholder="t('common.pleaseEnter') + t('baseCar.car.trailerNum')"
            style="width: 200px"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item :label="t('baseCar.car.isHandDevice')" prop="isHandDevice">
        <el-input
            v-model="queryParams.isHandDevice"
            :placeholder="t('common.pleaseEnter') + t('baseCar.car.isHandDevice')"
            style="width: 200px"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item :label="t('baseCar.car.isHasDevice')" prop="isHasDevice">
        <el-input
            v-model="queryParams.isHasDevice"
            :placeholder="t('common.pleaseEnter') + t('baseCar.car.isHasDevice')"
            style="width: 200px"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item :label="t('baseCar.car.longitude')" prop="longitude">
        <el-input
            v-model="queryParams.longitude"
            :placeholder="t('common.pleaseEnter') + t('baseCar.car.longitude')"
            style="width: 200px"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item :label="t('baseCar.car.latitude')" prop="latitude">
        <el-input
            v-model="queryParams.latitude"
            :placeholder="t('common.pleaseEnter') + t('baseCar.car.latitude')"
            style="width: 200px"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item :label="t('baseCar.car.tiresTotal')" prop="tiresTotal">
        <el-input
            v-model="queryParams.tiresTotal"
            :placeholder="t('common.pleaseEnter') + t('baseCar.car.tiresTotal')"
            style="width: 200px"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item :label="t('common.isRemove')" prop="isDelete">
        <el-input
            v-model="queryParams.isDelete"
            :placeholder="t('common.pleaseEnter') + t('common.isRemove')"
            style="width: 200px"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item :label="t('common.createTime')" prop="createTime">
        <el-date-picker
            clearable
            style="width: 200px"
            v-model="queryParams.createTime"
            :placeholder="t('common.PleaseSelect') + t('common.createTime')"
            type="date"
            format="YYYY/MM/DD"
            value-format="YYYY-MM-DD"
        />
      </el-form-item>
      <el-form-item :label="t('common.creatorId')" prop="createId">
        <el-input
            v-model="queryParams.createId"
            :placeholder="t('common.pleaseEnter') + t('common.creatorId')"
            style="width: 200px"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item :label="t('common.createBy')" prop="createBy">
        <el-input
            v-model="queryParams.createBy"
            :placeholder="t('common.pleaseEnter') + t('common.createBy')"
            style="width: 200px"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item :label="t('common.creatorName')" prop="createName">
        <el-input
            v-model="queryParams.createName"
            :placeholder="t('common.pleaseEnter') + t('common.creatorName')"
            style="width: 200px"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item :label="t('common.editTime')" prop="modifyTime">
        <el-date-picker
            clearable
            style="width: 200px"
            v-model="queryParams.modifyTime"
            :placeholder="t('common.PleaseSelect') + t('common.editTime')"
            type="date"
            format="YYYY/MM/DD"
            value-format="YYYY-MM-DD"
        />
      </el-form-item>
      <el-form-item :label="t('common.editID')" prop="modifyId">
        <el-input
            v-model="queryParams.modifyId"
            :placeholder="t('common.pleaseEnter') + t('common.editID')"
            style="width: 200px"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item :label="t('common.editBy')" prop="modifyBy">
        <el-input
            v-model="queryParams.modifyBy"
            :placeholder="t('common.pleaseEnter') + t('common.editBy')"
            style="width: 200px"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label=" ">
        <el-button type="primary" icon="Search" @click="handleQuery">{{ t('option.search') }}</el-button>
        <el-button icon="Refresh" @click="resetQuery">{{ t('option.reset') }}</el-button>
      </el-form-item>
    </el-form>

    <!--    顶部操作按钮-->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
            type="primary"
            plain
            icon="Plus"
            @click="handleAdd"
            v-hasPermi="['basecar:car:add']"
        >{{ t('option.add') }}
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            type="success"
            plain
            icon="Edit"
            :disabled="single"
            @click="handleUpdate"
            v-hasPermi="['basecar:car:edit']"
        >{{ t('option.edit') }}
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            type="danger"
            plain
            icon="Delete"
            :disabled="multiple"
            @click="handleDelete"
            v-hasPermi="['basecar:car:remove']"
        >{{ t('option.remove') }}
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            type="warning"
            plain
            icon="Download"
            @click="handleExport"
            v-hasPermi="['basecar:car:export']"
        >{{ t('option.export') }}
        </el-button>
      </el-col>
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <!--    表格主体-->
    <el-table v-loading="loading" :data="postList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" fixed/>
      <el-table-column :label="t('baseCar.car.companyCode')" align="center" prop="companyCode" width="150"/>
      <el-table-column :label="t('baseCar.car.carQueueId')" align="center" prop="carQueueId" width="150"/>
      <el-table-column :label="t('baseCar.car.carTypeId')" align="center" prop="carTypeId" :width="locale ? 150:170"/>
      <el-table-column :label="t('baseCar.car.carLicense')" align="center" prop="carLicense" width="150"/>
      <el-table-column :label="t('baseCar.car.carLicenseIn')" align="center" prop="carLicenseIn"
                       :width="locale ? 150:170"/>
      <el-table-column :label="t('baseCar.car.carLicenseParent')" align="center" prop="carLicenseParent"
                       :width="locale ? 150:170"/>
      <el-table-column :label="t('baseCar.car.carIdParent')" align="center" prop="carIdParent" width="150"/>
      <el-table-column :label="t('baseCar.car.userId')" align="center" prop="userId" width="150"/>
      <el-table-column :label="t('baseCar.car.userName')" align="center" prop="userName" width="150"/>
      <el-table-column :label="t('baseCar.car.deviceId')" align="center" prop="deviceId" width="150"/>
      <el-table-column :label="t('baseCar.car.deviceBindTime')" align="center" prop="deviceBindTime"
                       :width="locale ? 150:170"/>
      <el-table-column :label="t('baseCar.car.firstChangeDate')" align="center" prop="firstChangeDate"
                       :width="locale ? 150:170"/>
      <el-table-column :label="t('baseCar.car.trailerNum')" align="center" prop="trailerNum" width="150"/>
      <el-table-column :label="t('baseCar.car.isHandDevice')" align="center" prop="isHandDevice"
                       :width="locale ? 150:310"/>
      <el-table-column :label="t('baseCar.car.isHasDevice')" align="center" prop="isHasDevice"
                       :width="locale ? 150:260"/>
      <el-table-column :label="t('baseCar.car.longitude')" align="center" prop="longitude" width="150"/>
      <el-table-column :label="t('baseCar.car.latitude')" align="center" prop="latitude" width="150"/>
      <el-table-column :label="t('baseCar.car.tiresTotal')" align="center" prop="tiresTotal" width="150"/>
      <el-table-column :label="t('common.isRemove')" align="center" prop="isDelete" width="150"/>
      <el-table-column :label="t('common.createTime')" align="center" prop="createTime" width="160"/>
      <el-table-column :label="t('common.creatorId')" align="center" prop="createId" width="150"/>
      <el-table-column :label="t('common.createBy')" align="center" prop="createBy" width="150"/>
      <el-table-column :label="t('common.creatorName')" align="center" prop="createName" width="150"/>
      <el-table-column :label="t('common.editTime')" align="center" prop="modifyTime" width="150"/>
      <el-table-column :label="t('common.editID')" align="center" prop="modifyId" width="150"/>
      <el-table-column :label="t('common.editBy')" align="center" prop="modifyBy" width="150"/>
      <el-table-column :label="t('option.option')" align="center" class-name="small-padding fixed-width" fixed="right"
                       width="160">
        <template #default="scope">
          <el-button
              type="text"
              icon="Edit"
              @click="handleUpdate(scope.row)"
              v-hasPermi="['basecar:car:edit']"
          >{{ t('option.edit') }}
          </el-button>
          <el-button
              type="text"
              icon="Delete"
              @click="handleDelete(scope.row)"
              v-hasPermi="['basecar:car:remove']"
          >{{ t('option.remove') }}
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <!--    分页-->
    <pagination
        v-show="total > 0"
        :total="total"
        v-model:page="queryParams.pageNum"
        v-model:limit="queryParams.pageSize"
        @pagination="getList"
    />

    <!-- 添加或修改岗位对话框 -->
    <el-dialog :title="title" v-model="open" width="500px" append-to-body>
      <el-form ref="postRef" :model="form" :rules="rules" :label-width=" locale ? '120px':'140px'">
        <el-form-item prop="id" v-if="false">
          <el-input v-model="form.id"/>
        </el-form-item>
        <el-form-item :label="t('baseCar.car.companyCode')" prop="companyCode">
          <el-input
              v-model="form.companyCode"
              :placeholder=" t('common.pleaseEnter') + t('baseCar.car.companyCode')"/>
        </el-form-item>
        <el-form-item :label="t('baseCar.car.carQueueId')" prop="carQueueId">
          <el-input
              v-model="form.carQueueId"
              :placeholder="t('common.pleaseEnter') + t('baseCar.car.carQueueId')"/>
        </el-form-item>
        <el-form-item :label="t('baseCar.car.carTypeId')" prop="carTypeId">
          <el-input
              v-model="form.carTypeId"
              :placeholder="t('common.pleaseEnter') + t('baseCar.car.carTypeId')"/>
        </el-form-item>
        <el-form-item :label="t('baseCar.car.carLicense')" prop="carLicense">
          <el-input
              v-model="form.carLicense"
              :placeholder="t('common.pleaseEnter') + t('baseCar.car.carLicense')"/>
        </el-form-item>
        <el-form-item :label="t('baseCar.car.carLicenseIn')" prop="carLicenseIn">
          <el-input
              v-model="form.carLicenseIn"
              :placeholder="t('common.pleaseEnter') + t('baseCar.car.carLicenseIn')"/>
        </el-form-item>
        <el-form-item :label="t('baseCar.car.carLicenseParent')" prop="carLicenseParent">
          <el-input
              v-model="form.carLicenseParent"
              :placeholder="t('common.pleaseEnter') + t('baseCar.car.carLicenseParent')"/>
        </el-form-item>
        <el-form-item :label="t('baseCar.car.carIdParent')" prop="carIdParent">
          <el-input
              v-model="form.carIdParent"
              :placeholder="t('common.pleaseEnter') + t('baseCar.car.carIdParent')"/>
        </el-form-item>
        <el-form-item :label="t('baseCar.car.userId')" prop="userId">
          <el-input
              v-model="form.userId"
              :placeholder="t('common.pleaseEnter') + t('baseCar.car.userId')"/>
        </el-form-item>
        <el-form-item :label="t('baseCar.car.userName')" prop="userName">
          <el-input
              v-model="form.userName"
              :placeholder="t('common.pleaseEnter') + t('baseCar.car.userName')"/>
        </el-form-item>
        <el-form-item :label="t('baseCar.car.deviceId')" prop="deviceId">
          <el-input
              v-model="form.deviceId"
              :placeholder="t('common.pleaseEnter') + t('baseCar.car.deviceId')"/>
        </el-form-item>
        <el-form-item :label="t('baseCar.car.deviceBindTime')" prop="deviceBindTime">
          <el-date-picker
              clearable
              v-model="form.deviceBindTime"
              type="date"
              format="YYYY/MM/DD"
              value-format="YYYY-MM-DD"
              :placeholder="t('common.PleaseSelect') + t('baseCar.car.deviceBindTime')"
          />
        </el-form-item>
        <el-form-item :label="t('baseCar.car.firstChangeDate')" prop="firstChangeDate">
          <el-date-picker
              clearable
              v-model="form.firstChangeDate"
              type="date"
              format="YYYY/MM/DD"
              value-format="YYYY-MM-DD"
              :placeholder="t('common.PleaseSelect') + t('baseCar.car.firstChangeDate')"
          />
        </el-form-item>
        <el-form-item :label="t('baseCar.car.trailerNum')" prop="trailerNum">
          <el-input
              v-model="form.trailerNum"
              :placeholder="t('common.pleaseEnter') + t('baseCar.car.trailerNum')"/>
        </el-form-item>
        <el-form-item :label="t('baseCar.car.isHandDevice')" prop="isHandDevice">
          <el-input
              v-model="form.isHandDevice"
              :placeholder="t('common.pleaseEnter') + t('baseCar.car.isHandDevice')"/>
        </el-form-item>
        <el-form-item :label="t('baseCar.car.isHasDevice')" prop="isHasDevice">
          <el-input
              v-model="form.isHasDevice"
              :placeholder="t('common.pleaseEnter') + t('baseCar.car.isHasDevice')"/>
        </el-form-item>
        <el-form-item :label="t('baseCar.car.longitude')" prop="longitude">
          <el-input
              v-model="form.longitude"
              :placeholder="t('common.pleaseEnter') + t('baseCar.car.longitude')"/>
        </el-form-item>
        <el-form-item :label="t('baseCar.car.latitude')" prop="latitude">
          <el-input
              v-model="form.latitude"
              :placeholder="t('common.pleaseEnter') + t('baseCar.car.latitude')"/>
        </el-form-item>
        <el-form-item :label="t('baseCar.car.tiresTotal')" prop="tiresTotal">
          <el-input
              v-model="form.tiresTotal"
              :placeholder="t('common.pleaseEnter') + t('baseCar.car.tiresTotal')"/>
        </el-form-item>
        <el-form-item :label="t('common.isRemove')" prop="isDelete">
          <el-input
              v-model="form.isDelete"
              :placeholder="t('common.pleaseEnter') + t('common.isRemove')"/>
        </el-form-item>
        <el-form-item :label="t('common.createTime')" prop="createTime">
          <el-date-picker
              clearable
              v-model="form.createTime"
              type="date"
              format="YYYY/MM/DD"
              value-format="YYYY-MM-DD"
              :placeholder="t('common.PleaseSelect') + t('common.createTime')"
          />
        </el-form-item>
        <el-form-item :label="t('common.creatorId')" prop="createId">
          <el-input
              v-model="form.createId"
              :placeholder="t('common.pleaseEnter') + t('common.creatorId')"/>
        </el-form-item>
        <el-form-item :label="t('common.createBy')" prop="createBy">
          <el-input
              v-model="form.createBy"
              :placeholder="t('common.pleaseEnter') + t('common.createBy')"/>
        </el-form-item>
        <el-form-item :label="t('common.creatorName')" prop="createName">
          <el-input
              v-model="form.createName"
              :placeholder="t('common.pleaseEnter') + t('common.creatorName')"/>
        </el-form-item>
        <el-form-item :label="t('common.editTime')" prop="modifyTime">
          <el-date-picker
              clearable
              v-model="form.modifyTime"
              type="date"
              format="YYYY/MM/DD"
              value-format="YYYY-MM-DD"
              :placeholder="t('common.PleaseSelect') + t('common.editTime')"
          />
        </el-form-item>
        <el-form-item :label="t('common.editID')" prop="modifyId">
          <el-input
              v-model="form.modifyId"
              :placeholder="t('common.pleaseEnter') + t('common.editID')"/>
        </el-form-item>
        <el-form-item :label="t('common.editBy')" prop="modifyBy">
          <el-input
              v-model="form.modifyBy"
              :placeholder="t('common.pleaseEnter') + t('common.editBy')"/>
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitForm">{{ t('option.ok') }}</el-button>
          <el-button @click="cancel">{{ t('option.cancel') }}</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup name="basetyre">
import {addBaseCar, delBaseCar, getBaseCar, listBaseCar, updateBaseCar} from "@/api/basecar/car";

import {useI18n} from 'vue-i18n';
import Cookies from "js-cookie";

const {t} = useI18n();

const locale = (Cookies.get('language') || 'zhCn') === 'zhCn'
const {proxy} = getCurrentInstance();
const {sys_normal_disable} = proxy.useDict("sys_normal_disable");


// 表格数据
const postList = ref([]);
// 模态框开关标识
const open = ref(false);
// 表格加载状态开关标识
const loading = ref(true);
// 搜索区域开关标识
const showSearch = ref(true);
// 选择行id
const ids = ref([]);
// 修改按钮是否可用标识
const single = ref(true);
// 删除按钮是否可用标识
const multiple = ref(true);
// 总条数
const total = ref(0);
// 模态框标题
const title = ref("");

// 搜索参数
const queryParams = ref({
  pageNum: 1,
  pageSize: 10,
  companyCode: undefined,
  carQueueId: undefined,
  carTypeId: undefined,
  carLicense: undefined,
  carLicenseIn: undefined,
  carLicenseParent: undefined,
  carIdParent: undefined,
  userId: undefined,
  userName: undefined,
  deviceId: undefined,
  deviceBindTime: undefined,
  firstChangeDate: undefined,
  trailerNum: undefined,
  isHandDevice: undefined,
  isHasDevice: undefined,
  longitude: undefined,
  latitude: undefined,
  tiresTotal: undefined,
  isDelete: undefined,
  createTime: undefined,
  createId: undefined,
  createBy: undefined,
  createName: undefined,
  modifyTime: undefined,
  modifyId: undefined,
  modifyBy: undefined,
})

// 表单验证规则
const rules = {
  brand: [{required: true, message: "轮胎品牌不能为空", trigger: "blur"}],
  type: [{required: true, message: "轮胎型号不能为空", trigger: "blur"}],
  serialNumber: [{required: true, message: "轮胎编号不能为空", trigger: "blur"}],
  depth: [{required: true, message: "花纹深度不能为空", trigger: "blur"}],
}

// 表单数据
const form = ref({
  id: null,
  companyCode: null,
  carQueueId: null,
  carTypeId: null,
  carLicense: null,
  carLicenseIn: null,
  carLicenseParent: null,
  carIdParent: null,
  userId: null,
  userName: null,
  deviceId: null,
  deviceBindTime: null,
  firstChangeDate: null,
  trailerNum: null,
  isHandDevice: null,
  isHasDevice: null,
  longitude: null,
  latitude: null,
  tiresTotal: null,
  isDelete: null,
  createTime: null,
  createId: null,
  createBy: null,
  createName: null,
  modifyTime: null,
  modifyId: null,
  modifyBy: null
});

/** 查询岗位列表 */
function getList() {
  loading.value = true;
  listBaseCar(queryParams.value).then(response => {
    postList.value = response.rows;
    total.value = response.total;
  }).finally(() => {
    loading.value = false;
  });
}

/** 取消按钮 */
function cancel() {
  open.value = false;
  reset();
}

/** 表单重置 */
function reset() {
  form.value = {
    id: null,
    companyCode: null,
    carQueueId: null,
    carTypeId: null,
    carLicense: null,
    carLicenseIn: null,
    carLicenseParent: null,
    carIdParent: null,
    userId: null,
    userName: null,
    deviceId: null,
    deviceBindTime: null,
    firstChangeDate: null,
    trailerNum: null,
    isHandDevice: null,
    isHasDevice: null,
    longitude: null,
    latitude: null,
    tiresTotal: null,
    isDelete: null,
    createTime: null,
    createId: null,
    createBy: null,
    createName: null,
    modifyTime: null,
    modifyId: null,
    modifyBy: null
  };
  proxy.resetForm("postRef");
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
const resetQuery = () => {
  proxy.resetForm("queryRef");
  handleQuery();
}

/** 多选框选中数据 */
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.id);
  single.value = selection.length !== 1;
  multiple.value = !selection.length;
}

/** 新增按钮操作 */
function handleAdd() {
  reset();
  open.value = true;
  title.value = t('baseCar.car.addTitle');
}

/** 修改按钮操作 */
function handleUpdate(row) {
  reset();
  const postId = row.id || ids.value;
  getBaseCar(postId).then(response => {
    form.value = response.data;
    open.value = true;
    title.value = t('baseCar.car.editTitle');
  });
}

/** 提交按钮 */
function submitForm() {
  proxy.$refs["postRef"].validate(valid => {
    if (valid) {
      if (form.value.postId != undefined) {
        updateBaseCar(form.value).then(response => {
          proxy.$modal.msgSuccess(t('option.modificationSuccessful'));
          open.value = false;
          getList();
        });
      } else {
        addBaseCar(form.value).then(response => {
          proxy.$modal.msgSuccess(t('option.addedSuccessfully'));
          open.value = false;
          getList();
        });
      }
    }
  });
}

/** 删除按钮操作 */
function handleDelete(row) {
  const postIds = row.id || ids.value;
  proxy.$modal.confirm(t('option.confirmDeletion', {
    key: t('baseCar.car.companyCode'), value: postIds
  })).then(function () {
    return delBaseCar(postIds);
  }).then(() => {
    getList();
    proxy.$modal.msgSuccess(t('option.successfullyDeleted'));
  }).catch(() => {
  });
}

/** 导出按钮操作 */
function handleExport() {
  proxy.download("system/post/export", {
    ...queryParams.value
  }, `post_${new Date().getTime()}.xlsx`);
}

getList();
</script>
