<!--
  功能：盘点结果确认
  作者：Libra
  邮箱：mingxichen@163.com
  时间：2024年04月08日 15:45:37
  版本：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="queryFormRefData" :inline="true">
        <el-row :gutter="20">
          <el-col :span="4">
            <el-form-item label="" prop="sheetPlan">
              <CustomInput v-model:params="queryFormRefData.sheetPlan" placeholder="盘点计划名" clearable
                @keydown.enter.prevent="handleQuery" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div class="page-search-btns">
        <el-button type="primary" @click="handleQuery">搜索</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>CheckPlanInfo：</span>
          </div>
        </div>
      </div>
      <el-table border v-loading="checkTableConfig.loading" :data="checkTableConfig.data" highlight-current-row
        row-key="id" style="width: 100%">
        <template v-for="(col, index) in checkTableConfig.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>
        <template v-slot:empty>
          <svg-icon icon-class="noData" width="160px" height="160px" />
        </template>
      </el-table>
      <pagination v-if="queryFormRefData.total > 0" :total="queryFormRefData.total"
        v-model:pageNumTo="queryFormRefData.pageNum" v-model:pageSizeTo="queryFormRefData.pageSize"
        @pagination="handleQuery" />
    </div>
    <el-row class="page-search mt10" justify="space-between" align="middle">
      <div class="page-search-btns">
        <el-button type="primary" @click="SubmitReceive">提交审核</el-button>
        <el-button type="primary" @click="WithDrawReceive">撤回审核</el-button>
      </div>
      <div class="page-search-btns">
        <el-button type="primary" @click="handleRevise">修改</el-button>
        <el-button type="primary" @click="handleSubmit">确认</el-button>
      </div>
    </el-row>

  </div>
</template>

<script lang="ts" setup>
import { reactive, ref, onMounted, toRefs, getCurrentInstance } from "vue";
import { ElForm, ElMessageBox, ElTree } from "element-plus";
import { getQueryPageList, BpelEvent } from "@/api/common/index"
import { IFTRUE } from "@/utils/CommonUtil";
const queryFormRef = ref(ElForm);
const queryFormRefData = reactive({
  sheetPlan: '',
  total: 0,
  pageNum: 1,
  pageSize: 10
})
const checkTableConfig = ref({
  loading: false,
  data: [] as any,
  column: [] as any,
})
onMounted(() => {
  checkTableConfig.value.column = [
    { header: '工厂', field: 'SITENAME', hide: false },
    { header: '计划日期', field: 'PLANDATE', hide: false },
    { header: ' 盘点计划名', field: 'SHEETPLANNAME', hide: false },
    { header: '盘点物料类别', field: 'SHEETMATERIALPLAN', hide: false },
    { header: '盘点方式', field: 'SHEETTYPE', hide: false },
    { header: '物料编号', field: 'MATERIALSPECNAME', hide: false },
    { header: 'ERP库位', field: 'ERPLOCATION', hide: false },
    { header: '计划盘点数量', field: 'PLANQTY', hide: false },
    { header: '实际盘点数量', field: 'ACTQTY', hide: false },
    { header: '差值', field: 'DIFFERENCE', hide: false },
  ]
});
const handleQuery = () => {
  checkTableConfig.value.loading = true
  getQueryPageList({
    queryId: "GetCheckPlanForSDK",
    version: "00001",
    params: {
      CHECKPLANNAME: queryFormRefData.sheetPlan
    },
    pageNum: queryFormRefData.pageNum,
    pageSize: queryFormRefData.pageSize
  }).then((res: any) => {
    checkTableConfig.value.data = res.data.list
    queryFormRefData.total = res.data.total
  }).catch((error: any) => {
    ElMessageBox.alert(error, '提醒框', {
      confirmButtonText: 'OK',
    })
  })
  // setTimeout(() => {
  //   checkTableConfig.value.data = [
  //     {
  //       id: 1,
  //       SITENAME: '工厂1',
  //       PLANDATE: '2023-04-08',
  //       SHEETPLANNAME: '盘点计划1',
  //       SHEETMATERIALPLAN: '物料类别1',
  //       SHEETTYPE: '盘点方式1',
  //       MATERIALSPECNAME: '物料编号1',
  //       ERPLOCATION: 'ERP库位1',
  //       PLANQTY: '10',
  //       ACTQTY: '9',
  //       DIFFERENCE: '1'
  //     }
  //   ]
  //   checkTableConfig.value.loading = false
  // }, 1000);

  checkTableConfig.value.loading = false
}

//提交审核
function SubmitReceive() {
  BpelEvent({
    header: {
      MESSAGENAME: "",
      LANGUAGE: "Chinese"
    },
    body: {

    }
  }).then((res: any) => {
    if (IFTRUE(res)) {
      console.log(res.data)
    } else {
      ElMessageBox.alert(res.data.RETURNCODE + '->' + res.data.RETURNMESSAGE, '', {
        confirmButtonText: 'OK',
      })
    }
  }).catch((error: any) => {
    ElMessageBox.alert(error, '提醒框', {
      confirmButtonText: 'OK',
    })
  })

}
//撤回审核
function WithDrawReceive() {
  BpelEvent({
    header: {
      MESSAGENAME: "",
      LANGUAGE: "Chinese"
    },
    body: {

    }
  }).then((res: any) => {
    if (IFTRUE(res)) {
      console.log(res.data)
    } else {
      ElMessageBox.alert(res.data.RETURNCODE + '->' + res.data.RETURNMESSAGE, '', {
        confirmButtonText: 'OK',
      })
    }
  }).catch((error: any) => {
    ElMessageBox.alert(error, '提醒框', {
      confirmButtonText: 'OK',
    })
  })
}
//修改
function handleRevise() {
  BpelEvent({
    header: {
      MESSAGENAME: "",
      LANGUAGE: "Chinese"
    },
    body: {

    }
  }).then((res: any) => {
    if (IFTRUE(res)) {
      console.log(res.data)
    } else {
      ElMessageBox.alert(res.data.RETURNCODE + '->' + res.data.RETURNMESSAGE, '', {
        confirmButtonText: 'OK',
      })
    }
  }).catch((error: any) => {
    ElMessageBox.alert(error, '提醒框', {
      confirmButtonText: 'OK',
    })
  })
}
//确认
function handleSubmit() {
  BpelEvent({
    header: {
      MESSAGENAME: "",
      LANGUAGE: "Chinese"
    },
    body: {

    }
  }).then((res: any) => {
    if (IFTRUE(res)) {
      console.log(res.data)
    } else {
      ElMessageBox.alert(res.data.RETURNCODE + '->' + res.data.RETURNMESSAGE, '', {
        confirmButtonText: 'OK',
      })
    }
  }).catch((error: any) => {
    ElMessageBox.alert(error, '提醒框', {
      confirmButtonText: 'OK',
    })
  })
}


</script>

<style scoped></style>
