BaseMoney.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <template>
  2. <view :class="{ line: line, weight: weight }"
  3. :style="{color: '#' + incolor,fontWeight: fontWeight, display:(discount || inline) ? 'inline-block' : 'block', fontFamily: line?'Futura-Light':'Futura' }"
  4. class="base-money">
  5. <text v-if="!discount" class="symbol" :style="{'font-size': symbolSize +'rpx'}">¥</text><text class="integer"
  6. :style="{'font-size': integerSize +'rpx'}">{{ integer }}</text>
  7. <text v-if="digits && decimal != '00' && decimal != '0'" class="decimal"
  8. :style="{'font-size': decimalSize +'rpx'}">.{{ decimal }}</text>
  9. </view>
  10. </template>
  11. <script>
  12. // +----------------------------------------------------------------------
  13. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  14. // +----------------------------------------------------------------------
  15. // | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
  16. // +----------------------------------------------------------------------
  17. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  18. // +----------------------------------------------------------------------
  19. // | Author: CRMEB Team <admin@crmeb.com>
  20. // +----------------------------------------------------------------------
  21. export default {
  22. name: 'BaseMoney',
  23. props: {
  24. // 小数位数,为0则不显示
  25. digits: {
  26. type: Number,
  27. default: 2
  28. },
  29. fontWeight: {
  30. type: Number | String,
  31. default: 'inherit'
  32. },
  33. money: {
  34. type: String | Number,
  35. default: ""
  36. },
  37. // 删除线
  38. line: {
  39. type: Boolean,
  40. default: false
  41. },
  42. // 粗体
  43. weight: {
  44. type: Boolean,
  45. default: false
  46. },
  47. incolor: {
  48. type: String,
  49. default: '424242'
  50. },
  51. symbolSize: {
  52. type: String,
  53. default: '20'
  54. },
  55. integerSize: {
  56. type: String,
  57. default: '26'
  58. },
  59. decimalSize: {
  60. type: String,
  61. default: '24'
  62. },
  63. discount: {
  64. type: Boolean,
  65. default: false
  66. },
  67. inline: {
  68. type: Boolean,
  69. default: false
  70. }
  71. },
  72. data() {
  73. return {
  74. integer: 0,
  75. decimal: 0
  76. };
  77. },
  78. watch: {
  79. money: {
  80. handler(newValue, oldValue) {
  81. let value = Number(newValue).toFixed(this.digits);
  82. value = value.split('.');
  83. this.integer = value[0].replace(/\B(?=(\d{3})+(?!\d))/g, ',');
  84. if (value[1]) {
  85. this.decimal = (value[1].length == 2 && value[1].charAt(1) != 0) ? value[1] : (value[1].charAt(
  86. 0) || 0);
  87. }
  88. },
  89. immediate: true
  90. }
  91. }
  92. }
  93. </script>
  94. <style lang="scss" scoped>
  95. .base-money {
  96. font-family: Futura;
  97. &.line {
  98. .symbol,.decimal,.integer{
  99. text-decoration: line-through;
  100. }
  101. }
  102. &.weight {
  103. font-weight: 500;
  104. }
  105. }
  106. </style>