panhui 3 лет назад
Родитель
Сommit
a43061289d
3 измененных файлов с 52 добавлено и 2 удалено
  1. 10 1
      src/components/ProductInfo.vue
  2. 33 0
      src/plugins/calc.js
  3. 9 1
      src/views/ProductDetailPage.vue

+ 10 - 1
src/components/ProductInfo.vue

@@ -17,7 +17,7 @@
                     <div class="name">日化收益</div>
                 </div>
                 <div class="data">
-                    <div class="val">{{ info.premium || 0 }}</div>
+                    <div class="val">{{ nextPrice || 0 }}</div>
                     <div class="name">明日可卖({{ $t('balance.symbol') }})</div>
                 </div>
             </div>
@@ -29,6 +29,7 @@
 import { computed } from 'vue'
 import { useRouter } from 'vue-router'
 import { useSystemStore } from '../stores/system'
+import { accAdd, accMul } from '../plugins/calc'
 
 const props = defineProps({
     info: {
@@ -64,6 +65,14 @@ const goDetail = () => {
 const riseRatePercent = computed(() => {
     return useSystemStore().riseRatePercent
 })
+
+const riseRate = computed(() => {
+    return useSystemStore().riseRate
+})
+
+const nextPrice = computed(() => {
+    return accMul(props.info.currentPrice, accAdd(1, riseRate.value)).toFixed(2)
+})
 </script>
 
 <style lang="less" scoped>

+ 33 - 0
src/plugins/calc.js

@@ -0,0 +1,33 @@
+function accAdd(arg1, arg2) {
+    var r1, r2, m
+    try {
+        r1 = arg1.toString().split('.')[1].length
+    } catch (e) {
+        r1 = 0
+    }
+    try {
+        r2 = arg2.toString().split('.')[1].length
+    } catch (e) {
+        r2 = 0
+    }
+    m = Math.pow(10, Math.max(r1, r2))
+    return (arg1 * m + arg2 * m) / m
+}
+function accMul(arg1, arg2) {
+    var m = 0,
+        s1 = arg1.toString(),
+        s2 = arg2.toString()
+    try {
+        m += s1.split('.')[1].length
+    } catch (e) {
+        /* empty */
+    }
+    try {
+        m += s2.split('.')[1].length
+    } catch (e) {
+        /* empty */
+    }
+    return (Number(s1.replace('.', '')) * Number(s2.replace('.', ''))) / Math.pow(10, m)
+}
+
+export { accAdd, accMul }

+ 9 - 1
src/views/ProductDetailPage.vue

@@ -39,7 +39,7 @@
                         <div class="price-right-content">
                             <div class="val">
                                 <small>{{ $t('balance.symbol') }}</small>
-                                <span>{{ info.premium || 0 }}</span>
+                                <span>{{ nextPrice || 0 }}</span>
                             </div>
                             <div class="name">明日可卖</div>
                         </div>
@@ -143,6 +143,7 @@ import { IonButton, alertController } from '@ionic/vue'
 import { useUserStore } from '@/stores/user'
 import { mapState } from 'pinia'
 import { useSystemStore } from '../stores/system'
+import { accAdd, accMul } from '../plugins/calc'
 
 const route = useRoute()
 const router = useRouter()
@@ -170,6 +171,13 @@ const riseRatePercent = computed(() => {
     return useSystemStore().riseRatePercent
 })
 
+const riseRate = computed(() => {
+    return useSystemStore().riseRate
+})
+const nextPrice = computed(() => {
+    return (accMul(info.value.currentPrice || 0, accAdd(1, riseRate.value)) || 0).toFixed(2)
+})
+
 const showPayModal = ref(false)
 const { height: windowHeight } = useWindowSize()
 const breakpoint = computed(() => {