zhaoxiaohai 2 anos atrás
pai
commit
c6b77941d8

+ 55 - 9
packageA/orderForm/detail.js

@@ -313,20 +313,66 @@ Page({
         })
     },
     /* 设置是否使用返利金 */
-    async changeRebateUsed() {
+    changeRebateUsed() {
         if (this.data.detail.status != '新建') return wx.showToast({
             title: '当前订单状态不可设置!',
             icon: "none"
         })
-        this.setData({
-            "detail.rebate_used": this.data.detail.rebate_used == 1 ? 0 : 1
+        let amount = (this.data.detail.order_rebate_userate / 100) * this.data.detail.amount; //最大可用金额
+        let rebatebalance = this.data.detail.rebatebalance; //返利金账户余额
+        _Http.basic({
+            "id": 20230218225002,
+            "content": {
+                "sa_orderid": this.data.sa_orderid, //订单金额
+                "isused": this.data.detail.rebate_used == 1 ? 0 : 1, //是否使用
+                "rebateamount": rebatebalance > amount ? amount : rebatebalance //返利金使用金额
+            }
+        }).then(res => {
+            console.log('设置启用返利金', res)
+            if (res.msg != '成功') {
+                wx.showToast({
+                    title: res.msg,
+                    icon: "none"
+                });
+                this.setData({
+                    "detail.rebate_used": this.data.detail.rebate_used
+                })
+                return;
+            }
+            this.getDetail(true, false)
+        })
+    },
+    /* 修改返利金 */
+    setRebate_amount(e = 0) {
+        let value = e.detail.value;
+        let rebatebalance = this.data.detail.rebatebalance; //返利金账户余额
+        value = value > rebatebalance ? rebatebalance : value;
+        let amount = (this.data.detail.order_rebate_userate / 100) * this.data.detail.amount; //最大可用金额
+        _Http.basic({
+            "id": 20230218225002,
+            "content": {
+                "sa_orderid": this.data.sa_orderid, //订单金额
+                "isused": 1, //是否使用
+                "rebateamount": value > amount ? amount : value
+            }
+        }, false).then(res => {
+            console.log('设置返利金', res)
+            if (res.msg != '成功') {
+                wx.showToast({
+                    title: res.msg,
+                    icon: "none"
+                });
+                this.setData({
+                    "detail.accountclass.rebate_amount": this.data.detail.accountclass.rebate_amount
+                })
+                return;
+            };
+            this.getDetail(false, false)
+            if (value > amount || amount == 0) wx.showToast({
+                title: "返利金最大可使用" + amount + "元",
+                icon: "none"
+            })
         })
-        let res = await this.changeDetail();
-        if (res.msg != '成功') {
-            this.setData({
-                "detail.rebate_used": this.data.detail.rebate_used == 1 ? 0 : 1
-            });
-        }
     },
     /* 删除订单 */
     deleteItem() {

+ 10 - 10
packageA/orderForm/detail.wxml

@@ -64,16 +64,16 @@
         </view>
     </view>
 
-    <navigator url="#" class="row" style="font-size: 0;" bindtap="changeRebateUsed">
-        <view class="label">是否使用返利金(余额:{{detail.accountclass.rebate_amount}})</view>
-        <checkbox disabled="{{detail.status!='新建'}}" checked="{{detail.rebate_used==1}}" color='var(--assist)' />
-    </navigator>
-
-
-    <view class="row" wx:if="{{detail.rebate_used==1}}">
-        <view class="label">返利金支付(最多订单金额20%)</view>
-        <input disabled="{{detail.status!='新建'}}" bindtap="isEdit" type="digit" class="remarks" placeholder-class='placeholder' value="{{detail.accountclass.rebate_amount}}" placeholder="使用金额" />
-    </view>
+    <block wx:if="{{detail.type=='标准订单'||detail.type=='特殊订单'}}">
+        <navigator url="#" class="row" style="font-size: 0;" bindtap="changeRebateUsed">
+            <view class="label">是否使用返利金(余额:{{detail.rebatebalance}})</view>
+            <checkbox disabled="{{detail.status!='新建'}}" checked="{{detail.rebate_used==1}}" color='var(--assist)' />
+        </navigator>
+        <view class="row" wx:if="{{detail.rebate_used==1}}">
+            <view class="label">返利金支付(最多订单金额{{detail.order_rebate_userate}}%)</view>
+            <input disabled="{{detail.status!='新建'}}" bindtap="isEdit" type="digit" class="remarks" placeholder-class='placeholder' value="{{detail.rebateamount}}" placeholder="使用金额" bindblur="setRebate_amount" />
+        </view>
+    </block>
 </view>
 
 <view class="box" style="padding: 10rpx 30rpx;">

+ 11 - 3
packageA/orderForm/modules/product/index.js

@@ -131,6 +131,7 @@ Component({
 						page.setData({
 							"detail.amount": amount - 0
 						})
+						page.setRebate_amount();
 					}
 				}
 				this.setData({
@@ -166,9 +167,16 @@ Component({
 						/* 更新金额 */
 						let page = getCurrentPages()[getCurrentPages().length - 1];
 						let amount = (page.data.detail.amount - detail.amount).toFixed(2);
-						if (page) page.setData({
-							"detail.amount": amount - 0
-						})
+						if (page) {
+							page.setData({
+								"detail.amount": amount - 0
+							})
+							page.setRebate_amount({
+								detail: {
+									value: page.data.detail.rebateamount
+								}
+							})
+						}
 					})
 				}
 			})