<!--
  功能：功能描述 货物状态管理
  作者：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">
        <el-row :gutter="20">
          <el-col :span="6">
            <el-form-item label="货位查询" prop="SITENAME">
              <el-Input v-model="state.queryParams.params.STORAGENAME" placeholder="货位查询" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="货位状态" prop="STORAGESTATE">
            <el-select v-model="state.queryParams.params.STORAGESTATE" placeholder="货位状态查询" style="width: 160px">
              <el-option v-for="item in formDataRefData.StateList2" :key="item.LK_CN" :label="item.LK_CN"
                :value="item.LK_CN" />
            </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="库区" prop="AREANAME">
            <el-select v-model="state.queryParams.params.AREANAME" placeholder="库区查询" style="width: 160px" clearable>
              <el-option v-for="item in formDataRefData.AreaList" :key="item.AREANAME" :label="item.AREANAME"
                :value="item.AREANAME" />
            </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div class="page-search-btns">
        <el-button type="primary" @click="queryInfo">搜索</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.locationStatusList" highlight-current-row
        row-key="id" style="width: 100%" @row-click="handle">
        <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 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-form ref="queryFormRef" :model="queryParamsData" :inline="true">
        <el-row :gutter="20">
<!--          <el-col :span="3">-->
<!--            <el-form-item label="工厂" prop="SITENAME">-->
<!--              <el-Input v-model="formDataRefData.SITENAME" placeholder="工厂" clearable />-->
<!--            </el-form-item>-->
<!--          </el-col>-->
<!--          <el-col :span="3">-->
<!--            <el-form-item label="货位" prop="STORAGENAME">-->
<!--              <el-Input v-model="formDataRefData.STORAGENAME" placeholder="货位" clearable />-->
<!--            </el-form-item>-->
<!--          </el-col>-->
          <el-col :span="3">
            <el-select v-model="formDataRefData.ChangeState" placeholder="货位状态" style="width: 160px">
              <el-option v-for="item in formDataRefData.StateList" :key="item.LK_CN" :label="item.LK_CN"
                :value="item.LK_EN" />
            </el-select>
          </el-col>
          <el-col :span="2">
            <el-button type="primary" @click="saveInfo" :disabled="state.disableds" v-loadig="state.loadings">修改</el-button>
          </el-col>
        </el-row>
      </el-form>
     
    </div>
  </div>
</template>
<script lang="ts">
export default {
  name: 'locationStausInfo'
};
</script>
<script lang="ts" setup>
import { reactive, ref, onMounted, toRefs, getCurrentInstance, nextTick } from "vue";
import { getQueryList, getQueryPageList, BpelEvent, BpelEvent2 } from '@/api/common';
import { ElForm, ElMessageBox, ElTable } from "element-plus";
import { bTableHeight } from "../../../../composables/calcTableHeight";

const { tableContainer, tableHeight, updateTableHeight, handleResize } = bTableHeight(240);
const queryFormRef = ref(ElForm);
const formDataRef = ref(ElForm);
const queryParamsData = ref({
  MATERIALSPECNAME: ''
})
const formDataRefData = reactive({
  SITENAME: '',//工厂
  STORAGENAME: '',
  USESTATE: '',
  SITENAMElIST: [{ label: 'A', value: 'a' }],//工厂列表
  StateList: [] as any,//状态列表
  StateList2: [] as any,//状态列表
  AreaList: [] as any,//
  ChangeState: '',//选中的状态
  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: '',//物料类别
})
const materialTableConfig = ref({
  loading: false,
  column: [] as any,
  data: [],
})

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

onMounted(() => {
  materialTableConfig.value.column = [
    { header: "库区", field: "AREANAME", hide: false },
    { header: "货位", field: "STORAGENAME", hide: false },
    { header: "货位状态", field: "LK_CN", hide: false },
    { header: "货位类型", field: "DESCRIPTION", hide: false },
    { header: "货位属性", field: "STORAGEUSETYPE", hide: false },

  ]
  // handleQuery();
  QueryState();
  QueryArea();
  updateTableHeight();
  window.addEventListener('resize', handleResize);
});
const queryInfo = () =>  {
  state.queryParams.pageNum = 1
  handleQuery()
}
const handleQuery = () => {
  console.log(state.queryParams)
  state.locationStatusList = []
   getQueryPageList(state.queryParams)
    .then((res: any) => {
      console.log(res.data);
      if(res.data.list.length == 0){
        ElMessageBox.alert('搜索结果为空', '提示框', {
          confirmButtonText: 'OK'
        })
      } else {
        state.locationStatusList = res.data.list;
        state.total = res.data.total;
      }
    })
    .catch(() => { });
}

const resetQuery = () => {
  queryFormRef.value.resetFields();
}
const updateList = (col: any) => {
  materialTableConfig.value.column = col
}
const buildInfo = () => { }
const editInfo = () => { }
const saveInfo = () => {
  state.disableds = true;
  state.loadings = true;
  BpelEvent({
    header: {
      MESSAGENAME: 'ChangeShelfState',
      LANGUAGE: 'Chinese',
    },
    body: {
      SITENAME: localStorage.getItem('siteName') || 'SDK',
      STORAGE: formDataRefData.STORAGENAME,
      STORAGESTATE: formDataRefData.ChangeState
    }
  }).then((res: any) => {
    if (res.code == '0' || res.code == '500' || res.data == 'UndefinedCode') {
      if (res.success) {
        ElMessageBox.alert('修改成功', '提醒框', {
          confirmButtonText: 'OK',
        })
        state.disableds = false;
        state.loadings = false;
        handleQuery()
      } else {
        ElMessageBox.alert(res.data.msg, '提醒框', {
          confirmButtonText: 'OK',
        })
        state.disableds = false;
        state.loadings = false;
      }
      formDataRefData.SITENAME = ''
      formDataRefData.STORAGENAME = ''
      state.disableds = false;
      state.loadings = false;
    }
  })
}
const exiteInfo = () => {
  formDataRef.value.resetFields()
}

function handle(row: any, event: any, column: any) {
  formDataRefData.SITENAME = row.SITENAME
  formDataRefData.STORAGENAME = row.STORAGENAME

}

function QueryState() {
  getQueryList({
    queryId: "GetStorageState",
    version: "00001",
    params: {
      //SITENAME: localStorage.get("siteName"),
      SITENAME: 'SDK',
    },
  }).then((res: any) => {
    formDataRefData.StateList = res.data
    formDataRefData.StateList.push({ "LK_EN": '', "LK_CN": '' })
    formDataRefData.StateList2 = res.data
    formDataRefData.StateList2.push({ "LK_EN": '', "LK_CN": '' })
  })
}


function QueryArea() {
  getQueryList({
    queryId: "GetArea_forSDK",
    version: "00001",
    params: {
      //SITENAME: localStorage.get("siteName"),
      SITENAME: 'SDK',
    },
  }).then((res: any) => {
    formDataRefData.AreaList = res.data
    formDataRefData.AreaList.push({ "AREANAME": '' })
  })
}
</script>

<style scoped></style>
