index.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <template>
  2. <div class="app-container">
  3. <el-row>
  4. <el-col :span="24" class="card-box">
  5. <el-card>
  6. <div slot="header"><span>搜索信息</span></div>
  7. <div class="el-table el-table--enable-row-hover el-table--medium">
  8. <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="120px">
  9. <el-form-item label="活动开始时间" prop="startTime">
  10. <el-date-picker clearable
  11. v-model="queryParams.startTime"
  12. type="date"
  13. value-format="yyyy-MM-dd"
  14. placeholder="请选择活动开始时间">
  15. </el-date-picker>
  16. </el-form-item>
  17. <el-form-item label="活动结束时间" prop="endTime">
  18. <el-date-picker clearable
  19. v-model="queryParams.endTime"
  20. type="date"
  21. value-format="yyyy-MM-dd"
  22. placeholder="请选择活动结束时间">
  23. </el-date-picker>
  24. </el-form-item>
  25. <el-form-item>
  26. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  27. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  28. </el-form-item>
  29. </el-form>
  30. </div>
  31. </el-card>
  32. </el-col>
  33. <el-col :span="8" class="card-box">
  34. <el-card>
  35. <div slot="header"><span>活动统计</span></div>
  36. <div class="el-table el-table--enable-row-hover el-table--medium">
  37. <div ref="activities" style="height: 500px" />
  38. </div>
  39. </el-card>
  40. </el-col>
  41. <el-col :span="16" class="card-box">
  42. <el-card>
  43. <div slot="header">
  44. <span>人数统计</span>
  45. </div>
  46. <el-row :gutter="24">
  47. <el-col :span="4" v-for="(item, index) in userData" :key="index"><div style="margin-top: 8px;">{{ item.name }}: {{ item.value }}人</div></el-col>
  48. </el-row>
  49. <div class="el-table el-table--enable-row-hover el-table--medium">
  50. <div ref="usedmemory" style="height: 440px" />
  51. </div>
  52. </el-card>
  53. </el-col>
  54. </el-row>
  55. </div>
  56. </template>
  57. <script>
  58. import { activityCountByType, userCountByType, userCountByTag, userTotalCountByTag, userTimesByTag, userTotalTimesByTag } from "@/api/stat/index";
  59. import echarts from "echarts";
  60. export default {
  61. name: "Cache",
  62. data() {
  63. return {
  64. activities: null,
  65. // cache信息
  66. cache: [],
  67. queryParams: {},
  68. dateRange: [],
  69. userData: [],
  70. titleList: [
  71. { name: '文化娱乐', value: 'whyl' },
  72. { name: '志愿服务', value: 'zyfu' },
  73. { name: '教育宣讲', value: 'jyxj' },
  74. { name: '治理防范', value: 'zlff' },
  75. { name: '环境卫生', value: 'hjws' },
  76. { name: '关爱服务', value: 'gafw' }
  77. ]
  78. }
  79. },
  80. mounted() {
  81. this.handleQuery();
  82. // this.openLoading();
  83. },
  84. methods: {
  85. // 搜索
  86. handleQuery() {
  87. this.$modal.loading("正在加载活动统计数据,请稍候!");
  88. this.getActivity();
  89. this.getUser();
  90. this.getUserList();
  91. },
  92. // 重置
  93. resetQuery() {
  94. this.dateRange = [];
  95. this.resetForm("queryForm");
  96. this.handleQuery();
  97. },
  98. /** 人数信息 */
  99. async getUserList() {
  100. const typeUser = await userCountByTag(this.queryParams);
  101. // 用户群体按字典排序
  102. typeUser.data.sort((a, b) =>
  103. (this.dict.type.user_tags.find(tag => tag.label === a.name)?.raw.dictSort ?? Infinity) -
  104. (this.dict.type.user_tags.find(tag => tag.label === b.name)?.raw.dictSort ?? Infinity)
  105. );
  106. const allUser = await userTotalTimesByTag(this.queryParams);
  107. const allData = [{ name: '总人次', value: allUser.data }];
  108. this.userData = [ ...allData, ...typeUser?.data ];
  109. this.$modal.closeLoading();
  110. },
  111. async getActivity() {
  112. const res = await activityCountByType(this.queryParams);
  113. const data = res?.data.map(e => {
  114. const type = this.titleList.find(j => j.value == e.name);
  115. if (type) e.name = type.name;
  116. return e;
  117. });;
  118. const myChart = echarts.init(this.$refs.activities, 'macarons');
  119. const option = {
  120. tooltip: {
  121. trigger: 'item',
  122. formatter: "{b}: {c} ({d}%)",
  123. },
  124. series: [
  125. {
  126. type: "pie",
  127. roseType: "radius",
  128. radius: [15, 95],
  129. center: ["50%", "38%"],
  130. data,
  131. animationEasing: "cubicInOut",
  132. animationDuration: 1000,
  133. }
  134. ]
  135. };
  136. myChart.setOption(option);
  137. },
  138. async getUser() {
  139. const res = await userCountByType(this.queryParams);
  140. const data = res?.data.map(e => {
  141. const type = this.titleList.find(j => j.value == e.name);
  142. if (type) e.name = type.name;
  143. return e;
  144. });
  145. const myChart = echarts.init(this.$refs.usedmemory);
  146. const option = {
  147. xAxis: {
  148. type: 'category',
  149. data: (() => {
  150. let list = [];
  151. data.map((item) => {
  152. list.push(item.name);
  153. });
  154. return list;
  155. })(),
  156. },
  157. yAxis: {
  158. type: 'value'
  159. },
  160. series: [
  161. {
  162. data,
  163. type: 'bar',
  164. showBackground: true,
  165. backgroundStyle: {
  166. color: 'rgba(180, 180, 180, 0.2)'
  167. },
  168. label: {
  169. show: true,
  170. position: 'top'
  171. },
  172. itemStyle: {
  173. normal: {
  174. color: function(params) {
  175. return '#3f48cc'
  176. }
  177. }
  178. }
  179. }
  180. ]
  181. };
  182. myChart.setOption(option);
  183. }
  184. }
  185. };
  186. </script>