Item.vue 2.4 KB

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