Преглед на файлове

各页面金额显示逻辑修改。

yangc преди 8 години
родител
ревизия
b9e5fe5161

+ 27 - 2
components/product/ComponentGoods.vue

@@ -70,7 +70,7 @@
           </div>
           <div v-for="price in compGoods.prices">
             <!--| formateNumber : 6-->
-            <span>{{price.uSDPrice}}</span>
+            <span>{{price.uSDPrice | currency}}</span>
           </div>
         </td>
         <td>
@@ -79,7 +79,7 @@
           </div>
           <div v-for="price in compGoods.prices">
             <!--formateNumber : 6-->
-            <span>{{price.rMBPrice}}</span>
+            <span>{{price.rMBPrice | currency}}</span>
           </div>
         </td>
         <td>
@@ -143,6 +143,31 @@
         return goodsPage
       }
     },
+    filters: {
+      currency: function (num) {
+        if (typeof num === 'number') {
+          if (num <= 0.000001) {
+            num = 0.000001
+          } else {
+            if (num.toString().indexOf('.') === -1) {
+              num += '.00'
+            } else {
+              let inputStr = num.toString()
+              let floatNum = inputStr.split('.')[1]
+              if (floatNum.length > 6) {
+                num = inputStr.substring(0, inputStr.length - 1)
+                if (Number(floatNum.charAt(6)) > 4) {
+                  num = Number(num) + 0.000001
+                }
+              } else if (floatNum.length === 1) {
+                num = num + '0'
+              }
+            }
+          }
+        }
+        return num
+      }
+    },
     methods: {
       addToCart: function (goods, buyNow) {
         return null

+ 17 - 2
components/product/component/StoreInfo.vue

@@ -159,8 +159,23 @@
     filters: {
       currency: function (num) {
         if (typeof num === 'number') {
-          if (num.toString().indexOf('.') === -1) {
-            num += '.00'
+          if (num <= 0.000001) {
+            num = 0.000001
+          } else {
+            if (num.toString().indexOf('.') === -1) {
+              num += '.00'
+            } else {
+              let inputStr = num.toString()
+              let floatNum = inputStr.split('.')[1]
+              if (floatNum.length > 6) {
+                num = inputStr.substring(0, inputStr.length - 1)
+                if (Number(floatNum.charAt(6)) > 4) {
+                  num = Number(num) + 0.000001
+                }
+              } else if (floatNum.length === 1) {
+                num = num + '0'
+              }
+            }
           }
         }
         return num

+ 17 - 2
components/search/GoodList.vue

@@ -175,8 +175,23 @@
     filters: {
       currency: function (input) {
         if (typeof input === 'number') {
-          if (input.toString().indexOf('.') === -1) {
-            input = input + '.00'
+          if (input <= 0.000001) {
+            input = 0.000001
+          } else {
+            if (input.toString().indexOf('.') === -1) {
+              input = input + '.00'
+            } else {
+              let inputStr = input.toString()
+              let floatNum = inputStr.split('.')[1]
+              if (floatNum.length > 6) {
+                input = inputStr.substring(0, inputStr.length - 1)
+                if (Number(floatNum.charAt(6)) > 4) {
+                  input = Number(input) + 0.000001
+                }
+              } else if (floatNum.length === 1) {
+                input = input + '0'
+              }
+            }
           }
         }
         return input

+ 27 - 2
components/store/CommodityInfo.vue

@@ -109,10 +109,10 @@
                       <span v-text="price.start"></span>+
                     </div>
                     <div class="price">
-                      <span v-if="price.rMBPrice" v-text="price.rMBPrice || 0"></span>
+                      <span v-if="price.rMBPrice">{{price.rMBPrice || 0 | currency}}</span>
                     </div>
                     <div class="price">
-                      <span v-if="price.uSDPrice" v-text="price.uSDPrice || 0"></span>
+                      <span v-if="price.uSDPrice">{{price.uSDPrice || 0 | currency}}</span>
                     </div>
                   </li>
                 </ul>
@@ -176,6 +176,31 @@ export default {
         canSub: true}
     }
   },
+  filters: {
+    currency: function (num) {
+      if (typeof num === 'number') {
+        if (num <= 0.000001) {
+          num = 0.000001
+        } else {
+          if (num.toString().indexOf('.') === -1) {
+            num += '.00'
+          } else {
+            let inputStr = num.toString()
+            let floatNum = inputStr.split('.')[1]
+            if (floatNum.length > 6) {
+              num = inputStr.substring(0, inputStr.length - 1)
+              if (Number(floatNum.charAt(6)) > 4) {
+                num = Number(num) + 0.000001
+              }
+            } else if (floatNum.length === 1) {
+              num = num + '0'
+            }
+          }
+        }
+      }
+      return num
+    }
+  },
   computed: {
     storeInfo () {
       return this.$store.state.shop.storeInfo.store.data

+ 27 - 2
components/store/CommodityList.vue

@@ -79,13 +79,13 @@
               <div v-show="commodity.currencyName.indexOf('USD')==-1 || !commodity.prices">
                 <span>—</span>
               </div>
-              <div v-for="price in commodity.prices" v-text="price.uSDPrice"></div>
+              <div v-for="price in commodity.prices">{{price.uSDPrice | currency}}</div>
             </td>
             <td>
               <div v-show="commodity.currencyName.indexOf('RMB')==-1 || !commodity.prices">
                 <span>—</span>
               </div>
-              <div v-for="price in commodity.prices" v-text="price.rMBPrice"></div>
+              <div v-for="price in commodity.prices" >{{price.rMBPrice | currency}}</div>
             </td>
             <td>
               <div v-if="commodity.b2cMinDelivery">交期:
@@ -164,6 +164,31 @@ export default {
       ids: null
     }
   },
+  filters: {
+    currency: function (num) {
+      if (typeof num === 'number') {
+        if (num <= 0.000001) {
+          num = 0.000001
+        } else {
+          if (num.toString().indexOf('.') === -1) {
+            num += '.00'
+          } else {
+            let inputStr = num.toString()
+            let floatNum = inputStr.split('.')[1]
+            if (floatNum.length > 6) {
+              num = inputStr.substring(0, inputStr.length - 1)
+              if (Number(floatNum.charAt(6)) > 4) {
+                num = Number(num) + 0.000001
+              }
+            } else if (floatNum.length === 1) {
+              num = num + '0'
+            }
+          }
+        }
+      }
+      return num
+    }
+  },
   computed: {
     commodities () {
       return this.$store.state.shop.storeInfo.storeCommodity.data