<!-- 入库信息审核 -->
<template>
  <basic-container>
    <el-form :model="formData" label-width="100px" class="whole_form">
      <el-row :gutter="20">
        <el-col :span="6">
          <el-form-item label="库点简称">
            <el-input v-model="formData.warehouse" clearable placeholder="请输入" style="width: 280px" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="入库类型">
            <el-select v-model="formData.inboundType" class="m-2" placeholder="请选择" clearable style="width: 280px">
              <el-option v-for="item in indound_type" :key="item.value" :label="item.label" :value="item.value" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="物资名称">
            <el-input v-model="formData.materialNameVo" clearable placeholder="请输入" style="width: 280px" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-button type="primary" :icon="Search" @click="handleSearch">查询</el-button>
          <el-button :icon="RefreshRight" @click="handleReSearch">清空</el-button>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="6">
          <el-form-item label="审批节点">
            <el-select v-model="formData.status" class="m-2" placeholder="请选择" clearable style="width: 280px">
              <el-option
                v-for="(item, index) in auditing_status"
                :key="index"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <el-table :data="tableData" style="width: 100%" stripe border>
      <el-table-column type="index" label="序号" header-align="center" align="center" width="60" />
      <el-table-column prop="warehouse" label="库点简称" header-align="center" align="center" />
      <el-table-column prop="inboundType" label="出库类型" header-align="center" align="center">
        <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="物资大类" header-align="center" align="center" />
      <el-table-column prop="materialType" label="物资类别" header-align="center" align="center" />
      <el-table-column prop="materialName" label="物资名称" header-align="center" align="center" />
      <el-table-column prop="quantity" label="数量" header-align="center" align="center" />
      <el-table-column prop="inboundTime" label="入库日期" header-align="center" align="center" />
      <el-table-column prop="status" label="当前审批节点" header-align="center" align="center">
        <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="提交时间" header-align="center" align="center">
        <template #default="scope">
          {{ scope.row.submitTime }}
        </template>
      </el-table-column>
      <el-table-column label="操作" header-align="center" width="160">
        <template #default="scope">
          <el-button link type="success" size="small" style="margin-left: 30px" @click="handleShow(scope.row)"
            >查看</el-button
          >
          <el-button
            v-if="
              (deptType == '1' && scope.row.status == '3') ||
              (deptType == '2' && (scope.row.status == '2' || scope.row.status == '6'))
            "
            link
            type="primary"
            size="small"
            @click="handleProcess(scope.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"
      layout="->,total, sizes, prev, pager, next, jumper"
      @pagination="getList"
    />
  </basic-container>
</template>

<script setup lang="ts">
import { reactive, toRefs, onMounted } from "vue";
import { getInAuditList } from "@/api/inAndOut/inAudit/index";
import { getDictItemList } from "@/api/admin/index";
import { Search, RefreshRight } from "@element-plus/icons-vue";
import { useRouter } from "vue-router";
import { useDict } from "@/hooks/dict";

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

const router = useRouter();
const data = reactive({
  tableData: [],
  deptType: ""
});
let page = reactive({
  currentPage: 1,
  pageSize: 10,
  total: 0
});
let formData = reactive({
  warehouse: "",
  inboundType: "",
  materialNameVo: "",
  status: ""
});

let { tableData, deptType } = toRefs(data);

// 获取列表
const getList = () => {
  const data = reactive({
    size: page.pageSize,
    current: page.currentPage,
    params: { ...formData }
  });
  getInAuditList(data).then((res: any) => {
    if (res.code === 0) {
      tableData.value = res.data.records;
      page.total = res.data.total;
    }
  });
};
// 根据码回显中文
const showCh = (value: any, option: any) => {
  const filterItem = option.filter((item: any) => item.value == value);
  return filterItem.length ? filterItem[0].label : "-";
};
// 查询
const handleSearch = () => {
  getList();
};
// 重置
const handleReSearch = () => {
  page = {
    currentPage: 1,
    pageSize: 10,
    total: 0
  };
  formData.warehouse = "";
  formData.inboundType = "";
  formData.materialNameVo = "";
  formData.status = "";
  getList();
};
// 审核
const handleProcess = (row: any) => {
  router.push({
    path: "enterWarehouseAuditDetail",
    query: {
      id: row.inboundId,
      type: "audit"
    }
  });
};
// 查看
const handleShow = (row: any) => {
  router.push({
    path: "enterWarehouseAuditDetail",
    query: {
      id: row.inboundId,
      type: "show"
    }
  });
};

onMounted(() => {
  getList();
  let deptObj: any = sessionStorage.getItem("userInfo");
  deptType = deptObj ? JSON.parse(deptObj).deptType : "";
});
</script>

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