app-price.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <template>
  2. <view class="app-price t-omit" :class="sign !== 'gift' ? '' : theme+'-color ' + theme" :style="{'color': sign !== 'gift' ? theme.color : ''}" v-if="actual.price != -1">
  3. {{sign === 'integral_mall' && actual.price !== '' ? '+' : ''}}<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. theme: [Object, String],
  40. sign: String
  41. },
  42. data() {
  43. return {
  44. priceType: this.type,
  45. }
  46. },
  47. computed: {
  48. actual() {
  49. let actualPrice = -1;
  50. let price = -1;
  51. let min = -1;
  52. let max = -1;
  53. let defaultPrice = -1;
  54. let type = this.type;
  55. if (this.price !== 'undefined') {
  56. price = Number(this.price);
  57. }
  58. if (this.min !== 'undefined') {
  59. min = Number(this.min);
  60. }
  61. if (this.max !== 'undefined') {
  62. max = Number(this.max);
  63. }
  64. if (this.defaultPrice !== 'undefined') {
  65. defaultPrice = Number(this.defaultPrice);
  66. }
  67. if (!isNaN(price) && price >= 0) {
  68. actualPrice = price;
  69. } else if (max > min && min >= 0) {
  70. actualPrice = min + '-' + max;
  71. } else if (max === min && min >= 0) {
  72. actualPrice = min;
  73. } else if (defaultPrice >= 0) {
  74. actualPrice = defaultPrice;
  75. }
  76. if (actualPrice === 0) {
  77. actualPrice = '免费';
  78. type = '';
  79. }
  80. if (this.sign === 'integral_mall' && actualPrice === '免费') {
  81. actualPrice = '';
  82. }
  83. return {
  84. price: actualPrice,
  85. type: type
  86. };
  87. }
  88. }
  89. }
  90. </script>
  91. <style scoped lang="scss">
  92. .text-price::before {
  93. content: '¥';
  94. font-size: 100%;
  95. }
  96. .text-price-all::before {
  97. content: '¥';
  98. font-size: 100%;
  99. }
  100. </style>