customBarChart.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <template>
  2. <view class="barContent">
  3. <view class="bar-list">
  4. <view class="bar-list-item" v-for="(item, index) in dataList" :key="index">
  5. <view class="left">
  6. {{item.left}}
  7. </view>
  8. <!-- :style="`backgroundImage: linear-gradient(${themeColor}, ${themeColor50})};`" -->
  9. <view class="mid">
  10. <view class="mid-line" v-if="isThemeColor" :style="`width: ${item.percent + '%'};`"></view>
  11. <view class="mid-line" v-else :style="`width: ${item.percent + '%'}`"></view>
  12. </view>
  13. <view class="right">
  14. {{item.right}}
  15. </view>
  16. </view>
  17. </view>
  18. </view>
  19. </template>
  20. <script>
  21. export default {
  22. props: {
  23. isThemeColor: {
  24. type: Boolean,
  25. default: true
  26. },
  27. orginalList: Array
  28. },
  29. data() {
  30. return {
  31. dataList: [],
  32. themeColor: null,
  33. fuzhuColor: null,
  34. themeColor50: null,
  35. themeColor25: null,
  36. fuzhuColor50: null,
  37. fuzhuColor15: null
  38. }
  39. },
  40. mounted() {
  41. let globalData = getApp().globalData
  42. this.themeColor = globalData.themeColor
  43. this.themeColor50 = globalData.themeColor50
  44. this.themeColor25 = globalData.themeColor25
  45. this.fuzhuColor = globalData.fuzhuColor
  46. this.fuzhuColor50 = globalData.fuzhuColor50
  47. this.fuzhuColor15 = globalData.fuzhuColor15
  48. },
  49. methods: {
  50. reloadList() {
  51. if (this.orginalList.length > 0) {
  52. var tempList = JSON.parse(JSON.stringify(this.orginalList || []))
  53. tempList = tempList.sort((item1, item2) => {
  54. return item1.value - item2.value > 0
  55. })
  56. // debugger
  57. var maxValue = tempList[0].value
  58. tempList.forEach((item, index) => {
  59. item['percent'] = (item.value / maxValue * 100).toFixed(2)
  60. })
  61. this.dataList = tempList
  62. // // console.log('数据打印111111:', this.dataList)
  63. }
  64. }
  65. },
  66. watch: {
  67. orginalList: {
  68. handler(e) {
  69. this.reloadList()
  70. }
  71. },
  72. immediate: true
  73. }
  74. }
  75. </script>
  76. <style scoped lang="scss">
  77. .barContent {
  78. width: 100%;
  79. .bar-list {
  80. width: 100%;
  81. .bar-list-item {
  82. display: flex;
  83. flex-direction: row;
  84. justify-content: space-between;
  85. font-size: 14rpx;
  86. font-family: Verdana;
  87. white-space: nowrap;
  88. height: 60rpx;
  89. // line-height: 60rpx;
  90. padding: 0 20rpx 0 52rpx;
  91. box-sizing: border-box;
  92. min-height: 60rpx;
  93. .left {
  94. color: #393939;
  95. width: 25%;
  96. align-self: center;
  97. }
  98. .right {
  99. color: #3CD9D9;
  100. width: 20%;
  101. text-align: right;
  102. align-self: center;
  103. }
  104. .mid {
  105. margin-top: -10rpx;
  106. width: 50%;
  107. position: relative;
  108. align-self: center;
  109. .mid-line {
  110. position: absolute;
  111. background-color: #DD524D;
  112. height: 12rpx;
  113. border-radius: 6rpx;
  114. top: 0;
  115. }
  116. }
  117. }
  118. }
  119. }
  120. </style>