chenlu
2025-11-21 c34a7dd22602a6b1fba2b3de663957bd0b428074
north-glass-erp/northglass-erp/src/views/pp/glassOptimize/page/ProjectDetail.vue
@@ -1,5 +1,5 @@
<script setup>
import {nextTick, onMounted, reactive, ref, watch,onBeforeUnmount } from "vue";
import {nextTick, onMounted, reactive, ref, watch,onBeforeUnmount, provide } from "vue";
import {useI18n} from "vue-i18n";
import {Folder, Plus, Setting, Operation,} from "@element-plus/icons-vue";
import OptimizeCompute from "@/views/pp/glassOptimize/page/OptimizeCompute.vue";
@@ -8,7 +8,7 @@
import CheckInventory from "@/views/pp/glassOptimize/page/CheckInventory.vue";
import request from "@/utils/request";
import {ElMessage, ElMessageBox} from "element-plus";
import {useRoute} from 'vue-router';
import {useRoute, useRouter} from 'vue-router';
import useUserInfoStore from "@/stores/userInfo";
import useOrderInfoStore from "@/stores/sd/order/orderInfo";
import {addListener,toolbarButtonClickEvent} from "@/hook/mouseMove";
@@ -17,6 +17,7 @@
const userStore = useUserInfoStore()
const orderInfo = useOrderInfoStore()
const username = userStore.user.userName
const router = useRouter()
let cellArea = ref()
const xGrid = ref()
@@ -115,7 +116,7 @@
      sortable: true
    },
    {
      field: 'product_name',
      field: 'productName',
      width: 150,
      title: t('order.product'),
      filters: [{data: ''}],
@@ -139,7 +140,7 @@
      sortable: true
    },
    {
      field: 'building_number',
      field: 'buildingNumber',
      width: 150,
      title: '楼层号',
      filters: [{data: ''}],
@@ -188,7 +189,7 @@
      sortable: true
    },
    {
      field: 'icon',
      field: 'markIcon',
      width: 150,
      title: '印标类型',
      filters: [{data: ''}],
@@ -244,6 +245,24 @@
  },
});
const checkAutoRedirectToOptimize = () => {
  // 检查路由中是否有自动跳转标识
  if (route.query.redirect === 'optimizeControl') {
    setTimeout(() => {
      const projectNo = route.params.projectNo || localStorage.getItem('currentProjectNo');
      if (projectNo) {
        router.push({
          name: 'OptimizeControl',
          params: {
            processId: projectNo
          }
        });
      }
    });
  }
};
// 右键菜单
const operationConfigs = [
@@ -427,8 +446,15 @@
};
const handleCommand = async (command) => {
  await emit('changeDialog', command)
}
  if (command === 3) {
    // 执行模拟计算
    await emit('changeDialog', command);
  } else {
    // 其他命令直接执行
    await emit('changeDialog', command);
  }
};
let originalFilm=ref(true)
let surplusMaterial=ref(false)
@@ -458,49 +484,51 @@
      return;
    }
    emit('getSmallPieceData', 1);
    xGrid.value.getTableData().fullData.forEach(items=>{
    optimizeData.value.glassDetails = [];
    // 从表格中获取 glassDetail 数据,而不是从后端接口读取
    const tableData = xGrid.value.getTableData().fullData;
    const glassDetailData = tableData.map(item => {
      let rackNoValue = 0;
      if (items.rackNo !== undefined && items.rackNo !== null && items.rackNo !== '') {
        rackNoValue = items.rackNo;
      if (item.rackNo !== undefined && item.rackNo !== null && item.rackNo !== '') {
        rackNoValue = item.rackNo;
      }
      const detail={
        width :null,
        height :null,
        processId :null,
        layer :null,
        totalLayer :null,
        orderSort :null,
        markIcon :null,
        quantity:null,
        patchState :null,
        upGrind :null,
        downGrind :null,
        leftGrind:null,
        rightGrind :null,
      return {
        width: item.width,
        height: item.height,
        processId: item.processId,
        layer: item.layer,
        totalLayer: item.totalLayer,
        orderSort: item.order_number,
        markIcon: item.markIcon,
        quantity: item.quantity,
        patchState: item.patchState,
        upGrind: item.longGrind1,
        downGrind: item.longGrind2,
        leftGrind: item.shortGrind1,
        rightGrind: item.shortGrind2,
        heatLayoutId: item.heatLayoutId,
        process: item.process,
        orderNo: item.orderNo,
        customerName: item.customerName,
        processingNote: item.processingNote,
        projectName: item.projectName,
        productName: item.productName,
        buildingNumber: item.buildingNumber,
        rackNo: rackNoValue
      }
      detail.width=items.width
      detail.height=items.height
      detail.processId=items.process_ids
      detail.layer=items.layer
      detail.totalLayer=items.total_layer
      detail.orderSort=items.order_number
      detail.markIcon=items.icon
      detail.patchState=items.patch_state
      detail.quantity=items.quantity
      detail.upGrind=items.longGrind1
      detail.downGrind=items.longGrind2
      detail.leftGrind=items.shortGrind1
      detail.rightGrind=items.shortGrind2
      detail.rackNo=items.rackNo
      };
    });
      optimizeData.value.glassDetails .push(detail)
    })
    // 更新 optimizeData 中的 glassDetails
    optimizeData.value.glassDetails = glassDetailData;
    // 打开优化对话框
    dialogVisible.value[4] = true;
  }else{
    dialogVisible.value[index] = true;
  }
};
//关闭弹窗
const closeDialog = (index) => {
  dialogVisible.value[index] = false;
@@ -508,9 +536,21 @@
//右键菜单统一修边
const props = defineProps({
  TrimmingDialogVisible: Boolean,
  CheckboxChangeData: null
  TrimmingDialogVisible: {
    type: [Boolean, Object],
    required: false,
    default: null
  },
  CheckboxChangeData: {
    type: Array,
    required: false,
    default: null
  }
});
const selectedGlassDataForTrimming = ref([]);
/*watch(() => props.TrimmingDialogVisible, (newValue) => {
  if (newValue === true) {
    dialogVisible.value[3] = newValue;
@@ -518,46 +558,65 @@
});*/
watch(
    ()=> [props.TrimmingDialogVisible,props.CheckboxChangeData],
    ([newValue, oldValue])=> {
      if (props.TrimmingDialogVisible!=null){
        dialogVisible.value[3] = newValue;
    () => props.TrimmingDialogVisible,
    (newVal, oldVal) => {
      // 处理打开修边对话框的逻辑
      if (newVal != null && typeof newVal === 'object' && newVal.action === 'open-trimming-dialog') {
        dialogVisible.value[3] = true;
        // 更新选中的玻璃数据
        if (newVal.selectedData && newVal.selectedData.length > 0) {
          selectedGlassDataForTrimming.value = newVal.selectedData;
        } else {
          selectedGlassDataForTrimming.value = [];
        }
      }
      if (props.CheckboxChangeData!=null && props.CheckboxChangeData.length>0){
        props.CheckboxChangeData.forEach(items=>{
          const detail={
            width :null,
            height :null,
            stockCode  :null,
            quantity  :null,
            upTrim :null,
            downTrim :null,
            leftTrim :null,
            rightTrim:null,
            priority:0
    }
);
// 单独处理选中原片数据的逻辑
watch(
    () => props.CheckboxChangeData,
    (newData, oldData) => {
      // 只有当有选中数据时才处理
      if (newData != null && newData.length > 0) {
        optimizeData.value.materialDetails = [];
        newData.forEach(items => {
          const detail = {
            width: null,
            height: null,
            stockCode: null,
            quantity: null,
            upTrim: null,
            downTrim: null,
            leftTrim: null,
            rightTrim: null,
            priority: 0
          }
          detail.width=items.width
          detail.height=items.height
          detail.stockCode=items.id
          detail.quantity=items.available_quantity
          detail.upTrim=items.upTrim
          detail.downTrim=items.downTrim
          detail.leftTrim=items.leftTrim
          detail.rightTrim=items.rightTrim
          detail.width = items.width
          detail.height = items.height
          detail.stockCode = items.id
          detail.quantity = items.available_quantity
          detail.upTrim = items.upTrim
          detail.downTrim = items.downTrim
          detail.leftTrim = items.leftTrim
          detail.rightTrim = items.rightTrim
          optimizeData.value.materialDetails.push(detail)
        })
        dialogVisible.value[4] = true;
      }else{
      } else if (newData !== null && newData.length === 0) {
        // 只有当明确传入空数组时才提示选择原片
        ElMessage.warning('请选择原片');
      }
      console.log(optimizeData.value)
    });
    }
);
const route = useRoute();
//工程号
const projectNo = ref(route.params.projectNo);
provide('projectNo', projectNo);
const projectName = ref('');
const thickNess = ref(route.params.thickNess);
const model = ref(route.params.model);
@@ -568,132 +627,131 @@
  localStorage.setItem('projectNo', projectNo.value);
});
const saveOptimizeData = () => {
  if(orderInfo.optimizeData!==null){
    if(quantitys.value===orderInfo.optimizeData.optimalResults.glassTotalQuantity){
      console.log("保存数据1",orderInfo.optimizeData)
      request.post(`/glassOptimize/saveOptimizeData/${projectNo.value}`,orderInfo.optimizeData).then((res) => {
        if ((Number(res.code) === 200)) {
          ElMessage.success("保存成功");
        } else {
          ElMessage.warning(res.msg);
        }
const saveOptimizeData = async () => {
  try {
    // 先从后端查询工程状态
    const stateRes = await request.post(`/glassOptimize/getProjectState/${projectNo.value}`);
    if (Number(stateRes.code) === 200) {
      const projectData = stateRes.data.data;
      }).catch((error) => {
        console.error("获取数据出错:", error);
      });
    }else{
      ElMessage.warning("原片不足,小片未全部优化");
      // 检查 optimize_state 状态
      if (projectData.optimize_state === 1) {
        // 如果已完成优化,提示用户并阻止继续执行
        ElMessage.warning('已完成优化保存,不允许重复提交');
        return;
      }
    } else {
      ElMessage.warning(stateRes.msg);
      return;
    }
  }else {
    ElMessage.warning("数据未优化");
    if(orderInfo.optimizeData!==null){
      if(quantitys.value===orderInfo.optimizeData.optimalResults.glassTotalQuantity){
        console.log("保存数据1",orderInfo.optimizeData)
        request.post(`/glassOptimize/saveOptimizeData/${projectNo.value}`,orderInfo.optimizeData).then((res) => {
          if ((Number(res.code) === 200)) {
            ElMessage.success("保存成功");
          } else {
            ElMessage.warning(res.msg);
          }
        }).catch((error) => {
          console.error("获取数据出错:", error);
        });
      }else{
        ElMessage.warning("原片不足,小片未全部优化");
      }
    }else {
      ElMessage.warning("数据未优化");
    }
  } catch (error) {
    ElMessage.error('检查工程状态失败,请稍后重试');
    console.error('检查工程状态失败:', error);
  }
}
const fetchData = () => {
  //启用表格拖动选中
  addListener(xGrid.value,gridOptions,cellArea.value)
  request.post(`/glassOptimize/projectInfo/${projectNo.value}/${username}`).then((res) => {
  request.post(`/glassOptimize/optimizeInfo/${projectNo.value}/${username}`).then((res) => {
    if ((Number(res.code) === 200)) {
      let data = res.data.data;
      const grindingTrimming = res.data.grindingTrimming;
      optimizeState.value=res.data.optimizeState;
      // 加载磨量配置
      loadGrindingConfiguration().then((grindConfig) => {
        console.log("加载的磨量配置:", grindConfig);
        data = data.map(item => {
          // 保留从后端返回的原始磨量值,如果存在的话
          const originalLongGrind1 = item.longGrind1;
          const originalLongGrind2 = item.longGrind2;
          const originalShortGrind1 = item.shortGrind1;
          const originalShortGrind2 = item.shortGrind2;
          // 如果没有原始磨量值,则初始化为0
          item.longGrind1 = originalLongGrind1 !== undefined && originalLongGrind1 !== null ?
              parseFloat(originalLongGrind1) : 0;
          item.longGrind2 = originalLongGrind2 !== undefined && originalLongGrind2 !== null ?
              parseFloat(originalLongGrind2) : 0;
          item.shortGrind1 = originalShortGrind1 !== undefined && originalShortGrind1 !== null ?
              parseFloat(originalShortGrind1) : 0;
          item.shortGrind2 = originalShortGrind2 !== undefined && originalShortGrind2 !== null ?
              parseFloat(originalShortGrind2) : 0;
          // 处理 grindingTrimming 数据(如果存在)
          if(grindingTrimming!==null && grindingTrimming.length > 0){
            const formattedData = grindingTrimming.map(item => {
              const formattedItem = {};
              for (const key in item) {
                if (typeof item[key] === 'string') {
                  //去除字符串属性值开头和结尾的双引号
                  formattedItem[key] = item[key].replace(/^\"|\"$/g, '');
                } else {
                  formattedItem[key] = item[key];
                }
              }
              return formattedItem;
            });
            // 如果有自动填充配置,使用它来设置磨量
            if(formattedData[0].autoFillEdge==="true"){
              const minAutoLenght = parseFloat(formattedData[0].minAutoLenght) || 0;
              const leftEdge = parseFloat(formattedData[0].leftEdge) || 0;
              const rightEdge = parseFloat(formattedData[0].rightEdge) || 0;
              const upEdge = parseFloat(formattedData[0].upEdge) || 0;
              const downEdge = parseFloat(formattedData[0].downEdge) || 0;
              if(item.width >= minAutoLenght){
                item.longGrind1 = leftEdge;
                item.longGrind2 = rightEdge;
              }
              if(item.height >= minAutoLenght){
                item.shortGrind1 = upEdge;
                item.shortGrind2 = downEdge;
              }
            }
          } else if(grindConfig) {
            // 使用从 getConfiguration 接口加载的配置
            if(grindConfig.autoFillEdge==="true"){
              const minAutoLenght = parseFloat(grindConfig.minAutoLenght) || 0;
              const leftEdge = parseFloat(grindConfig.leftEdge) || 0;
              const rightEdge = parseFloat(grindConfig.rightEdge) || 0;
              const upEdge = parseFloat(grindConfig.upEdge) || 0;
              const downEdge = parseFloat(grindConfig.downEdge) || 0;
              if(item.width >= minAutoLenght){
                item.longGrind1 = leftEdge;
                item.longGrind2 = rightEdge;
              }
              if(item.height >= minAutoLenght){
                item.shortGrind1 = upEdge;
                item.shortGrind2 = downEdge;
              }
            }else {
              // 即使没有启用自动填充,也应该应用默认的磨量值
              item.longGrind1 = parseFloat(grindConfig.leftEdge) || 0;
              item.longGrind2 = parseFloat(grindConfig.rightEdge) || 0;
              item.shortGrind1 = parseFloat(grindConfig.upEdge) || 0;
              item.shortGrind2 = parseFloat(grindConfig.downEdge) || 0;
      // 处理 grindingTrimming 数据(如果存在)
      let processedGrindConfig = null;
      if(grindingTrimming!==null && grindingTrimming.length > 0){
        // 处理 grindingTrimming 数据,去除双引号
        const formattedData = grindingTrimming.map(item => {
          const formattedItem = {};
          for (const key in item) {
            if (typeof item[key] === 'string') {
              //去除字符串属性值开头和结尾的双引号
              formattedItem[key] = item[key].replace(/^\"|\"$/g, '');
            } else {
              formattedItem[key] = item[key];
            }
          }
          item.height=parseFloat(item.height.toFixed(2))
          item.width=parseFloat(item.width.toFixed(2))
          return item;
          return formattedItem;
        });
        processedGrindConfig = formattedData[0];
      }
        console.log("处理后的数据:", data);
      data = data.map(item => {
        // 直接将 grindingTrimming 中的磨量信息写到表中
        if (processedGrindConfig) {
          // 使用 grindingTrimming 中的配置设置磨量
          const leftEdge = parseFloat(processedGrindConfig.leftEdge) || 0;
          const rightEdge = parseFloat(processedGrindConfig.rightEdge) || 0;
          const upEdge = parseFloat(processedGrindConfig.upEdge) || 0;
          const downEdge = parseFloat(processedGrindConfig.downEdge) || 0;
        xGrid.value.loadData(data);
        gridOptions.data = data;
        projectName.value = data[0].project_name;
        quantitys.value=res.data.project.glass_total
        areas.value=res.data.project.glass_total_area
          item.longGrind1 = leftEdge;   // 长磨1
          item.longGrind2 = rightEdge;  // 长磨2
          item.shortGrind1 = upEdge;    // 短磨1
          item.shortGrind2 = downEdge;  // 短磨2
          // 如果启用了自动填充功能,根据尺寸判断是否应用磨量
          if(processedGrindConfig.autoFillEdge === "true"){
            const minAutoLength = parseFloat(processedGrindConfig.minAutoLenght) || 0;
            // 如果宽度小于最小自动长度,不应用左右磨量
            if(item.width < minAutoLength){
              item.longGrind1 = 0;
              item.longGrind2 = 0;
            }
            // 如果高度小于最小自动长度,不应用上下磨量
            if(item.height < minAutoLength){
              item.shortGrind1 = 0;
              item.shortGrind2 = 0;
            }
          }
        } else {
          // 如果没有 grindingTrimming 数据,初始化为0
          item.longGrind1 = item.longGrind1 !== undefined && item.longGrind1 !== null ?
              parseFloat(item.longGrind1) : 0;
          item.longGrind2 = item.longGrind2 !== undefined && item.longGrind2 !== null ?
              parseFloat(item.longGrind2) : 0;
          item.shortGrind1 = item.shortGrind1 !== undefined && item.shortGrind1 !== null ?
              parseFloat(item.shortGrind1) : 0;
          item.shortGrind2 = item.shortGrind2 !== undefined && item.shortGrind2 !== null ?
              parseFloat(item.shortGrind2) : 0;
        }
        item.height=parseFloat(item.height.toFixed(2))
        item.width=parseFloat(item.width.toFixed(2))
        return item;
      });
      xGrid.value.loadData(data);
      gridOptions.data = data;
      projectName.value = data[0].project_name;
      quantitys.value=res.data.project.glass_total
      areas.value=res.data.project.glass_total_area
      // 更新 optimizeData 中的磨量配置
      updateOptimizeDataWithGrindingConfig(processedGrindConfig);
    } else {
      ElMessage.warning(res.msg);
    }
@@ -702,6 +760,19 @@
  });
};
const updateOptimizeDataWithGrindingConfig = (grindConfig) => {
  if (grindConfig) {
    // 更新 optimizeData 中的磨量配置
    optimizeData.value.grindingConfig = {
      leftEdge: parseFloat(grindConfig.leftEdge) || 0,
      upEdge: parseFloat(grindConfig.upEdge) || 0,
      rightEdge: parseFloat(grindConfig.rightEdge) || 0,
      downEdge: parseFloat(grindConfig.downEdge) || 0,
      autoFillEdge: grindConfig.autoFillEdge === "true",
      minAutoLength: parseFloat(grindConfig.minAutoLenght) || 0
    };
  }
};
const firstLoading = async() => {
  request.post(`/glassOptimize/selectOptimizeParms/${username}`).then((res) => {
@@ -725,15 +796,18 @@
onMounted(() => {
  if (projectNo.value) {
    localStorage.setItem('currentProjectNo', projectNo.value);
    orderInfo.projectNo=route.params
    fetchData();
    firstLoading();
    checkAutoRedirectToOptimize();
  }else if(orderInfo.projectNo!==null){
    projectNo.value=orderInfo.projectNo.projectNo
    model.value=orderInfo.projectNo.model
    thickNess.value=orderInfo.projectNo.thickNess
    fetchData();
    firstLoading();
    checkAutoRedirectToOptimize();
  }
});
@@ -798,6 +872,7 @@
  });*/
};
const grindingConfig = ref(null);
const loadGrindingConfiguration = async () => {
  return new Promise((resolve) => {
@@ -817,10 +892,11 @@
            }
            return formattedItem;
          });
          // 保存磨量配置
          grindingConfig.value = formattedData[0];
          resolve(formattedData[0]);
        } else {
          // 提供默认配置
          resolve({
          const defaultConfig = {
            leftEdge: '0',
            upEdge: '0',
            rightEdge: '0',
@@ -828,12 +904,13 @@
            quickEdge: '1',
            autoFillEdge: 'false',
            minAutoLenght: '0'
          });
          };
          grindingConfig.value = defaultConfig;
          resolve(defaultConfig);
        }
      } else {
        ElMessage.warning(res.msg);
        // 提供默认配置
        resolve({
        const defaultConfig = {
          leftEdge: '0',
          upEdge: '0',
          rightEdge: '0',
@@ -841,11 +918,12 @@
          quickEdge: '1',
          autoFillEdge: 'false',
          minAutoLenght: '0'
        });
        };
        grindingConfig.value = defaultConfig;
        resolve(defaultConfig);
      }
    }).catch(() => {
      // 提供默认配置
      resolve({
      const defaultConfig = {
        leftEdge: '0',
        upEdge: '0',
        rightEdge: '0',
@@ -853,7 +931,9 @@
        quickEdge: '1',
        autoFillEdge: 'false',
        minAutoLenght: '0'
      });
      };
      grindingConfig.value = defaultConfig;
      resolve(defaultConfig);
    });
  });
};
@@ -924,7 +1004,10 @@
        <el-button id="button" type="primary" @click="openDialog(3)">设置修边</el-button>
        <el-dialog v-model="dialogVisible[3]" title="设置修边(mm)" destroy-on-close
                   style="width: 35%;height:80%;margin-top: 3vh;">
          <set-trimming :closeDialog="closeDialog" @send-data-event="handleTrimmingData"/>
          <set-trimming
              :closeDialog="closeDialog"
              :selected-glass-data="selectedGlassDataForTrimming"
              @send-data-event="handleTrimmingData"/>
        </el-dialog>
        <el-button id="button" type="primary" @click="saveOptimizeData()">保存</el-button>
        <el-button id="button" type="primary" @click="openDialog(4)">优化</el-button>