wu
5 天以前 7c0f20e25e870e055f88952f9ec57677730eda67
UI-Project/src/views/StockBasicData/stockBasicData.vue
@@ -1,145 +1,389 @@
<script setup>
import {Search} from "@element-plus/icons-vue";
import {reactive} from "vue";
import {onBeforeUnmount, onMounted, onUnmounted, reactive, ref} from "vue";
import {useRouter} from "vue-router"
import request from "@/utils/request"
import {closeWebSocket, initializeWebSocket} from '@/utils/WebSocketService';
import {ElMessage, ElMessageBox} from 'element-plus'
import {useI18n} from 'vue-i18n'
const router = useRouter()
import { ref } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
const tableData = [
  {
    id: '1',
    long: '1005',
    wide: '183.6',
    thick: '1991',
    type: '待识别',
    typea: '1',
  },
  {
    id: '2',
    long: '105',
    wide: '183',
    thick: '191',
    typea: '1',
    type: '待识别'
  },
  {
    id: '2',
    long: '105',
    wide: '183',
    thick: '191',
    typea: '1',
    type: '待识别'
  },
]
const open = () => {
  ElMessageBox.confirm(
    '是否删除该条信息?',
    '提示',
    {
      confirmButtonText: '是',
      cancelButtonText: '取消',
      type: 'warning',
const adda = ref(false)
const {t} = useI18n()
let language = ref(localStorage.getItem('lang') || 'zh')
const tableData = ref([])
const blindb = ref(false)
const slot = ref('')
const requestData = {
  line: 2001
};
const timeRange = ref([])
const selectValuesa = reactive([]);
// 磨边任务查询
const setEdgGlassInfoRequest = async () => {
  let celllist=[]
  let stateList=[]
  if(selectValuesa[0]!=null&&selectValuesa[0]!='undefined'){
    if(selectValuesa[0]!=""){
      celllist=[selectValuesa[0]];
    }
  )
    .then(() => {
      ElMessage({
        type: 'success',
        message: '删除成功!',
      })
    })
    .catch(() => {
      ElMessage({
        type: 'info',
        message: '删除失败',
      })
    })
  }
  if(selectValuesa[1]!=null&&selectValuesa[1]!='undefined'){
    if(selectValuesa[1]!=""){
      stateList=[selectValuesa[1]];
    }
  }
  const response = await request.post("/cacheGlass/edgGlassTaskInfo/setEdgGlassInfoRequest", {
    cellList: celllist,
    stateList: stateList,
    beginDate: timeRange.value[0],
    endDate: timeRange.value[1],
  })
  if (response.code === 200) {
    ElMessage.success(response.message);
  } else {
    ElMessage.error(response.message);
  }
}
const getTableRow = (row,type) =>{
  switch (type) {
    case 'edit' :{
      //alert('我接收到子组件传送的编辑信息')
      router.push({path: '/main/returns/createReturns', query: { ReturnID: 'TH24010101' }})
      break
// 破损
 const open = async(row) => {
  try {
    const confirmResult = await ElMessageBox.confirm(
      t('workOrder.messagedamaged'),
      t('workOrder.prompt'),
      {
        confirmButtonText: t('workOrder.yes'),
        cancelButtonText: t('workOrder.cancel'),
        type: 'warning',
      }
    );
    if (confirmResult === 'confirm') {
      const response = await request.post("/cacheGlass/edgStorageCage/edgReportStatus", {
        glassId: row.glassId,
        state: 8,
        line: row.line,
        workingProcedure: '磨边',
    })
    if (response.code === 200) {
      ElMessage.success(response.message);
      } else {
      ElMessage.error(response.msg);
      }
    }
  } catch (error) {
  }
};
// 拿走
 const opena = async(row) => {
  try {
    const confirmResult = await ElMessageBox.confirm(
      t('workOrder.takemessage'),
      t('workOrder.prompt'),
      {
        confirmButtonText: t('workOrder.yes'),
        cancelButtonText: t('workOrder.cancel'),
        type: 'warning',
      }
    );
    if (confirmResult === 'confirm') {
      const response = await request.post("/cacheGlass/edgStorageCage/edgReportStatus", {
        glassId: row.glassId,
        state: 9,
        line: row.line,
        workingProcedure: '磨边',
    })
    if (response.code === 200) {
      ElMessage.success(response.message);
      } else {
      ElMessage.error(response.msg);
      }
    }
  } catch (error) {
  }
};
let socket = null;
const socketUrl = `ws://${window.ipConfig.serverUrl}/api/cacheGlass/api/talk/edgTasks`;
const handleMessage = (data) => {
  const formattedTasks = data.edgTasks[0].map(cageInfo => {
    if (cageInfo && cageInfo.createTime) {
      cageInfo.formattedCreateTime = formatTimestamp(cageInfo.createTime);
    }
    case 'delete':{
      alert('我接收到子组件传送的删除信息')
      break
    return cageInfo;
  });
  tableData.value = formattedTasks
};
//  模拟数据
// const generateMockData = () => {
//   const mockList = [
//     {
//       glassId: 'GL251209001',
//       width: 520,
//       height: 310,
//       thickness: 10,
//       filmsid: '钢化玻璃',
//       line: 1,
//       state: 2, // 未磨边
//       createTime: Date.now() - 3600 * 1000 * 2, // 2小时前的时间戳
//       formattedCreateTime: formatTimestamp(Date.now() - 3600 * 1000 * 2)
//     },
//     {
//       glassId: 'GL251209002',
//       width: 600,
//       height: 380,
//       thickness: 12,
//       filmsid: '浮法玻璃',
//       line: 2,
//       state: 1, // 磨边中
//       createTime: Date.now() - 3600 * 1000 * 1, // 1小时前的时间戳
//       formattedCreateTime: formatTimestamp(Date.now() - 3600 * 1000 * 1)
//     },
//     {
//       glassId: 'GL251209003',
//       width: 480,
//       height: 290,
//       thickness: 8,
//       filmsid: '夹胶玻璃',
//       line: 1,
//       state: 1, // 已磨边
//       createTime: Date.now() - 3600 * 1000 * 6, // 6小时前的时间戳
//       formattedCreateTime: formatTimestamp(Date.now() - 3600 * 1000 * 6)
//     },
//     {
//       glassId: 'GL251209004',
//       width: 550,
//       height: 330,
//       thickness: 9,
//       filmsid: '中空玻璃',
//       line: 2,
//       state: 0,
//       createTime: Date.now() - 3600 * 1000 * 3,
//       formattedCreateTime: formatTimestamp(Date.now() - 3600 * 1000 * 3)
//     },
//     {
//       glassId: 'GL251209005',
//       width: 580,
//       height: 350,
//       thickness: 11,
//       filmsid: '防弹玻璃',
//       line: '1',
//       state: 0,
//       createTime: Date.now() - 3600 * 1000 * 4,
//       formattedCreateTime: formatTimestamp(Date.now() - 3600 * 1000 * 4)
//     }
//   ];
//   return mockList;
// };
//   tableData.value = generateMockData();
//   ElMessage.success('模拟数据加载成功!');
// 历史任务
const iframeUrl = ref('');
const handlehistorical = (row) => {
  blindb.value = true;
  iframeUrl.value = `${window.location.origin}/#/StockBasicData/stockhistory`;
};
onMounted(() => {
  socket = initializeWebSocket(socketUrl, handleMessage);
});
  onUnmounted(() => {
    if (socket) {
      closeWebSocket(socket);
    }
  });
//   function getStatusTypeb(state) {
//   switch (state) {
//     case 0:
//       return 'info';
//     case 1:
//       return 'success';
//     case 1:
//       return 'danger';
//   }
// }
// 1. 辅助:获取行真实索引
function getRowRealIndex(row) {
  return tableData.value.findIndex(item => item.glassId === row.glassId);
}
// 2. 辅助:获取指定线路最新行状态
function getLineLatestState(line) {
  const targetLine = String(line || '').trim();
  if (!targetLine) return -1;
  for (const row of tableData.value) {
    const rowLine = String(row.line || '').trim();
    if (rowLine === targetLine) {
      return Number(row.state);
    }
  }
  return -1;
}
// 3. 核心判断:是否需要高亮/标红
function isNeedHighlight(row) {
  const currentState = Number(row.state);
  const currentLine = String(row.line || '').trim();
  if (!currentLine) return false;
  // 原有逻辑:未磨边 + 前序有磨边中/已磨边
  if (currentState === 0) {
    const currentIndex = getRowRealIndex(row);
    if (currentIndex === -1) return false;
    for (let i = 0; i < currentIndex; i++) {
      const compareRow = tableData.value[i];
      const compareLine = String(compareRow?.line || '').trim();
      const compareState = Number(compareRow?.state);
      if (compareLine === currentLine && [1, 2].includes(compareState)) {
        return true;
      }
    }
  }
  // 新增逻辑:磨边中 + 同线路最新是已磨边
  if (currentState === 1) {
    const latestState = getLineLatestState(currentLine);
    if (latestState === 2) {
      return true;
    }
  }
  return false;
}
// 4. 原始颜色映射
function getOriginalColor(state) {
  const stateNum = Number(state);
  switch (stateNum) {
    case 0: return 'info';
    case 1: return 'success';
    case 2: return 'primary';
    default: return 'info';
  }
}
const gridOptions = reactive({
  border:  "full",//表格加边框
  keepSource: true,//保持源数据
  align: 'center',//文字居中
  stripe:true,//斑马纹
  rowConfig: {isCurrent: true, isHover: true,height: 50},//鼠标移动或选择高亮
  id: 'OrderList',
  showFooter: true,//显示脚
  printConfig: {},
  importConfig: {},
  exportConfig: {},
  scrollY:{ enabled: true },//开启虚拟滚动
  showOverflow:true,
  columnConfig: {
    resizable: true,
    useKey: true
  },
  filterConfig: {   //筛选配置项
    remote: true
  },
  customConfig: {
    storage: true
  },
  editConfig: {
    trigger: 'click',
    mode: 'row',
    showStatus: true
  },
  data:  [
    {
      'id': '1',
      'long': '5',
      'wide': '1005',
      'thick': '183.6',
    }
  ],
})
// 5. 标签类型函数(调用isNeedHighlight)
function getStatusTypeb(row) {
  const currentState = Number(row.state);
  if ([0, 1].includes(currentState) && isNeedHighlight(row)) {
    return 'danger';
  }
  return getOriginalColor(row.state);
}
// 6. 行样式函数(调用isNeedHighlight)
function getTableRowClass({ row }) {
  const currentState = Number(row.state);
  if ([0, 1].includes(currentState) && isNeedHighlight(row)) {
    return 'leak-edge-highlight';
  }
  return '';
}
function getStatusTextb(state) {
  switch (state) {
    case 0:
      return t('workOrder.nedging');
    case 1:
      return t('workOrder.edging');
    case 2:
      return t('workOrder.finedging');
  }
}
function formatTimestamp(timestamp) {
  const date = new Date(timestamp);
  const year = date.getFullYear();
  const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份从0开始,需要加1,并补零
  const day = String(date.getDate()).padStart(2, '0'); // 补零
  const hours = String(date.getHours()).padStart(2, '0'); // 补零(如果需要显示时间)
  const minutes = String(date.getMinutes()).padStart(2, '0'); // 补零(如果需要显示时间)
  const seconds = String(date.getSeconds()).padStart(2, '0'); // 补零(如果需要显示时间)
  return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
}
onBeforeUnmount(() => {
  closeWebSocket();
});
</script>
<template>
  <div>
    <el-card style="flex: 1;margin-left: 10px;margin-top: 5px;" v-loading="loading">
      <div style="width: 98%; height: calc(100% - 35px); overflow-y: auto;max-height: 200px;">
        <el-table height="100%" ref="table"
  <div style="height: 500px;">
    <div>
      <el-card style="flex: 1;margin-left: 10px;margin-top: 20px;" >
        <div style="display: flex;">
        <!-- <el-button style="margin-left: 20px;" id="searchButton" type="success" @click="handlehistorical">{{
          $t('searchOrder.historicaltasks')
        }}
      </el-button> -->
        <el-select v-model="selectValuesa[0]" filterable :placeholder="$t('workOrder.cway')" clearable
                   style="margin-left: 20px;margin-bottom: 10px;">
          <el-option :label="$t('workOrder.edgingone')" value="930"></el-option>
          <el-option :label="$t('workOrder.edgingtwo')" value="931"></el-option>
        </el-select>
        <el-select v-model="selectValuesa[1]" filterable :placeholder="$t('workOrder.cstate')" clearable
                   style="margin-left: 20px;margin-bottom: 10px;">
          <el-option :label="$t('workOrder.nedging')" value="0"></el-option>
          <el-option :label="$t('workOrder.edging')" value="1"></el-option>
          <el-option :label="$t('workOrder.finedging')" value="2"></el-option>
          </el-select>
          <span class="demonstration" style="margin-left: 20px;margin-top: 3px;">{{ $t('workOrder.time') }}</span>
            <el-date-picker v-model="timeRange" type="datetimerange" range-separator="至" :start-placeholder="$t('reportmanage.starttime')"  style="margin-left: 15px;" value-format = "YYYY-MM-DD hh:mm:ss"
              :end-placeholder="$t('reportmanage.endtime')">
            </el-date-picker>
          <el-button type="primary" style="margin-left: 10px;margin-bottom: 10px;" @click="setEdgGlassInfoRequest()">{{
        $t('reportmanage.inquire')
      }}</el-button>
      </div>
      <div style="width: 98%; height: calc(100% - 35px); overflow-y: auto;">
        <el-table height="750" ref="table"
        @selection-change="handleSelectionChange"
        :data="tableData" :header-cell-style="{background:'#F2F3F5 ',color:'#1D2129'}">
          <el-table-column prop="id" align="center" label="id" min-width="80" />
          <el-table-column prop="long" align="center" label="长" min-width="120" />
          <el-table-column prop="wide" align="center" label="宽" min-width="120" />
          <el-table-column prop="wide" align="center" label="厚度" min-width="120" />
          <el-table-column prop="wide" align="center" label="膜系" min-width="120" />
          <el-table-column prop="wide" align="center" label="出片顺序" min-width="120" />
          <el-table-column prop="wide" align="center" label="流程卡号" min-width="120" />
          <el-table-column prop="wide" align="center" label="其他" min-width="120" />
          <el-table-column fixed="right" label="操作" align="center" width="200">
            <template #default>
              <el-button size="mini" type="text" plain  @click="dialogFormVisiblea = true">破损</el-button>
              <el-button size="mini" type="text" plain  @click="dialogFormVisiblea = true">删除</el-button>
            </template>
        :data="tableData" :header-cell-style="{background:'#F2F3F5 ',color:'#1D2129'}"
        :row-class-name="getTableRowClass"
        >
        <el-table-column prop="glassId" align="center" :label="$t('workOrder.glassID')" min-width="180" />
          <el-table-column prop="width" align="center" :label="$t('workOrder.width')" min-width="120" />
          <el-table-column prop="height" align="center" :label="$t('workOrder.height')" min-width="80" />
          <el-table-column prop="thickness" align="center" :label="$t('workOrder.thickness')" min-width="120" />
          <el-table-column prop="filmsid" align="center" :label="$t('workOrder.glasstype')" min-width="120" />
          <el-table-column prop="line" align="center" :label="$t('workOrder.line')" min-width="120" />
          <el-table-column prop="formattedCreateTime" align="center" :label="$t('workOrder.time')" min-width="120" />
          <el-table-column prop="state" :label="$t('workOrder.status')" align="center" width="200">
            <!-- <template #default="scope">
              {{ scope.row.status==0?"未磨边":scope.row.status==1?"磨边中":"已磨边" }}
            </template> -->
            <template #default="scope">
          <el-tag :type="getStatusTypeb(scope.row || {}, scope.index)">
          {{ getStatusTextb(scope.row.state) }}
        </el-tag>
        <!-- <el-tag :type="getStatusTypeb(scope.row.state)">
          {{ getStatusTextb(scope.row.state) }}
        </el-tag>   -->
      </template>
        </el-table-column>
          <el-table-column fixed="right" :label="$t('workOrder.operate')" align="center" width="200">
            <template #default="scope">
              <el-button type="text" plain @click="open(scope.row)">{{
                  $t('workOrder.breakage')
                }}
              </el-button>
              <el-button type="text" plain @click="opena(scope.row)">{{
                  $t('workOrder.takeout')
                }}
              </el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </el-card>
      </el-card>
    </div>
  <!-- 历史任务 -->
<el-dialog v-model="blindb" top="10vh" width="95%" @close="iframeUrl=''">
     <iframe
     :src="iframeUrl"
     marginwidth="2000px"
     marginheight="2000px"
     width="100%"
     height="700px"
     frameborder="0"
     ></iframe>
  </el-dialog>
  </div>
</template>
<style scoped>
#dt { display:block; float:left;line-height: 20px;margin-left: 100px;}
#dta { display:block; float:left;line-height: 20px;margin-left: 80%;}
#dialog-footer{
@@ -156,14 +400,20 @@
   margin-left: 28%;
}
#awatch{
  height: 450px;
  height: 460px;
  /* margin-top: -60px; */
}
#main-body{
  margin-top: -20px;
  margin-left: 300px;
/* 漏磨边行整行高亮样式(穿透scoped) */
:deep(.leak-edge-highlight) {
  background-color: #fff1f0 !important; /* 浅红背景(和danger标签呼应) */
}
#main-bodya{
  margin-top: -10px;
  margin-left: 100px;
/* 行内单元格文字标红 */
:deep(.leak-edge-highlight > td) {
  color: #f5222d !important; /* 红色文字 */
  font-weight: 500 !important; /* 可选:文字加粗,更醒目 */
}
/* 鼠标悬浮时保持高亮(可选) */
:deep(.el-table__row.leak-edge-highlight:hover > td) {
  background-color: #fee2e2 !important;
}
</style>