<!-- 应急物资分类表 -->
<template>
  <basic-container>
    <el-form class="whole_form" :inline="true">
      <el-form-item label="入库类型">
        <el-select v-model="searchList.inboundType" style="width:200px" clearable>
          <el-option v-for="item in indound_type" :key="item.id" :label="item.label" :value="item.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="物资名称">
        <el-input v-model="searchList.materialNameVo" style="width:200px" clearable />
      </el-form-item>
      <el-form-item>
        <el-button :icon="Search" type="primary" @click="getList">查询</el-button>
        <el-button :icon="RefreshRight" @click="clearSearch">清空</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="inboundType" label="入库类型" align="center" width="100">
        <template #default="scope">
          {{ scope.row.inboundType ? showCh(scope.row.inboundType, indound_type) : scope.row.inboundType }}
        </template>
      </el-table-column>
      <el-table-column prop="materialGroup" label="物资大类" align="center" width="100" />
      <el-table-column prop="materialType" label="物资类别" align="center" />
      <el-table-column prop="materialName" label="物资名称" align="center" />
      <el-table-column prop="quantity" label="数量" align="center" width="80" />
      <el-table-column prop="inboundTime" label="入库日期" align="center" width="115" />
      <el-table-column prop="isAvailable" label="是否可用" align="center" width="100">
        <template #default="scope">
          {{ scope.row.isAvailable ? showCh(scope.row.isAvailable, is_available) : scope.row.isAvailable }}
        </template>
      </el-table-column>
      <el-table-column prop="status" label="状态" align="center" width="75">
        <template #default="scope">
          {{ scope.row.status ? showCh(scope.row.status, auditing_status) : scope.row.status }}
        </template>
      </el-table-column>
      <el-table-column prop="submitTime" label="提交时间" align="center" width="175" />
      <el-table-column fixed="right" label="操作" width="150" align="center">
        <template #default="{ row }">
          <el-button link type="success" size="small" @click="openDetail(row, 'look')">查看</el-button>
          <el-button link v-if="row.status == 1" type="primary" size="small" @click="openDetail(row, 'edit')"
            >编辑</el-button
          >
          <el-button link v-if="row.status == 1" 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, onMounted } from "vue";
import { getInPage, deleteInData } from "@/api/inAndOut/formationFilling/in";
import router from "@/router";
import { ElMessage } from "element-plus";
import { useDict } from "@/hooks/dict";
import { setQuery } from "@/hooks/detailQuery/index";

const { indound_type, is_available, auditing_status } = useDict("indound_type", "is_available", "auditing_status");

const searchList = ref({
  inboundType: "",
  materialNameVo: ""
});
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 = {
    inboundType: "",
    materialNameVo: ""
  };
  getList();
};
/** 添加/修改/查看进入详情操作 */
const openDetail = (row: any, type) => {
  setQuery("/InformationFilling/enterWarehouseInfoDetail", { id: row.inboundId, type: type });
  // router.push({
  //   path: "/InformationFilling/enterWarehouseInfoDetail",
  //   query: {id: row.inboundId, type: type}
  // });
};
/** 列表数据获取 */
const getList = () => {
  const data = reactive({
    size: page.pageSize,
    current: page.currentPage,
    ...searchList.value
  });
  getInPage(data).then((res: any) => {
    if (res.code === 0) {
      tableData.value = res.data.records;
      page.total = res.data.total;
    }
  });
};
/** 删除操作 */
const deleteClick = (row) => {
  deleteInData(row.inboundId).then((res: any) => {
    if (res.code === 0) {
      getList();
      ElMessage({
        message: "删除成功！",
        type: "success"
      });
    }
  });
};
/** 初始化 **/
onMounted(() => {
  getList();
});
</script>

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