Item.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <template>
  2. <div class="count-item">
  3. <span class="title">{{ title }}</span>
  4. <div class="count-content">
  5. <span v-for="num in nums" :class="num == ',' ? 'separator' : num == 0 ? 'zero num' : 'num'">{{ num }}</span>
  6. <!-- <span v-if="nums.length < 7">个</span>
  7. <span v-if="nums.length > 7">万</span>-->
  8. <span class="num">个</span>
  9. </div>
  10. </div>
  11. </template>
  12. <script>
  13. export default {
  14. name: 'count-item',
  15. props: {
  16. value: {
  17. default: 0,
  18. type: Number
  19. },
  20. title: {
  21. type: String
  22. }
  23. },
  24. data () {
  25. return {
  26. isMore: false
  27. }
  28. },
  29. methods: {
  30. formatNumber (num) {
  31. let re = /(\d+)(\d{3})/
  32. if (num > 9999) {
  33. this.isMore = true
  34. console.log(num.toString().charAt(4))
  35. }
  36. num = (Array(10 - String(num).length).join(0) + num)
  37. while (re.test(num)) {
  38. num = num.replace(re, '$1,$2')
  39. }
  40. num = num.split('')
  41. // console.log(num)
  42. return num
  43. }
  44. },
  45. computed: {
  46. nums () {
  47. return this.formatNumber(this.value)
  48. }
  49. }
  50. }
  51. </script>
  52. <style lang="scss" scoped>
  53. @import '~assets/scss/variables';
  54. .count-item {
  55. text-align: center;
  56. line-height: 20px;
  57. .title {
  58. display: inline-block;
  59. width: 60px;
  60. float: left;
  61. font-weight: bold;
  62. line-height: 40px;
  63. color: #fff;
  64. font-size: 14px;
  65. }
  66. .separator, .num {
  67. display: inline-block;
  68. }
  69. .separator {
  70. font-size: 12px;
  71. color: #6cb7f3;
  72. line-height: 38px !important;
  73. margin: 0 5px 0 -5px;
  74. width: 3px;
  75. }
  76. .count-content{
  77. width: 145px;
  78. background: #fff;
  79. float: right;
  80. height: 30px;
  81. margin-top: 5px;
  82. margin-right: 5px;
  83. span{
  84. float: left;
  85. line-height: 24px;
  86. font-weight: bold;
  87. }
  88. span.zero{
  89. color: #bbdffb;
  90. }
  91. span:first-child{
  92. margin-left: 3px;
  93. }
  94. span:last-child{
  95. line-height: 30px;
  96. color: #6cb7f3;
  97. }
  98. }
  99. .num {
  100. background: #9dd0f9;
  101. width: 18px;
  102. height: 24px;
  103. margin-right: 2px;
  104. line-height: 24px;
  105. text-align: center;
  106. color: $white;
  107. font-weight: bold;
  108. border-radius: 2px;
  109. margin-top: 3px;
  110. }
  111. }
  112. </style>