index.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <template>
  2. <div class="planting-record">
  3. <p class="title">设备数据统计</p>
  4. <div class="planting-record__content clearfix">
  5. <div class="planting-record__left">
  6. <PieEchart v-show="leftList.length" :leftList="leftList" @changePieIndex="changePieIndex" />
  7. <no-data v-if="!leftList.length" />
  8. </div>
  9. <div class="planting-record__right" ref="scrollContainer">
  10. <div
  11. class="record_list"
  12. :class="activeIndex == index ? 'active' : ''"
  13. v-for="(i, index) in leftList"
  14. :key="index"
  15. >
  16. <div class="name">
  17. <div class="empty-circle" :style="circleStyle(index)"></div>
  18. {{ i.name }}:
  19. </div>
  20. <div class="value">{{ i.value }}&nbsp;台</div>
  21. </div>
  22. </div>
  23. </div>
  24. </div>
  25. </template>
  26. <script>
  27. import PieEchart from '../Echarts/PieEcharts.vue'
  28. import noData from '../noData.vue'
  29. import { formatNumber } from '@/util/helpers.js'
  30. export default {
  31. name: 'PlantRecord',
  32. props: {
  33. landSummaryData: {
  34. type: Array,
  35. default: () => []
  36. },
  37. payAllCount: {
  38. type: Number,
  39. default: 0
  40. }
  41. },
  42. watch: {},
  43. components: {
  44. PieEchart,
  45. noData
  46. },
  47. data() {
  48. return {
  49. colors: [
  50. '#00A6CA',
  51. '#00E0B0',
  52. '#FFC859',
  53. '#1671F8',
  54. '#E67B3E',
  55. '#159AFF',
  56. '#FF5951',
  57. '#6B53FF',
  58. '#FFC97A',
  59. '#6EE484',
  60. '#E7EB4B',
  61. '#1561F3',
  62. '#FA73F5',
  63. '#66EDED',
  64. '#6DE28B',
  65. '#A2845E',
  66. '#018B3F',
  67. '#00C7BE'
  68. ],
  69. leftList: [
  70. {
  71. name: '农资',
  72. rate: '35',
  73. value: 35
  74. },
  75. {
  76. name: '农具',
  77. rate: '25',
  78. value: 25
  79. },
  80. {
  81. name: '人工',
  82. rate: '40',
  83. value: 40
  84. }
  85. ],
  86. activeIndex: 0,
  87. residualArea: 0,
  88. percentAll: 0
  89. }
  90. },
  91. mounted() {
  92. this.getEchartsData()
  93. },
  94. methods: {
  95. circleStyle(index) {
  96. return {
  97. 'background-color': this.colors[index % this.colors.length]
  98. }
  99. },
  100. changePieIndex(i) {
  101. this.activeIndex = i
  102. const container = this.$refs.scrollContainer
  103. if (container.scrollTop + container.clientHeight >= container.scrollHeight + 25) {
  104. container.scrollTop = 0
  105. } else {
  106. container.scrollTop += 20 // 每次滚动1px
  107. }
  108. },
  109. handelnumber(val) {
  110. return formatNumber(val)
  111. },
  112. getEchartsData() {
  113. this.$axios({
  114. method: 'POST',
  115. url: '/api/v2/home/device/statistic/'
  116. }).then((res) => {
  117. // console.log(res);
  118. const { result, total_num } = res.data.data.items
  119. this.$emit('deviceCount', total_num)
  120. this.leftList = result.map((item) => ({
  121. name: item.name,
  122. value: Number(item.value),
  123. rate: parseFloat(((item.value / total_num) * 100).toFixed(2))
  124. }))
  125. })
  126. }
  127. }
  128. }
  129. </script>
  130. <style lang="less" scoped>
  131. .planting-record {
  132. height: 100%;
  133. border-radius: 4px;
  134. background: rgba(0, 0, 0, 0.32);
  135. .title {
  136. img {
  137. }
  138. padding-left: 60px;
  139. box-sizing: border-box;
  140. height: 40px;
  141. line-height: 40px;
  142. background-image: url('../../assets/title-bg.png');
  143. font-size: 18px;
  144. color: #ffffff;
  145. // margin-bottom: 12px;
  146. }
  147. &__content {
  148. // display: flex;
  149. padding: 20px 20px 20px 5px;
  150. box-sizing: border-box;
  151. height: calc(100% - 40px);
  152. }
  153. &__left {
  154. width: 220px;
  155. height: 220px;
  156. // margin-right: 6px;
  157. float: left;
  158. }
  159. &__right {
  160. // flex: 1;
  161. float: right;
  162. height: 100%;
  163. overflow-y: auto;
  164. padding-right: 10px;
  165. .record_list {
  166. display: flex;
  167. align-items: center;
  168. justify-content: space-between;
  169. width: 100%;
  170. margin-bottom: 12px;
  171. height: 20px;
  172. line-height: 20px;
  173. color: #ffffff;
  174. font-family: 'Source Han Sans CN';
  175. font-size: 14px;
  176. // .empty-circle0 {
  177. // border: 2px solid #00e0b0; /* 边框的样式和宽度 */
  178. // }
  179. // .empty-circle1 {
  180. // border: 2px solid #ffc859; /* 边框的样式和宽度 */
  181. // }
  182. // .empty-circle2 {
  183. // border: 2px solid #0184fe; /* 边框的样式和宽度 */
  184. // }
  185. .name {
  186. .empty-circle {
  187. float: left;
  188. width: 8px;
  189. height: 8px;
  190. margin-right: 8px;
  191. margin-top: 6px;
  192. border-radius: 50%;
  193. }
  194. }
  195. }
  196. .active {
  197. border-top: 2px solid;
  198. border-bottom: 2px solid;
  199. border-image: linear-gradient(to right, #13314400, #5190c9, #13314400) 1;
  200. background: linear-gradient(90deg, #0a344100 0%, #044a99b3 33.49%, #13314400 100%);
  201. }
  202. }
  203. }
  204. </style>