<!--
  功能：库区信息
  作者：李文虎
  邮箱：1439135148@qq.com
  时间：2024年05月10日 13:27:29
  版本：v1.0
  修改记录：
  修改内容：
  修改人员：
  修改时间：
-->
<template>
  <div class="vue-element-page-wrap" ref="tableContainer">
    <el-row class="page-search" justify="space-between" align="middle">
      <el-form ref="queryFormRef" :model="state.queryParams.params" :inline="true">
        <el-row :gutter="20">
          <el-col :span="6">
            <el-form-item label="库区名称" prop="MATERIALSPECNAME">
              <el-Input v-model="state.queryParams.params.AREANAME" placeholder="库区名称" clearable />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div class="page-search-btns">
        <el-button type="primary" @click="queryInfo">搜索</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 :height="tableHeight" border v-loading="materialTableConfig.loading" :data="state.wareAreaList" 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="state.total > 0" :total="state.total" v-model:pageNumTo="state.queryParams.pageNum"
        v-model:pageSizeTo="state.queryParams.pageSize" @pagination="handleQuery" />
    </div>
  </div>
</template>
<script lang="ts">
export default {
  name: "wareAreaInfo",
};
</script>
<script lang="ts" setup>
import { reactive, ref, onMounted, toRefs, getCurrentInstance, nextTick } from "vue";
import { ElForm, ElMessageBox, ElTable } from "element-plus";
import { getQueryList, 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 formDataRefData = ref({
  SITENAME: '',//工厂
  SITENAMElIST: [{ label: 'A', value: 'a' }],//工厂列表
  MATERIALSPECNAME: '',//物料编号
  MATERIALSPECDESCRIPTION: '',//物料描述
  CHECKSTATE: '',//check state
  CHECKSTATELIST: [{ label: 'A', value: 'a' }],//check state列表
  ERPLOCATION: '',//ERP库位
  MATERIALTYPE: '',//物料类型
  MATERIALLIFEMARK: '',//寿命管理标记
  MATERIALGROUP: '',//物料组
  DESC_CN: '',//中文描述
  DESC_EN: '',//英文描述
  EXPIRINGDATE: '',//过期时间
  STOCKDATE: '',//入库有效期
  MATERIALGROUPDESCRIPTION: '',//物料组描述
  MATERIALUNIT: '',//单位
  MATERIALWEIGHT: '',//物料重量
  ERPFACTORY: '',//ERP工厂
  MATERIALSPECTYPE: '',//物料类别
})

/***---------------------------------------------------------------------------
 * -------------------------------------页面SQL语句配置------------------------------------------ */
const state = reactive({
  rsa: '',
  DBProcessType: 'save',
  queryParams: {
    queryId: 'GetWareAreaInfo',
    version: '00003',
    params: {
      AREANAME: '',
      SITENAME: 'SDK',
    },
    pageNum: 1,
    pageSize: 10
  },
  ChangeParams: {
    header: {
      MESSAGENAME: '',
      LANGUAGE: 'Chinese',
    },
    body: {
      IS_STORAGE: '',
      IS_OEM: '',
      ERPLOCATIONNAME: '',
      IN_USE: '',
      ERPFACTORYNAME: '',
      INRATIO: '',
      OUTRATIO: '',
      IS_CON_TEMP: '',
      DESCRIPTION: '',
      MATERIALSPECNAME: '',
      SITENAME: 'SDK',
      MATERIALSPECDESCRIPTION: '',
      CHECKSTATE: '',
      MATERIALSPECTYPE: '',
      MAKEDATE: '',
      MAKEUSER: '',
      DESC_CN: '',
      DESC_EN: '',
      MATERIALTYPE: '',
      MATERIALGROUP: '',
      MATERIALGROUPDESCRIPTION: '',
      MATERIALUNIT: '',
      MATERIALWEIGHT: '',
      ERPFACTORY: '',
      ERPLOCATION: '',
      MATERIALLIFEMARK: '',
      EXPIRINGDATE: '',
      STOCKDATE: '',
    }
  },
  wareAreaList: [] as any,
  total: 0,
  loading: false,
  dialog: {
    title: '新增用户',
    visible: false
  },

  formData: {
    SUPPLIERNO: '',
    SUPPLIERNAME: '',
    NATIONALNO: '',
    DESCRIPTION: '',
    ADDRESS: '',
    POSTCODE: '',
    CITY: '',
    TEL: '',
    FAX: '',
    INCHARGE: '',
    EMAIL: '',
    LASTEVENTTIME: '',
  } as any,
  column: [] as any,
  selectItem: undefined as any,
  currentTime: '',
  allRole: [] as any

})

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

/***---------------------------------------------------------------------------
 * -------------------------------------钩子函数区域------------------------------------------ */
onMounted(() => {
  materialTableConfig.value.column = [
    { header: "库区", field: "AREANAME", hide: false },
    { header: "仓库名称", field: "DESCRIPTION", hide: false },
    // { header: "上级库区", field: "SUPERAREANAME", hide: false },
    // { header: "库位状态", field: "RESOURCESTATE", hide: false },

  ]
  // 初始化时调用 handleQuery  
  handleQuery();
  updateTableHeight();
  window.addEventListener('resize', handleResize);
});
const queryInfo = () =>  {
  state.queryParams.pageNum = 1
  handleQuery()
}
const handleQuery = () => {
  state.wareAreaList = []
  getQueryPageList(state.queryParams)
    .then((res: any) => {
      console.log(res.data);
      state.wareAreaList = res.data.list;
      state.total = res.data.total;
    })
    .catch(() => { });
}

const resetQuery = () => {
  state.queryParams.params.AREANAME = '';
  queryFormRef.value.resetFields();
}
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>
