Item.vue 2.6 KB

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