海南旅游项目 前端仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.1 KiB

  1. <template>
  2. <view>
  3. <block v-if="isPoint">
  4. <text class="text-price lf-font-48 lf-font-bold lf-color-price">{{ showPrice(1) }}</text>
  5. <text class="lf-font-28 lf-font-bold lf-color-price">.{{ showPrice(2) | formDate }}</text>
  6. </block>
  7. <block v-else>
  8. <text class="text-price lf-font-48 lf-font-bold lf-color-price">{{ showPrice() }}</text>
  9. </block>
  10. </view>
  11. </template>
  12. <script>
  13. export default {
  14. props: {
  15. price: {
  16. type: [Number, String],
  17. default: ''
  18. }
  19. },
  20. filters: {
  21. formDate(val) {
  22. return val.slice(0,2)
  23. }
  24. },
  25. computed: {
  26. // 是否存在小数点
  27. isPoint(){
  28. let price = parseFloat(this.$props.price).toString();
  29. return price.indexOf('.') >= 0;
  30. },
  31. showPrice(){
  32. let price = parseFloat(this.$props.price).toString(); // 过滤价格出现.00的情况
  33. return function(type){
  34. let price_arr = price.split('.');
  35. if(type == 1){
  36. return price_arr[0];
  37. }else if(type == 2){
  38. return price_arr[1];
  39. }else{
  40. return price_arr[0];
  41. }
  42. }
  43. }
  44. }
  45. }
  46. </script>
  47. <style lang="scss" scoped="scoped">
  48. </style>