Jelajahi Sumber

fix: 农事详情报价

刘秀芳 1 hari lalu
induk
melakukan
eab6e287b5
1 mengubah file dengan 72 tambahan dan 3 penghapusan
  1. 72 3
      src/views/old_mini/modify_work/completedWork.vue

+ 72 - 3
src/views/old_mini/modify_work/completedWork.vue

@@ -439,6 +439,7 @@ const handleRemindExecute = () => {
 }
 
 const handleForward = () => {
+    console.log('quotationData.value',quotationData.value)
     if(quotationData.value.itemsList && quotationData.value.itemsList.length > 0) {
         onlyShare.value = true;
         setTimeout(() => {
@@ -497,9 +498,77 @@ onActivated(async () => {
     }
     if (query.value?.farmWorkOrderId || detailData.value?.flowStatus === 4) {
         const farmWorkOrderId = query.value?.farmWorkOrderId || detailData.value.orderId;
-        const { data } = await VE_API.z_farm_work_record_cost.listByOrderId({ farmWorkOrderId });
-        if (data && data.length > 0) {
-            const priceDataObj = data[0];
+        let priceDataObj = {}
+        if (curRole.value == 2) {
+            const {data} = await VE_API.z_farm_work_record_cost.getByRecordId({ farmWorkRecordId: detailData.value.id });
+            priceDataObj = data;
+        } else {
+            const {data} = await VE_API.z_farm_work_record_cost.listByOrderId({ farmWorkOrderId });
+            priceDataObj = data[0];
+        }
+        console.log('priceD3333ataObj',priceDataObj)
+        if (priceDataObj && Object.keys(priceDataObj).length > 0) {
+            
+            // 合并外层字段
+            quotationData.value = {
+                ...detailData.value,
+                ...priceDataObj,
+                agriculturalId: priceDataObj.agriculturalId,
+            };
+            
+            // 根据 itemsList 的 pesticideFertilizerId 匹配并赋值品牌和价格
+            if (priceDataObj.itemsList && Array.isArray(priceDataObj.itemsList) && detailData.value.prescriptionList) {
+                // 创建价格映射表
+                const priceMap = new Map();
+                priceDataObj.itemsList.forEach(item => {
+                    priceMap.set(String(item.pesticideFertilizerId), {
+                        brand: item.brand || '',
+                        price: item.price || 0,
+                        totalPrice: item.totalPrice || null
+                    });
+                });
+                
+                // 遍历处方列表,赋值品牌和价格,并计算格式化字段供 price-table 使用
+                quotationData.value.prescriptionList = detailData.value.prescriptionList.map(prescription => {
+                    return {
+                        ...prescription,
+                        pesticideFertilizerList: prescription.pesticideFertilizerList.map(pesticide => {
+                            const pesticideId = String(pesticide.pesticideFertilizerId || '');
+                            const priceInfo = priceMap.get(pesticideId);
+                            
+                            if (priceInfo) {
+                                const price = priceInfo.price || 0;
+                                const muUsage = pesticide.muUsage || 0;
+                                const unit = pesticide.unit || '';
+                                const area = detailData.value.area || 0;
+                                
+                                // 计算总价:优先使用 totalPrice,否则计算 price * muUsage * area
+                                const total = priceInfo.totalPrice 
+                                    ? priceInfo.totalPrice 
+                                    : (price * muUsage * area);
+                                
+                                return {
+                                    ...pesticide,
+                                    brand: priceInfo.brand || '--',
+                                    totalPrice: priceInfo.totalPrice,
+                                    // 格式化字段供 price-table 组件使用
+                                    price: price > 0 ? `${price}元/${unit}` : '--', // 格式化单价显示
+                                    dosage: muUsage > 0 ? `${muUsage}${unit}` : '--', // 格式化用量显示
+                                    total: total > 0 ? total.toFixed(2) : '--' // 格式化总价显示
+                                };
+                            }
+                            return pesticide;
+                        })
+                    };
+                });
+            }
+        }
+    } else if (curRole.value == 2) {
+        let priceDataObj = {}
+        const {data} = await VE_API.z_farm_work_record_cost.getByRecordId({ farmWorkRecordId: detailData.value.id });
+        priceDataObj = data;
+        console.log('priceD3333ataObj',priceDataObj)
+        if (priceDataObj && Object.keys(priceDataObj).length > 0) {
             
             // 合并外层字段
             quotationData.value = {