<!-- 应急物资分类表 -->
<template>
  <basic-container>
    <el-form class="whole_form" :inline="true">
      <el-form-item label="姓名">
        <el-input v-model="searchList.name" style="width:200px" clearable />
      </el-form-item>
      <el-form-item>
        <el-button :icon="Search" type="primary" @click="getList">查询</el-button>
        <el-button type="primary" :icon="Plus" @click="openDetail">新增</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="tableData" style="width: 100%" stripe border>
      <el-table-column type="index" label="序号" align="center" width="60">
        <template #default="scope">
          {{ (page.currentPage - 1) * page.pageSize + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column prop="name" label="姓名" align="center" />
      <el-table-column prop="gender" label="性别" align="center">
        <template #default="scope">
          {{ scope.row.gender ? showCh(scope.row.gender, gender) : scope.row.gender }}
        </template>
      </el-table-column>
      <el-table-column prop="idCard" label="身份证号" align="center" />
      <el-table-column prop="phoneNumber" label="联系电话" align="center" />
      <el-table-column prop="drivingLicense" label="驾驶证号" align="center" />
      <el-table-column label="操作" width="150" align="center">
        <template #default="{ row }">
          <el-button link type="success" size="small" @click="openDetail(row, 'look')">查看</el-button>
          <el-button link type="primary" size="small" @click="openDetail(row, 'edit')">编辑</el-button>
          <el-button link type="danger" size="small" @click="deleteClick(row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="page.total > 0"
      v-model:page="page.currentPage"
      v-model:limit="page.pageSize"
      :total="page.total"
      @pagination="getList"
    />
  </basic-container>
</template>

<script setup lang="ts">
import { Plus, Search, RefreshRight } from "@element-plus/icons-vue";
import { ref, reactive } from "vue";
import { getDriverList, deleteDriver } from "@/api/transportationMng";
import router from "@/router";
import { ElMessage } from "element-plus";
import { useDict } from "@/hooks/dict";
import store from "@/store";
import { setQuery } from "@/hooks/detailQuery/index";

const { gender } = useDict(
  "gender"
);

const searchList = ref({
  name: ""
});
const tableData: any = ref([]);
const page = reactive({
  currentPage: 1,
  pageSize: 10,
  total: 0
});
const handleClick = () => {
  console.log("click");
};
// 根据码回显中文
const showCh = (value, option) => {
  const filterItem = option.filter((item) => item.value == value);
  return filterItem.length ? filterItem[0].label : "-";
};

// 清空搜索条件
const clearSearch = () => {
  searchList.value = {
    name: ""
  };
  getList();
};
/** 添加/修改/查看进入详情操作 */
const openDetail = (row: any, type) => {
  setQuery("/transportationMng/driverMngDetail", { id: row.driverId, type: type });
  // router.push({
  //   path: "/InformationFilling/outIssueDetail",
  //   query: {id: row.outboundId, type: type}
  // });
};
/** 列表数据获取 */
const getList = () => {
  console.log(store.state.searchQuery)
  store.commit('SET_SEARCH_QUERY', {
    name: searchList.value.name
  });
  const data = reactive({
    // status: 7,
    lower: 1,
    size: page.pageSize,
    current: page.currentPage,
    ...searchList.value
  });
  getDriverList(data).then((res: any) => {
    if (res.code === 0) {
      tableData.value = res.data.records;
      page.total = res.data.total;
    }
  });
};
/** 删除操作 */
const deleteClick = (row) => {
  deleteDriver(row.driverId).then((res: any) => {
    if (res.code === 0) {
      getList();
      ElMessage({
        message: "删除成功！",
        type: "success"
      });
    }
  });
};
searchList.value = store.state.searchQuery.searchQuery || {}
getList();
</script>

<style lang="scss" scoped></style>
