<!--
  功能：仓库信息
  作者：李文虎
  邮箱：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" @submit.native.prevent>
        <el-row :gutter="20">
          <el-col :span="6" class="col_height">
            <el-form-item label="仓库编码" prop="MATERIALSPECNAME">
              <el-Input v-model="state.queryParams.params.ERPLOCATIONNAME" placeholder="仓库编码"
                v-on:keyup.enter="queryInfo" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="6" class="col_height">
            <el-form-item label="仓库名称" prop="DESCRIPTION">
              <el-Input v-model="state.queryParams.params.DESCRIPTION" placeholder="仓库名称" v-on:keyup.enter="queryInfo"
                clearable />
            </el-form-item>
          </el-col>
          <el-col :span="6" class="col_height">
            <el-form-item label="是否货位管理" prop="DESCRIPTION">
              <el-select v-model="queryParams.params.USE_LOCATION" placeholder="是否货位管理" style="width: 240px"
                default-first-option>
                <el-option v-for="item in formDataRefData.Use_LocationList" :key="item.value" :label="item.label"
                  :value="item.value" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6" class="col_height">
            <el-form-item label="是否恒温恒湿" prop="DESCRIPTION">
              <el-select v-model="queryParams.params.CONST_TEMP" placeholder="是否恒温恒湿" style="width: 240px"
                default-first-option>
                <el-option v-for="item in formDataRefData.TEMPList" :key="item.value" :label="item.label"
                  :value="item.value" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6" class="col_height" >
            <el-form-item label="是否自动备货" prop="DESCRIPTION">
              <el-select v-model="queryParams.params.ZDBHFLAG" placeholder="是否自动备货" style="width: 240px"
                default-first-option>
                <el-option v-for="item in formDataRefData.MRPList" :key="item.value" :label="item.label"
                  :value="item.value" />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div class="page-search-btns">
        <el-button type="primary" @click="queryInfo"  :disabled="state.disableds" v-loading="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: "wareHouse",
};
</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(190);

const queryFormRef = ref(ElForm);
const formDataRef = ref(ElForm);

const formDataRefData = ref({
  SITENAME: '',//工厂
  MRPList: [{ label: '全部', value: '' },{ label: '是', value: 'Y' }, { label: '否', value: 'N' }] as any,
  TEMPList: [{ label: '全部', value: '' },{ label: '是', value: 'Y' }, { label: '否', value: 'N' }] as any,
  Use_LocationList: [{ label: '全部', value: '' }, { label: '是', value: 'Y' }, { label: '否', value: 'N' }] as any,
  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({
  loadings : false,
  disableds : false,
  rsa: '',
  DBProcessType: 'save',
  queryParams: {
    queryId: 'GetERPLocation',
    version: '00001',
    params: {
      ERPLOCATIONNAME: '',
      USE_LOCATION: '',
      USE_MRP: '',
      CONST_TEMP: '',
      SITENAME: 'SDK',
      DESCRIPTION: '',
      ZDBHFLAG : '',
    },
    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: '',
    }
  },
  total: 0,
  loading: false,
  wareHouseList: [] as any,
  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: [],
})

const {
  rsa,
  queryParams,
  total,
  loading,
  dialog,
  formData,
  column,
  selectItem,
  currentTime,
  allRole
} = toRefs(state);

/***---------------------------------------------------------------------------
 * -------------------------------------钩子函数区域------------------------------------------ */
onMounted(() => {
  materialTableConfig.value.column = [
    { header: "组织", field: "ERPFACTORYNAME", hide: false },
    { header: "组织(CN)", field: "ORGNAME", hide: false },
    { header: "仓库", field: "ERPLOCATIONNAME", hide: false },
    { header: "仓库(CN)", field: "DESCRIPTION", hide: false },
    // { header: "启用状态", field: "IN_USE", hide: false },
    // { header: "委外标志", field: "IS_OEM", hide: false },
    { header: "是否恒温仓", field: "CONST_TEMP", hide: false },
    { header: "是否货位管理", field: "USE_LOCATION", hide: false },
    { header: "是否自动备货", field: "ZDBHFLAG", hide: false },
    { header: "是否熟化", field: "IS_OVEN", hide: false },
    // { header: "熟化时间", field: "USE_MRP", hide: false },
  ]
  // 初始化时调用 handleQuery  
  handleQuery();
  updateTableHeight();
  window.addEventListener('resize', handleResize);
});
const queryInfo = () =>  {
  state.queryParams.pageNum = 1
  handleQuery()
}
const handleQuery = () => {
  state.disableds = true;
  state.loadings = true;
  state.wareHouseList = [];
   getQueryPageList(state.queryParams)
    .then((res: any) => {
      console.log(res.data);
      if(res.data.list.length == 0){
        ElMessageBox.alert('查无此数据', '提醒框', {
          confirmButtonText: 'OK',
        })
        state.disableds = false;
        state.loadings = false;
      } else {
        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.ERPLOCATIONNAME = '';
  state.queryParams.params.USE_LOCATION = '';
  state.queryParams.params.CONST_TEMP = '';
  state.queryParams.params.USE_MRP = '';
}
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 == 'save') {
    ElMessageBox.alert('保存操作之前，请先创建或修改', '提醒框', {
      confirmButtonText: 'OK',
    })
  } else {
    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>
.col_height {
  padding-top: 3.5px;
  padding-bottom: 3.5px;
}
</style>
