<!-- 出库信息审核 -->
<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.outboundType" class="m-2" placeholder="请选择" clearable style="width: 280px">
              <el-option v-for="item in outdound_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-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="outboundType" label="出库类型" header-align="center" 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="物资大类" 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="calledProvince" label="调用省份" header-align="center" 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="出库日期" 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 { ref, reactive, toRefs, onMounted } from "vue";
import { getInAuditList } from "@/api/inAndOut/outAudit/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";
import { useGetters } from "@/hooks/storeHooks";
import store from "@/store";
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 { userInfo } = useGetters(["userInfo"]);

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

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

// 获取列表
const getList = () => {
  console.log(store.state.searchQuery);
  store.commit("SET_SEARCH_QUERY", {
    outAudit: {
      outboundType: formData.value.outboundType,
      materialNameVo: formData.value.materialNameVo,
      status: formData.value.status,
      warehouse: formData.value.warehouse
    }
  });
  const data = reactive({
    size: page.pageSize,
    current: page.currentPage,
    params: { ...formData.value }
  });
  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.value.outboundType = "";
  formData.value.materialNameVo = "";
  formData.value.status = "";
  formData.value.warehouse = "";
  getList();
};
// 审核
const handleProcess = (row: any) => {
  // router.push({
  //   path: "outWarehouseAuditDetail",
  //   query: {
  //     id: row.outboundId,
  //     type: "audit"
  //   }
  // });
  setQuery("outWarehouseAuditDetail", { id: row.outboundId, type: "audit" });
};
// 查看
const handleShow = (row: any) => {
  // router.push({
  //   path: "outWarehouseAuditDetail",
  //   query: {
  //     id: row.outboundId,
  //     type: "show"
  //   }
  // });
  setQuery("outWarehouseAuditDetail", { id: row.outboundId, type: "show" });
};

onMounted(() => {
  formData.value = store.state.searchQuery.searchQuery.outAudit || {};
  getList();
  deptType = userInfo.value.deptType ? userInfo.value.deptType : "";
});
</script>

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