<template>
  <div>
    <layout>
      <layout-header>
        <div class="">
          <h1 style="margin: 0%;margin-bottom: 10px;">出库报工</h1>
          <el-input v-model="add_searchInfo" placeholder="扫描订单二维码获取订单信息" 
			  				  @keyup.enter="add_onSubmit"
							  id="searchInput" 
			  				  style="width: 270px;margin: 5px;height: 50px;">
			  				  </el-input>
			      <el-button type="primary" icon="search" @click="add_onSubmit" style="margin: 5px;height: 50px;">查询</el-button>
            <!-- <el-date-picker v-model="add_riqiformData['日期']" type="date" style="width: 150px;height: 40px;"/> -->
            <el-button type="primary" @click="add_Dialog" style="margin: 5px;height: 50px;">确认出库</el-button>
        </div>
      </layout-header>
      <layout>
        <layout-content >
        <el-main>
          <div class="gva-table-box">
           <el-table ref="multipleTable" style="width: 100%;height: 65vh" tooltip-effect="dark"
                      :row-style="{ height: '20px' }"  :header-cell-style="{ padding: '0px' }"
                      :cell-style="{ padding: '0px' }" :header-row-style="{ height: '20px' }"
                      :data="add_tableData"  border row-key="ID"
                      size="small" 
                      highlight-current-row="true"  @row-dblclick="add_updateCompanyFunc"
                      @row-click="add_tableRowClick" :show-overflow-tooltip="true"
                      @selection-change="handleSelectionChange">
			        <el-table-column type="selection" width="80" />
              <el-table-column  sortable  align="left" label="订单编号" prop="订单编号" width="300" />
              <el-table-column  sortable  align="left" label="订单子编号" prop="子订单编号" width="300"/>
              <el-table-column  sortable  align="left" label="生产款号" prop="生产款号" width="300" />
              <el-table-column  sortable  align="left" label="款式" prop="款式" width="300" />
              <el-table-column  sortable  align="left" label="颜色" prop="颜色" width="300"  />
              <!-- <el-table-column  sortable  align="left" label="工序" prop="工序" width="150" />
              <el-table-column  sortable  align="left" label="面料出库人" prop="面料出库人" width="150" />
              <el-table-column  sortable  align="left" label="日期" prop="日期" width="160" /> -->
            </el-table>
          </div>
        </el-main>
      </layout-content>
      </layout>
    </layout>
  </div>
</template>
<script setup>
// 全量引入格式化工具 请按需保留
import { Layout, LayoutSider, LayoutContent } from '@arco-design/web-vue';
import {ref, reactive} from 'vue'
import {getSpotList,getSpotTab} from '@/api/mes/job'
import {ElMessage} from "element-plus";
defineOptions({name: 'Company'})

//全局调用获取当前日期
const today = new Date();
const year = today.getFullYear();
const month = String(today.getMonth() + 1).padStart(2, '0'); // 月份从 0 开始，需要补零
const day = String(today.getDate()).padStart(2, '0');
const hours = String(today.getHours()).padStart(2, '0');
const minutes = String(today.getMinutes()).padStart(2, '0');
const seconds = String(today.getSeconds()).padStart(2, '0');
const currentDate = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
const currentDates = `${year}-${month}-${day}`;


const add_searchInfo = ref('')
const add_tableData = reactive([])

//点击【查询】按钮
const add_onSubmit = async ()=>{
  if(add_searchInfo.value === '' || add_searchInfo.value === undefined){
    const WorkListdata = [];
    add_tableData.splice(0,add_tableData.length,...WorkListdata);
      ElMessage({type: 'warning',message: '搜索内容不能为空' })
  }else{
    const order =add_searchInfo.value;
    const getSpotLists = await getSpotList({order:order,code:'出库'});
    console.log(getSpotLists)
    add_tableData.splice(0,add_tableData.length,...getSpotLists.data.data);//表格数据

    // add_searchInfo.value  = '';
    setTimeout(() => {
        const inputElement = document.querySelector('#searchInput');
        if (inputElement) {
            inputElement.focus();
        }
    }, 100); // 延迟100毫秒
  }
};

//复选框选择
const ckSelection = ref('')
const handleSelectionChange = (selection, type) => {
  const ids = selection.map(item => {
    return item.子订单编号
  })
  ckSelection.value = ids.join(',')
  console.log(ckSelection.value)
}

//确认出库按钮
const add_Dialog = async ()=>{
  if(ckSelection.value === ''){
    ElMessage({type: 'warning',message: '请勾选具体的出库订单后，再操作此功能'})
  }else{
    //复选框中子订单编号去重
    let params = {}
    params.order_id = ckSelection.value;
    params.code_ck_rq = currentDates;
    console.log(params)
    const ck_gettab = await getSpotTab(params);
    if (ck_gettab.code === 0) {
      ElMessage({type: 'success',message: '出库成功'});
        // const getSpotToLists = await getSpotToList();
        // add_tableData.splice(0,add_tableData.length,...getSpotToLists.data.data);//表格数据
        add_searchInfo.value = ''
    } else {
      ElMessage({ type: 'error',message: '出库失败'})
    }
  }
}

// =========== 分页 ===========
// 分页相关的响应式变量
const page = ref(1)
const total = ref(0)
const pageSize = ref(10)
// 分页
const handleCurrentChange = (val) => {
  page.value = val;
  _getStaffList();
};

// 修改页面容量 点击多少条/页
const handleSizeChange = (val) => {
  page.value = 10;//默认显示
  pageSize.value = val;
  _getStaffList();
};

</script>
<style scoped>
.form-container {
  display: flex;
  flex-wrap: wrap;
}

.form-column {
  /*flex: 1;*/
  margin-right: 15px; /* 调整列之间的间距 */
}

/* 左侧输入框宽度调整 */
.form-column .el-form-item .el-input {
  width: 150px; /* 调整左侧输入框的宽度 */
}

/* 媒体查询，根据需要调整断点 */
@media screen and (max-width: 768px) {
  .form-column {
    flex: 1 0 100%; /* 在小屏幕下变成单列布局 */
    margin-right: 0;
  }
}
/*:deep(.el-table td .cell) {*/
/*  line-height: 30px !important;*/
/*}*/
.JKWTree-container {
  display: flex;
}
.JKWTree-tree {
  /*width: 300px;*/
  background-color: #fff;
  padding: 10px;
  margin-right: 20px;
}
.JKWTree-tree h3 {
  font-size: 15px;
  font-weight: 700;
  margin: 10px 0;
}
.JKWTree-content {
  flex: 1;
}
/* 图片上传 */
.upload-box {
  width: 200px;
  height: 200px;
  border: 2px dashed #e2e2e2;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  cursor: pointer;
}
.uploaded-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.upload-icon {
  font-size: 40px;
  color: #c0c4cc;
}
.file-input {
  display: none;
}
.el-table .warning-row {
  background: oldlace;
}
/* 表格复选框大小调整 */
:deep(.el-checkbox.el-checkbox--small .el-checkbox__inner) {
    width: 45px; /* 复选框宽度 */
    height: 23px; /* 复选框高度 */
}
:deep(.el-checkbox.el-checkbox--small.is-checked .el-checkbox__inner::after) {
    transform: scale(1.2) rotate(45deg); /* 调整选中后的对勾大小 */
    top: 5%; /* 调整对勾位置 */
    left: 40%; /* 调整对勾位置 */
    width: 5px; /* 调整对勾宽度 */
    height: 9px; /* 调整对勾高度 */
}

/* 选中某行时的背景色 */
:deep(.el-table__body tr.current-row) > td {
  background: #ff80ff !important;
}
</style>
<style scoped>
:deep(.el-table td .cell) {
  line-height: 20px !important;
}
:deep(.el-tabs__header){
  margin-bottom: 0;
}
.search{
  margin-left: 0px !important;
  margin-right: 10px !important;
}
.bt{
  margin-left: 2px !important;
  padding: 3px !important;
  font-size: 12px;
}
.el-tabs__header{
  margin: 0px !important;
}
.gva-table-box{
  padding: 0px !important;
}
.mab{
  margin-bottom: 5px;
}
</style>
