From 173855b299e89930b5ea2ff9a9295fde9d0f55b5 Mon Sep 17 00:00:00 2001
From: gaoluyang <2820782392@qq.com>
Date: 星期六, 07 十一月 2026 08:51:43 +0800
Subject: [PATCH] feat: 同步质检、生产、销售、财务与人事前端功能

---
 src/views/hrm/salary/calculation/index.vue |  345 +++++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 298 insertions(+), 47 deletions(-)

diff --git a/src/views/hrm/salary/calculation/index.vue b/src/views/hrm/salary/calculation/index.vue
index 33a1f36..2378496 100644
--- a/src/views/hrm/salary/calculation/index.vue
+++ b/src/views/hrm/salary/calculation/index.vue
@@ -2,23 +2,23 @@
 import type { VxeTableGridOptions } from '#/adapter/vxe-table';
 import type { HrmSalaryCalculationApi } from '#/api/hrm/salary/calculation';
 
-import { ref } from 'vue';
+import { computed, ref, watch } from 'vue';
 
 import { Page } from '#/packages/effects/common-ui/src';
 import { downloadFileFromBlobPart } from '#/packages/utils/src';
 
-import { message, Modal, Form, FormItem, DatePicker, TreeSelect, Table, InputNumber, Alert, Tag } from 'ant-design-vue';
+import { Alert, Button, DatePicker, Form, FormItem, InputNumber, message, Modal, Table, Tag, TreeSelect } from 'ant-design-vue';
 
 import { DICT_TYPE } from '#/packages/constants/src';
 import { getDictLabel } from '#/packages/effects/hooks/src';
 
 import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
 import {
-  calculateSalary,
   confirmSalary,
   deleteSalaryCalculation,
   exportSalaryCalculation,
   getSalaryCalculationPage,
+  getWorkWageDetail,
   previewSalaryCalculation,
   revokeSalaryCalculation,
   saveSalaryCalculation,
@@ -37,14 +37,34 @@
 const previewLoading = ref(false);
 const previewData = ref<HrmSalaryCalculationApi.SalaryCalculation[]>([]);
 const submitLoading = ref(false);
-const calculateLoading = ref(false);
+/** 宸插畬鎴愰瑙堢殑鏉′欢锛堝懆鏈�+閮ㄩ棬锛夛紱涓虹┖琛ㄧず杩樻病棰勮鎴栨潯浠跺凡鍙樺寲 */
+const previewSignature = ref('');
+const canSubmit = computed(
+  () => previewSignature.value !== '' && previewData.value.length > 0,
+);
+
+function buildQuerySignature() {
+  return `${calculatePeriod.value ?? ''}|${calculateDeptId.value ?? ''}`;
+}
+
+/** 娓呯┖棰勮缁撴灉锛屽己鍒堕噸鏂伴瑙堝悗鎵嶈兘淇濆瓨 */
+function invalidatePreview() {
+  previewData.value = [];
+  previewSignature.value = '';
+}
+
+watch([calculatePeriod, calculateDeptId], () => {
+  if (buildQuerySignature() !== previewSignature.value) {
+    invalidatePreview();
+  }
+});
 
 // 鎵撳紑鏍哥畻寮圭獥
 async function openCalculateModal() {
   const formValues = await gridApi.formApi.getValues();
   calculatePeriod.value = formValues.period;
   calculateDeptId.value = formValues.deptId;
-  previewData.value = [];
+  invalidatePreview();
   // 鍔犺浇閮ㄩ棬鏍�
   const data = await getDeptList();
   deptTreeData.value = handleTree(data);
@@ -56,43 +76,122 @@
   gridApi.query();
 }
 
-/** 鎵ц钖叕鏍哥畻锛堣嚜鍔ㄨ绠楀苟淇濆瓨锛� */
-async function handleCalculate() {
-  if (!calculatePeriod.value) {
-    message.warning('璇烽�夋嫨鏍哥畻鍛ㄦ湡');
-    return;
-  }
-  calculateLoading.value = true;
-  try {
-    await calculateSalary({
-      period: calculatePeriod.value,
-      deptId: calculateDeptId.value,
-    });
-    message.success('钖叕鏍哥畻鎵ц鎴愬姛');
-    calculateVisible.value = false;
-    handleRefresh();
-  } finally {
-    calculateLoading.value = false;
-  }
-}
-
-/** 棰勮鏍哥畻鏁版嵁 */
+/** 棰勮鏍哥畻鏁版嵁锛氫繚瀛樺墠蹇呴』鍏堝畬鎴愰瑙� */
 async function handlePreview() {
   if (!calculatePeriod.value) {
-    message.warning('璇烽�夋嫨鏍哥畻鍛ㄦ湡');
+    message.warning('璇峰厛閫夋嫨鏍哥畻鍛ㄦ湡锛屽啀棰勮鏍哥畻鏁版嵁');
     return;
   }
+  const signature = buildQuerySignature();
   previewLoading.value = true;
   try {
-    previewData.value = await previewSalaryCalculation({
+    const list = await previewSalaryCalculation({
       period: calculatePeriod.value,
       deptId: calculateDeptId.value,
     });
+    // 棰勮鏈熼棿鏉′欢琚慨鏀规椂涓㈠純鏈缁撴灉锛岄伩鍏嶇敤鏃ф潯浠剁殑鏁版嵁淇濆瓨
+    if (signature !== buildQuerySignature()) {
+      return;
+    }
+    previewData.value = list ?? [];
     if (previewData.value.length === 0) {
-      message.info('璇ユ潯浠朵笅娌℃湁闇�瑕佹牳绠楃殑鍛樺伐');
+      previewSignature.value = '';
+      message.info('璇ュ懆鏈�/閮ㄩ棬涓嬫病鏈夐渶瑕佹牳绠楃殑鍛樺伐锛岃璋冩暣鏉′欢鍚庨噸鏂伴瑙�');
+    } else {
+      previewSignature.value = signature;
+      message.success(`棰勮瀹屾垚锛屽叡 ${previewData.value.length} 浜猴紝璇锋牳瀵瑰悗淇濆瓨`);
     }
   } finally {
     previewLoading.value = false;
+  }
+}
+
+// ==================== 鎶ュ伐宸ヨ祫鏄庣粏 ====================
+const wageDetailVisible = ref(false);
+const wageDetailLoading = ref(false);
+const wageDetailList = ref<HrmSalaryCalculationApi.WorkWageDetail[]>([]);
+/** 榛樿灞曞紑鎵�鏈夋姤宸ヨ锛岀洿鎺ュ睍绀鸿嚜瀹氫箟宸ヨ祫瀛楁鏄庣粏 */
+const wageDetailExpandedKeys = ref<Array<number | string>>([]);
+const wageDetailTitle = ref('');
+const wageDetailPeriod = ref('');
+/** 褰撳墠鏍哥畻琛屼笂鐨勩�屾姤宸ュ伐璧勩�嶏紝鐢ㄤ簬鍜屾槑缁嗗悎璁℃瘮瀵� */
+const wageDetailExpected = ref(0);
+
+/** 璁$畻瑙掕壊鏂囨锛氫笌宸ュ簭宸ヨ祫瀛楁鐨勮绠楄鑹蹭繚鎸佷竴鑷� */
+const WAGE_ROLE_LABELS: Record<number, string> = {
+  1: '绯绘暟',
+  2: '鍔犲噺閲戦',
+  3: '璁′环鏁伴噺',
+  4: '浠呰褰�',
+};
+const WAGE_ROLE_COLORS: Record<number, string> = {
+  1: 'blue',
+  2: 'orange',
+  3: 'green',
+  4: 'default',
+};
+
+const wageDetailColumns = [
+  { title: '鎶ュ伐鍗曞彿', dataIndex: 'feedbackNo', width: 170 },
+  { title: '宸ュ簭', dataIndex: 'processName', width: 150 },
+  { title: '鎶ュ伐鏃堕棿', dataIndex: 'feedbackTime', width: 160 },
+  { title: '鎶ュ伐鏁伴噺', dataIndex: 'feedbackQuantity', width: 100 },
+  { title: '鍚堟牸鏁伴噺', dataIndex: 'qualifiedQuantity', width: 100 },
+  { title: '涓诲伐璧�', dataIndex: 'mainWage', width: 100 },
+  { title: '杈呭姪宸ヨ祫', dataIndex: 'auxWage', width: 100 },
+  { title: '瀛楁璋冩暣', dataIndex: 'fieldWage', width: 100 },
+  { title: '璐ㄩ噺璋冩暣', dataIndex: 'qualityAdjustment', width: 100 },
+  { title: '鏈�缁堝伐璧�', dataIndex: 'finalWage', width: 110 },
+];
+
+const wageFieldColumns = [
+  { title: '瀛楁缂栫爜', dataIndex: 'code', width: 140 },
+  { title: '瀛楁鍚嶇О', dataIndex: 'name', width: 160 },
+  { title: '璁$畻瑙掕壊', dataIndex: 'role', width: 110 },
+  { title: '瀛楁鍊�', dataIndex: 'value', width: 120 },
+  { title: '鍗曚环', dataIndex: 'unitPrice', width: 110 },
+  { title: '璁″叆閲戦', dataIndex: 'amount', width: 110 },
+];
+
+/** 閲戦灞曠ず锛岀┖鍊兼樉绀� 0.00 */
+function fmtAmount(value?: null | number) {
+  return Number(value ?? 0).toFixed(2);
+}
+
+/** 鏄庣粏鍚堣锛堝悇鎶ュ伐鍗曟渶缁堝伐璧勪箣鍜岋級 */
+const wageDetailTotal = computed(() =>
+  wageDetailList.value.reduce((sum, item) => sum + Number(item.finalWage ?? 0), 0),
+);
+
+/**
+ * 鎵撳紑鎶ュ伐宸ヨ祫鏄庣粏
+ * @param record 鏍哥畻琛岋紙鏉ヨ嚜棰勮寮圭獥鎴栧垪琛級
+ */
+async function openWageDetail(record: HrmSalaryCalculationApi.SalaryCalculation) {
+  const period = record.period || calculatePeriod.value;
+  if (!period) {
+    message.warning('缂哄皯鏍哥畻鍛ㄦ湡锛屾棤娉曟煡鐪嬫姤宸ュ伐璧勬槑缁嗭紝璇峰厛閫夋嫨鏍哥畻鍛ㄦ湡鍚庨噸璇�');
+    return;
+  }
+  if (!record.userId) {
+    message.warning('缂哄皯鍛樺伐淇℃伅锛屾棤娉曟煡鐪嬫姤宸ュ伐璧勬槑缁嗭紝璇峰埛鏂板垪琛ㄥ悗閲嶈瘯');
+    return;
+  }
+  wageDetailTitle.value = `${record.userName ?? ''} ${period} 鎶ュ伐宸ヨ祫鏄庣粏`;
+  wageDetailPeriod.value = period;
+  wageDetailExpected.value = Number(record.workWage ?? 0);
+  wageDetailList.value = [];
+  wageDetailExpandedKeys.value = [];
+  wageDetailVisible.value = true;
+  wageDetailLoading.value = true;
+  try {
+    wageDetailList.value = (await getWorkWageDetail({ period, userId: record.userId })) ?? [];
+    // 榛樿灞曞紑鍏ㄩ儴鎶ュ伐鍗曪紝瀛楁鏄庣粏鏃犻渶鍐嶇偣寮�
+    wageDetailExpandedKeys.value = wageDetailList.value
+      .map((item) => item.feedbackId)
+      .filter((id): id is number => id !== undefined && id !== null);
+  } finally {
+    wageDetailLoading.value = false;
   }
 }
 
@@ -103,7 +202,8 @@
     (record.overtimePay || 0) +
     (record.mealAllowance || 0) +
     (record.transportAllowance || 0) +
-    (record.otherAllowance || 0);
+    (record.otherAllowance || 0) +
+    (record.workWage || 0);
   const deduction = (record.socialSecurityDeduction || 0) +
     (record.housingFundDeduction || 0) +
     (record.taxDeduction || 0) +
@@ -124,8 +224,8 @@
     message.warning('璇烽�夋嫨鏍哥畻鍛ㄦ湡');
     return;
   }
-  if (previewData.value.length === 0) {
-    message.warning('璇峰厛棰勮鏍哥畻鏁版嵁');
+  if (!canSubmit.value) {
+    message.warning('璇峰厛鐐瑰嚮鈥滈瑙堟牳绠椻�濈敓鎴愭暟鎹紝鏍稿鏃犺鍚庡啀淇濆瓨');
     return;
   }
   submitLoading.value = true;
@@ -145,7 +245,7 @@
 /** 鍙栨秷寮圭獥 */
 function handleCancel() {
   calculateVisible.value = false;
-  previewData.value = [];
+  invalidatePreview();
 }
 
 /** 纭钖叕鏍哥畻 */
@@ -269,12 +369,12 @@
     <Modal
       v-model:open="calculateVisible"
       title="钖叕鏍哥畻"
-      width="1200px"
+      width="1800px"
       :footer="null"
       :maskClosable="false"
     >
       <Alert
-        message="涓ょ鏍哥畻鏂瑰紡锛�1. 鎵ц鏍哥畻 - 鑷姩璁$畻骞朵繚瀛橈紱2. 棰勮鏁版嵁 - 鎵嬪姩璋冩暣鍚庝繚瀛�"
+        message="鎿嶄綔姝ラ锛氶�夋嫨鏍哥畻鍛ㄦ湡锛堝拰閮ㄩ棬锛夆啋 鐐瑰嚮鈥滈瑙堟牳绠椻�濈敓鎴愭暟鎹� 鈫� 鏍稿骞惰皟鏁� 鈫� 淇濆瓨鏍哥畻銆傛湭棰勮鎴栦慨鏀规潯浠跺悗涓嶈兘淇濆瓨銆�"
         type="info"
         show-icon
         style="margin-bottom: 16px"
@@ -303,14 +403,14 @@
           />
         </FormItem>
         <FormItem>
-          <a-button type="primary" :loading="calculateLoading" @click="handleCalculate">
-            鎵ц鏍哥畻
-          </a-button>
+          <Button type="primary" :loading="previewLoading" @click="handlePreview">
+            棰勮鏍哥畻
+          </Button>
         </FormItem>
-        <FormItem>
-          <a-button :loading="previewLoading" @click="handlePreview">
-            棰勮鏁版嵁
-          </a-button>
+        <FormItem v-if="canSubmit">
+          <span class="text-xs text-green-600">
+            宸叉寜褰撳墠鏉′欢棰勮 {{ previewData.length }} 浜猴紝鍙皟鏁村悗淇濆瓨
+          </span>
         </FormItem>
       </Form>
 
@@ -319,7 +419,7 @@
         :columns="usePreviewColumns()"
         :data-source="previewData"
         :pagination="{ pageSize: 20, showSizeChanger: true, showTotal: (t) => `鍏� ${t} 浜篳 }"
-        :scroll="{ x: 1800, y: 400 }"
+        :scroll="{ x: 1920, y: 420 }"
         size="small"
         row-key="userId"
         bordered
@@ -385,6 +485,19 @@
               style="width: 80px"
               @change="(val: number) => updateFieldValue(record, 'otherAllowance', val)"
             />
+          </template>
+          <template v-else-if="column.dataIndex === 'workWage'">
+            <div class="flex items-center gap-1">
+              <InputNumber
+                v-model:value="record.workWage"
+                :min="0"
+                :precision="2"
+                size="small"
+                style="width: 82px"
+                @change="(val) => updateFieldValue(record, 'workWage', Number(val ?? 0))"
+              />
+              <a class="text-xs whitespace-nowrap" @click="openWageDetail(record)">鏄庣粏</a>
+            </div>
           </template>
           <template v-else-if="column.dataIndex === 'socialSecurityDeduction'">
             <InputNumber
@@ -461,12 +574,144 @@
         </template>
       </Table>
 
-      <div class="flex justify-end gap-2" v-if="previewData.length > 0">
-        <a-button @click="handleCancel">鍙栨秷</a-button>
-        <a-button type="primary" :loading="submitLoading" @click="handleSubmit">
+      <div class="flex items-center justify-end gap-2">
+        <span v-if="!canSubmit" class="mr-auto text-xs text-gray-500">
+          璇峰厛閫夋嫨鏍哥畻鍛ㄦ湡骞剁偣鍑烩�滈瑙堟牳绠椻�濓紝棰勮瀹屾垚鍚庢墠鑳戒繚瀛�
+        </span>
+        <Button @click="handleCancel">鍙栨秷</Button>
+        <Button
+          type="primary"
+          :loading="submitLoading"
+          :disabled="!canSubmit"
+          @click="handleSubmit"
+        >
           淇濆瓨鏍哥畻
-        </a-button>
+        </Button>
       </div>
+    </Modal>
+
+    <!-- 鎶ュ伐宸ヨ祫鏄庣粏寮圭獥 -->
+    <Modal
+      v-model:open="wageDetailVisible"
+      :title="`鎶ュ伐宸ヨ祫鏄庣粏 - ${wageDetailTitle}`"
+      width="1200px"
+      :footer="null"
+    >
+      <Alert
+        type="info"
+        show-icon
+        class="mb-4"
+        :message="`缁熻鍙e緞锛氭牳绠楀懆鏈� ${wageDetailPeriod} 鍐咃紝璇ュ憳宸ュ悕涓嬫墍鏈夊凡瀹℃牳锛堟湭瀹℃牳/宸插鏍革級鍜屽凡瀹屾垚鐨勬姤宸ュ崟宸ヨ祫銆傞噾棰濇瀯鎴� = 涓诲伐璧� + 杈呭姪宸ヨ祫 + 鑷畾涔夊伐璧勫瓧娈佃皟鏁� + 璐ㄩ噺璋冩暣銆俙"
+      />
+
+      <div class="mb-4 flex flex-wrap items-center gap-x-8 gap-y-2 text-sm">
+        <span>
+          鎶ュ伐鍗曪細
+          <span class="font-bold">{{ wageDetailList.length }}</span> 鏉�
+        </span>
+        <span>
+          鏄庣粏鍚堣锛�
+          <span class="font-bold text-green-600">楼{{ fmtAmount(wageDetailTotal) }}</span>
+        </span>
+        <span>
+          鏍哥畻涓殑鎶ュ伐宸ヨ祫锛�
+          <span class="font-bold">楼{{ fmtAmount(wageDetailExpected) }}</span>
+        </span>
+      </div>
+
+      <Alert
+        v-if="!wageDetailLoading && Math.abs(wageDetailTotal - wageDetailExpected) > 0.005"
+        type="warning"
+        show-icon
+        class="mb-4"
+        :message="`鏄庣粏鍚堣 楼${fmtAmount(wageDetailTotal)} 涓庢牳绠椾腑鐨勬姤宸ュ伐璧� 楼${fmtAmount(wageDetailExpected)} 涓嶄竴鑷达紝璇ュ�煎彲鑳藉凡浜哄伐璋冩暣锛涘闇�鎭㈠绯荤粺璁$畻鍊硷紝璇烽噸鏂伴瑙堟牳绠椼�俙"
+      />
+
+      <Table
+        v-model:expanded-row-keys="wageDetailExpandedKeys"
+        :columns="wageDetailColumns"
+        :data-source="wageDetailList"
+        :loading="wageDetailLoading"
+        :pagination="{ pageSize: 10, showSizeChanger: true, showTotal: (t) => `鍏� ${t} 鏉 }"
+        :scroll="{ x: 1200 }"
+        size="small"
+        row-key="feedbackId"
+        bordered
+      >
+        <template #bodyCell="{ column, record }">
+          <template v-if="column.dataIndex === 'mainWage'">
+            {{ fmtAmount(record.mainWage) }}
+          </template>
+          <template v-else-if="column.dataIndex === 'auxWage'">
+            {{ fmtAmount(record.auxWage) }}
+          </template>
+          <template v-else-if="column.dataIndex === 'fieldWage'">
+            <span :class="Number(record.fieldWage ?? 0) === 0 ? 'text-gray-400' : ''">
+              {{ fmtAmount(record.fieldWage) }}
+            </span>
+          </template>
+          <template v-else-if="column.dataIndex === 'qualityAdjustment'">
+            <span
+              :class="Number(record.qualityAdjustment ?? 0) < 0 ? 'text-red-500' : 'text-gray-500'"
+            >
+              {{
+                Number(record.qualityAdjustment ?? 0) === 0
+                  ? '-'
+                  : fmtAmount(record.qualityAdjustment)
+              }}
+            </span>
+          </template>
+          <template v-else-if="column.dataIndex === 'finalWage'">
+            <span class="font-bold text-green-600">{{ fmtAmount(record.finalWage) }}</span>
+          </template>
+        </template>
+
+        <template #expandedRowRender="{ record }">
+          <div class="px-2 py-1">
+            <div class="mb-2 text-xs text-gray-500">
+              鑷畾涔夊伐璧勫瓧娈碉紙鍊间紭鍏堝彇杩囩▼妫�楠屽~鍐欏�硷紝鍏舵鍙栧伐搴忓浐瀹氬�硷級
+            </div>
+            <Table
+              v-if="record.fields && record.fields.length > 0"
+              :columns="wageFieldColumns"
+              :data-source="record.fields"
+              :pagination="false"
+              size="small"
+              bordered
+            >
+              <template #bodyCell="{ column, record: field }">
+                <template v-if="column.dataIndex === 'role'">
+                  <Tag :color="WAGE_ROLE_COLORS[field.role] ?? 'default'">
+                    {{ WAGE_ROLE_LABELS[field.role] ?? '鏈缃�' }}
+                  </Tag>
+                </template>
+                <template v-else-if="column.dataIndex === 'unitPrice'">
+                  {{
+                    field.unitPrice === undefined || field.unitPrice === null
+                      ? '-'
+                      : fmtAmount(field.unitPrice)
+                  }}
+                </template>
+                <template v-else-if="column.dataIndex === 'amount'">
+                  <span :class="Number(field.amount ?? 0) < 0 ? 'text-red-500' : ''">
+                    {{ fmtAmount(field.amount) }}
+                  </span>
+                </template>
+                <template v-else-if="column.dataIndex === 'value'">
+                  {{
+                    field.value === undefined || field.value === null || field.value === ''
+                      ? '-'
+                      : field.value
+                  }}
+                </template>
+              </template>
+            </Table>
+            <div v-else class="text-xs text-gray-400">
+              璇ユ姤宸ュ崟鐨勫伐搴忔病鏈夐厤缃嚜瀹氫箟宸ヨ祫瀛楁
+            </div>
+          </div>
+        </template>
+      </Table>
     </Modal>
 
     <Grid table-title="钖叕鏍哥畻鍒楄〃">
@@ -507,6 +752,12 @@
           {{ getDictLabel(DICT_TYPE.HRM_SALARY_STATUS, row.status) }}
         </Tag>
       </template>
+      <template #workWage="{ row }">
+        <div class="flex items-center gap-1">
+          <span>{{ fmtAmount(row.workWage) }}</span>
+          <a class="text-xs text-blue-600" @click="openWageDetail(row)">鏄庣粏</a>
+        </div>
+      </template>
       <template #actions="{ row }">
         <TableAction
           :actions="[

--
Gitblit v1.9.3