| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- <template>
- <div class="count-item">
- <span class="title">{{ title }}</span>
- <div class="count-content">
- <span v-for="num in nums" :class="num == ',' ? 'separator' : num == 0 ? 'zero num' : 'num'">{{ num }}</span>
- <!-- <span v-if="nums.length < 7">个</span>
- <span v-if="nums.length > 7">万</span>-->
- <span v-text="isMore?'万':'个'"></span>
- </div>
- </div>
- </template>
- <script>
- export default {
- name: 'count-item',
- props: {
- value: {
- default: 0,
- type: Number
- },
- title: {
- type: String
- }
- },
- data () {
- return {
- isMore: false
- }
- },
- methods: {
- formatNumber (num) {
- console.log(num)
- let re = /(\d+)(\d{3})/
- 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
- }
- }
- num = (Array(7 - String(num).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 {
- text-align: center;
- line-height: 20px;
- .title {
- display: inline-block;
- width: 58px;
- float: left;
- font-weight: bold;
- line-height: 40px;
- color: #fff;
- font-size: 14px;
- }
- .separator, .num {
- display: inline-block;
- }
- .separator {
- font-size: 12px;
- color: #6cb7f3;
- line-height: 38px !important;
- margin: 0 5px 0 -5px;
- width: 3px;
- }
- .count-content{
- width: 145px;
- background: #fff;
- float: right;
- height: 30px;
- margin-top: 5px;
- margin-right: 5px;
- span{
- float: left;
- line-height: 24px;
- font-weight: bold;
- }
- span.zero{
- color: #bbdffb;
- }
- span:first-child{
- margin-left: 3px;
- }
- span:last-child{
- line-height: 30px;
- color: #6cb7f3;
- margin-left: 2px;
- }
- }
- .num {
- background: #9dd0f9;
- width: 18px;
- height: 24px;
- margin-right: 2px;
- line-height: 24px;
- text-align: center;
- color: $white;
- font-weight: bold;
- border-radius: 2px;
- margin-top: 3px;
- }
- }
- </style>
|