Explorar el Código

申请退款可退商品数量计算

wenjie hace 1 semana
padre
commit
545dab2374
Se han modificado 1 ficheros con 21 adiciones y 8 borrados
  1. 21 8
      pages/applyRefund/applyRefund.js

+ 21 - 8
pages/applyRefund/applyRefund.js

@@ -47,10 +47,16 @@ Page({
     }else{
       refundItem = wx.getStorageSync("refundItem");
       console.log('拿到缓存里的订单项数据refundItem:',refundItem)
-      refundItem.orderItemDtos.forEach(item=>{
-        item.num = 1
-        item.checked = true
+      let orderItemDtos = []
+      refundItem.orderItemDtos.forEach((item1,index)=>{
+        let item = item1
+        if(item.prodCount-item.refundCount){//剩余商品数量大于0
+          item.num = item.prodCount-item.refundCount
+          item.checked = true
+          orderItemDtos.push(item)
+        }
       })
+      refundItem.orderItemDtos = orderItemDtos
       this.setData({
         refundId,
         refundItem: refundItem,
@@ -86,10 +92,17 @@ Page({
         orderNumber
       },
       callBack: function(res) {
-        res.orderItemDtos.forEach(item=>{
-        item.num = 1
-        item.checked = true
+        let orderItemDtos = []
+        res.orderItemDtos.forEach((item1,index)=>{
+          let item = item1
+          if(item.prodCount-item.refundCount){//剩余商品数量大于0
+            item.num = item.prodCount-item.refundCount
+            item.checked = true
+            orderItemDtos.push(item)
+          }
       })
+  
+      res.orderItemDtos = orderItemDtos
       wx.hideLoading();
       ths.setData({
         refundId,
@@ -344,7 +357,7 @@ Page({
      let num = 0
       this.data.refundItem.orderItemDtos.forEach(item=>{
         if(item.checked){
-          total+=((item.price*100)*(item.num*100))/10000
+          total= (total*100 + ((item.price*100)*(item.num*100))/100)/100
           num+=item.num
         }
       })
@@ -370,7 +383,7 @@ Page({
         duration: 1200,
         icon: 'none',
       })
-    }else if(num == 1&&refundItem.orderItemDtos[index].num == refundItem.orderItemDtos[index].prodCount){
+    }else if(num == 1&&refundItem.orderItemDtos[index].num == (refundItem.orderItemDtos[index].prodCount-refundItem.orderItemDtos[index].refundCount)){
       return wx.showToast({
         title: '不能超过购买数量',
         duration: 1200,