<template>
  <div>
    <el-card>
      <el-form
        :model="searchForm"
        label-width="90px"
        @submit.prevent="fnGetDataTransfer"
      >
        <el-row>
          <el-col :span="6">
            <el-form-item label="车牌号" prop="PLATE_NUMBER">
              <el-input
                v-model="searchForm.PLATE_NUMBER"
                placeholder="请填写车牌号"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="车辆颜色" prop="VEHICLE_COLOR">
              <el-select v-model="searchForm.VEHICLE_COLOR">
                <el-option
                  v-for="item in troubleshootingCycleList"
                  :key="item.BIANMA"
                  :label="item.NAME"
                  :value="item.NAME"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="车架号" prop="FRAMES_NUMBER">
              <el-input
                v-model="searchForm.FRAMES_NUMBER"
                placeholder="请填写车架号"
              />
            </el-form-item>
          </el-col>

          <el-col :span="6">
            <el-form-item label="编号" prop="GOODSSELFNUMBER">
              <el-input
                v-model="searchForm.GOODSSELFNUMBER"
                placeholder="请填写编号"
              />
            </el-form-item>
          </el-col>

          <el-col :span="6">
            <el-form-item label="归属部门" prop="BELONGING_DEPARTMENT">
              <el-input
                v-model="searchForm.BELONGING_DEPARTMENT"
                placeholder="请填写归属部门"
              />
            </el-form-item>
          </el-col>

          <el-col :span="6">
            <el-form-item label="入网状态" prop="NETWORK_STATUS">
              <el-select v-model="searchForm.NETWORK_STATUS">
                <el-option
                  v-for="item in networkStatusLevelList"
                  :key="item.BIANMA"
                  :label="item.NAME"
                  :value="item.NAME"
                />
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="6">
            <el-form-item label="主动安全" prop="ACTIVE_SAFETY">
              <el-select v-model="searchForm.ACTIVE_SAFETY">
                <el-option
                  v-for="item in activeSafety"
                  :key="item.BIANMA"
                  :label="item.NAME"
                  :value="item.NAME"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item label-width="10px">
              <el-button type="primary" native-type="submit">搜索</el-button>
              <el-button native-type="reset" @click="fnResetPaginationTransfer">
                重置
              </el-button>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label-width="10px" class="end">
              <el-button>导出</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </el-card>
    <layout-card>
      <layout-table
        v-model:pagination="pagination"
        :data="list"
        @get-data="fnGetDataTransfer"
      >
        <el-table-column label="序号" width="70">
          <template #default="{ $index }">
            {{ serialNumber(pagination, $index) }}
          </template>
        </el-table-column>
        <el-table-column prop="GOODSSELFNUMBER" label="编号" />
        <el-table-column prop="PLATE_NUMBER" label="车牌号" />
        <el-table-column prop="VEHICLE_COLOR" label="车辆颜色" />
        <el-table-column prop="FRAMES_NUMBER" label="车架号" width="140" />
        <el-table-column prop="CONTACT" label="联系人" />
        <el-table-column
          prop="CONTACT_NUMBER"
          label="联系电话"
          width="140"
          show-overflow-tooltip
        />
        <el-table-column prop="VEHICLE_TYPE" label="车辆类型" width="140" />
        <el-table-column prop="TRANSPORT_TYPE" label="运输类别" width="140" />
        <el-table-column prop="FIRSTSHOW_DATE" label="初登日期" />
        <el-table-column prop="EXPIRE_DATE" label="到期日期" />
        <el-table-column
          prop="BELONGING_DEPARTMENT"
          label="归属部门"
          width="140"
          show-overflow-tooltip
        />
        <el-table-column label="操作" width="150">
          <template #default="{ row }">
            <el-button
              type="primary"
              text
              link
              @click="
                router.push({
                  path: '/enterprise_management/basics_info_management/operation_vehicle/view',
                  query: { OPERATING_ID: row.OPERATING_ID },
                })
              "
            >
              查看
            </el-button>
            <el-button
              type="primary"
              text
              link
              @click="
                router.push({
                  path: '/enterprise_management/basics_info_management/operation_vehicle/view',
                  query: { OPERATING_ID: row.OPERATING_ID },
                })
              "
            >
              画像
            </el-button>
            <el-button
              type="primary"
              text
              link
              @click="
                router.push({
                  path: '/enterprise_management/basics_info_management/operation_vehicle/edit',
                  query: { OPERATING_ID: row.OPERATING_ID },
                })
              "
            >
              修改
            </el-button>
            <el-button
              v-if="buttonJurisdiction.del"
              type="primary"
              text
              link
              @click="fnDelete(row.OPERATING_ID)"
            >
              删除
            </el-button>
          </template>
        </el-table-column>
        <template #button>
          <el-button
            v-if="buttonJurisdiction.add"
            type="primary"
            @click="
              router.push({
                path: '/enterprise_management/basics_info_management/operation_vehicle/add',
              })
            "
          >
            新增
          </el-button>
        </template>
      </layout-table>
    </layout-card>
  </div>
</template>

<script setup>
import { serialNumber } from "@/assets/js/utils.js";
import useListData from "@/assets/js/useListData.js";
import {
  layoutFnGetVehicleColor,
  layoutFnGetNetworkStatus,
  layoutFnGetActiveSafety,
} from "@/assets/js/operation_vehicle.js";
import {
  getOperationVehicleList,
  setOperationVehicleDelete,
} from "@/request/operation_vehicle.js";
import { useRouter } from "vue-router";
import useButtonJurisdiction from "@/assets/js/useButtonJurisdiction.js";
import { debounce } from "throttle-debounce";
import { ElMessage, ElMessageBox } from "element-plus";

const router = useRouter();
const { list, pagination, searchForm, fnGetData, fnResetPagination } =
  useListData(getOperationVehicleList, {});
const troubleshootingCycleList = await layoutFnGetVehicleColor();
const networkStatusLevelList = await layoutFnGetNetworkStatus();
const activeSafety = await layoutFnGetActiveSafety();
const fnGetDataTransfer = () => {
  fnGetData({
    DEPTIDS: searchForm.value.DEPTIDS?.join(","),
  });
};
const fnResetPaginationTransfer = () => {
  searchForm.value = {};
  fnResetPagination({
    DEPTIDS: searchForm.value.DEPTIDS?.join(","),
  });
};
const fnDelete = debounce(
  1000,
  async (OPERATING_ID) => {
    await ElMessageBox.confirm("确定要删除吗？", { type: "warning" });
    await setOperationVehicleDelete({ OPERATING_ID });
    ElMessage.success("删除成功");
  },
  { atBegin: true }
);

const buttonJurisdiction = await useButtonJurisdiction("operation");
</script>
<style scoped></style>
