Commit 583bd25095fe5865c0f26781b79aebcbee378253
1 parent
aefa78e6
计算折扣的计算属性优化~
Showing
1 changed file
with
14 additions
and
1 deletions
src/pages/discountList/discountList.vue
| @@ -151,7 +151,20 @@ | @@ -151,7 +151,20 @@ | ||
| 151 | // 售价/原价 | 151 | // 售价/原价 |
| 152 | let x = (price * 100) / (prices * 100); | 152 | let x = (price * 100) / (prices * 100); |
| 153 | 153 | ||
| 154 | - return ((Math.floor(x * 1000) / 1000) * 10).toString() + '折'; | 154 | + // 折扣 |
| 155 | + let discount = ((Math.floor(x * 1000) / 1000) * 10).toString(); | ||
| 156 | + | ||
| 157 | + // 判断折扣大于0 | ||
| 158 | + if (discount > 0) { | ||
| 159 | + | ||
| 160 | + // 判断折扣是否太长,如果太长截断 | ||
| 161 | + if (discount.length > 3) { | ||
| 162 | + discount = discount.substr(0, 3); | ||
| 163 | + } | ||
| 164 | + | ||
| 165 | + // 返回折扣数据 | ||
| 166 | + return discount + '折'; | ||
| 167 | + } | ||
| 155 | } | 168 | } |
| 156 | } | 169 | } |
| 157 | }, | 170 | }, |