BaseMoney.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <template>
  2. <view :class="{ line: line, weight: weight }"
  3. :style="{color:color, fontFamily: SemiBold ? 'SemiBold' : 'Regular'}"
  4. class="base-money">
  5. <text v-show="preFix" class="preFix" :style="{'font-size': preFixSize + 'rpx','color':textColor}">{{preFix}}</text>
  6. <text v-if="symbol" class="symbol" :style="{'font-size': symbolSize +'rpx'}">¥</text><text class="integer"
  7. :style="{'font-size': integerSize +'rpx'}">{{ integer }}</text>
  8. <text v-if="digits && ((isCoupon && decimal != '00') || !isCoupon)" class="decimal"
  9. :style="{'font-size': decimalSize +'rpx'}">.{{ decimal }}</text>
  10. </view>
  11. </template>
  12. <script>
  13. export default {
  14. name: 'BaseMoney',
  15. props: {
  16. // 小数位数,为0则不显示
  17. digits: {
  18. type: Number,
  19. default: 2
  20. },
  21. money: {
  22. type: String | Number,
  23. default: ""
  24. },
  25. // 删除线
  26. line: {
  27. type: Boolean,
  28. default: false
  29. },
  30. // 粗体
  31. weight: {
  32. type: Boolean,
  33. default: false
  34. },
  35. symbol: {
  36. type: Boolean,
  37. default: true
  38. },
  39. color:{
  40. type: String,
  41. default: 'var(--view-theme)'
  42. },
  43. textColor:{
  44. type: String,
  45. default: '#999'
  46. },
  47. symbolSize: {
  48. type: String,
  49. default: '20'
  50. },
  51. integerSize: {
  52. type: String,
  53. default: '26'
  54. },
  55. decimalSize: {
  56. type: String,
  57. default: '24'
  58. },
  59. inline: {
  60. type: Boolean,
  61. default: false
  62. },
  63. preFix:{
  64. type: String,
  65. default: ''
  66. },
  67. preFixSize:{
  68. type: String,
  69. default: '24'
  70. },
  71. SemiBold:{
  72. type: Boolean,
  73. default: true
  74. },
  75. isCoupon:{
  76. type: Boolean,
  77. default: false
  78. }
  79. },
  80. data() {
  81. return {
  82. integer: 0,
  83. decimal: 0
  84. };
  85. },
  86. watch: {
  87. money: {
  88. handler(newValue, oldValue) {
  89. let value = Number(newValue).toFixed(this.digits);
  90. value = value.split('.');
  91. this.integer = value[0].replace(/\B(?=(\d{3})+(?!\d))/g, ',');
  92. if (value[1]) {
  93. this.decimal = value[1];
  94. }
  95. },
  96. immediate: true
  97. }
  98. },
  99. computed:{}
  100. }
  101. </script>
  102. <style lang="scss" scoped>
  103. .base-money {
  104. display: inline-block;
  105. &.line {
  106. text-decoration: line-through;
  107. }
  108. &.weight {
  109. font-weight: 500;
  110. }
  111. }
  112. .preFix{
  113. font-weight: 500 !important;
  114. font-family: PingFang SC-Medium, PingFang SC !important;
  115. }
  116. .SemiBold{
  117. font-family:'SemiBold';
  118. }
  119. .Regular{
  120. font-family:'Regular';
  121. }
  122. </style>