panhui %!s(int64=2) %!d(string=hai) anos
pai
achega
40b1698e55
Modificáronse 2 ficheiros con 45 adicións e 5 borrados
  1. 18 1
      src/plugins/calc.js
  2. 27 4
      src/views/BLFPage.vue

+ 18 - 1
src/plugins/calc.js

@@ -29,5 +29,22 @@ function accMul(arg1, arg2) {
     }
     }
     return (Number(s1.replace('.', '')) * Number(s2.replace('.', ''))) / Math.pow(10, m)
     return (Number(s1.replace('.', '')) * Number(s2.replace('.', ''))) / Math.pow(10, m)
 }
 }
+//除法
+function accDiv(arg1, arg2) {
+    var t1 = 0,
+        t2 = 0,
+        r1,
+        r2
+    try {
+        t1 = arg1.toString().split('.')[1].length
+    } catch (e) {}
+    try {
+        t2 = arg2.toString().split('.')[1].length
+    } catch (e) {}
+
+    r1 = Number(arg1.toString().replace('.', ''))
+    r2 = Number(arg2.toString().replace('.', ''))
+    return accMul(r1 / r2, Math.pow(10, t2 - t1))
+}
 
 
-export { accAdd, accMul }
+export { accAdd, accMul, accDiv }

+ 27 - 4
src/views/BLFPage.vue

@@ -31,7 +31,7 @@
                         $t('blf.computing')
                         $t('blf.computing')
                     }}</van-button>
                     }}</van-button>
                     <van-button type="primary" class="getted" v-else block
                     <van-button type="primary" class="getted" v-else block
-                        >{{ $t('blf.buying') }} +{{ orderInfo.profit }}</van-button
+                        >{{ $t('blf.buying') }} +{{ profit }}</van-button
                     >
                     >
                 </template>
                 </template>
                 <template v-if="orderInfo.productId !== productInfo.id">
                 <template v-if="orderInfo.productId !== productInfo.id">
@@ -62,8 +62,9 @@ import '@/styles/animate.css'
 import http from '@/plugins/http'
 import http from '@/plugins/http'
 import { useRouter } from 'vue-router'
 import { useRouter } from 'vue-router'
 import { onIonViewWillEnter } from '@ionic/vue'
 import { onIonViewWillEnter } from '@ionic/vue'
-import { differenceInMilliseconds } from 'date-fns'
+import { differenceInMilliseconds, differenceInSeconds } from 'date-fns'
 import { useUserStore } from '@/stores/user'
 import { useUserStore } from '@/stores/user'
+import { accDiv, accMul } from '@/plugins/calc'
 
 
 const userStore = useUserStore()
 const userStore = useUserStore()
 const user = computed(() => {
 const user = computed(() => {
@@ -107,7 +108,6 @@ function onFinish() {
 }
 }
 
 
 const productInfo = ref({})
 const productInfo = ref({})
-const orderInfo = ref({})
 const time = ref(0)
 const time = ref(0)
 function init() {
 function init() {
     http.http
     http.http
@@ -128,6 +128,27 @@ function init() {
         })
         })
 }
 }
 
 
+const profit = ref(0)
+let time1 = null
+function getProfit() {
+    if (time1) {
+        clearTimeout(time1)
+    }
+    if (orderInfo.value.profit) {
+        let _se = differenceInSeconds(new Date(orderInfo.value.redeemTime), new Date(orderInfo.value.createdAt))
+        let _se2 = differenceInSeconds(new Date(), new Date(orderInfo.value.createdAt))
+        if (_se2 < _se) {
+            profit.value = accMul(accDiv(orderInfo.value.profit, _se), _se2).toFixed(2)
+            time1 = setTimeout(getProfit, 1000)
+        } else {
+            profit.value = orderInfo.value.profit
+        }
+    } else {
+        profit.value = 0
+    }
+}
+
+const orderInfo = ref({})
 function getOrder() {
 function getOrder() {
     http.http
     http.http
         .post(
         .post(
@@ -135,13 +156,15 @@ function getOrder() {
             {
             {
                 query: {
                 query: {
                     status: 'PENDING, STAKING'
                     status: 'PENDING, STAKING'
-                }
+                },
+                sort: 'id,desc'
             },
             },
             { body: 'json' }
             { body: 'json' }
         )
         )
         .then(res => {
         .then(res => {
             if (!res.empty) {
             if (!res.empty) {
                 orderInfo.value = res.content[0]
                 orderInfo.value = res.content[0]
+                getProfit()
             }
             }
         })
         })
 }
 }