Explorar o código

[edit] 校验逻辑

wenliming %!s(int64=3) %!d(string=hai) anos
pai
achega
0feaf71cf6
Modificáronse 3 ficheiros con 109 adicións e 59 borrados
  1. 16 0
      src/uilts/help.js
  2. 81 43
      src/view/components/give-dialog.vue
  3. 12 16
      src/view/components/option-withdraw.vue

+ 16 - 0
src/uilts/help.js

@@ -60,4 +60,20 @@ export function guid() {
     var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
     return v.toString(16);
   });
+}
+
+export function scaleNumber(num) {
+    let length = num.toString().split('.')[1].length;
+    
+    let scale = '1';
+    
+    for(let i = 0; i < length; i++) {
+        scale += '0';
+    }
+
+    let val = num * scale;
+    return {
+      val,
+      scale
+    };
 }

+ 81 - 43
src/view/components/give-dialog.vue

@@ -236,7 +236,9 @@
                             </div>
 
                             <div class="submit-btn-wrapper">
-                                <div class="submit-btn" @click="confirm">
+                                <div class="submit-btn"
+                                    :class="{ 'disabled-submit': iptErrMsgTxt != '' }"
+                                    @click="confirm">
                                     <img
                                         class="icon-loading"
                                         v-if="submitIng"
@@ -244,7 +246,7 @@
                                             require('../../assets/svg/icon-btn-loading.svg')
                                         "
                                     />
-                                    NEXT
+                                    {{iptErrMsgTxt ? iptErrMsgTxt : 'NEXT'}}
                                 </div>
                             </div>
                         </div>
@@ -291,6 +293,7 @@ import { ref, watch, reactive, defineProps, defineEmits, onMounted } from "vue";
 import { postPublish, verifyPaypalResult, syncChainTokenRechargeRecord } from "../../http/publishApi";
 import { payCalcFee, getPayConfig } from "../../http/pay";
 import { getFrontConfig } from "../../http/account";
+import { scaleNumber } from "../../uilts/help"
 import { ElMessage, ElLoading } from "element-plus";
 import "element-plus/es/components/message/style/css";
 
@@ -327,7 +330,8 @@ let dialogHeight = ref(680);
 let submitIng = ref(false);
 // 艾特关注人列表
 let atUserList = ref([]);
-let iptErrMsgTxt = ref("");
+
+let iptErrMsgTxt = ref("Please enter the ‘reward’ amount");
 // 是否返回
 let isBack = ref(false);
 // 展示消息提示 
@@ -451,7 +455,7 @@ const getPayAmount = async (amountValue) => {
         params: {
             amountValue,
             currencyCode: currentCurrencyInfo.value.currencyCode,
-            payNetwork: 'paypal',
+            payChannel: 'paypal',
         },
     });
     if (res.code == 0) {
@@ -465,16 +469,13 @@ const getPayAmount = async (amountValue) => {
 };
 
 const confirm = () => {
-    if (submitIng.value) {
+    if (submitIng.value || iptErrMsgTxt) {
         return;
     }
     let { totalCount = 0 } = baseFormData;
     if (!totalCount) {
         return;
     }
-    if (!calcIptValue()) {
-        return;
-    }
     submitRequest();
 };
 
@@ -631,26 +632,6 @@ const submitRequest = async () => {
     });
 };
 
-/**
- * 输入结果计算、校验
- */
-const calcIptValue = (cb) => {
-    let amountValue = baseFormData.amountValue;
-    let totalCount = baseFormData.totalCount;
-    let flag = true;
-
-    if (!amountValue || !totalCount) {
-        return flag;
-    }
-
-    //每人平均要分到大于 0.01美元(1美分)
-    if ((amountValue * 100) / totalCount < 1) {
-        flag = false;
-    }
-    cb && cb(flag);
-    return flag;
-};
-
 /**
  * 初始化提交参数
  */
@@ -772,11 +753,15 @@ const onCountInput = () => {
 const onAmountBlur = () => {
     if (!baseFormData.amountValue) {
         iptErrMsgTxt.value =
-            "Please enter the giveaways amount in USD input box.";
+            "Please enter the ‘reward’ amount";
     } else {
         setIptAmountErrorMsg((res) => {
-            if (res) {
-                iptErrMsgTxt.value = "";
+            if (res.flag) {
+                if(!baseFormData.totalCount) {
+                    iptErrMsgTxt.value = "Please enter the ‘winners' amount";
+                } else {
+                    iptErrMsgTxt.value = "";
+                }
             }
         });
     }
@@ -788,31 +773,80 @@ const onAmountBlur = () => {
 const onCountBlur = () => {
     if (!baseFormData.totalCount) {
         iptErrMsgTxt.value =
-            "Please enter the number of giveaways in Quantity input box.";
+            "Please enter the ‘winners' amount";
     } else {
         setIptAmountErrorMsg((res) => {
-            if (res) {
+            if (res.flag) {
                 iptErrMsgTxt.value = "";
             }
         });
     }
 };
 
+/**
+ * 输入结果计算、校验
+ */
+const calcIptValue = (cb) => {
+    let amountValue = baseFormData.amountValue;
+    let totalCount = baseFormData.totalCount;
+    let flag = true;
+
+    if (!amountValue || !totalCount) {
+        return {
+            flag
+        };
+    }
+
+    let num = amountValue, scale = 1;
+    if(amountValue.indexOf('.') > -1) {
+        num = amountValue.toString();
+        let obj = scaleNumber(num);
+        num = obj.val;
+        scale = obj.scale;
+    }
+    let minAmount = currentCurrencyInfo.value.minAmount;
+    // 输入的token数量或者法币金额,平均分到每个红包,是否小于最小单位
+    if (num / totalCount  < minAmount * scale) {
+        flag = false;
+    }
+    console.log('minAmount')
+
+    cb && cb(flag);
+    return {
+        flag,
+        count: math.floor((num / minAmount * scale)/ (scale * scale))
+    };
+};
+
+
+
 /**
  * 输入金额提示语
  */
 const setIptAmountErrorMsg = (cb) => {
-    let res = calcIptValue();
-    if (!res) {
-        iptErrMsgTxt.value = `If you wish to send ${
-            baseFormData.totalCount
-        } red packets, please send USD amount > $${
-            baseFormData.totalCount * 0.01
-        }`;
-    } else {
-        iptErrMsgTxt.value = "";
+    let amountValue = baseFormData.amountValue;
+    let num = amountValue, scale = 1;
+    if(amountValue.indexOf('.') > -1) {
+        num = amountValue.toString();
+        let obj = scaleNumber(num);
+        num = obj.val;
+        scale = obj.scale;
     }
-    cb && cb(res);
+    if(num < currentCurrencyInfo.value.balance * scale) {
+        let res = calcIptValue();
+        if (!res.flag) {
+            iptErrMsgTxt.value = `Please reduce the 'winners' amount to ${res.count}`;
+        } else {
+            if(!baseFormData.totalCount) {
+                iptErrMsgTxt.value = "Please enter the ‘winners' amount";
+            } else {
+                iptErrMsgTxt.value = "";
+            }
+        }
+        cb && cb(res);
+    } else if(currentCurrencyInfo.value.currencyCode != 'USD') {
+        iptErrMsgTxt.value = `Insufficient ${currentCurrencyInfo.value.currencyName} balance, please recharge`;
+    } 
 };
 
 /**
@@ -1297,6 +1331,10 @@ onMounted(() => {
                             margin-right: 3px;
                         }
                     }
+
+                    .disabled-submit {
+                        background-color: #D9D9D9; 
+                    }
                 }
             }
         }

+ 12 - 16
src/view/components/option-withdraw.vue

@@ -27,7 +27,7 @@
                     </div>
                     <div class="form-item">
                         <div class="label">Withdrawal amount<span
-                                class="msg">(${{ walletWithdrawConfig.withdrawUSDPreMinAmount }} minimum)</span></div>
+                                class="msg">(${{ walletWithdrawConfig.withdrawPerMinAmount }} minimum)</span></div>
                         <div class="input-wrapper amount-wrapper">
                             <input type="text" 
                                 v-model="requestWithdrawParams.amountValue" 
@@ -43,7 +43,7 @@
 
                     <div class="error-msg">
                         <template v-if="showWithdrawError">
-                            The minimum withdrawal amount is ${{ walletWithdrawConfig.withdrawUSDPreMinAmount }} USD
+                            The minimum withdrawal amount is ${{ walletWithdrawConfig.withdrawPerMinAmount }} USD
                         </template>
                         <template v-if="showWithdrawIptError">
                             The withdrawal amount exceeds the total account balance of ${{ canWithdrawBalance }} USD
@@ -66,7 +66,7 @@
                             计算中
                         </template>
                     </div>
-                    <div>{{ walletWithdrawConfig.withdrawUSDPaypalFeeDesc }}</div>
+                    <div>{{ walletWithdrawConfig.withdrawFeeDesc }}</div>
                 </div>
             </div>
             <div @click="withdraw" class="confirm-btn">
@@ -104,16 +104,6 @@ const props = defineProps({
     amountValue: {
         type: Number,
         default: 0,
-    },
-    walletWithdrawConfig: {
-        type: Object,
-        default: () => {
-            return {
-                withdrawUSDPreMinAmount: 100,
-                withdrawUSDSwitch: "",
-                withdrawUSDPaypalFeeDesc: ''
-            }
-        }
     }
 });
 let withdraw_info = inject('withdraw_info')
@@ -133,6 +123,12 @@ let showWithdrawIptError = ref(false);
 let isSubmit = ref(false);
 let withdrawIng = ref(false);
 
+let walletWithdrawConfig = ref({
+        withdrawPerMinAmount: 1,
+        withdrawUSDSwitch: "",
+        withdrawFeeDesc: ''
+    });
+
 let finalWithdrawalAmount = ref('');
 let calcReq = ref(false);
 
@@ -149,10 +145,10 @@ const queryWithdrawConfig = () => {
             withdrawNetwork: 'paypal'
         },
     }).then((res) => {
-        console.log(res);
         if (res.code == 0) {
             walletWithdrawConfig.value = res.data;
         }
+        console.log('queryWithdrawConfig',walletWithdrawConfig.value);
     });
 };
 
@@ -268,7 +264,7 @@ const onAmountInput = () => {
     setWithdrawIptStatus(value);
 
     // 输入金额大于可提现金额
-    if (value > canWithdrawBalance.value) {
+    if (parseInt(value) > parseInt(canWithdrawBalance.value)) {
         if (!showWithdrawError.value) {
             showWithdrawIptError.value = true;
         }
@@ -285,7 +281,7 @@ const setWithdrawIptStatus = (amount) => {
     //显示tips
     if (
         amount > 0 &&
-        amount < withdraw_info.paypal.wallet_withdraw_config.withdrawUSDPreMinAmount
+        amount < walletWithdrawConfig.value.withdrawPerMinAmount
     ) {
         showWithdrawError.value = true;
     } else {