app-price.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <template>
  2. <view class="app-price t-omit" v-if="actual.price != -1">
  3. <text :class="actual.type">{{actual.price}}</text>
  4. </view>
  5. </template>
  6. <script>
  7. export default {
  8. props: {
  9. max: {
  10. type: String,
  11. default() {
  12. return '-1';
  13. }
  14. },
  15. min: {
  16. type: String,
  17. default() {
  18. return '-1';
  19. }
  20. },
  21. defaultPrice: {
  22. type: String,
  23. default() {
  24. return '-1';
  25. }
  26. },
  27. price: {
  28. type: [String, Number],
  29. default() {
  30. return '-1';
  31. }
  32. },
  33. type: {
  34. type: String,
  35. default() {
  36. return 'text-price'; // 目前支持text-price和text-price-all
  37. }
  38. }
  39. },
  40. data() {
  41. return {
  42. priceType: this.type,
  43. }
  44. },
  45. computed: {
  46. actual() {
  47. let actualPrice = -1;
  48. let price = -1;
  49. let min = -1;
  50. let max = -1;
  51. let defaultPrice = -1;
  52. let type = this.type;
  53. if (this.price != 'undefined') {
  54. price = Number(this.price);
  55. }
  56. if (this.min != 'undefined') {
  57. min = Number(this.min);
  58. }
  59. if (this.max != 'undefined') {
  60. max = Number(this.max);
  61. }
  62. if (this.defaultPrice != 'undefined') {
  63. defaultPrice = Number(this.defaultPrice);
  64. }
  65. if (price && price > 0) {
  66. actualPrice = price;
  67. } else if (price == 0) {
  68. actualPrice = '免费';
  69. type = '';
  70. } else if (max > min && min >= 0) {
  71. actualPrice = min + '-' + max;
  72. } else if (max == min && min >= 0) {
  73. actualPrice = min;
  74. } else if (defaultPrice > 0) {
  75. actualPrice = defaultPrice;
  76. } else if (defaultPrice == 0) {
  77. actualPrice = '免费';
  78. type = '';
  79. }
  80. return {
  81. price: actualPrice,
  82. type: type
  83. };
  84. }
  85. }
  86. }
  87. </script>
  88. <style scoped lang="scss">
  89. .text-price::before {
  90. content: '¥';
  91. font-size: 60%;
  92. }
  93. .text-price-all::before {
  94. content: '¥';
  95. font-size: 100%;
  96. }
  97. </style>