<!--BOX出入库查询-->
<!--页面渲染区域-->
<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="80px" label-position="left">
        <el-row :gutter="20">
          <el-col :span="6">
              <el-form-item label="批次" prop="params.CHARGE">
                  <el-Input v-model="queryParams.params.CHARGE" clearable />
              </el-form-item>
          </el-col>
          <el-col :span="6" class="col_height">
            <el-form-item label="物料编号" prop="params.MATERIALSPECNAME">
              <el-Input v-model="queryParams.params.MATERIALSPECNAME" placeholder="输入物料编号" clearable />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div class="page-search-btns">
        <el-button type="primary" @click="handleQueryInfo" v-loading="state.loadings">搜索</el-button>
      </div>
    </el-row>
    <!--table 区域-->
    <div class="vue-element-page-table">
      <el-table :height="tableHeight" border v-loading="loading" :data="state.BoxHistoryList" highlight-current-row row-key="id"
        style="width: 100%" >
        <template v-for="(col, index) in Column" :key="index">
          <el-table-column v-if="!col.hide" :label="col.header" :prop="col.field" show-overflow-tooltip>
            <template #default="scope">
              <span v-if="col.field === 'status'">
                <span v-if="scope.row[col.field]" class="table-status-active">启用</span>
                <span v-else class="table-status-inActive">禁用</span>
              </span>
              <span v-else>{{ scope.row[col.field] }}</span>
            </template>
          </el-table-column>
        </template>
        <template v-slot:empty>
          <svg-icon icon-class="noData" width="160px" height="160px" />
        </template>
      </el-table>
      <div>
        <pagination v-if="total > 0" :total="total" v-model:pageNumTo="queryParams.pageNum"
          v-model:pageSizeTo="queryParams.pageSize" @pagination="handleQuery" />
      </div>
    </div>
  </div>
</template>
<script lang="ts">
export default {
  name: 'account'
};
</script>
<!--script区域-->
<script lang="ts" setup>
/*引入区域*/
import { reactive, ref, onMounted, toRefs, getCurrentInstance, h, computed} from "vue";
import { ElForm , ElMessageBox , ElTable } from "element-plus";
import { getQueryList, getQueryPageList ,getQueryAccountPageList} from "@/api/common";
import { msToDate } from '@/utils/CommonUtil';
const { proxy }: any = getCurrentInstance();

import queryListStore from '@/store/modules/queryList'  // 统一查询接口
import { bTableHeight } from "../../../../composables/calcTableHeight";

const { tableContainer, tableHeight, updateTableHeight, handleResize } = bTableHeight(100);

const store: any = queryListStore()
const list = computed(() => store.list)
const storetTotal = computed(() => store.total)
const dataArr = computed(() => store.dataArr)

const queryFormRef = ref(ElForm);
const state = reactive({
  loadings : false,
  queryParams: {
    queryId: "AccountToNC",
    version: "WEB0001",
    params: {
      MATERIALSPECNAME: "",
      CHARGE: ""
    },
    pageNum: 1,
    pageSize: 10,
  },
  queryParamsERPLocation: {
    queryId: "GetErpLocationList",
    version: "WEB00001",
    params: {
      SITENAME: localStorage.getItem("siteName") || 'SDK',
    },
    pageNum: 1,
    pageSize: 10
  },

  page: {
    pageNum: 1,
    pageSize: 15,
    total: 0
  },
  operateParams: {
    date: new Date(),
  },
  Column: [] as any,
  total: 0 as any,
  loading: false,
  BoxHistoryList: [] as any
});
const {
  queryParams,
  Column,
  total,
  loading,
  BoxHistoryList
} = toRefs(state);
/*钩子函数区域*/
onMounted(() => {
  state.Column = [
    // bd_material_v.CODE NC_MATERIALSPECNAME,
    // vfree1 NC_SDK_ID,
    // V_SIZE.NAME NC_SPECNAME,
    // BD_DEFDOC.CODE NC_PHASE,
    // vbatchcode  NC_CHARGE,
    // bd_stordoc.code NC_ERPLOCATION,
    // bd_stordoc.name NC_ERPLOCATIONDESC,
    // bd_rack.code NC_LOCATIONNAME,
    // bd_rack.name NC_LOCATIONNAMEDESC,
    // ic_onhandnum.nonhandnum NC_MATERIALQUANTITY
    { header: "料号(NC)", field: "NC_MATERIALSPECNAME", hide: false },
    { header: "SDK_ID(NC)", field: "NC_SDK_ID", hide: false },
    { header: "规格描述(NC)", field: "NC_SPECNAME", hide: false },
    { header: "阶段(NC)", field: "NC_PHASE", hide: false },
    { header: "批次(NC)", field: "NC_CHARGE", hide: false },
    { header: '库位代码(NC)', field: 'NC_ERPLOCATION', hide: false },
    { header: '库位名称(NC)', field: 'NC_ERPLOCATIONDESC', hide: false },
    { header: '货位代码(NC)', field: 'NC_LOCATIONNAME', hide: false },
    { header: '货位名称(NC)', field: 'NC_LOCATIONNAMEDESC', hide: false },
    { header: '数量(NC)', field: 'NC_MATERIALQUANTITY', hide: false },

    { header: "料号(WMS)", field: "MATERIALSPECNAME", hide: false },
    { header: "SDK_ID(WMS)", field: "SDK_ID", hide: false },
    { header: "规格描述(WMS)", field: "SPECNAME", hide: false },
    { header: "阶段(WMS)", field: "PHASE", hide: false },
    { header: "批次(WMS)", field: "CHARGE", hide: false },
    { header: '库位代码(WMS)', field: 'ERPLOCATION', hide: false },
    { header: '库位名称(WMS)', field: 'ERPLOCATIONDESC', hide: false },
    { header: '货位代码(WMS)', field: 'LOCATIONNAME', hide: false },
    { header: '货位名称(WMS)', field: 'LOCATIONNAMEDESC', hide: false },
    { header: '数量(WMS)', field: 'MATERIALQUANTITY', hide: false },
    { header: '状态(WMS)', field: 'STOCKSTATE', hide: false },
  ];
  updateTableHeight();
  window.addEventListener('resize', handleResize);
});
function handleQueryInfo() {
  state.queryParams.pageNum = 1
  handleQuery()
}
/*列表*/
function handleQuery() {
  state.loadings = true;
  console.log(state.queryParams.params.MATERIALSPECNAME)
  console.log(state.queryParams.params.CHARGE)
  state.BoxHistoryList = []
  if(state.queryParams.params.MATERIALSPECNAME != '' || state.queryParams.params.CHARGE != ''){
    getQueryAccountPageList(state.queryParams).then((res: any) => {
      if(res.data.list.length == 0){
        ElMessageBox.alert('查无此数据', '提醒框', {
          confirmButtonText: 'OK',
        })
        state.loadings = false;
      }else {
        state.BoxHistoryList = res.data.list;
        state.total = res.data.total;
        state.loading = false;
        state.loadings = false;
      }
    });
  } else {
    ElMessageBox.alert('输入条件为空', '提醒框', {
      confirmButtonText: 'OK',
    })
    state.loadings = false;
  }
}
</script>
<!--style 区域-->
<style>
.col_height {
  padding-top: 3.5px;
  padding-bottom: 3.5px;
}
</style>