Explorar o código

fix: 服务报价单

lxf hai 12 horas
pai
achega
d406e3125a
Modificáronse 2 ficheiros con 71 adicións e 111 borrados
  1. 61 105
      src/components/popup/priceSheetPopup.vue
  2. 10 6
      src/views/old_mini/modify_work/modify.vue

+ 61 - 105
src/components/popup/priceSheetPopup.vue

@@ -38,7 +38,7 @@
                         </div>
                         <div class="total-bar">
                             <span class="total-label">报价合计:</span>
-                            <span class="total-value">{{ priceData?.totalCost ? formatArea(priceData.totalCost) : '--' }}</span>
+                            <span class="total-value">{{ totalCost ? formatArea(totalCost) : "--" }}</span>
                             <span class="total-unit">元</span>
                         </div>
                     </div>
@@ -47,7 +47,7 @@
                     <div class="fertilizer-cost-section">
                         <div class="section-header">
                             <div class="section-title">肥药费用</div>
-                            <div class="section-total">{{ priceData?.pesticideFertilizerCost ? formatArea(priceData.pesticideFertilizerCost) : '--' }}<span class="unit-text">元</span></div>
+                            <div class="section-total">{{ pesticideCostTotal ? formatArea(pesticideCostTotal) : "--" }}<span class="unit-text">元</span></div>
                         </div>
                         <div class="cost-table">
                             <div class="table-header">
@@ -60,15 +60,15 @@
                             </div>
                             <div 
                                 class="table-row"
-                                v-for="(item, index) in processedPrescriptionList"
+                                v-for="(item, index) in priceData?.prescription?.pesticideFertilizerList || []"
                                 :key="index"
                             >
                                 <div class="col-1">{{ item.typeName || '--' }}</div>
-                                <div class="col-2">{{ item.defaultName || item.pesticideFertilizerName || '--' }}</div>
+                                <div class="col-2">{{ item.name || item.pesticideFertilizerName || '--' }}</div>
                                 <div class="col-3">{{ item.brand || '--' }}</div>
                                 <div class="col-4">{{ item.price || '--' }}</div>
-                                <div class="col-5">{{ item.usageDisplay || '--' }}</div>
-                                <div class="col-6">{{ item.totalDisplay === '--' ? '--' : (item.totalDisplay + '元') }}</div>
+                                <div class="col-5">{{ item.dosage ? item.dosage + item.unit : '--' }}</div>
+                                <div class="col-6">{{ getTotal(item) }}</div>
                             </div>
                         </div>
                     </div>
@@ -77,7 +77,7 @@
                     <div class="service-cost-section">
                         <div class="section-header">
                             <div class="section-title">服务费用</div>
-                            <div class="section-total">{{ priceData?.farmWorkServiceCost ? getServiceCost(priceData.farmWorkServiceCost, quotationData.area) : '--' }}<span class="unit-text">元</span></div>
+                            <div class="section-total">{{ priceData?.serviceMuPrice ? serviceCostTotal : '--' }}<span class="unit-text">元</span></div>
                         </div>
                         <div class="service-details">
                             <div class="detail-item">
@@ -85,11 +85,11 @@
                                 <div class="detail-label">执行方式</div>
                             </div>
                             <div class="detail-item">
-                                <div class="detail-value">{{ (priceData?.farmWorkServiceCost || priceData?.manualServicePrice ? (priceData.farmWorkServiceCost || priceData.manualServicePrice) + '元/亩' : '--') }}</div>
+                                <div class="detail-value">{{ (priceData?.serviceMuPrice ? priceData?.serviceMuPrice + '元/亩' : '--') }}</div>
                                 <div class="detail-label">亩单价</div>
                             </div>
                             <div class="detail-item">
-                                <div class="detail-value">{{ quotationData?.area ? (formatArea(quotationData?.area) + '亩') : '--' }}</div>
+                                <div class="detail-value">{{ priceData?.farm?.mianji ? (formatArea(priceData?.farm?.mianji) + '亩') : '--' }}</div>
                                 <div class="detail-label">亩数</div>
                             </div>
                         </div>
@@ -146,63 +146,46 @@ onActivated(() => {
     fetchPriceData()
 })
 
-// 处理后的处方列表(展平并匹配价格)
-const processedPrescriptionList = computed(() => {
-    if (!priceData.value?.prescriptionList || !Array.isArray(priceData.value.prescriptionList)) {
-        return [];
-    }
+const getTotal = (item) => {
+    const price = Number(item?.price ?? 0);
+    const dosage = Number(item?.dosage ?? 0);
+    const area = Number(priceData.value?.farm?.mianji ?? 0);
+    if (!price || !dosage || !area) return '--';
+    return (price * dosage * area).toFixed(2);
+}
 
-    // 创建价格映射表,方便快速查找
-    const priceMap = new Map();
-    if (priceData.value?.itemsList && Array.isArray(priceData.value.itemsList)) {
-        priceData.value.itemsList.forEach(item => {
-            priceMap.set(String(item.pesticideFertilizerId), { price: item.price, brand: item.brand, totalPrice: item.totalPrice });
-        });
-    }
-    // 展平 prescriptionList 中的所有 pesticideFertilizerList
-    const result = [];
-    priceData.value.prescriptionList.forEach(prescription => {
-        if (prescription.pesticideFertilizerList && Array.isArray(prescription.pesticideFertilizerList)) {
-            prescription.pesticideFertilizerList.forEach(item => {
-                const pesticideFertilizerId = String(item.pesticideFertilizerId || '');
-                const mapped = priceMap.get(pesticideFertilizerId) || {};
-                const price = mapped.price || 0;
-                const brand = mapped.brand || item.brand || '';
-                const total = mapped.totalPrice || item.total || '';
-                const muUsage = priceData.value.usageMode === "叶面施" ? (item.muUsage2 || item.muUsage) : item.muUsage
-                const unit = item.unit || '';
-
-                result.push({
-                    typeName: item.typeName || item.pesticideFertilizerTypeName || '--',
-                    defaultName: item.defaultName || item.pesticideFertilizerName || '--',
-                    brand: brand,
-                    priceVal: price || null,
-                    pesticideFertilizerId: item.pesticideFertilizerId,
-                    price: price ? `${price}元` : '--',
-                    unit: unit,
-                    muUsage: muUsage,
-                    // total: total,
-                    // 显示的格式化字符串
-                    priceDisplay: price > 0 ? `${price}元/${unit}` : '--',
-                    usageDisplay: muUsage > 0 ? `${muUsage}${unit}` : '--',
-                    totalDisplay: total > 0 ? `${total.toFixed(2)}` : '--'
-                });
-            });
-        }
-    });
 
-    return result;
+// 药肥费用总计:∑(单价 * 单亩用量 * 亩数)
+const pesticideCostTotal = computed(() => {
+    const list = priceData.value?.prescription?.pesticideFertilizerList || [];
+    const area = Number(priceData.value?.farm?.mianji || 0);
+    if (!list.length || !area) return 0;
+
+    const sum = list.reduce((acc, item) => {
+        const price = Number(item?.price || 0);
+        const dosage = Number(item?.dosage || 0);
+        if (!price || !dosage) return acc;
+        return acc + price * dosage * area;
+    }, 0);
+
+    return Number(sum.toFixed(2));
+});
+
+// 报价合计 = 药肥费用 + 服务费用
+const totalCost = computed(() => {
+    const pesticide = Number(pesticideCostTotal.value || 0);
+    const service = Number(serviceCostTotal.value || 0);
+    if (!pesticide && !service) return 0;
+    return Number((pesticide + service).toFixed(2));
 });
 
-function getServiceCost(cost, area) {
-    if (!cost || !area) return '--';
-    return (parseFloat(cost) * parseFloat(area)).toFixed(2);
-}
 
+const ids = ref({});
 const handleShowPopup = ({id, farmId, agriculturalId}) => {
     if (id) {
         loading.value = true;
-        getDetail(id, farmId, agriculturalId);
+        ids.value = {id, farmId, agriculturalId};
+        getDetail();
     }
     showPopup.value = true;
 };
@@ -219,7 +202,8 @@ function fetchPriceData(id) {
     // });
 }
 
-const getDetail = async (id, farmId, agriculturalId) => {
+const getDetail = async () => {
+    const { id, farmId, agriculturalId } = ids.value;
     const { data, code } = await VE_API.farm.getFarmWorkLib({ id, farmId, agriculturalId });
     if(code === 0) {
         priceData.value = data;
@@ -243,11 +227,11 @@ const getPriceList = async (schemeId, pesticideFertilizerCodes) => {
 
 // 检查 itemsList 是否都有价格和品牌
 function checkItemsListHasPrice() {
-    if (!priceData.value?.itemsList || !Array.isArray(priceData.value.itemsList) || priceData.value.itemsList.length === 0) {
+    if (!priceData.value?.prescription?.pesticideFertilizerList || !Array.isArray(priceData.value.prescription.pesticideFertilizerList) || priceData.value.prescription.pesticideFertilizerList.length === 0) {
         return false;
     }
     // 检查所有项是否都有 price 且 price 不为 0,以及 brand 有值
-    return priceData.value.itemsList.every(item => {
+    return priceData.value.prescription.pesticideFertilizerList.every(item => {
         const hasPrice = item.price != null && item.price !== '' && item.price !== 0;
         const hasBrand = item.brand && item.brand.trim() !== '';
         return hasPrice && hasBrand;
@@ -259,41 +243,6 @@ async function checkOrder() {
     if (!checkItemsListHasPrice()) {
         return false; // 没有价格,返回 false
     }
-    if (!priceData.value?.id) {
-        // 如果 itemsList 都有价格,调用接口创建报价
-        const pesticideFertilizerQuoteList = processedPrescriptionList.value.map(item => {
-            return {
-                pesticideFertilizerId: item.pesticideFertilizerId,
-                price: item.priceVal,
-                brand: item.brand,
-            }
-        });
-        
-        const payload = {
-            farmWorkRecordId: quotationData.value?.id,
-            pesticideFertilizerQuoteList,
-            servicePrice: priceData.value.farmWorkServiceCost,
-            executionMethod: priceData.value.executionMethod,
-        };
-        
-        try {
-            const { code } = await VE_API.z_farm_work_record.acceptFarmWorkRecord(payload);
-            if (code === 0) {
-                // 创建成功后,重新获取价格数据
-                await fetchPriceData();
-                return true; // 创建成功,返回 true
-            } else {
-                return false; // 创建失败,返回 false
-            }
-        } catch (error) {
-            return false; // 接口调用失败,返回 false
-        }
-    }
-    
-    // 如果有 id,检查 itemsList 是否都有价格
-    if (!checkItemsListHasPrice()) {
-        return false; // 没有价格,返回 false
-    }
     
     // 有 id 且都有价格,返回 true
     return true;
@@ -309,14 +258,14 @@ const handleShare = async () => {
         }, 1000);
         return;
     }
-    const userId = quotationData.value.farmMiniUserId;
+    const userId = priceData.value.farmMiniUserId;
     const parmasPage = {
-        farmWorkOrderId:quotationData.value.orderId,
+        farmWorkOrderId:priceData.value.orderId,
         farmMiniUserId:userId,
-        farmMiniUserName:quotationData.value.farmMiniUserName,
-        farmId:quotationData.value.farmId,
-        farmWorkName:quotationData.value.farmWorkName,
-        id:quotationData.value.id,
+        farmMiniUserName:priceData.value.farmMiniUserName,
+        farmId:priceData.value.farmId,
+        farmWorkName:priceData.value.farmWorkName,
+        id:priceData.value.id,
         type:'quotation'
     }
     if(userId){
@@ -328,7 +277,7 @@ const handleShare = async () => {
 
 const handleWechat = async () => {
     // 检查订单状态,如果返回 false 说明数据不完整
-    const canProceed = await checkOrder();
+    const canProceed = await checkItemsListHasPrice();
     if (!canProceed) {
         ElMessage.warning('请补全报价数据');
         return;
@@ -344,6 +293,14 @@ const handleWechat = async () => {
     });
 };
 
+// 服务费用总计(数值):亩单价 * 亩数
+const serviceCostTotal = computed(() => {
+    const price = Number(priceData.value?.serviceMuPrice || 0);
+    const area = Number(priceData.value?.farm?.mianji || 0);
+    if (!price || !area) return 0;
+    return Number((price * area).toFixed(2));
+});
+
 const handleSaveImage = async () => {
     try {
         if (!contentEl.value) return;
@@ -415,10 +372,9 @@ const handleEdit = () => {
         path: "/modify",
         query: {
             isEdit: true,
-            id: priceData.value.id,
+            onlyPrice: true,
             farmId: priceData.value.farm.id,
             farmWorkId: priceData.value.id,
-            containerSpaceTimeId: priceData.value.containerSpaceTimeId,
             agriculturalStoreId: priceData.value.agriculturalStoreId,
         },
     });

+ 10 - 6
src/views/old_mini/modify_work/modify.vue

@@ -13,7 +13,7 @@
                 <div class="farm-card">
                     <div class="card-title between common-inputs">
                         <div>{{ detailData?.name }}<span class="type-tag">标准农事</span></div>
-                        <el-select v-if="isEdit" size="small" v-model="tagName" placeholder="标记为" style="width: 94px">
+                        <el-select v-if="isEdit && !onlyPrice" size="small" v-model="tagName" placeholder="标记为" style="width: 94px">
                             <el-option
                             v-for="item in tagList"
                             :key="item.value"
@@ -76,7 +76,7 @@
                     </div>
                 </div>
 
-                <div class="farm-card">
+                <div class="farm-card" v-if="!onlyPrice">
                     <!-- 农情互动 -->
                     <div class="card-title border-bottom between">
                         <div>农情互动</div>
@@ -133,7 +133,7 @@
                 </div>
 
                 <template v-if="isEdit">
-                    <div class="farm-card prescription-content common-inputs">
+                    <div class="farm-card prescription-content common-inputs" v-if="!onlyPrice">
                         <div class="card-title pb-12 between">
                             药物处方
                             <div class="add-tag" @click="addDomain()">
@@ -555,9 +555,11 @@ const interactFormData = ref({
 const phenologyList = ref([]);
 
 const isEdit = ref(false);
+const onlyPrice = ref(false);
 
 onActivated(() => {
     isEdit.value = route.query.isEdit ? true : false;
+    onlyPrice.value = route.query.onlyPrice ? true : false;
     if (route.query.farmWorkId) {
         getDetail();
     }
@@ -933,10 +935,10 @@ const submitForm = (formEl) => {
     formEl.validate(async (valid) => {
         if (valid) {
             // 校验农情互动,不通过,直接返回失败
-            if (!validateInteractForm()) return false;
+            if (!onlyPrice.value && !validateInteractForm()) return false;
 
             // 校验药肥的亩兑水量和单亩用量是否填写
-            if (!validatePesticideDosage()) return;
+            if (!onlyPrice.value && !validatePesticideDosage()) return;
 
             // 保存报价信息前先校验是否填写完整
             if (!validatePriceInfos()) return;
@@ -1011,7 +1013,9 @@ const submit = () => {
     };
     VE_API.monitor.saveFarmWorkLib(data);
     
-    handleSaveInteract()
+    if (!onlyPrice.value) {
+        handleSaveInteract();
+    }
 
     // 保存报价信息
     const priceList = {