<!--待入库看板-->
<!--页面渲染区域-->
<template>
  <div class="vue-element-page-wrap" ref="tableContainer">
    <el-row class="page-search" justify="space-between" align="bottom">
      <el-form ref="queryFormRef" :model="queryParams" :inline="true" label-width="100px" label-position="left">
        <el-row :gutter="20">
          <el-col :span="5">
            <el-form-item label="未入库数量" prop="params.sumNoStock">
              <el-Input v-model="queryParams.params.sumNoStock" disabled clearable />
            </el-form-item>
          </el-col>
<!--          <el-col :span="1"></el-col>-->
<!--          <el-col :span="5"  >-->
<!--            <el-form-item label="未上架数量" prop="params.sumNoLocation">-->
<!--              <el-Input v-model="queryParams.params.sumNoLocation" disabled clearable />-->
<!--            </el-form-item>-->
<!--          </el-col>-->
          <el-col :span="1"></el-col>
          <el-col :span="5"  >
            <el-form-item label="料号" prop="params.materialspecName">
              <el-Input v-model="queryParams.params.materialspecName"  clearable />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div class="page-search-btns">
        <el-button type="primary" @click="handleQueryInfo">搜索</el-button>
      </div>
    </el-row>
    <!--table 区域-->
    <div class="vue-element-page-table">
      <div class="page-table-operate">
        <div class="page-table-title">
          <div class="page-table-title-left">
            <span>物料信息列表</span>
          </div>
        </div>
      </div>
      <el-table border v-loading="loading" :data="MaterialList" highlight-current-row row-key="id" style="width: 100%;min-height: 200px;"
       @row-click="BoxListActive">
        <template v-for="(col, index) in Column" :key="index">
          <el-table-column v-if="!col.hide" :label="col.header" show-overflow-tooltip>
            <template #default="scope">
              <span>{{ scope.row[col.field] }}</span>
            </template>
          </el-table-column>
        </template>
      </el-table>
    </div>

    <div class="vue-element-page-table">
      <div class="page-table-operate">
        <div class="page-table-title">
          <div class="page-table-title-left">
            <span>批次信息</span>
          </div>
        </div>
      </div>
      <el-table border v-loading="loading" :data="BoxDetailList" highlight-current-row row-key="id" style="width: 100%"
      :height="tableHeight">
        <template v-for="(col, index) in Column1" :key="index">
          <el-table-column v-if="!col.hide" :label="col.header" show-overflow-tooltip>
            <template #default="scope">
              <span>{{ scope.row[col.field] }}</span>
            </template>
          </el-table-column>
        </template>
      </el-table>
    </div>
  </div>
</template>
<script lang="ts">
export default {
  name: 'materialPreStockedQuery'
};
</script>
<!--script区域-->
<script lang="ts" setup>
/*引入区域*/
import { reactive, ref, onMounted, toRefs, getCurrentInstance, nextTick } from "vue";
import { ElForm, ElMessageBox, ElTable } from "element-plus";
import { getQueryList, getQueryPageList } from "@/api/common";
import { msToDate } from '@/utils/CommonUtil';
import { bTableHeight } from "../../../../composables/calcTableHeight";

const { tableContainer, tableHeight, updateTableHeight, handleResize } = bTableHeight(330);
/*对象生成赋值区域*/

const queryFormRef = ref(ElForm);
const size = ref<'default' | 'large' | 'small'>('small');//formdata时间设置
const state = reactive({
  queryParams: {
    queryId: "GetPreStockedList",
    version: "WEB10001",
    params: {
      SITENAME: localStorage.getItem("siteName") || 'SDK',
      //显示部分
      sumNoStock: 0,
      sumNoLocation: 0,
      materialspecName : ''
    },
    pageNum: 1,
    pageSize: 10
  },
  queryParamsActivate: {
    queryId: "PRESTOCKED",
    version: "WEB11111",
    params: {
      SITENAME: localStorage.getItem("siteName") || 'SDK',
      ERPLOCATION: '',
      ERPFACTORY: '',
      MATERIALSPECNAME: '',
      RECEIVEREQUESTNAME: '',
    }
  },
  Column: [] as any,
  total: 0,
  loading: false,
  BoxHistoryList: [] as any,
  ERPFactoryList: [] as any,
  ERPLocationList: [] as any,
  MaterialList: [] as any,
  ProcessGroupNameList: [] as any,
  Column1: [] as any,
  BoxDetailList: [] as any
});
const {
  queryParams,
  Column,
  total,
  loading,
  BoxHistoryList,
  MaterialList,
  ERPFactoryList,
  ERPLocationList,
  ProcessGroupNameList,
  Column1,
  BoxDetailList
} = toRefs(state);
//时间范围定义

/*钩子函数区域*/
onMounted(() => {
  state.Column = [
    { header: "物料编号", field: "MATERIALSPECNAME", hide: false },
    { header: "品名", field: "DESC_CN", hide: false },
    { header: "到货单", field: "RECEIVEREQUESTNAME", hide: false },
    // { header: "未分配库位数量", field: "UNLOCATIONQTY", hide: false },
    { header: "未入库数量", field: "UNSTOCKINQTY", hide: false },
    { header: "单位", field: "FNAME", hide: false },
    { header: "仓库", field: "ERPLOCATION", hide: true },
    { header: "组织", field: "ERPFACTORY", hide: true },
    { header: "仓库", field: "ERPLOCATIONDESC", hide: false },
    { header: "组织", field: "ERPFACTORYDESC", hide: false },
    // { header: "生产日期", field: "MAKEDATE", hide: false },
    // { header: "订单行项", field: "RECEIVEREQUESTDETAILNAME", hide: false },
    // { header: "到货单", field: "RECEIVEREQUESTNAME", hide: false },
    { header: "供应商名称", field: "SUPPLIERNAME", hide: false },
  ];
  state.Column1 = [
    { header: "标签", field: "MATERIALPACKINGNAME", hide: false },
    { header: "批次", field: "CHARGE", hide: false },
    { header: "物料总数量", field: "MATERIALQUANTITY", hide: false },
    { header: "最后的操作时间", field: "LASTEVENTTIME", hide: false },
    { header: "最后的操作人员", field: "LASTEVENTUSER", hide: false },
    { header: "最后操作事件", field: "LASTEVENTNAME", hide: false },
  ];
  InAdvanceQuery();
  updateTableHeight();
  window.addEventListener('resize', handleResize);
});
/*其它函数区域*/
function handleQueryInfo() {
  state.queryParams.pageNum = 1
  InAdvanceQuery()
}
//提前查询数量
function InAdvanceQuery() {
  getQueryList(state.queryParams)
    .then((res: any) => {
      state.MaterialList = res.data;
      if (res.data.length > 0) {
        state.queryParams.params.sumNoStock = 0;
        state.queryParams.params.sumNoLocation = 0;
        for (let i = 0; i < res.data.length; i++) {
          state.queryParams.params.sumNoStock += (res.data[i].UNSTOCKINQTY != "" ? res.data[i].UNSTOCKINQTY : "0")
          state.queryParams.params.sumNoLocation += ((res.data[i].UNLOCATIONQTY != null && res.data[i].UNLOCATIONQTY != "") ? res.data[i].UNLOCATIONQTY : 0);
        }
      } else {

        ElMessageBox.alert('查无数据', '提醒框', {
          confirmButtonText: 'OK',
        })
      }
    })
    .catch(() => { });
}

function BoxListActive(row: any, event: any, column: any) {
  state.queryParamsActivate.params.ERPFACTORY = row.ERPFACTORY;
  state.queryParamsActivate.params.ERPLOCATION = row.ERPLOCATION;
  state.queryParamsActivate.params.MATERIALSPECNAME = row.MATERIALSPECNAME;
  state.queryParamsActivate.params.RECEIVEREQUESTNAME = row.RECEIVEREQUESTNAME;
  getQueryList(state.queryParamsActivate)
    .then((res: any) => {
      state.BoxDetailList = res.data;
    })
    .catch(() => { });
}

</script>
<!--style 区域-->
<style></style>