Item.vue 2.6 KB

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