<!-- 应急物资分类表 -->
<template>
  <basic-container>
    <el-form class="whole_form" :inline="true">
      <el-form-item label="出库类型">
        <el-select v-model="searchList.outboundType" style="width:200px" clearable>
          <el-option v-for="item in outdound_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="outboundType" label="出库类型" align="center">
        <template #default="scope">
          {{ scope.row.outboundType ? showCh(scope.row.outboundType, outdound_type) : scope.row.outboundType }}
        </template>
      </el-table-column>
      <el-table-column prop="materialGroup" label="物资大类" align="center" />
      <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="calledProvince" label="调用省份" align="center">
        <template #default="scope">
          {{ scope.row.calledProvince ? showCh(scope.row.calledProvince, province_ch) : scope.row.calledProvince }}
        </template>
      </el-table-column>
      <el-table-column prop="outboundTime" label="出库日期" align="center" width="115" />
      <el-table-column prop="submitTime" label="填写时间" align="center" width="115" />
      <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 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, onMounted } from "vue";
import { getOutPage, deleteOutData } from "@/api/inAndOut/formationFilling/out";
import router from "@/router";
import { ElMessage } from "element-plus";
import { useDict } from "@/hooks/dict";
import { setQuery } from "@/hooks/detailQuery/index";

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

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

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