<template>
  <div>
    <el-card>
      <el-form
        :model="searchForm"
        label-width="100px"
        @submit.prevent="fnResetPagination"
      >
        <el-row>
          <el-col :span="6">
            <el-form-item label="运输企业" prop="TRANSPORTCOMPANY">
              <el-input v-model="searchForm.TRANSPORTCOMPANY" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="运输车辆" prop="TRANSPORTVEHICLE">
              <el-input v-model="searchForm.TRANSPORTVEHICLE" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label-width="10px">
              <el-button type="primary" native-type="submit">搜索</el-button>
              <el-button native-type="reset" @click="fnResetPagination">
                重置
              </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="fnGetData"
      >
        <el-table-column label="序号" width="60">
          <template #default="{ $index }">
            {{ serialNumber(pagination, $index) }}
          </template>
        </el-table-column>
        <el-table-column
          prop="REGISTRATIONNUMBER"
          label="登记编号"
          width="130"
        />
        <el-table-column prop="DEPARTURESTATUS" label="出车状态" width="130" />
        <el-table-column prop="DRIVINGCONDITION" label="行车状态" width="130" />
        <el-table-column prop="TRANSPORTVEHICLE" label="运输车辆" width="130" />
        <el-table-column prop="EMPLOYEES" label="从业人员" width="130" />
        <el-table-column prop="CONTACTPHONE" label="联系电话" width="130" />
        <el-table-column prop="WEATHERCONDITION" label="天气预报" width="130" />
        <el-table-column prop="TRANSPORTNATURE" label="运输性质" width="130" />
        <el-table-column prop="DEPARTURETIME" label="发车时间" />
        <el-table-column prop="ARRIVALTIME" label="收车时间" />
        <el-table-column prop="TRANSPORTCOMPANY" label="运输企业" />
        <el-table-column label="操作" width="180">
          <template #default="{ row }">
            <el-button
              type="primary"
              text
              link
              @click="
                router.push({
                  path: '/driving_inspections/driving_log/drivingLog_info',
                  query: {
                    DRIVING_LOG_ID: row.DRIVING_LOG_ID,
                  },
                })
              "
            >
              查看
            </el-button>
            <el-button
              type="primary"
              text
              link
              @click="
                router.push({
                  path: '/driving_inspections/safety_meeting/add',
                })
              "
            >
              添加
            </el-button>
            <el-button
              type="danger"
              text
              link
              @click="deleteItem(row.DRIVING_LOG_ID)"
            >
              删除
            </el-button>
          </template>
        </el-table-column>
      </layout-table>
    </layout-card>
    <edit
      v-model:visible="data.analysisDialog.visible"
      :info="data.analysisDialog.info"
      @get-data="fnResetPagination"
    />
  </div>
</template>

<script setup>
import { serialNumber } from "@/assets/js/utils";
import useListData from "@/assets/js/useListData.js";
import { reactive } from "vue";
import {
  getSafetyDrivingLogList,
  setDrivingLogDelete,
} from "@/request/traffic_driving_log.js";
import router from "@/router/index.js";
import { ElMessage, ElMessageBox } from "element-plus";

const { list, pagination, searchForm, fnGetData, fnResetPagination } =
  useListData(getSafetyDrivingLogList);
const data = reactive({
  analysisDialog: {
    visible: false,
    info: {},
  },
});
// 删除事件
const deleteItem = async (value) => {
  await ElMessageBox.confirm(`确定要删除吗？`, {
    type: "warning",
  });
  await setDrivingLogDelete({ DRIVING_LOG_ID: value });
  ElMessage.success("删除成功");
  fnGetData();
};
</script>

<style scoped></style>
