| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- <template>
- <div class="count-item">
- <span>{{ nums }}</span>
- <span v-text="isMore?'万':'个'" v-if="!isShow && index !==3"></span>
- <span v-text="isMore?'万':'家'" v-if="!isShow && index ===3"></span>
- <span v-if="isShow">亿</span>
- </div>
- </template>
- <script>
- export default {
- name: 'count-item',
- props: {
- value: {
- default: 0,
- type: Number
- },
- index: {
- default: 0,
- type: Number
- }
- },
- data () {
- return {
- isMore: false,
- isShow: false,
- len: 0
- }
- },
- methods: {
- formatNumber (num) {
- // let re = /(\d+)(\d{3})/
- if (num > 99999999) {
- this.isShow = true
- let str2 = num.toString()
- num = Math.floor(num / 100000000)
- if (parseInt(str2.charAt(str2.length - 8)) > 8) {
- num = num + 1
- }
- }
- if (num > 9999) {
- this.isMore = true
- let str = num.toString()
- num = Math.floor(num / 10000)
- if (parseInt(str.charAt(str.length - 4)) > 4) {
- num = num + 1
- }
- }
- let length = String(num).length
- this.len = length > 3 ? length + 1 : length
- num = (Array(7 - length).join(0) + num)
- // while (re.test(num)) {
- // num = num.replace(re, '$1,$2')
- // }
- // num = num.split('')
- // console.log(num)
- return num
- }
- },
- computed: {
- nums () {
- return this.formatNumber(this.value)
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- @import '~assets/scss/variables';
- .count-item {
- width: 100%;
- height: 30px;
- span{
- &:first-child{
- position: relative;
- top: -2px;
- }
- &:last-child{
- font-size: 16px;
- color: #376ef3;
- font-weight: bold;
- padding: 0px 34px 0px 7px;
- position: relative;
- top: -5px;
- }
- }
- }
- </style>
|