BaseMoney.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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 class="symbol" :style="{'font-size': symbolSize +'rpx'}">¥</text><text class="integer"
  7. :style="{'font-size': integerSize +'rpx'}">{{ integer }}</text>
  8. <text v-if="digits && showDigits" 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. color:{
  36. type: String,
  37. default: 'var(--view-theme)'
  38. },
  39. textColor:{
  40. type: String,
  41. default: '#999'
  42. },
  43. symbolSize: {
  44. type: String,
  45. default: '20'
  46. },
  47. integerSize: {
  48. type: String,
  49. default: '26'
  50. },
  51. decimalSize: {
  52. type: String,
  53. default: '24'
  54. },
  55. inline: {
  56. type: Boolean,
  57. default: false
  58. },
  59. preFix:{
  60. type: String,
  61. default: ''
  62. },
  63. preFixSize:{
  64. type: String,
  65. default: '24'
  66. },
  67. SemiBold:{
  68. type: Boolean,
  69. default: true
  70. },
  71. isCoupon:{
  72. type: Boolean,
  73. default: false
  74. }
  75. },
  76. data() {
  77. return {
  78. integer: 0,
  79. decimal: 0
  80. };
  81. },
  82. watch: {
  83. money: {
  84. handler(newValue, oldValue) {
  85. let value = Number(newValue).toFixed(this.digits);
  86. value = value.split('.');
  87. this.integer = value[0].replace(/\B(?=(\d{3})+(?!\d))/g, ',');
  88. if (value[1]) {
  89. this.decimal = value[1];
  90. }
  91. },
  92. immediate: true
  93. }
  94. },
  95. computed:{
  96. showDigits(){
  97. if(this.isCoupon){
  98. if(this.decimal == '00') return false
  99. }else{
  100. return true
  101. }
  102. }
  103. }
  104. }
  105. </script>
  106. <style lang="scss" scoped>
  107. .base-money {
  108. display: inline-block;
  109. &.line {
  110. text-decoration: line-through;
  111. }
  112. &.weight {
  113. font-weight: 500;
  114. }
  115. }
  116. .preFix{
  117. font-weight: 500 !important;
  118. font-family: PingFang SC-Medium, PingFang SC !important;
  119. }
  120. .SemiBold{
  121. font-family:'SemiBold';
  122. }
  123. .Regular{
  124. font-family:'Regular';
  125. }
  126. </style>