From b1dc2d5e939ebf014de356b0b066a0c6ed868c5d Mon Sep 17 00:00:00 2001
From: spring <2396852758@qq.com>
Date: 星期三, 25 三月 2026 11:46:29 +0800
Subject: [PATCH] fix: 完成采购审批申请、审批功能

---
 src/views/collaborativeApproval/approvalProcess/components/approvalDia.vue |  181 ++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 171 insertions(+), 10 deletions(-)

diff --git a/src/views/collaborativeApproval/approvalProcess/components/approvalDia.vue b/src/views/collaborativeApproval/approvalProcess/components/approvalDia.vue
index 584a6c2..7d34424 100644
--- a/src/views/collaborativeApproval/approvalProcess/components/approvalDia.vue
+++ b/src/views/collaborativeApproval/approvalProcess/components/approvalDia.vue
@@ -32,7 +32,24 @@
 						</el-form-item>
 					</el-col>
 				</el-row>
-				<el-row>
+				<!-- 鎶ラ攢閲戦锛堜粎褰� approveType 涓� 4 鏃舵樉绀猴級 -->
+				<el-row v-if="props.approveType == 4">
+					<el-col :span="24">
+						<el-form-item label="鎶ラ攢閲戦锛�" prop="price">
+							<el-input-number
+								v-model="form.price"
+								placeholder="璇疯緭鍏ユ姤閿�閲戦"
+								:min="0"
+								:precision="2"
+								:step="0.01"
+								style="width: 100%"
+								disabled
+								clearable
+							/>
+						</el-form-item>
+					</el-col>
+				</el-row>
+				<el-row v-if="!isPurchaseApproval">
 					<el-col :span="24">
 						<el-form-item label="瀹℃壒浜嬬敱锛�" prop="approveReason">
 							<el-input v-model="form.approveReason" placeholder="璇疯緭鍏�" clearable type="textarea" disabled/>
@@ -73,6 +90,51 @@
 					</el-col>
 				</el-row>
 			</el-form>
+      <div v-if="isPurchaseApproval" style="margin: 10px 0 18px;">
+        <el-divider content-position="left">閲囪喘璇︽儏</el-divider>
+        <el-skeleton :loading="purchaseLoading" animated>
+          <template #template>
+            <el-skeleton-item variant="h3" style="width: 30%" />
+            <el-skeleton-item variant="text" style="width: 100%" />
+            <el-skeleton-item variant="text" style="width: 100%" />
+          </template>
+          <template #default>
+            <el-empty v-if="!purchaseDetail || !purchaseDetail.purchaseContractNumber" description="鏈煡璇㈠埌瀵瑰簲閲囪喘璇︽儏" />
+            <template v-else>
+              <el-descriptions :column="2" border>
+                <el-descriptions-item label="閲囪喘鍚堝悓鍙�">{{ purchaseDetail.purchaseContractNumber }}</el-descriptions-item>
+                <el-descriptions-item label="渚涘簲鍟嗗悕绉�">{{ purchaseDetail.supplierName }}</el-descriptions-item>
+                <el-descriptions-item label="椤圭洰鍚嶇О">{{ purchaseDetail.projectName }}</el-descriptions-item>
+                <el-descriptions-item label="閿�鍞悎鍚屽彿">{{ purchaseDetail.salesContractNo }}</el-descriptions-item>
+                <el-descriptions-item label="绛捐鏃ユ湡">{{ purchaseDetail.executionDate }}</el-descriptions-item>
+                <el-descriptions-item label="褰曞叆鏃ユ湡">{{ purchaseDetail.entryDate }}</el-descriptions-item>
+                <el-descriptions-item label="浠樻鏂瑰紡">{{ purchaseDetail.paymentMethod }}</el-descriptions-item>
+                <el-descriptions-item label="鍚堝悓閲戦" :span="2">
+                  <span style="font-size: 18px; color: #e6a23c; font-weight: bold;">
+                    楼{{ Number(purchaseDetail.contractAmount ?? 0).toFixed(2) }}
+                  </span>
+                </el-descriptions-item>
+              </el-descriptions>
+
+              <div style="margin-top: 20px;">
+                <h4>浜у搧鏄庣粏</h4>
+                <el-table :data="purchaseProducts" border style="width: 100%">
+                  <el-table-column prop="productCategory" label="浜у搧鍚嶇О" />
+                  <el-table-column prop="specificationModel" label="瑙勬牸鍨嬪彿" />
+                  <el-table-column prop="unit" label="鍗曚綅" />
+                  <el-table-column prop="quantity" label="鏁伴噺" />
+                  <el-table-column prop="taxInclusiveUnitPrice" label="鍚◣鍗曚环">
+                    <template #default="scope">楼{{ Number(scope.row.taxInclusiveUnitPrice ?? 0).toFixed(2) }}</template>
+                  </el-table-column>
+                  <el-table-column prop="taxInclusiveTotalPrice" label="鍚◣鎬讳环">
+                    <template #default="scope">楼{{ Number(scope.row.taxInclusiveTotalPrice ?? 0).toFixed(2) }}</template>
+                  </el-table-column>
+                </el-table>
+              </div>
+            </template>
+          </template>
+        </el-skeleton>
+      </div>
       <el-form :model="{ activities }" ref="formRef" label-position="top">
         <el-steps :active="getActiveStep()" finish-status="success" process-status="process" align-center direction="vertical">
           <el-step
@@ -102,6 +164,10 @@
               <div v-if="!activity.isShen" class="node-reason">
                 <span>瀹℃壒鎰忚锛�</span>{{ activity.approveNodeReason }}
               </div>
+              <div v-if="!activity.isShen" class="node-reason">
+                <span>绛惧悕锛�</span>
+								<img :src="activity.urlTem" class="signImg" alt="" v-if="activity.urlTem"/>
+              </div>
               <div v-else-if="activity.isShen">
                 <el-form-item
                   :prop="'activities.' + index + '.approveNodeReason'"
@@ -116,7 +182,7 @@
       </el-form>
       <template #footer v-if="operationType === 'approval'">
         <div class="dialog-footer">
-          <el-button type="primary" @click="openSignatureDialog(2)">涓嶉�氳繃</el-button>
+          <el-button type="primary" @click="submitForm(2)">涓嶉�氳繃</el-button>
           <el-button type="primary" @click="openSignatureDialog(1)">閫氳繃</el-button>
           <el-button @click="closeDia">鍙栨秷</el-button>
         </div>
@@ -142,16 +208,18 @@
 </template>
 
 <script setup>
-import { getCurrentInstance, reactive, ref, toRefs } from "vue";
+import { computed, getCurrentInstance, reactive, ref, toRefs } from "vue";
 import vueEsign from "vue-esign";
 import {
 	approveProcessDetails,
 	getDept,
 	updateApproveNode
 } from "@/api/collaborativeApproval/approvalProcess.js";
+import { getPurchaseByCode } from "@/api/procurementManagement/procurementLedger.js";
 import useUserStore from "@/store/modules/user.js";
 import {userListNoPageByTenantId} from "@/api/system/user.js";
 import { WarningFilled, Edit, Check, MoreFilled } from '@element-plus/icons-vue'
+import { getToken } from "@/utils/auth";
 const emit = defineEmits(['close'])
 const { proxy } = getCurrentInstance()
 
@@ -162,6 +230,14 @@
 const userStore = useUserStore()
 const productOptions = ref([]);
 const userList = ref([])
+const purchaseLoading = ref(false)
+const currentPurchase = ref({})
+const isPurchaseApproval = computed(() => Number(props.approveType) === 5)
+const purchaseDetail = computed(() => currentPurchase.value?.data || currentPurchase.value || {})
+const purchaseProducts = computed(() => {
+  const detail = purchaseDetail.value || {}
+  return detail.productData || detail.products || detail.children || []
+})
 const data = reactive({
 	form: {
 		approveTime: "",
@@ -180,6 +256,20 @@
 const esign = ref(null);
 const lineWidth = ref(0);
 const lineColor = ref("#000000");
+const props = defineProps({
+	approveType: {
+		type: [Number, String],
+		default: 0
+	}
+})
+
+// 涓婁紶閰嶇疆
+const upload = reactive({
+  // 涓婁紶鐨勫湴鍧�
+  url: import.meta.env.VITE_APP_BASE_API + "/file/upload",
+  // 璁剧疆涓婁紶鐨勮姹傚ご閮�
+  headers: { Authorization: "Bearer " + getToken() },
+});
 
 // 鑺傜偣鏍囬
 const getNodeTitle = (index, len) => {
@@ -206,15 +296,35 @@
 const openDialog = (type, row) => {
   operationType.value = type;
   dialogFormVisible.value = true;
+  currentPurchase.value = {}
 	userListNoPageByTenantId().then((res) => {
 		userList.value = res.data;
 	});
 	form.value = {...row}
 	getProductOptions()
+  if (isPurchaseApproval.value) {
+    const purchaseContractNumber = row?.approveReason
+    if (purchaseContractNumber) {
+      purchaseLoading.value = true
+      getPurchaseByCode({ purchaseContractNumber }).then((res) => {
+        // 鍏煎鍚庣杩斿洖 {code,data} 鎴栫洿鎺ヨ繑鍥炶鎯呭璞′袱绉嶇粨鏋�
+        currentPurchase.value = res || {}
+      }).catch(() => {
+        proxy.$modal.msgError("鏌ヨ閲囪喘璇︽儏澶辫触")
+      }).finally(() => {
+        purchaseLoading.value = false
+      })
+    }
+  }
   approveProcessDetails(row.approveId).then((res) => {
     activities.value = res.data
     // 澧炲姞isApproval瀛楁
     activities.value.forEach(item => {
+			if (item.url && item.url.includes('word')) {
+				item.urlTem = item.url.replaceAll('word', 'img')
+			} else {
+				item.urlTem = item.url
+			}
       if (item.approveNodeStatus === 2) {
         item.isApproval = '宸查┏鍥�';
       } else if (item.approveNodeStatus === 1) {
@@ -243,23 +353,67 @@
 const confirmSignature = () => {
 	esign.value.generate().then((res) => {
 		console.log(res);
-		signatureImg.value = res;
-		signatureDialogVisible.value = false;
-		clearSignature()
-		submitForm(submitStatus);
+		// 灏哹ase64杞崲涓轰簩杩涘埗
+		const base64Data = res.split(',')[1]; // 绉婚櫎data:image/png;base64,鍓嶇紑
+		const binaryString = atob(base64Data);
+		const bytes = new Uint8Array(binaryString.length);
+		for (let i = 0; i < binaryString.length; i++) {
+			bytes[i] = binaryString.charCodeAt(i);
+		}
+		signatureImg.value = bytes;
+		
+		// 鍒涘缓鏂囦欢瀵硅薄鐢ㄤ簬涓婁紶
+		const blob = new Blob([bytes], { type: 'image/png' });
+		const file = new File([blob], 'signature.png', { type: 'image/png' });
+		
+		// 鍒涘缓FormData
+		const formData = new FormData();
+		formData.append('file', file);
+		
+		// 涓婁紶绛惧悕鍥剧墖
+		fetch(upload.url, {
+			method: 'POST',
+			headers: upload.headers,
+			body: formData
+		})
+		.then(response => response.json())
+		.then(data => {
+			if (data.code === 200) {
+				console.log('data---', data)
+				let tempFileIds = [];
+				tempFileIds.push(data.data.tempId);
+				signatureDialogVisible.value = false;
+				clearSignature();
+				// 鍙湁閫氳繃鏃舵墠浼犻�掔鍚嶆枃浠禝D
+				if (submitStatus === 1) {
+					submitForm(submitStatus, tempFileIds);
+				} else {
+					submitForm(submitStatus);
+				}
+			} else {
+				proxy.$modal.msgError("绛惧悕鍥剧墖涓婁紶澶辫触锛�" + data.msg);
+			}
+		})
+		.catch(error => {
+			console.error('涓婁紶澶辫触:', error);
+			proxy.$modal.msgError("绛惧悕鍥剧墖涓婁紶澶辫触");
+		});
 	}).catch((err) => {
 		console.log(err);
 		proxy.$modal.msgWarning("璇峰厛绛惧悕锛�");
 	})
 };
 // 鎻愪氦瀹℃壒
-const submitForm = (status) => {
+const submitForm = (status, tempFileIds) => {
   const filteredActivities = activities.value.filter(activity => activity.isShen);
   filteredActivities[0].approveNodeStatus = status;
-  filteredActivities[0].signatureImg = signatureImg.value; // 鏂板绛惧悕鍥剧墖瀛楁
+  // 鍙湁閫氳繃鏃舵墠闇�瑕佺鍚�
+  if (status === 1 && tempFileIds) {
+    filteredActivities[0].tempFileIds = tempFileIds;
+  }
   // 鍒ゆ柇鏄惁涓烘渶鍚庝竴姝�
   const isLast = activities.value.findIndex(a => a.isShen) === activities.value.length-1;
-  updateApproveNode({ ...filteredActivities[0], isLast, signatureImg: signatureImg.value }).then(() => {
+  updateApproveNode({ ...filteredActivities[0], isLast }).then(() => {
     proxy.$modal.msgSuccess("鎻愪氦鎴愬姛");
     closeDia();
   });
@@ -268,6 +422,8 @@
 const closeDia = () => {
   proxy.resetForm("formRef");
   dialogFormVisible.value = false;
+  purchaseLoading.value = false
+  currentPurchase.value = {}
   emit('close')
 };
 defineExpose({
@@ -301,4 +457,9 @@
 	height: 30px;
 	border-radius: 50px;
 }
+.signImg {
+	cursor: pointer;
+	width: 200px;
+	height: 60px;
+}
 </style>
\ No newline at end of file

--
Gitblit v1.9.3