<!--
  功能：功能描述 货位信息
  作者：Libra
  邮箱：mingxichen@163.com
  时间：2024年04月08日 15:46:01
  版本：v1.0
  修改记录：
  修改内容：
  修改人员：liwenhu
  修改时间：2024/04/15
-->
<template>
  <div class="vue-element-page-wrap" ref="tableContainer">
    <el-row class="page-search" justify="space-between" align="middle">
      <el-form ref="queryFormRef" :model="queryParamsData" :inline="true" @submit.native.prevent>
        <el-row :gutter="20">
          <!-- <el-col :span="4">
            <el-form-item label="组织" prop="params.RECEIVEREQUESTNAME">
              <el-Input v-model="state.queryParams.params.ERPFACTORY" placeholder="组织" v-on:keyup.enter="queryInfo"
                clearable />
            </el-form-item>
          </el-col> -->
          <el-col :span="4">
            <el-form-item label="仓库" prop="params.RECEIVEREQUESTNAME">
              <el-Input v-model="state.queryParams.params.ERPLOCATION" placeholder="仓库" v-on:keyup.enter="queryInfo"
                clearable />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="货位查询" prop="params.RECEIVEREQUESTNAME">
              <el-Input v-model="state.queryParams.params.STORAGENAME" placeholder="货位查询" v-on:keyup.enter="queryInfo"
                clearable />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="货位名称查询" prop="params.RECEIVEREQUESTNAME">
              <el-Input v-model="state.queryParams.params.DESCRIPTION" placeholder="货位名称查询"
                v-on:keyup.enter="queryInfo" clearable />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div class="page-search-btns">
        <el-button type="primary" @click="queryInfo" :disabled="state.disableds" v-loadig="state.loadings">搜索</el-button>
        <el-button @click="resetQuery">重置</el-button>
      </div>
    </el-row>

    <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 class="page-table-operateBtns">
          <el-popover :persistent="false" placement="right" popper-class="config-table-wrap" trigger="click">
            <template #reference>
              <el-button class="operateBtns-setting">
                <svg-icon icon-class="table_title" width="16px" height="16px" />
              </el-button>
            </template>
            <ConfigTable :list="materialTableConfig.column" @updateList="updateList" />
          </el-popover>
        </div>
      </div>
      <el-table border :height="tableHeight" v-loading="materialTableConfig.loading" :data="state.wareHouseList" highlight-current-row
        row-key="id" style="width: 100%">
        <template v-for="(col, index) in materialTableConfig.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>
      <pagination v-if="total > 0" :total="total" v-model:pageNumTo="queryParams.pageNum"
        v-model:pageSizeTo="queryParams.pageSize" @pagination="handleQuery" />
    </div>
  </div>
</template>
<script lang="ts">
export default {
  name: "wareHouseLocation",
};
</script>
<script lang="ts" setup>
import { reactive, ref, onMounted, toRefs, getCurrentInstance, nextTick } from "vue";
import { ElForm, ElMessageBox, ElTable } from "element-plus";
import { getQueryPageList, BpelEvent } from '@/api/common';
import { bTableHeight } from "../../../../composables/calcTableHeight";

const { tableContainer, tableHeight, updateTableHeight, handleResize } = bTableHeight(180);
const queryFormRef = ref(ElForm);
const formDataRef = ref(ElForm);
const queryParamsData = ref({
  MATERIALSPECNAME: ''
})
const formDataRefData = ref({
  SITENAME: 'SDK',
  F: [{ label: 'A', value: 'a' }],
  S: [{ label: 'A', value: 'a' }],
  Y: [{ label: 'A', value: 'a' }],
  X: [{ label: 'A', value: 'a' }],
  Z: [{ label: 'A', value: 'a' }],
  STORAGEOPERATIONTYPE: [{ label: 'A', value: 'a' }],//库位操作类型
  CAPACITY: '',//容量
  USESTATE: '',//库位使用状态
  RESOURCESTATE: '',//资源状态
  RESPPERSON: '',//责任人
  STORAGENAME: '',//库位名称
})


const materialTableConfig = ref({
  loading: false,
  column: [] as any,
  data: [],
})




/***---------------------------------------------------------------------------
 * -------------------------------------页面SQL语句配置------------------------------------------ */
const state = reactive({
  disableds : false,
  loadings : false,
  rsa: '',
  DBProcessType: 'save',
  queryParams: {
    queryId: 'GetSTORAGEList',
    version: '00001',
    params: {
      SITENAME: 'SDK',
      ERPFACTORY: '',
      ERPLOCATION: '',
      STORAGENAME: '',
      STORAGEOPERATIONTYPE: 'Manual',
      DESCRIPTION: '',
    },
    pageNum: 1,
    pageSize: 10
  },
  ChangeParams: {
    header: {
      MESSAGENAME: '',
      LANGUAGE: 'Chinese',
    },
    body: {
      ERPFACTORY: '',
      ERPLOCATION: '',
      SITENAME: 'SDK',
      DESCRIPTION: '',
      USESTATE: '',//库位使用状态
      RESOURCESTATE: '',//资源状态
      RESPPERSON: '',//责任人
      STORAGENAME: '',//库位名称
    }
  },
  wareHouseList: [] as any,
  total: 0
})

const {
  rsa,
  queryParams,
  total,

} = toRefs(state);

/***---------------------------------------------------------------------------
 * -------------------------------------钩子函数区域------------------------------------------ */
onMounted(() => {
  materialTableConfig.value.column = [
    { header: "组织", field: "ERPFACTORY", hide: false },
    { header: "组织(CN)", field: "ORGNAME", hide: false },
    { header: "仓库", field: "ERPLOCATION", hide: false },
    { header: "仓库(CN)", field: "ERPLOCATIONNAME", hide: false },
    { header: "货位编码", field: "STORAGENAME", hide: false },
    { header: "货位描述", field: "DESCRIPTION", hide: false },
  ]
  let pwd: any = localStorage.getItem('remeberPwd');
  state.queryParams.params.ERPFACTORY = JSON.parse(localStorage.getItem('orgNo')) || '';
  handleQuery();
  updateTableHeight();
  window.addEventListener('resize', handleResize);
});
const queryInfo = () =>  {
  state.queryParams.pageNum = 1
  handleQuery()
}
const handleQuery = () => {
  console.log(queryParamsData.value);
  state.disableds = true;
  state.loadings = true;
  state.wareHouseList = [];
  getQueryPageList(state.queryParams)
    .then((res: any) => {
      if(res.data.list.length == 0){
        ElMessageBox.alert('查无数据', '提醒框', {
          confirmButtonText: 'OK',
        })
        state.disableds = false;
        state.loadings = false;
      } else {
        console.log(res.data);
        state.wareHouseList = res.data.list;
        state.total = res.data.total;
        state.disableds = false;
        state.loadings = false;
      }
    })
    .catch(() => { });
}

const resetQuery = () => {
  queryFormRef.value.resetFields();
  state.queryParams.params.ERPFACTORY = '';
  state.queryParams.params.ERPLOCATION = '';
  state.queryParams.params.STORAGENAME = '';
  state.queryParams.params.DESCRIPTION = '';
}
const updateList = (col: any) => {
  materialTableConfig.value.column = col
}
const buildInfo = () => { state.DBProcessType = 'Insert' }
const editInfo = () => { state.DBProcessType = 'Update' }
/* 功能：保存修改/创建信息 
   参数：ChangeParams
   时间：:2024-4-24
   作者：李文虎
*/
const saveInfo = () => {
  if (state.DBProcessType == 'Insert') {
    state.ChangeParams.header.MESSAGENAME = 'CreateMaterialSpec'
  } else if (state.DBProcessType == 'Update') {
    state.ChangeParams.header.MESSAGENAME = 'ModifyMaterialSpec'
  }
  BpelEvent(state.ChangeParams).then((res: any) => {

  })
    .catch(() => { });
}
const exiteInfo = () => {
  formDataRef.value.resetFields()
}
</script>

<style scoped></style>
