index.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. <template>
  2. <div class="app-content" @click="dropdownShow = false">
  3. <!-- sel -wrap -->
  4. <div class="sel-wrap">
  5. <dropdown-list :show="dropdownShow" :top="80" :width="750" :height="400">
  6. <template v-slot:selectionbox>
  7. <div class="sel-open-btn" @click.stop="dropdownShow = dropdownShow ? false : true">
  8. <span>{{ typeName }}</span>
  9. <i class="iconfont iconsanjiao_xia"></i>
  10. </div>
  11. </template>
  12. <template v-slot:dropdownbox>
  13. <div class="sel-list-wrap">
  14. <scroll-view scroll-y class="tui-dropdown-scroll">
  15. <div class="sel-list" v-for="(item, index) in typeData" :key="index" @click.stop="selCategory(item)">{{ item.name }}</div>
  16. </scroll-view>
  17. </div>
  18. </template>
  19. </dropdown-list>
  20. </div>
  21. <!-- 收入统计 -->
  22. <div class="module-com">
  23. <div class="module-tit"></div>
  24. <div class="module-det">
  25. <echart-trend ref="echartIncome" :chartData="incomeStat" color="#FC243A" yName="金额(¥)" serviceName="收入统计"></echart-trend>
  26. </div>
  27. </div>
  28. <!-- 访问统计 -->
  29. <div class="module-com">
  30. <div class="module-tit"></div>
  31. <div class="module-det">
  32. <echart-trend ref="echartVisit" :chartData="visitStat" color="#3385FF" yName="数量(人)" serviceName="访问统计"></echart-trend>
  33. </div>
  34. </div>
  35. <!-- 客户数统计 -->
  36. <div class="module-com">
  37. <div class="module-tit"></div>
  38. <div class="module-det">
  39. <echart-trend ref="echartUser" :chartData="userStat" color="#28C57D" yName="数量(人)" serviceName="客户数统计"></echart-trend>
  40. </div>
  41. </div>
  42. <!-- 收入来源统计 -->
  43. <div class="module-com">
  44. <div class="module-tit">收入来源统计</div>
  45. <div class="module-det">
  46. <echart-circle ref="echartCircle" :chartData="incomeSourceStat"></echart-circle>
  47. </div>
  48. </div>
  49. <!-- 分类统计 -->
  50. <div class="module-com">
  51. <div class="module-tit">分类统计</div>
  52. <div class="module-det">
  53. <div class="category-list-wrap">
  54. <div class="category-list" v-for="(item, index) in categoryStat.list" :key="index">
  55. <div class="list-tit">{{ `${index + 1} ${item.name}` }}</div>
  56. <div class="list-det">
  57. <div class="progress-wrap">
  58. <div class="progress" :style="{ width: item.percentage + '%' }"></div>
  59. </div>
  60. <div class="progress-num">{{ item.num }}</div>
  61. </div>
  62. </div>
  63. </div>
  64. </div>
  65. </div>
  66. <!-- 用途统计 -->
  67. <div class="module-com">
  68. <div class="module-tit">用途统计</div>
  69. <div class="module-det">
  70. <echart-columnar ref="echartColumnar" :chartData="useStat"></echart-columnar>
  71. </div>
  72. </div>
  73. </div>
  74. </template>
  75. <script>
  76. import EchartTrend from './components/echart-trend'
  77. import EchartCircle from './components/echart-circle'
  78. import EchartColumnar from './components/echart-columnar'
  79. import DropdownList from '@/components/plugin/dropdown-list'
  80. // api
  81. import { getStatList } from '@/api/stat'
  82. export default {
  83. name: 'statistics',
  84. components: {
  85. EchartTrend,
  86. EchartCircle,
  87. EchartColumnar,
  88. DropdownList
  89. },
  90. data() {
  91. return {
  92. dropdownShow: false,
  93. typeData: [
  94. {
  95. name: '最近7天',
  96. value: 1
  97. },
  98. {
  99. name: '最近30天',
  100. value: 2
  101. },
  102. {
  103. name: '本月',
  104. value: 3
  105. },
  106. {
  107. name: '上月',
  108. value: 4
  109. },
  110. {
  111. name: '最近3月',
  112. value: 30
  113. },
  114. {
  115. name: '最近半年',
  116. value: 31
  117. },
  118. {
  119. name: '最近一年',
  120. value: 32
  121. },
  122. {
  123. name: '今年',
  124. value: 33
  125. }
  126. ],
  127. typeName: '最近7天',
  128. type: 1,
  129. // 收入统计
  130. incomeStat: {},
  131. // 访问量统计
  132. visitStat: {},
  133. // 客户数统计
  134. userStat: {},
  135. // 粉丝数统计
  136. fansStat: {},
  137. // 收入来源统计
  138. incomeSourceStat: {},
  139. // 分类统计
  140. categoryStat: {},
  141. // 用途统计
  142. useStat: {}
  143. }
  144. },
  145. onLoad() {},
  146. mounted() {
  147. this.mInit()
  148. },
  149. methods: {
  150. mInit() {
  151. this._getData()
  152. },
  153. _getData() {
  154. getStatList({ type: this.type }).then(res => {
  155. if (!this.$util.isEmpty(res.data)) {
  156. let data = res.data
  157. data.categoryStat.list = data.categoryStat.list.map(e => {
  158. e.percentage = ((e.num / data.categoryStat.total) * 100).toFixed(2)
  159. return e
  160. })
  161. data.incomeSourceStat.list = data.incomeSourceStat.list.map(e => {
  162. e.name = `${e.name} ${((e.num / data.incomeSourceStat.total) * 100).toFixed(2)}% ${e.num}`
  163. e.value = e.num
  164. return e
  165. })
  166. Object.keys(data).forEach((i, index) => {
  167. if (i != 'categoryStat') {
  168. data[i].nameArr = data[i].list.map(e => e.name)
  169. data[i].numArr = data[i].list.map(e => e.num)
  170. }
  171. })
  172. this.incomeStat = data.incomeStat
  173. this.visitStat = data.visitStat
  174. this.userStat = data.userStat
  175. this.fansStat = data.fansStat
  176. this.incomeSourceStat = data.incomeSourceStat
  177. this.categoryStat = data.categoryStat
  178. this.useStat = data.useStat
  179. console.log(data)
  180. setTimeout(() => {
  181. this.initChart()
  182. }, 100)
  183. }
  184. })
  185. },
  186. initChart() {
  187. this.$refs.echartIncome.initChart()
  188. this.$refs.echartVisit.initChart()
  189. this.$refs.echartUser.initChart()
  190. this.$refs.echartCircle.initChart()
  191. this.$refs.echartColumnar.initChart()
  192. },
  193. selCategory(item) {
  194. this.typeName = item.name
  195. this.type = item.value
  196. this.dropdownShow = false
  197. this._getData()
  198. }
  199. }
  200. }
  201. </script>
  202. <style lang="scss" scoped>
  203. .sel-wrap {
  204. width: 100%;
  205. height: 80upx;
  206. // background-color: ;
  207. // 下拉框
  208. .sel-open-btn {
  209. width: 30%;
  210. height: 80upx;
  211. line-height: 80upx;
  212. padding-left: 30upx;
  213. }
  214. .iconfont {
  215. color: $fontColor2;
  216. }
  217. .iconsanjiao_xia {
  218. font-size: 24upx;
  219. margin-left: 10upx;
  220. }
  221. .sel-list-wrap {
  222. background-color: #fff;
  223. box-shadow: 6upx 6upx 10upx #cccccc;
  224. .sel-list {
  225. padding: 20upx 30upx;
  226. // border-top: 1px solid $borderColor;
  227. }
  228. }
  229. .tui-dropdown-scroll {
  230. height: 400upx;
  231. }
  232. }
  233. .module-com {
  234. background-color: #fff;
  235. padding: 20upx 16upx 20upx 14upx;
  236. margin-bottom: 20upx;
  237. .module-tit {
  238. font-size: 28upx;
  239. margin-bottom: 26upx;
  240. padding-left: 16upx;
  241. }
  242. }
  243. .category-list-wrap {
  244. padding: 0 20upx;
  245. .category-list {
  246. margin-bottom: 20upx;
  247. .list-tit {
  248. color: $fontColor2;
  249. margin-bottom: 10upx;
  250. }
  251. .list-det {
  252. height: 30upx;
  253. @include disFlex(center, space-between);
  254. .progress-wrap {
  255. width: 84%;
  256. height: 100%;
  257. background-color: #f0f2f6;
  258. border-radius: 6upx;
  259. .progress {
  260. height: 100%;
  261. background-color: $mainColor;
  262. border-radius: 6upx;
  263. }
  264. .progress-num {
  265. color: $fontColor2;
  266. }
  267. }
  268. }
  269. }
  270. }
  271. </style>