From 7f54cffaf13d9fc48f415a89c63950f526b3e06d Mon Sep 17 00:00:00 2001
From: 于杰 <1210123631@qq.com>
Date: 星期五, 21 十一月 2025 11:35:03 +0800
Subject: [PATCH] 修改前端展示信息来源,优化数据来源由原来的数据库改为前端表格数据

---
 north-glass-erp/northglass-erp/src/views/pp/glassOptimize/page/ProjectDetail.vue | 1180 +++++++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 1,073 insertions(+), 107 deletions(-)

diff --git a/north-glass-erp/northglass-erp/src/views/pp/glassOptimize/page/ProjectDetail.vue b/north-glass-erp/northglass-erp/src/views/pp/glassOptimize/page/ProjectDetail.vue
index 5c710fd..4e4b7d7 100644
--- a/north-glass-erp/northglass-erp/src/views/pp/glassOptimize/page/ProjectDetail.vue
+++ b/north-glass-erp/northglass-erp/src/views/pp/glassOptimize/page/ProjectDetail.vue
@@ -1,22 +1,38 @@
 <script setup>
-import {reactive, ref} from "vue";
+import {nextTick, onMounted, reactive, ref, watch,onBeforeUnmount, provide } from "vue";
 import {useI18n} from "vue-i18n";
-import {Folder} from "@element-plus/icons-vue";
-const { t } = useI18n()
+import {Folder, Plus, Setting, Operation,} from "@element-plus/icons-vue";
+import OptimizeCompute from "@/views/pp/glassOptimize/page/OptimizeCompute.vue";
+import SetAmount from "@/views/pp/glassOptimize/page/SetAmount.vue";
+import SetTrimming from "@/views/pp/glassOptimize/page/SetTrimming.vue";
+import CheckInventory from "@/views/pp/glassOptimize/page/CheckInventory.vue";
+import request from "@/utils/request";
+import {ElMessage, ElMessageBox} from "element-plus";
+import {useRoute, useRouter} from 'vue-router';
+import useUserInfoStore from "@/stores/userInfo";
+import useOrderInfoStore from "@/stores/sd/order/orderInfo";
+import {addListener,toolbarButtonClickEvent} from "@/hook/mouseMove";
 
+const { t } = useI18n();
+const userStore = useUserInfoStore()
+const orderInfo = useOrderInfoStore()
+const username = userStore.user.userName
+const router = useRouter()
+
+let cellArea = ref()
 const xGrid = ref()
 const gridOptions = reactive({
-  height:'100%',
+  height: '100%',
   loading: false,
-  border:  "full",//琛ㄦ牸鍔犺竟妗�
+  border: "full",//琛ㄦ牸鍔犺竟妗�
   keepSource: true,//淇濇寔婧愭暟鎹�
   align: 'center',//鏂囧瓧灞呬腑
-  stripe:true,//鏂戦┈绾�
-  rowConfig: {isCurrent: true, isHover: true,height: 30, useKey: true},//榧犳爣绉诲姩鎴栭�夋嫨楂樹寒
+  stripe: true,//鏂戦┈绾�
+  rowConfig: {isCurrent: true, isHover: true, height: 30, useKey: true},//榧犳爣绉诲姩鎴栭�夋嫨楂樹寒
   id: 'ProjectDetail',
-  scrollX:{enabled: true},
-  scrollY:{ enabled: true ,gt:0},//寮�鍚櫄鎷熸粴鍔�
-  showOverflow:true,
+  scrollX: {enabled: true},
+  scrollY: {enabled: true, gt: 0},//寮�鍚櫄鎷熸粴鍔�
+  showOverflow: true,
   columnConfig: {
     resizable: true,
     useKey: true
@@ -28,127 +44,1077 @@
     storage: true
   },
   editConfig: {
-    trigger: 'click',
+    trigger: 'dblclick',
     mode: 'row',
     showStatus: true
   },
-  /*formConfig: {
-    data: {
-      width: '',
-      height: '',
-      quantity: ''
-    },
-    items: [
-      { field: 'width', title: t('order.width')+':', itemRender: { name: 'VxeInput' } },
-      { field: 'height', title: t('order.height')+':', itemRender: { name: 'VxeInput' } },
-      { field: 'quantity', title: t('order.quantity')+':', itemRender: { name: 'VxeInput' } },
-      {
-        itemRender: {
-          name: 'VxeButtonGroup',
-          options: [
-            { type: 'submit', content: t('craft.sure'), status: 'primary' },
-            { type: 'reset', content: t('product.msg.reset') }
-          ]
-        }
-      }
-    ]
-  },*/
-  columns:[
-    {title: '璁㈠簭', width: 70},
-    {field:'state',width: 150,title: t('order.width'),filters:[{ data: '' }], slots: { filter: 'num2_filter' }},
-    {type: 'seq',width: 150,title: t('order.height')},
-    {field: 'id',width: 150, title: t('order.quantity'),filters:[{ data: '' }],slots: { filter: 'num1_filter' }, sortable: true},
-    {field: 'id',width: 150, title: '闀跨(1',filters:[{ data: '' }],slots: { filter: 'num1_filter' }, sortable: true},
-    {field: 'id',width: 150, title: '闀跨(2',filters:[{ data: '' }],slots: { filter: 'num1_filter' }, sortable: true},
-    {field: 'id',width: 150, title: '鐭(1',filters:[{ data: '' }],slots: { filter: 'num1_filter' }, sortable: true},
-    {field: 'id',width: 150, title: '鐭(1',filters:[{ data: '' }],slots: { filter: 'num1_filter' }, sortable: true},
-    {field: 'id',width: 150, title: t('order.shape'),filters:[{ data: '' }],slots: { filter: 'num1_filter' }, sortable: true},
-    {field: 'id',width: 150, title: '娴佺▼鍗″彿',filters:[{ data: '' }],slots: { filter: 'num1_filter' }, sortable: true},
-    {field: 'id',width: 150, title: t('order.product'),filters:[{ data: '' }],slots: { filter: 'num1_filter' }, sortable: true},
-    {field: 'id',width: 150, title: t('order.buildingNumber'),filters:[{ data: '' }],slots: { filter: 'num1_filter' }, sortable: true},
-    {field: 'id',width: 150, title: t('basicData.remarks'),filters:[{ data: '' }],slots: { filter: 'num1_filter' }, sortable: true},
-    {field: 'id',width: 150, title: t('order.perimeter'),filters:[{ data: '' }],slots: { filter: 'num1_filter' }, sortable: true},
-    {field: 'id',width: 150, title: t('order.grossArea'),filters:[{ data: '' }],slots: { filter: 'num1_filter' }, sortable: true},
 
-    {field: 'id',width: 150, title: t('craft.glassChild'),filters:[{ data: '' }],slots: { filter: 'num1_filter' }, sortable: true},
-    {field: 'id',width: 150, title: t('craft.glassAddress'),filters:[{ data: '' }],slots: { filter: 'num1_filter' }, sortable: true},
-    {field: 'id',width: 150, title: t('craft.TrademarkAttribute'),filters:[{ data: '' }],slots: { filter: 'num1_filter' }, sortable: true},
+  columns: [
+    {type: 'seq', title: t('basicData.Number'), width: 80},
+    {field: 'order_number', title: '璁㈠簭', width: 70},
+    {field: 'width',
+      width: 100,
+      title: t('order.width'),
+      sortable: true
+    },
+    {
+      field: 'height',
+      width: 100,
+      title: t('order.height'),
+      sortable: true
+    },
+    {
+      field: 'quantity',
+      width: 150,
+      title: t('order.quantity'),
+      filters: [{data: ''}],
+      slots: {filter: 'num1_filter'},
+      sortable: true
+    },
+    {
+      field: 'longGrind1',
+      width: 150,
+      title: '闀跨(1',
+      editRender: { name: 'input' },filters:[{ data: '' }],slots: { filter: 'num1_filter' },
+      sortable: true
+    },
+    {
+      field: 'longGrind2',
+      width: 150,
+      title: '闀跨(2',
+      editRender: { name: 'input' },filters:[{ data: '' }],slots: { filter: 'num1_filter' },
+      sortable: true
+    },
+    {
+      field: 'shortGrind1',
+      width: 150,
+      title: '鐭(1',
+      editRender: { name: 'input' },filters:[{ data: '' }],slots: { filter: 'num1_filter' },
+      sortable: true
+    },
+    {
+      field: 'shortGrind2',
+      width: 150,
+      title: '鐭(2',
+      editRender: { name: 'input' },filters:[{ data: '' }],slots: { filter: 'num1_filter' },
+      sortable: true
+    },
+    {
+      field: 'shape',
+      width: 150,
+      title: t('order.shape'),
+      filters: [{data: ''}],
+      slots: {filter: 'num1_filter'},
+      sortable: true
+    },
+    {
+      field: 'process_id',
+      width: 150,
+      title: '娴佺▼鍗″彿',
+      filters: [{data: ''}],
+      slots: {filter: 'num1_filter'},
+      sortable: true
+    },
+    {
+      field: 'productName',
+      width: 150,
+      title: t('order.product'),
+      filters: [{data: ''}],
+      slots: {filter: 'num1_filter'},
+      sortable: true
+    },
+    {
+      field: 'price',
+      width: 150,
+      title: t('鍗曚环'),
+      filters: [{data: ''}],
+      slots: {filter: 'num1_filter'},
+      sortable: true
+    },
+    {
+      field: 'remark',
+      width: 150,
+      title: t('basicData.remarks'),
+      filters: [{data: ''}],
+      slots: {filter: 'num1_filter'},
+      sortable: true
+    },
+    {
+      field: 'buildingNumber',
+      width: 150,
+      title: '妤煎眰鍙�',
+      filters: [{data: ''}],
+      slots: {filter: 'num1_filter'},
+      sortable: true
+    },
+    {
+      field: 'perimeter',
+      width: 150,
+      title: t('order.perimeter'),
+      filters: [{data: ''}],
+      slots: {filter: 'num1_filter'},
+      sortable: true
+    },
+    {
+      field: 'area',
+      width: 150,
+      title: t('order.grossArea'),
+      filters: [{data: ''}],
+      slots: {filter: 'num1_filter'},
+      sortable: true
+    },
+
+    {
+      field: 'rackNo',
+      width: 150,
+      title: '鏋跺彿',
+      filters: [{data: ''}],
+      slots: {filter: 'num1_filter'},
+      sortable: true
+    },
+    {
+      field: 'layer',
+      width: 150,
+      title: '灞�',
+      filters: [{data: ''}],
+      slots: {filter: 'num1_filter'},
+      sortable: true
+    },
+    {
+      field: 'glass_child',
+      width: 150,
+      title: '鍗曠墖鍚嶇О',
+      filters: [{data: ''}],
+      slots: {filter: 'num1_filter'},
+      sortable: true
+    },
+    {
+      field: 'markIcon',
+      width: 150,
+      title: '鍗版爣绫诲瀷',
+      filters: [{data: ''}],
+      slots: {filter: 'num1_filter'},
+      sortable: true
+    },
   ],//琛ㄥご鍙傛暟
-  data:null,//琛ㄦ牸鏁版嵁
+  data: null,//琛ㄦ牸鏁版嵁
   toolbarConfig: {
-    buttons: [],
-    slots:{
-      buttons: "toolbar"
+    buttons: [
+    ],
+    import: false,
+    // export: true,
+    // print: true,
+    zoom: true,
+    custom: true
+  },
+  //鍙抽敭鑿滃崟
+  menuConfig: {
+    body: {
+      options: [
+        [
+          {code: 'setAmount', name: '璁剧疆缁熶竴纾ㄩ噺',},
+          {code: 'displayProcessCard', name: '鏄剧ず娴佺▼鍗�',},
+          {code: 'hideProcessCard', name: '闅愯棌娴佺▼鍗�',},
+          {code: 'setShape', name: '璁剧疆鍥惧舰',},
+          {code: 'Export', name: '鏁版嵁瀵煎嚭', prefixIcon: 'vxe-icon-download', visible: true, disabled: false},
+          {code: 'safeDXF', name: '鍥惧舰鍙﹀瓨涓篋XF',},
+          {code: 'exportOPTIMA', name: '瀵煎嚭鏁版嵁鍒癘PTIMA',},
+          {code: 'copyChecked', name: t('basicData.selectSame'), prefixIcon: 'vxe-icon-copy', visible: true, disabled: false },
+          {code: 'copyAll', name: t('basicData.sameAfterwards'), prefixIcon: 'vxe-icon-feedback', visible: true, disabled: false },
+        ],
+        []
+      ]
     },
   },
-
 })
-let emit = defineEmits([
-  'changeDialog'
-])
-const handleCommand = async (command)=>{
-  await emit('changeDialog',command)
+const processCardColumns = reactive({
+  columns:[
+    {field: 'process_id', title: '娴佺▼鍗�', width: 200, align: 'center'},
+    {field: 'project', title: '椤圭洰鍚�', width: 150, align: 'center'},
+    {field: 'order_number', title: '璁㈠簭', width: 100, align: 'center'},
+    {field: 'sizes', title: '灏哄', width: 200, align: 'center'},
+    {field: 'layer', title: '灞�', width: 100, align: 'center'},
+    {field: 'quantity', title: '鏁伴噺', width: 100, align: 'center'}
+  ],
+  toolbarConfig: {
+    buttons: [
+    ],
+    import: false,
+    // export: true,
+    // print: true,
+
+  },
+});
+
+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 = [
+  {
+    code: 'setAmount', // 璁剧疆缁熶竴纾ㄩ噺
+    successMsg: '宸叉墦寮�锛�',
+    gridRef: xGrid,
+    requiresRow: false,
+    openAmount: async () => {
+      dialogVisible.value[2] = true;
+    }
+  },
+  {
+    code: 'displayProcessCard',
+    successMsg: '鎿嶄綔鎴愬姛锛�',
+    gridRef: xGrid,
+    requiresRow: false,
+    displayProcess: () => {
+      getProcessCard();
+      // 鏄剧ず娴佺▼鍗℃椂锛屽皢 left-table 瀹藉害鏀逛负 50%
+      leftTableWidth.value = 60;
+      showProcessCardTable.value = true;
+    }
+  },
+  {
+    code: 'hideProcessCard',
+    successMsg: '鎿嶄綔鎴愬姛锛�',
+    gridRef: xGrid,
+    requiresRow: false,
+    hideProcess: () => {
+      leftTableWidth.value = 100;
+      showProcessCardTable.value = false;
+    }
+  },
+  {
+    code: 'setShape',
+    successMsg: '鎿嶄綔鎴愬姛锛�',
+    gridRef: xGrid,
+    requiresRow: false,
+    showMessage: () => {
+      ElMessage.info('姝ゅ姛鑳芥殏鏈畬鍠勶紝鏆傛椂鏃犳硶鎵ц璁剧疆鍥惧舰鎿嶄綔銆�');
+    }
+  },
+  {
+    code: 'Export', // 瀵煎嚭鏂囦欢鎿嶄綔鐨勯厤缃�
+    successMsg: '鏂囦欢瀵煎嚭鎴愬姛锛�',
+    gridRef: xGrid,
+    requiresRow: false,
+  },
+  {
+    code: 'safeDXF',
+    successMsg: '鎿嶄綔鎴愬姛锛�',
+    gridRef: xGrid,
+    requiresRow: false,
+    showMessage: () => {
+      ElMessage.info('姝ゅ姛鑳芥殏鏈畬鍠勶紝鏆傛椂鏃犳硶鎵ц鍥惧舰鍙﹀瓨涓篋XF鎿嶄綔銆�');
+    }
+  },
+  {
+    code: 'exportOPTIMA',
+    successMsg: '鎿嶄綔鎴愬姛锛�',
+    gridRef: xGrid,
+    requiresRow: false,
+    showMessage: () => {
+      ElMessage.info('姝ゅ姛鑳芥殏鏈畬鍠勶紝鏆傛椂鏃犳硶鎵ц瀵煎嚭鏁版嵁鍒癘PTIMA鎿嶄綔銆�');
+    }
+  },
+  {
+    code: 'copyChecked',
+    successMsg: '鎿嶄綔鎴愬姛锛�',
+    gridRef: xGrid,
+    requiresRow: false,
+    hideProcess: () => {
+    }
+  },
+  {
+    code: 'copyAll',
+    successMsg: '鎿嶄綔鎴愬姛锛�',
+    gridRef: xGrid,
+    requiresRow: false,
+    hideProcess: () => {
+    }
+  },
+]
+
+// 鍙抽敭鑿滃崟鐐瑰嚮閫昏緫
+const gridEvents = {
+  menuClick({menu}) {
+    const $grid = xGrid.value;
+    if ($grid) {
+      const config = operationConfigs.find(c => c.code === menu.code);
+      if (config) {
+        if (config.code === 'Export') {
+          config.gridRef.value.exportData();
+          ElMessage.success(config.successMsg);
+          return;
+        }
+        if (config.code === 'copyChecked') {
+          let result = toolbarButtonClickEvent()
+          if(result){
+            const dataList = xGrid.value.getTableData().visibleData
+            let firstVal=null;
+            if(result.cell.indexOf('.')>-1){
+              firstVal = eval("dataList["+result.start +"]."+result.cell)
+            }else {
+              firstVal=dataList[result.start][result.cell];
+            }
+            dataList.forEach((item,index) =>{
+              if(index>=result.start && index<=result.end){
+                //鍙栨秷閫変腑
+                if(parseInt(firstVal)<=0){
+                  xGrid.value.setCheckboxRow(item, false);
+                }
+                if(result.cell.indexOf('.')>-1){
+                  const  columnArr = result.cell.split('.')
+                  item[columnArr[0]][columnArr[1]]  = firstVal
+                }else{
+                  item[result.cell]  = firstVal
+                }
+
+              }
+            })
+          }
+          return;
+        }
+        if (config.code === 'copyAll') {
+          let result = toolbarButtonClickEvent()
+          if(result){
+            const dataList = xGrid.value.getTableData().visibleData
+            let firstVal=null;
+            if(result.cell.indexOf('.')>-1){
+              firstVal = eval("dataList["+result.start +"]."+result.cell)
+            }else {
+              firstVal=dataList[result.start][result.cell];
+            }
+            dataList.forEach((item,index) =>{
+              if(index>=result.start){
+                //鍙栨秷閫変腑
+                if(parseInt(firstVal)<=0){
+                  xGrid.value.setCheckboxRow(item, false);
+                }
+                if(result.cell.indexOf('.')>-1){
+                  const  columnArr = result.cell.split('.')
+                  item[columnArr[0]][columnArr[1]]  = firstVal
+                }else{
+                  item[result.cell]  = firstVal
+                }
+
+              }
+            })
+          }
+          return;
+        }
+        // 娣诲姞纭鎻愮ず寮圭獥锛岃闂敤鎴锋槸鍚﹁繘琛屽綋鍓嶆搷浣�
+        ElMessageBox.confirm('鏄惁杩涜褰撳墠鎿嶄綔锛�', '纭鎿嶄綔', {
+          confirmButtonText: '纭畾',
+          cancelButtonText: '鍙栨秷',
+          type: 'warning'
+        }).then(() => {
+          if (config.code === 'setAmount') {
+            config.openAmount();
+            ElMessage.success(config.successMsg);
+          } else if (config.code === 'displayProcessCard') {
+            config.displayProcess();
+            ElMessage.success(config.successMsg);
+          } else if (config.code === 'hideProcessCard') {
+            config.hideProcess();
+            ElMessage.success(config.successMsg);
+          } else if (['setShape', 'safeDXF', 'exportOPTIMA'].includes(config.code)) {
+            config.showMessage();
+          }
+        }).catch(() => {
+          // 鐢ㄦ埛鐐瑰嚮鍙栨秷鍚庢墽琛岀殑閫昏緫
+          ElMessage.info('宸插彇娑堟搷浣�');
+        });
+      } else {
+        console.error(`鏈壘鍒版搷浣滈�夐」 ${menu.code} 瀵瑰簲鐨勯厤缃紝璇锋鏌ラ厤缃」`);
+      }
+    }
+  },
+};
+
+const handleCommand = async (command) => {
+  if (command === 3) {
+    // 鎵ц妯℃嫙璁$畻
+    await emit('changeDialog', command);
+
+  } else {
+    // 鍏朵粬鍛戒护鐩存帴鎵ц
+    await emit('changeDialog', command);
+  }
+};
+
+let originalFilm=ref(true)
+let surplusMaterial=ref(false)
+
+//浼樺寲璁$畻
+const dialogVisible = ref({});
+
+const optimizeData = ref({
+  projectNo:null,
+  allowRotate:null,
+  cutOrigin:null,
+  minCutDistance :null,
+  optimizeMode:null,
+  travType:null,
+  rackCycleQty:null,
+  glassThickness:null,
+  glassType:null,
+  glassDetails :[],
+  materialDetails:[]
+});
+
+
+const openDialog = (index) => {
+  if(index===4){
+    if(parseInt(optimizeState.value)===1){
+      ElMessage.warning("璇ュ伐绋嬪凡浼樺寲")
+      return;
+    }
+    emit('getSmallPieceData', 1);
+    optimizeData.value.glassDetails = [];
+    // 浠庤〃鏍间腑鑾峰彇 glassDetail 鏁版嵁锛岃�屼笉鏄粠鍚庣鎺ュ彛璇诲彇
+    const tableData = xGrid.value.getTableData().fullData;
+    const glassDetailData = tableData.map(item => {
+      let rackNoValue = 0;
+      if (item.rackNo !== undefined && item.rackNo !== null && item.rackNo !== '') {
+        rackNoValue = item.rackNo;
+      }
+      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
+      };
+    });
+
+    // 鏇存柊 optimizeData 涓殑 glassDetails
+    optimizeData.value.glassDetails = glassDetailData;
+
+    // 鎵撳紑浼樺寲瀵硅瘽妗�
+    dialogVisible.value[4] = true;
+
+  }else{
+    dialogVisible.value[index] = true;
+  }
+};
+
+//鍏抽棴寮圭獥
+const closeDialog = (index) => {
+  dialogVisible.value[index] = false;
+};
+
+//鍙抽敭鑿滃崟缁熶竴淇竟
+const props = defineProps({
+  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;
+  }
+});*/
+
+watch(
+    () => 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 = [];
+        }
+      }
+    }
+);
+
+// 鍗曠嫭澶勭悊閫変腑鍘熺墖鏁版嵁鐨勯�昏緫
+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
+
+          optimizeData.value.materialDetails.push(detail)
+        })
+        dialogVisible.value[4] = true;
+      } else if (newData !== null && newData.length === 0) {
+        // 鍙湁褰撴槑纭紶鍏ョ┖鏁扮粍鏃舵墠鎻愮ず閫夋嫨鍘熺墖
+        ElMessage.warning('璇烽�夋嫨鍘熺墖');
+      }
+    }
+);
+
+
+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);
+const quantitys = ref();
+const areas = ref();
+const optimizeState = ref(route.params.optimizeState);
+onBeforeUnmount(() => {
+  localStorage.setItem('projectNo', projectNo.value);
+});
+
+const saveOptimizeData = async () => {
+  try {
+    // 鍏堜粠鍚庣鏌ヨ宸ョ▼鐘舵��
+    const stateRes = await request.post(`/glassOptimize/getProjectState/${projectNo.value}`);
+    if (Number(stateRes.code) === 200) {
+      const projectData = stateRes.data.data;
+
+      // 妫�鏌� optimize_state 鐘舵��
+      if (projectData.optimize_state === 1) {
+        // 濡傛灉宸插畬鎴愪紭鍖栵紝鎻愮ず鐢ㄦ埛骞堕樆姝㈢户缁墽琛�
+        ElMessage.warning('宸插畬鎴愪紭鍖栦繚瀛橈紝涓嶅厑璁搁噸澶嶆彁浜�');
+        return;
+      }
+    } else {
+      ElMessage.warning(stateRes.msg);
+      return;
+    }
+    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/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;
+
+      // 澶勭悊 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];
+            }
+          }
+          return formattedItem;
+        });
+        processedGrindConfig = formattedData[0];
+      }
+
+      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;
+
+          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);
+    }
+  }).catch((error) => {
+    console.error("鑾峰彇鏁版嵁鍑洪敊:", error);
+  });
+};
+
+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) => {
+    if (res.code == "200") {
+      const parsedData = JSON.parse(res.data);
+      optimizeData.value.projectNo=projectNo.value
+      optimizeData.value.glassType=model.value
+      optimizeData.value.glassThickness=thickNess.value
+      optimizeData.value.allowRotate=parsedData.optimization.smallPieceRotationProhibited
+      optimizeData.value.optimizeMode=parsedData.optimization.optimizationMethod
+      optimizeData.value.minCutDistance=parsedData.optimization.bendEdgeDistance
+      optimizeData.value.cutOrigin=parsedData.optimization.cutterOriginPosition
+      optimizeData.value.travType=parsedData.optimization.travType
+      optimizeData.value.rackCycleQty=parsedData.optimization.rackCycleQty
+    } else {
+      ElMessage.warning(res.msg)
+    }
+  })
+
+}
+
+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();
+  }
+});
+
+// 娴佺▼鍗� 瀹藉害
+const leftTableWidth = ref(100);
+const showProcessCardTable = ref(false);
+// 鐢ㄤ簬瀛樺偍娴佺▼鍗℃暟鎹�
+const processCardData = ref(null);
+//娴佺▼鍗�
+const getProcessCard = () => {
+  request.post(`/glassOptimize/getProcessCard/${projectNo.value}`).then((res) => {
+    if (Number(res.code) === 200) {
+      processCardData.value = res.data.data;
+    } else {
+      ElMessage.warning(res.msg);
+    }
+  });
+};
+
+
+// 浠庡瓙缁勪欢SetAmount鑾峰彇纾ㄩ噺鍊硷紝骞舵洿鏂拌〃鏍兼暟鎹�
+const Amount = (amountData) => {
+  // fetchData()
+  const data = gridOptions.data;
+  if (data) {
+    const updatedData = data.map(item => ({
+      ...item,
+      longGrind1: Number(amountData.quicksetTop),
+      longGrind2: Number(amountData.quicksetRight),
+      shortGrind1: Number(amountData.quicksetBottom),
+      shortGrind2: Number(amountData.quicksetLeft)
+    }));
+    gridOptions.data = updatedData;
+    xGrid.value.loadData(updatedData);
+  }
+  /*nextTick(() => {
+    const data = gridOptions.data;
+    if (data) {
+      try {
+        const updatedData = [];
+        for (let i = 0; i < data.length; i++) {
+          const item = data[i];
+          const updatedItem = {
+            ...item,
+            longGrind1: Number(amountData.quicksetTop),
+            longGrind2: Number(amountData.quicksetRight),
+            shortGrind1: Number(amountData.quicksetBottom),
+            shortGrind2: Number(amountData.quicksetLeft)
+          };
+          updatedData.push(updatedItem);
+        }
+        gridOptions.data = updatedData;
+        xGrid.value.loadData(updatedData);
+      } catch (error) {
+        console.error('鏇存柊琛ㄦ牸鏁版嵁鏃跺嚭閿�:', error);
+        // 杩欓噷鍙互鏍规嵁瀹為檯闇�姹傛坊鍔犱竴浜涘洖婊氭搷浣滄垨鑰呮彁绀虹敤鎴风殑閫昏緫锛屾瘮濡傛樉绀轰竴涓敊璇彁绀烘绛�
+        ElMessage.error('鏇存柊纾ㄩ噺鏁版嵁鏃跺嚭鐜伴敊璇紝璇锋鏌ヨ緭鍏ユ垨鑱旂郴绠$悊鍛�');
+      }
+    } else {
+      console.warn('琛ㄦ牸鏁版嵁涓虹┖锛屾棤娉曟洿鏂扮(閲忓��');
+    }
+  });*/
+};
+
+const grindingConfig = ref(null);
+
+const loadGrindingConfiguration = async () => {
+  return new Promise((resolve) => {
+    request.post(`/glassOptimize/getConfiguration/纾ㄩ噺/${username}`).then((res) => {
+      if (res.code == "200") {
+        const rawData = res.data.data;
+        if (Array.isArray(rawData) && rawData.length > 0) {
+          const formattedData = rawData.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;
+          });
+          // 淇濆瓨纾ㄩ噺閰嶇疆
+          grindingConfig.value = formattedData[0];
+          resolve(formattedData[0]);
+        } else {
+          const defaultConfig = {
+            leftEdge: '0',
+            upEdge: '0',
+            rightEdge: '0',
+            downEdge: '0',
+            quickEdge: '1',
+            autoFillEdge: 'false',
+            minAutoLenght: '0'
+          };
+          grindingConfig.value = defaultConfig;
+          resolve(defaultConfig);
+        }
+      } else {
+        ElMessage.warning(res.msg);
+        const defaultConfig = {
+          leftEdge: '0',
+          upEdge: '0',
+          rightEdge: '0',
+          downEdge: '0',
+          quickEdge: '1',
+          autoFillEdge: 'false',
+          minAutoLenght: '0'
+        };
+        grindingConfig.value = defaultConfig;
+        resolve(defaultConfig);
+      }
+    }).catch(() => {
+      const defaultConfig = {
+        leftEdge: '0',
+        upEdge: '0',
+        rightEdge: '0',
+        downEdge: '0',
+        quickEdge: '1',
+        autoFillEdge: 'false',
+        minAutoLenght: '0'
+      };
+      grindingConfig.value = defaultConfig;
+      resolve(defaultConfig);
+    });
+  });
+};
+
+//涓浆绔欐帴鍙桽etTrimming鐨勫�硷紙璁剧疆淇竟锛�
+const emit = defineEmits([
+  'changeDialog',
+  'forward-data-to-grandparent',
+  'send-inventory-to-op'
+]);
+
+const handleTrimmingData = (data) => {
+  emit('forward-data-to-grandparent', data);
+};
+
+//涓浆绔欐帴鍙桟heckInventory鐨勫�硷紙鏌ヨ搴撳瓨锛�
+const handleInventory = (selectedLabel1, selectedLabel2) => {
+  let type=0;
+  if(originalFilm.value===true&&surplusMaterial.value===true){
+    type=3
+  }else if(originalFilm.value===true&&surplusMaterial.value===false){
+    type=1
+  }else if(originalFilm.value===false&&surplusMaterial.value===true){
+    type=2
+  }else{
+    type=1
+  }
+  emit('send-inventory-to-op', selectedLabel1, selectedLabel2,type);
+}
 
 </script>
 
 <template>
-  <div style="width: 100%;height: 100%">
-    <vxe-grid
-        @filter-change="filterChanged"
-        height="100%"
-        class="mytable-scrollbar"
-        ref="xGrid"
-        v-bind="gridOptions"
-        v-on="gridEvents"
-    >
+  <div style="width: 100%;height: 85%;">
+    <!-- 澶撮儴 -->
+    <div id="header" >
+      <!--宸ョ▼鏂囦欢鑿滃崟-->
+      <el-dropdown @command="handleCommand">
+        <el-button type="primary" :icon="Folder" style="margin-top: 8px; margin-left: 5px">
+          宸ョ▼鏂囦欢
+        </el-button>
+        <template #dropdown>
+          <el-dropdown-menu>
+            <el-dropdown-item :command="1" :icon="Plus">鍒涘缓宸ョ▼</el-dropdown-item>
+            <el-dropdown-item :command="2" :icon="Setting">宸ョ▼绠$悊</el-dropdown-item>
+            <el-dropdown-item :command="3" :icon="Operation">妯℃嫙璁$畻</el-dropdown-item>
+          </el-dropdown-menu>
+        </template>
+      </el-dropdown>
 
-      <template #num2_filter="{ column, $panel }">
-        <div>
-          <div v-for="(option, index) in column.filters" :key="index">
-            <vxe-select v-model="option.data" :placeholder="$t('processCard.pleaseSelect')"  @change="changeFilterEvent($event, option, $panel)">
-              <vxe-option value="0" :label="$t('basicData.unchecked')"></vxe-option>
-              <vxe-option value="1" :label="$t('basicData.selected')"></vxe-option>
-            </vxe-select>
+      <div id="title">
+        <span>宸ョ▼缂栧彿锛�</span>
+        <el-input readonly placeholder="" style="width: 150px" v-model="projectNo"></el-input>&nbsp;
+        <span>宸ョ▼鍚嶇О锛�</span>
+        <el-input readonly placeholder="" style="width: 150px; margin-right: 140px;" v-model="projectName" ></el-input>
+        鍘熺墖<el-checkbox v-model="originalFilm" ></el-checkbox>
+        浣欐枡<el-checkbox v-model="surplusMaterial" ></el-checkbox>&nbsp;&nbsp;
+        <el-button id="checkinventory" type="primary" @click="openDialog(1)">鏌ヨ搴撳瓨</el-button>
+        <el-dialog v-model="dialogVisible[1]" title="鏌ヨ搴撳瓨" destroy-on-close style="width: 35%;height:35%;">
+          <check-inventory :closeDialog="closeDialog" :thickNess="thickNess" :model="model"
+                           @send-data-inventory="handleInventory"/>
+        </el-dialog>
+        <el-button id="button" type="primary" @click="openDialog(2)">璁剧疆纾ㄩ噺</el-button>
+        <el-dialog v-model="dialogVisible[2]" title="璁剧疆纾ㄩ噺锛坢m锛�" destroy-on-close
+                   style="width: 35%;height:80%;margin-top: 3vh;">
+          <set-amount :closeDialog="closeDialog" @set-amount="Amount"/>
+        </el-dialog>
+        <el-button id="button" type="primary" @click="openDialog(3)">璁剧疆淇竟</el-button>
+        <el-dialog v-model="dialogVisible[3]" title="璁剧疆淇竟锛坢m锛�" destroy-on-close
+                   style="width: 35%;height:80%;margin-top: 3vh;">
+          <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>
+        <el-dialog v-model="dialogVisible[4]" title="浼樺寲璁$畻" destroy-on-close
+                   style="width: 75%;height:90%;margin-top: 3vh;">
+          <optimize-compute :quantity="quantitys" :area="areas" :optimizeData="optimizeData"
+                            @send-data-event="handleTrimmingData"/>
+        </el-dialog>
+      </div>
+    </div>
+
+    <!-- 琛ㄦ牸瀹瑰櫒 -->
+    <div class="table-container">
+      <vxe-grid
+          class="left-table"
+          @filter-change="filterChanged"
+          height="100%"
+          ref="xGrid"
+          v-bind="gridOptions"
+          v-on="gridEvents"
+          v-bind:style="{ width: leftTableWidth + '%' }"
+      >
+        <template #num2_filter="{ column, $panel }">
+          <div>
+            <div v-for="(option, index) in column.filters" :key="index">
+              <vxe-select v-model="option.data" :placeholder="$t('processCard.pleaseSelect')"
+                          @change="changeFilterEvent($event, option, $panel)">
+                <vxe-option value="0" :label="$t('basicData.unchecked')"></vxe-option>
+                <vxe-option value="1" :label="$t('basicData.selected')"></vxe-option>
+              </vxe-select>
+            </div>
           </div>
-        </div>
-      </template>
-
-      <template #num1_filter="{ column, $panel }">
-        <div>
-          <div v-for="(option, index) in column.filters" :key="index">
-            <input
-                type="type"
-                v-model="option.data"
-                @keyup.enter.native="$panel.confirmFilter()"
-                @input="changeFilterEvent($event, option, $panel)"/>
+        </template>
+        <template #num1_filter="{ column, $panel }">
+          <div>
+            <div v-for="(option, index) in column.filters" :key="index">
+              <input
+                  type="type"
+                  v-model="option.data"
+                  @keyup.enter.native="$panel.confirmFilter()"
+                  @input="changeFilterEvent($event, option, $panel)"/>
+            </div>
           </div>
-        </div>
-      </template>
+        </template>
+      </vxe-grid>
 
-      <template #toolbar>
-        <el-dropdown @command="handleCommand" >
-          <el-button type="primary" :icon="Folder">
-            宸ョ▼鑿滃崟<el-icon class="el-icon--right"></el-icon>
-          </el-button>
-          <template #dropdown>
-            <el-dropdown-menu>
-              <el-dropdown-item :command="1">鍒涘缓宸ョ▼</el-dropdown-item>
-              <el-dropdown-item :command="2">宸ョ▼绠$悊</el-dropdown-item>
-              <el-dropdown-item :command="3">妯℃嫙璁$畻</el-dropdown-item>
-<!--              <el-dropdown-item command="4">鏂囦欢瀵煎嚭</el-dropdown-item>
-              <el-dropdown-item command="5">鏂囦欢瀵煎叆</el-dropdown-item>-->
-            </el-dropdown-menu>
-          </template>
-        </el-dropdown>
-      </template>
+      <!-- 娴佺▼鍗¤〃鏍� -->
+      <vxe-grid
+          height="100%"
+          class="right-table"
+          :data="processCardData"
+          v-bind="processCardColumns"
+          v-if="showProcessCardTable"
+          :header-cell-style="{'height': '51.9px'}"
+      >
+      </vxe-grid>
 
-    </vxe-grid>
+    </div>
+    <div class="vxe-table--cell-area" ref="cellArea" >
+      <span  class="vxe-table--cell-main-area"  ></span>
+
+      <span class="vxe-table--cell-active-area"  ></span>
+    </div>
   </div>
 </template>
 
 <style scoped>
+.table-container {
+  width: 100%;
+  height: 100%;
+  flex: 1;
+  display: flex;
+}
 
+.left-table {
+  float: left;
+}
+
+.right-table {
+  width: 40%;
+}
+
+:deep(.vxe-toolbar){
+  height: 40px;
+}
+
+#header {
+  height: 50px;
+  display: flex;
+
+}
+
+#title {
+  margin: 8px 5px;
+  width: 1240px;
+}
+
+#button {
+  margin-left: 10px;
+}
+
+.vxe-grid {
+  /* 绂佺敤娴忚鍣ㄩ粯璁ら�変腑 */
+  -webkit-user-select: none;
+  -moz-user-select: none;
+  -ms-user-select: none;
+  user-select: none;
+}
 
 </style>
\ No newline at end of file

--
Gitblit v1.8.0