Przeglądaj źródła

超节损excel导出

tty 1 rok temu
rodzic
commit
33baad9810
2 zmienionych plików z 157 dodań i 95 usunięć
  1. 6 6
      src/utils/excel.js
  2. 151 89
      src/view/performance/12-orderAccounting/index.vue

+ 6 - 6
src/utils/excel.js

@@ -1,4 +1,4 @@
-import { utils, writeFile } from "xlsx";
+import { utils, writeFile } from 'xlsx'
 
 /**
  * 导出 excel 文件
@@ -8,15 +8,15 @@ import { utils, writeFile } from "xlsx";
  */
 export function exportExcelFile(
   array = [],
-  sheetName = "sheet1",
-  fileName = "example.xlsx"
+  sheetName = 'sheet1',
+  fileName = 'example.xlsx'
 ) {
-  const jsonWorkSheet = utils.json_to_sheet(array);
+  const jsonWorkSheet = utils.json_to_sheet(array)
   const workBook = {
     SheetNames: [sheetName],
     Sheets: {
       [sheetName]: jsonWorkSheet,
     },
-  };
-  return writeFile(workBook, fileName);
+  }
+  return writeFile(workBook, fileName)
 }

+ 151 - 89
src/view/performance/12-orderAccounting/index.vue

@@ -15,7 +15,7 @@
                 v-model="searchInfo"
                 placeholder="搜索产品编号或产品名称"
                 clearable
-                style="width: 180px;"
+                style="width: 180px"
               />
               <el-button
                 type="primary"
@@ -27,7 +27,11 @@
                 type="primary"
                 icon="edit"
                 class="bt"
-                @click="() => {dialogDetail = true}"
+                @click="
+                  () => {
+                    dialogDetail = true;
+                  }
+                "
               ><i class="el-icon-edit" />查改
               </el-button>
               <!--                <el-button type="primary" disabled icon="edit" @click="" style="margin-left: 10px">工艺方案复制</el-button>-->
@@ -35,7 +39,11 @@
                 type="primary"
                 icon="edit"
                 class="bt"
-                @click="()=>{dialogGdcjstj = true}"
+                @click="
+                  () => {
+                    dialogGdcjstj = true;
+                  }
+                "
               >工单超节损统计
               </el-button>
 
@@ -43,7 +51,11 @@
                 type="primary"
                 icon="edit"
                 class="bt"
-                @click="()=>{dialogKhsz = true}"
+                @click="
+                  () => {
+                    dialogKhsz = true;
+                  }
+                "
               >考核设置
               </el-button>
 
@@ -51,7 +63,11 @@
                 type="primary"
                 icon="edit"
                 class="bt"
-                @click="()=>{dialogXzgdtl = true}"
+                @click="
+                  () => {
+                    dialogXzgdtl = true;
+                  }
+                "
               >修正工单投料
               </el-button>
 
@@ -59,7 +75,11 @@
                 type="primary"
                 icon="edit"
                 class="bt"
-                @click="()=>{dialogGxclhc = true}"
+                @click="
+                  () => {
+                    dialogGxclhc = true;
+                  }
+                "
               >工序产量核查
               </el-button>
 
@@ -67,7 +87,11 @@
                 type="primary"
                 icon="edit"
                 class="bt"
-                @click="()=>{dialogGdzjfptj = true}"
+                @click="
+                  () => {
+                    dialogGdzjfptj = true;
+                  }
+                "
               >工单质检废品统计
               </el-button>
 
@@ -75,7 +99,11 @@
                 type="primary"
                 icon="edit"
                 class="bt"
-                @click="()=>{dialogHjfpfb = true}"
+                @click="
+                  () => {
+                    dialogHjfpfb = true;
+                  }
+                "
               >核检废品分布
               </el-button>
 
@@ -91,18 +119,22 @@
                 type="primary"
                 icon="edit"
                 class="bt"
-                @click="()=>{pd_lcdlist = true; pd_lcdProductValue()}"
+                @click="
+                  () => {
+                    pd_lcdlist = true;
+                    pd_lcdProductValue();
+                  }
+                "
               >流程单查询
               </el-button>
 
-             <el-button
+              <el-button
                 type="primary"
                 icon="edit"
                 class="bt"
-                @click="testExcel"
-              >导出测试
+                @click="exportExcel"
+              >导出Excel
               </el-button>
-
             </el-form-item>
           </el-form>
 
@@ -113,7 +145,11 @@
               v-if="dialogDetail"
               :is-show="dialogDetail"
               :gdbh="gdbh"
-              @destroy="()=>{dialogDetail = false}"
+              @destroy="
+                () => {
+                  dialogDetail = false;
+                }
+              "
             />
 
             <!-- 工单超节损统计 -->
@@ -169,16 +205,27 @@
               title="工单工序生产进程"
               fullscreen
             >
-              <div style="width: 100%;height: 100%;">
+              <div style="width: 100%; height: 100%">
                 <el-button
                   type=""
-                  @click="()=>{pd_lcdlist = false}"
+                  @click="
+                    () => {
+                      pd_lcdlist = false;
+                    }
+                  "
                 >退出</el-button>
               </div>
-              <div style="width: 100%; height: 100%; display: flex; align-items: center;">
+              <div
+                style="
+                  width: 100%;
+                  height: 100%;
+                  display: flex;
+                  align-items: center;
+                "
+              >
                 <el-form-item
                   label="工单编号"
-                  style="margin-right: 20px; padding: 0;"
+                  style="margin-right: 20px; padding: 0"
                 >
                   <el-input
                     v-model="pd_lcdformData['gdbh']"
@@ -187,7 +234,7 @@
                 </el-form-item>
                 <el-form-item
                   label=""
-                  style="margin-right: 5px; padding: 0;"
+                  style="margin-right: 5px; padding: 0"
                 >
                   <el-input
                     v-model="pd_lcdformData['code']"
@@ -196,7 +243,7 @@
                 </el-form-item>
                 <el-form-item
                   label=""
-                  style="margin-right: 5px; padding: 0;"
+                  style="margin-right: 5px; padding: 0"
                 >
                   <el-input
                     v-model="pd_lcdformData['name']"
@@ -205,12 +252,12 @@
                   />
                 </el-form-item>
               </div>
-              <div style="width: 100%; height: 70vh; display: flex;">
+              <div style="width: 100%; height: 70vh; display: flex">
                 <layout>
                   <layout-sider
                     :resize-directions="['right']"
                     :width="240"
-                    style="margin-right: 10px;height: 70vh;"
+                    style="margin-right: 10px; height: 70vh"
                   >
                     <div class="JKWTree-tree">
                       <el-tree
@@ -227,7 +274,11 @@
                       <template v-for="item in processList.total_process">
                         <el-button
                           disabled
-                          :type="! processList.process.includes(item) ? 'danger' : 'info'"
+                          :type="
+                            !processList.process.includes(item)
+                              ? 'danger'
+                              : 'info'
+                          "
                           plain
                           style="width: 50px"
                         >{{ item }}</el-button>
@@ -237,9 +288,7 @@
                 </layout>
               </div>
             </el-dialog>
-
           </div>
-
         </div>
       </layout-header>
 
@@ -248,13 +297,13 @@
         <layout-sider
           :resize-directions="['right']"
           :width="190"
-          style="margin-right: 10px;"
+          style="margin-right: 10px"
         >
           <div
             class="JKWTree-tree"
-            style="height: 70vh;"
+            style="height: 70vh"
           >
-            <h3> 工单超节损核算</h3>
+            <h3>工单超节损核算</h3>
             <el-tree
               :data="treeData"
               highlight-current
@@ -265,11 +314,10 @@
 
         <!--  右侧内容区域 -->
         <layout-content>
-
           <!-- 上方列表 -->
           <div class="gva-table-box">
             <el-table
-              style="width: 100%;height:30vh;"
+              style="width: 100%; height: 30vh"
               :data="tableData1"
               row-key="ID"
               highlight-current-row
@@ -281,7 +329,11 @@
               :header-row-style="{ height: '20px' }"
               :header-cell-style="{ padding: '0px' }"
               @row-click="showOrderSuperLossGy"
-              @current-change="(row, oldRow) => { currentRow = row}"
+              @current-change="
+                (row, oldRow) => {
+                  currentRow = row;
+                }
+              "
             >
               <el-table-column
                 type="selection"
@@ -297,13 +349,12 @@
                 show-overflow-tooltip="true"
                 sortable
               />
-
             </el-table>
           </div>
 
           <!-- 下方表格 -->
           <el-table
-            style="width: 100%;height: 40vh;"
+            style="width: 100%; height: 40vh"
             row-key="ID"
             highlight-current-row
             border
@@ -342,7 +393,7 @@ export const getOrderProcessLeft = (params) => {
   return service({
     url: '/mes_server/work_order_verification/getOrderProcessLeft',
     method: 'get',
-    params
+    params,
   })
 }
 // 5.2流程单查询-获取工单工序生产进程右侧
@@ -350,28 +401,37 @@ export const getOrderProcessRight = (params) => {
   return service({
     url: '/mes_server/work_order_verification/getOrderProcessRight',
     method: 'get',
-    params
+    params,
   })
 }
 </script>
 <script setup>
-import { Layout, LayoutContent, LayoutHeader, LayoutSider } from '@arco-design/web-vue'
+import {
+  Layout,
+  LayoutContent,
+  LayoutHeader,
+  LayoutSider,
+} from '@arco-design/web-vue'
 import { ref, watch } from 'vue'
-import { getOrderSuperLossGy, getSide, getTable } from '@/api/mes_api_gty/orderAccounting'
+import {
+  getOrderSuperLossGy,
+  getSide,
+  getTable,
+} from '@/api/mes_api_gty/orderAccounting'
 import Gdcjstj from '@/view/performance/12-orderAccounting/componets/gdcjstj.vue'
 import Khsz from '@/view/performance/12-orderAccounting/componets/khsz.vue'
 import Xzgdtl from '@/view/performance/12-orderAccounting/componets/xzgdtl.vue'
 import Gxclhc from '@/view/performance/12-orderAccounting/componets/gxclhc.vue'
-import Gongdanzhijianfeipintongji
-  from '@/view/performance/09-workOrderVerification/componets/gongdanzhijianfeipintongji.vue'
+import Gongdanzhijianfeipintongji from '@/view/performance/09-workOrderVerification/componets/gongdanzhijianfeipintongji.vue'
 import Detail from '@/view/performance/12-orderAccounting/componets/detail.vue'
 import Hjfpfb from './componets/hjfpfb.vue'
 import PrintPage from '@/view/yunyin/shengchanguanli/components/print.vue'
 import { reactive } from 'vue'
 import { exportExcelFile } from '@/utils/excel'
 import { useUserStore } from '@/pinia/modules/user'
-const userStore = useUserStore() 
-const sys_id='['+userStore.userInfo.userName+'/'+userStore.userInfo.nickName+']'
+const userStore = useUserStore()
+const sys_id =
+  '[' + userStore.userInfo.userName + '/' + userStore.userInfo.nickName + ']'
 
 // 弹窗
 const dialogGdcjstj = ref(false)
@@ -395,7 +455,7 @@ const getSideData = async() => {
       const transformedItem = {
         label: `${date}(工单数:${total})`,
         date: date,
-        children: value.map(item => ({
+        children: value.map((item) => ({
           label: `${item['客户编号']}【${item['客户名称']}】(工单数:${item.total})`,
           date: date,
           code: item?.['客户编号'],
@@ -423,7 +483,7 @@ const tableCols1 = [
   { label: '目标合格率', prop: 'target_rate', width: '120' },
   { label: '实际合格率', prop: 'real_rate', width: '120' },
   { label: '奖惩系数', prop: 'reward_rate', width: '120' },
-  { label: '奖罚金额合计', prop: '', width: '140' },
+  // { label: '奖罚金额合计', prop: '', width: '140' },
   { label: '废品合计', prop: '废品合计', width: '120' },
   { label: '工单无形损', prop: '工单无形损', width: '120' },
   { label: '材料废', prop: '材料废', width: '120' },
@@ -468,9 +528,12 @@ const handleNodeClick = async(node) => {
   if (!node.children) {
     const { date, code } = node
     const res = await getTable({ date, code, limit: 9999, page: 1 })
-    tableData1.value = res.data.data.map(item => ({
+    tableData1.value = res.data.data.map((item) => ({
       ...item,
-      csgd: parseFloat(item['target_rate']) - parseFloat(item['real_rate']) > 0 ? '√' : '',
+      csgd:
+        parseFloat(item['target_rate']) - parseFloat(item['real_rate']) > 0
+          ? '√'
+          : '',
       date: date,
     }))
     console.log(res.data)
@@ -485,17 +548,20 @@ const showOrderSuperLossGy = async() => {
   const res = await getOrderSuperLossGy({ order })
   if (res.code === 0) {
     const { data } = res
-    tableData2.value = data.map(item => ({
+    tableData2.value = data.map((item) => ({
       ...item,
       Gy0_yjno: `${item.Gy0_yjno}-${item.Gy0_gxh}`,
-      Gy0_gxmc: item.Add_gxmc === '' ? item.Gy0_gxmc : `${item.Gy0_gxmc}〖${item.Add_gxmc}〗`,
+      Gy0_gxmc:
+        item.Add_gxmc === ''
+          ? item.Gy0_gxmc
+          : `${item.Gy0_gxmc}〖${item.Add_gxmc}〗`,
     }))
   }
 }
 // 定位
 const handleSearch = () => {
   if (searchInfo.value) {
-    tableData1.value = tableData1.value.filter(item => {
+    tableData1.value = tableData1.value.filter((item) => {
       return item['Gd_gdbh'] === searchInfo.value ?? item
     })
   }
@@ -533,16 +599,20 @@ const _getOrderProcessLeft_list = async() => {
   console.log(order)
   try {
     // 5.1流程单查询-工单工序生产进程菜单栏
-    const getOrderProcessLeft_list = await getOrderProcessLeft({ order: order })
+    const getOrderProcessLeft_list = await getOrderProcessLeft({
+      order: order,
+    })
     console.log(getOrderProcessLeft_list)
     pd_lcdformData['code'] = getOrderProcessLeft_list.data.Gd_info['code']
     pd_lcdformData['name'] = getOrderProcessLeft_list.data.Gd_info['name']
-    pd_lcd_treeData.value = [{
-      label: order + '-' + getOrderProcessLeft_list.data.Gd_info['name'],
-      // label: order + '-' + getOrderProcessLeft_list.data.Gd_info['code'] + '-' + getOrderProcessLeft_list.data.Gd_info['name'],
-      value: undefined,
-      children: []
-    }]
+    pd_lcd_treeData.value = [
+      {
+        label: order + '-' + getOrderProcessLeft_list.data.Gd_info['name'],
+        // label: order + '-' + getOrderProcessLeft_list.data.Gd_info['code'] + '-' + getOrderProcessLeft_list.data.Gd_info['name'],
+        value: undefined,
+        children: [],
+      },
+    ]
     const newData = []
     for (const key in getOrderProcessLeft_list.data.Gy_info) {
       const temp = getOrderProcessLeft_list.data.Gy_info[key]
@@ -551,7 +621,10 @@ const _getOrderProcessLeft_list = async() => {
     }
     pd_lcd_treeData.value[0].children = newData
     // 5.2流程单查询-获取工单工序生产进程右侧【进入页面默认显示第一个】
-    const getOrderProcessRight_list = await getOrderProcessRight({ order: order, gxNo: newData[0].value })
+    const getOrderProcessRight_list = await getOrderProcessRight({
+      order: order,
+      gxNo: newData[0].value,
+    })
     processList.value = getOrderProcessRight_list.data
   } catch (error) {
     console.error(error)
@@ -562,40 +635,30 @@ const pd_lcd_handleNodeClick = async(node) => {
   if (node.value === undefined) return
   const order = pd_lcdformData['gdbh']
   // //5.2流程单查询-获取工单工序生产进程右侧
-  const getOrderProcessRight_list = await getOrderProcessRight({ order: order, gxNo: node.value })
+  const getOrderProcessRight_list = await getOrderProcessRight({
+    order: order,
+    gxNo: node.value,
+  })
   console.log(getOrderProcessRight_list)
   processList.value = getOrderProcessRight_list.data
 }
-//导出
-const testExcel = () => {
-  const data = [
-  {
-      '第一列': '111',
-      '第二列': '222',
-      '第三列': '333',
-      '第四列': '444',
-    },
-    {
-      '第一列': '111',
-      '第二列': '222',
-      '第三列': '333',
-    },
-    {
-      '第一列': '111',
-      '第二列': '222',
-      '第三列': '333',
-    },
-    {
-      '第一列': '111',
-      '第二列': '222',
-      '第三列': '333',
-    },
-
-  ]
-  
-  exportExcelFile(data);
+// 导出excel
+const exportExcel = () => {
+  const labels = tableCols1.map((item) => item.label)
+  const props = tableCols1.map((item) => item.prop)
+
+  const data = tableData1.value.map((item) => {
+    const row = {}
+    props.forEach((prop, index) => {
+      row[labels[index]] = item?.[prop]
+    })
+    return row
+  })
+  if (data[0]?.[labels[0]] === undefined) {
+    return
+  }
+  exportExcelFile(data)
 }
-
 </script>
 
 <style scoped>
@@ -626,18 +689,17 @@ const testExcel = () => {
 }
 
 :deep(.el-table .yellow-row) {
-  background: #FFFF80;
+  background: #ffff80;
 }
 
 :deep(.red-cell div) {
-  color: #FF0000 !important;
+  color: #ff0000 !important;
 }
 
 /* 选中某行时的背景色 */
 :deep(.el-table__body tr.current-row) > td {
   background: #ff80ff !important;
 }
-
 </style>
 <style scoped>
 :deep(.el-table td .cell) {