Browse Source

生产管理

liuhairui 1 year ago
parent
commit
a893582e8f
2 changed files with 62 additions and 61 deletions
  1. 1 0
      package.json
  2. 61 61
      src/view/yunyin/shengchanguanli/gongdanshengchan.vue

+ 1 - 0
package.json

@@ -18,6 +18,7 @@
         "@wangeditor/editor-for-vue": "^5.1.12",
         "axios": "^1.4.0",
         "core-js": "^3.31.1",
+        "dayjs": "^1.11.10",
         "echarts": "^5.4.3",
         "element-plus": "^2.4.4",
         "highlight.js": "^11.8.0",

+ 61 - 61
src/view/yunyin/shengchanguanli/gongdanshengchan.vue

@@ -154,12 +154,13 @@
                         :data="paichengData" row-key="ID"
                         :cell-class-name="cjzcCellClass"
               >
-<!--                highlight-current-row="true"-->
+                <!--                highlight-current-row="true"-->
                 <template v-for="(item, idx) in paichengColumns">
                   <el-table-column #default="{ row, column, $index }" align="left" :label="item.label" :width="item.width" >
-                    <div v-if="['优先次序', '生产工时', '辅助工时', '班次安排', '排单备注','最早开工时间', '计划开工时间'].includes(item.prop)">
+                    <div v-if="['优先次序', '小时产能', '生产工时', '辅助工时', '班次安排', '排单备注','最早开工时间', '计划开工时间'].includes(item.prop)">
                       <el-input v-model="row[item.prop]" :clearable="false"
                                 :id="`input${idx}${$index}`"
+                                @blur="handleBlur(item['label'], item)"
                                 @keyup="handleKeyDown($event, idx, $index, item.prop)"
                       />
                       <!--                      <el-date-picker v-model="row[item.prop]" v-if="['最早开工时间', '计划开工时间'].includes(item.prop)" type="datetime" :clearable="false"-->
@@ -452,6 +453,7 @@ import {createCompany, deleteCompany, deleteCompanyByIds, updateCompany, findCom
 import { getDictFunc, formatDate, formatBoolean, filterDict, ReturnArrImg, onDownloadFile } from '@/utils/format'
 import { ElMessage, ElMessageBox } from 'element-plus'
 import { ref, reactive } from 'vue'
+import dayjs from 'dayjs'
 import {
   DataList,
   getProduct,
@@ -1223,10 +1225,10 @@ const pd_yysjcsonClick = () => {
 const paichengColumns = ref(
     [
       { label: '优先次序', prop: '优先次序', width: '105' },
-      { label: '工单编号', prop: '工单编号', width: '100' },
+      // { label: '工单编号', prop: '工单编号', width: '100' },
       // { label: '印件名称', prop: '印件名称', width: '220' },
-      { label: '印件名称', prop: '印件名称', width: '100' },
       { label: '接货数', prop: '接货数', width: '105' },
+      { label: '已完成', prop: '已完成', width: '105' },
       { label: '小时产能', prop: '小时产能', width: '100' },
       { label: '生产工时', prop: '生产工时', width: '100' },
       { label: '辅助工时', prop: '辅助工时', width: '100' },
@@ -1237,8 +1239,50 @@ const paichengColumns = ref(
       { label: '计划完工时间', prop: '计划完工时间', width: '180' },
       { label: '销售订单号', prop: '销售订单号', width: '120' },
       { label: '印件/工序', prop: '印件/工序', width: '110' },
-    ]
-)
+    ])
+
+const handleDataSortAndSettingDate = () => {
+  paichengData.value.sort((a, b) => {
+    const priorityA = parseFloat(a['优先次序']);
+    const priorityB = parseFloat(b['优先次序']);
+    // 将空白值放在最后
+    if (isNaN(priorityA)) return 1;
+    if (isNaN(priorityB)) return -1;
+    // 按优先次序升序排序
+    return priorityA - priorityB;
+  });
+
+
+  paichengData.value.map((item, index) => {
+    let hour = parseFloat(item['生产工时']) + parseFloat(item['辅助工时'])
+    if ( ((Math.floor(hour) * 10) % 10) !== 5) {
+      hour = Math.round(hour)
+    }
+    const sec = hour * 3600
+    const startTime = dayjs(item['计划开工时间']).unix()
+    item['计划完工时间'] = dayjs((startTime + sec) * 1000).format('YYYY-MM-DD HH:mm:ss')
+    if (index > 0) {
+      item['计划开工时间'] = paichengData.value[index-1]['计划完工时间']
+      hour = parseFloat(item['生产工时']) + parseFloat(item['辅助工时'])
+      if ( ((Math.floor(hour) * 10) % 10) !== 5) {
+        hour = Math.round(hour)
+      }
+      const sec = hour * 3600
+      const startTime = dayjs(item['计划开工时间']).unix()
+      item['计划完工时间'] = dayjs((startTime + sec) * 1000).format('YYYY-MM-DD HH:mm:ss')
+    }
+  })
+}
+
+const handleBlur = (name, item) => {
+  if (name === '优先次序' || name === '计划开工时间' || name === '辅助工时') {
+    handleDataSortAndSettingDate()
+  }
+  if (name === '小时产能') {
+    item['生产工时'] = Math.round( ( (item['计划接货数'] ?? 0) - Number(item['已完成'] ?? 0) ) / item['小时产能'] ).toFixed(1)
+    handleDataSortAndSettingDate()
+  }
+}
 const handleKeyDown = (event, x, y, prop) => {
   console.log(event)
   const currentElement = document.getElementById(`input${x}${y}`);
@@ -1247,57 +1291,7 @@ const handleKeyDown = (event, x, y, prop) => {
   switch (event.keyCode) {
     case 13: // Enter
       if (x === 0 && y === +y) {
-        console.log("排序前的值");
-        console.log(paichengData.value);
-
-        paichengData.value.sort((a, b) => {
-          const priorityA = parseFloat(a['优先次序']);
-          const priorityB = parseFloat(b['优先次序']);
-          // 将空白值放在最后
-          if (isNaN(priorityA)) return 1;
-          if (isNaN(priorityB)) return -1;
-          // 按优先次序升序排序
-          return priorityA - priorityB;
-        });
-        console.log("排序后的值");
-        console.log(paichengData.value);
-
-        // 封装时间格式化函数
-        function formatTimestamp(timestamp) {
-          const date = new Date(timestamp * 1000);
-          const year = date.getFullYear();
-          const month = (date.getMonth() + 1).toString().padStart(2, '0');
-          const day = date.getDate().toString().padStart(2, '0');
-          const hours = date.getHours().toString().padStart(2, '0');
-          const minutes = date.getMinutes().toString().padStart(2, '0');
-          const seconds = date.getSeconds().toString().padStart(2, '0');
-          const formattedDate = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
-          return formattedDate;
-        }
-        // 获取第一行数据
-        const firstRow = paichengData.value[+y];
-        console.log(firstRow)
-        // 初始化上一行的计划完工时间为第一行的计划开工时间
-        let prevCompletionTime = new Date(firstRow['计划开工时间']).getTime() / 1000;
-        // 遍历每一行数据
-        paichengData.value.forEach(row => {
-          const roundedValue = (Math.floor(row['生产工时'] * 10) % 10 === 5) ? row['生产工时'] : Math.round(row['生产工时']);
-          const result = parseFloat(roundedValue) + parseFloat(row['辅助工时']);
-          const resultTimestamp = result * 3600;
-          // 计算【计划开工时间】最终时间戳,使用上一行的计划完工时间
-          const finalTimestamp = prevCompletionTime + resultTimestamp;
-          // 将计划完工时间赋值到当前行
-          row['计划完工时间'] = formatTimestamp(finalTimestamp);
-          // row['计划开工时间'] =formatTimestamp(finalTimestamp);
-          // 更新上一行的计划完工时间为当前行的计划完工时间
-          prevCompletionTime = finalTimestamp;
-
-          console.log("=============================");
-          console.log("x是 y是 生产工时 + 辅助工时 * 3600 + 计划开工时间 = 时间戳↓↓↓↓↓↓↓↓↓");
-          console.log(`x是 ${x}  Y是 ${y} --- ${roundedValue} + ${row['辅助工时']} * 3600 + ${new Date(row['计划开工时间']).getTime() / 1000} = ${finalTimestamp}`);
-          console.log("=============================");
-
-        });
+            handleDataSortAndSettingDate()
       }
       const nextInputElement = document.getElementById(`input${x}${y + 1}`);
       if (nextInputElement) {
@@ -1356,11 +1350,17 @@ const pd_gdprintonClick = () => {
 }
 
 //车间设备排程【按钮】
-const oncjsbpcClick = () => {
+const oncjsbpcClick = async () => {
   cjsbpcformData['sbdh'] = _machine.value;
   paichengData.value = [];
-  _EquipmentSchedulingdata();
-  _ScheduleSelectiondata();
+  await _EquipmentSchedulingdata();
+  await _ScheduleSelectiondata();
+
+  paichengData.value.map((item, index) => {
+    item['优先次序'] = 50 + index
+  })
+
+  handleDataSortAndSettingDate()
   cjsbpclist.value = true;
 };
 //调用班次选择列表接口
@@ -1525,7 +1525,7 @@ const gxztgzzCellClass = ({row, column, rowIndex, columnIndex}) =>{
 }
 //车间设备制程排序背景
 const cjzcCellClass = ({row, column, rowIndex, columnIndex}) =>{
-  if (column.label === '优先次序' || column.label === '生产工时' || column.label === '辅助工时' || column.label === '班次安排' || column.label === '排单备注' || column.label === '最早开工时间'  || column.label === '计划开工时间') {
+  if (column.label === '小时产能' || column.label === '优先次序' || column.label === '生产工时' || column.label === '辅助工时' || column.label === '班次安排' || column.label === '排单备注' || column.label === '最早开工时间'  || column.label === '计划开工时间') {
     return 'background-color-column-fen';
   }
   if (row) {