<!--
  功能：功能描述  移库
  作者：Libra
  邮箱：mingxichen@163.com
  时间：2024年04月11日 11:33:18
  版本：v1.0
  修改记录：
  修改内容：
  修改人员：
  修改时间：/stocked/relocation
-->
<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.SHIPREQUESTNAME">
              <el-Input v-model="queryParams.params.SHIPREQUESTNAME" clearable />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div class="page-search-btns">
        <el-button type="primary" @click="handleQuery">搜索</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>
      <el-table border v-loading="loading" :data="userList" 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" show-overflow-tooltip>
            <template #default="scope">
              <span>{{ scope.row[col.field] }}</span>
            </template>
          </el-table-column>
        </template>
      </el-table>
    </div>
    <!-- 左右结构 -->
    <div class="vue-element-page-table">
      <el-row>
        <el-col :span="11">
          <div class="vue-element-page-table">
            <div class="page-table-operate">
              <div class="page-table-title">
                <div class="page-table-title-left">
                  <span>未分配Box信息</span>
                </div>
                <div class="page-table-title-check">
                  <el-checkbox label="全选" name="type" />
                </div>
                <div class="page-table-title-input">
                  <span>BoxID</span>
                  <el-Input v-model="queryParams.params.RECEIVEREQUESTNAME" style="width: 180px;" />
                </div>
              </div>
            </div>
            <el-table border v-loading="loading" :data="userList" highlight-current-row row-key="id" style="width: 100%">
              <el-table-column type="selection" width="40" />
              <template v-for="(col, index) in column1" :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>
          </div>
        </el-col>
        <el-col :span="2" class="transfer-switch">
          <el-button type="primary"><el-icon>
              <ArrowRight />
            </el-icon></el-button>
          <el-button type="primary"><el-icon>
              <ArrowLeft />
            </el-icon></el-button>
        </el-col>
        <el-col :span="11">
          <div class="vue-element-page-table">
            <div class="page-table-operate">
              <div class="page-table-title">
                <div class="page-table-title-left">
                  <span>已分配Box信息</span>
                </div>
              </div>
            </div>
            <el-table border v-loading="loading" :data="userList" highlight-current-row row-key="id" style="width: 100%">
              <el-table-column type="selection" width="40" />
              <template v-for="(col, index) in column2" :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>
          </div>
        </el-col>
      </el-row>
    </div>

    <el-row class="page-search" justify="end" align="middle">
      <div class="page-search-btns">
        <el-button type="primary" @click="handleReserve">预约</el-button>
      </div>
    </el-row>
  </div>
</template>

<script lang="ts">
export default {
  name: "relocation",
};
</script>

<script lang="ts" setup>
import { reactive, ref, onMounted, toRefs, getCurrentInstance, nextTick } from "vue";
import { ElForm, ElMessageBox, ElTable } from "element-plus";
import { getQueryList } from "@/api/common";
import { useRouter } from "vue-router";
const queryFormRef = ref(ElForm);
const operateFormRef = ref(ElForm);

const formDataRef = ref(ElForm);
const { proxy }: any = getCurrentInstance();

const router = useRouter();

const state = reactive({
  rsa: "",
  queryParams: {
    queryId: "GetCreateBoxList",
    version: "00001",
    params: {
      SITENAME: localStorage.getItem("siteName"),
      RECEIVEREQUESTNAME: "",
      RECEIVEACTNO: "",
      DELIVERYTYPE: "", //移动类型
      SUPPLIERNAME: "",
      SHIPREQUESTNAME: "1234567"
    },
  },
  operateParams: {
    date: new Date(),
  },
  operateOptions: [] as any, // 操作类型
  actNoOptions: [] as any, // 抬头文本
  checkResultOptions: [
    {
      label: "OK",
      value: "OK",
    },
    {
      label: "NG",
      value: "NG",
    },
  ], // 质检结果
  loading: false,
  userList: [] as any,
  column1: [] as any,
  column: [] as any,
  column2: [] as any,
});
const { rsa, queryParams, loading, userList, column, column1, column2, operateParams, operateOptions, actNoOptions, checkResultOptions } = toRefs(state);

onMounted(() => {
  state.column = [
    { header: "工厂", field: "SITENAME", hide: false },
    { header: "行项", field: "SHIPREQUESTDETAILNAME", hide: false },
    { header: "发货单号", field: "SHIPREQUESTNAME", hide: false },
    { header: "物料编号", field: "MATERIALSPECNAME", hide: false },
    { header: "中文描述", field: "DESC_CN", hide: false },
    { header: "批次", field: "CHARGE", hide: false },
    { header: "单位", field: "MATERIALUNIT", hide: false },
    { header: "移动类型", field: "SHIPREQUESTDETAILTYPE", hide: false },
    { header: "请求数量", field: "REQUESTQUANTITY", hide: false },
    { header: "绑定数量", field: "ASSIGNEDQUANTITY", hide: false },
    { header: "物料组", field: "MATERIALGROUP", hide: false },
  ];
  state.column1 = [
    { header: "工厂", field: "MATERIALPACKINGNAME", hide: false },
    { header: "行项", field: "SUPPLIERNAME", hide: false },
    { header: "发货单号", field: "MATERIALSPECNAME", hide: false },
    { header: "物料编号", field: "MATERIALQUANTITY", hide: false },
    { header: "中文描述", field: "LOCATIONNAME", hide: false },
    { header: "批次", field: "MAKEDATE", hide: false },
    { header: "单位", field: "EXPIRINGDATE", hide: false },
    { header: "移动类型", field: "CREATETIME", hide: false },
    { header: "请求数量", field: "SITENAME", hide: false },
  ];
  state.column2 = [
    { header: "BOXID", field: "MATERIALPACKINGNAME", hide: false },
    { header: "物料总数量", field: "MATERIALQUANTITY", hide: false },
    { header: "位置", field: "LOCATIONNAME", hide: false },
    { header: "工厂", field: "SITENAME", hide: false },
    { header: "生成时间", field: "CREATETIME", hide: false },
    { header: "物料类型", field: "MATERIALTYPE", hide: false },
    { header: "物料编号", field: "MATERIALSPECNAME", hide: false },
    { header: "生产日期", field: "MAKEDATE", hide: false },
    { header: "过期时间", field: "EXPIRINGDATE", hide: false },
  ];
});
// 更新列
function updateList(col: any) {
  state.column = col;
}
function handleQuery() {
  let flag = true;
  if (state.queryParams.params.RECEIVEACTNO == "") {
    getQueryList(state.queryParams)
      .then((res: any) => {
        let mpp = res.data;
        if (mpp.LASTEVENTUSER != null && mpp.LASTEVENTUSER != "") {
          if (mpp.LASTEVENTUSER != localStorage.getItem("userName")) {
            ElMessageBox.confirm("工号:" + mpp.LASTEVENTUSER + " 姓名:" + mpp.RECEIVER + " 也在收货" + "\r\n" + "最近作业时间:" + mpp.LASTEVENTTIME + "\r\n" + "请与其确认后再收货", "提示", {
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              type: "warning",
            }).then(() => {
              flag = false;
            });
          }
        }
        if (flag) {

          getViewData();
        }
      })
      .catch(() => { });
  }
}

function getViewData() {
  // 查出该单据下所有的抬头文本
  let queryParams = {
    queryId: "GetActInformationRow",
    version: "00001",
    params: {
      SITENAME: localStorage.getItem("siteName"),
      RECEIVEREQUESTNAME: state.queryParams.params.RECEIVEREQUESTNAME,
    },
  };

  if (state.queryParams.params.RECEIVEREQUESTNAME.trim() === "" && state.queryParams.params.RECEIVEACTNO != "") {
    proxy.$ElMessage.error("请输入或选择查询条件！");
    return;
  }
  if (state.queryParams.params.RECEIVEREQUESTNAME.trim() != "") {
    let queryPar = {
      queryId: "GetInvoiceInformation",
      version: "00001",
      params: {
        SITENAME: localStorage.getItem("siteName"),
        RECEIVEREQUESTNAME: state.queryParams.params.RECEIVEREQUESTNAME,
      },
    };
    getQueryList(queryPar).then((res: any) => {
      let systemType = res.data.SYSTEMTYPE;
      if (systemType != "" && systemType != "ERP") {
        proxy.$ElMessage.warning("该单据是虚拟单据，请确认！！！");
        return;
      }
    });
    // 查询PO Detail
    let queryPar1 = {
      queryId: "GetInvoiceInformation",
      version: "00001",
      params: {
        SITENAME: localStorage.getItem("siteName"),
        RECEIVEREQUESTNAME: state.queryParams.params.RECEIVEREQUESTNAME,
      },
    };
    getQueryList(queryPar1).then((res: any) => { });
  }
}
function resetQuery() {
  queryFormRef.value.resetFields();
  handleQuery();
}

function handleReserve() {
  router.push({
    path: '/material/stockOut/shipRequestConfirm',
    query: {
      SHIPREQUESTNAME: state.queryParams.params.SHIPREQUESTNAME
    }
  })
}
</script>

<style scoped lang="scss">
.operate-bottom {
  width: 80px;
  height: 28px;
  float: right;
  margin-top: 20px;
}
</style>
