userCoursePeriodDetails.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. <template>
  2. <div class="statistics-container">
  3. <!-- 营期课程选择 -->
  4. <div class="fixed-header">
  5. <el-form :inline="true" :model="queryParams" class="demo-form-inline">
  6. <el-form-item label="营期课程">
  7. <el-select
  8. v-model="queryParams.periodId"
  9. placeholder="请选择营期课程"
  10. style="width: 400px"
  11. clearable
  12. >
  13. <el-option
  14. v-for="item in courseOptions"
  15. :key="item.periodId"
  16. :label="item.periodName"
  17. :value="item.periodId"
  18. />
  19. </el-select>
  20. </el-form-item>
  21. <el-form-item>
  22. <el-button type="primary" @click="handleQuery">查询</el-button>
  23. </el-form-item>
  24. </el-form>
  25. <!-- 统计数据展示 -->
  26. <el-row :gutter="20" class="statistics-row">
  27. <el-col :span="4">
  28. <div class="statistics-item">
  29. <div class="statistics-title">到课数</div>
  30. <div class="statistics-value">{{ statistics.courseCompleteNum || 0 }}次</div>
  31. </div>
  32. </el-col>
  33. <el-col :span="4">
  34. <div class="statistics-item">
  35. <div class="statistics-title">总学习时长</div>
  36. <div class="statistics-value">{{ statistics.courseWatchNum || 0 }}分钟</div>
  37. </div>
  38. </el-col>
  39. <el-col :span="4">
  40. <div class="statistics-item">
  41. <div class="statistics-title">正确答题数</div>
  42. <div class="statistics-value">{{ statistics.correctAnswerNum || 0 }}次</div>
  43. </div>
  44. </el-col>
  45. <el-col :span="4">
  46. <div class="statistics-item">
  47. <div class="statistics-title">获得红包数</div>
  48. <div class="statistics-value">{{ statistics.redPacketCount || 0 }}次</div>
  49. </div>
  50. </el-col>
  51. <el-col :span="4">
  52. <div class="statistics-item">
  53. <div class="statistics-title">红包总金额</div>
  54. <div class="statistics-value">{{ statistics.redPacketAmount || 0 }}元</div>
  55. </div>
  56. </el-col>
  57. </el-row>
  58. </div>
  59. </div>
  60. </template>
  61. <script>
  62. import {getDays, periodCourseStatisticCount,periodList} from "@/api/course/userCoursePeriod";
  63. export default {
  64. name: "userCoursePeriodDetails",
  65. props: {
  66. periodId: {
  67. type: [String, Number],
  68. default: ''
  69. },
  70. active: {
  71. type: Boolean,
  72. default: false
  73. }
  74. },
  75. data() {
  76. return {
  77. // 遮罩层
  78. loading: false,
  79. // 总条数
  80. total: 0,
  81. // 课程选项
  82. courseOptions: [],
  83. // 统计数据
  84. statistics: {
  85. courseCompleteNum: 0,
  86. courseWatchNum: 0,
  87. redPacketCount: 0,
  88. correctAnswerNum: 0,
  89. redPacketAmount: 0
  90. },
  91. // 列表数据
  92. list: [],
  93. // 查询参数
  94. queryParams: {
  95. pageNum: 1,
  96. pageSize: 10,
  97. // videoId: '',
  98. periodId: '',
  99. trainingCampId:null,
  100. userId:null,
  101. },
  102. // 是否已初始化
  103. initialized: false
  104. };
  105. },
  106. created() {
  107. },
  108. methods: {
  109. getDetails(camp,userid) {
  110. this.queryParams.trainingCampId = camp.trainingCampId;
  111. this.camp = camp;
  112. this.userId=userid;
  113. this.queryParams.userId=userid;
  114. this.user=null;
  115. this.courseOptions = []
  116. this.queryParams.periodId = null;
  117. this.getCourseOptions();
  118. this.calculateTotalStatistics();
  119. },
  120. /** 查询按钮操作 */
  121. handleQuery() {
  122. this.calculateTotalStatistics();
  123. },
  124. /** 获取课程选项 */
  125. getCourseOptions() {
  126. this.loading = true;
  127. periodList(this.queryParams).then(r => {
  128. if (r.code === 200) {
  129. this.courseOptions = r.data;
  130. this.loading = false;
  131. } else {
  132. this.$message.error(r.msg || '获取数据失败');
  133. }
  134. this.loading = false;
  135. }).catch(() => {
  136. this.loading = false;
  137. });
  138. },
  139. /** 计算总统计数据 */
  140. calculateTotalStatistics() {
  141. console.log("this.queryParams:",this.queryParams)
  142. periodCourseStatisticCount(this.queryParams).then(response => {
  143. if (response.code === 200) {
  144. // 设置列表数据
  145. this.statistics.courseCompleteNum = response.data.courseCompleteNum || 0;
  146. this.statistics.courseWatchNum = response.data.courseWatchNum || 0;
  147. this.statistics.courseWatchTimes = response.data.courseWatchTimes || 0;
  148. this.statistics.redPacketCount = response.data.redPacketCount || 0;
  149. this.statistics.correctAnswerNum = response.data.correctAnswerNum || 0;
  150. this.statistics.redPacketAmount = response.data.redPacketAmount || 0;
  151. } else {
  152. this.$message.error(response.msg || '获取数据失败');
  153. }
  154. this.loading = false;
  155. }).catch(error => {
  156. console.error('获取数据失败:', error);
  157. this.$message.error('获取数据失败');
  158. this.loading = false;
  159. });
  160. }
  161. }
  162. };
  163. </script>
  164. <style scoped>
  165. .statistics-container {
  166. height: 100%;
  167. overflow: hidden;
  168. position: relative;
  169. }
  170. .fixed-header {
  171. position: sticky;
  172. top: 0;
  173. z-index: 10;
  174. background-color: #fff;
  175. padding: 10px 0;
  176. border-bottom: 1px solid #EBEEF5;
  177. }
  178. /* 覆盖原有的pagination-container样式 */
  179. :deep(.pagination-container) {
  180. height: auto !important;
  181. margin-bottom: 0 !important;
  182. margin-top: 0 !important;
  183. padding: 0 !important;
  184. }
  185. .statistics-row {
  186. margin: 20px 0;
  187. }
  188. .statistics-item {
  189. background-color: #f5f7fa;
  190. border-radius: 4px;
  191. padding: 15px;
  192. text-align: center;
  193. height: 100px;
  194. display: flex;
  195. flex-direction: column;
  196. justify-content: center;
  197. }
  198. .statistics-title {
  199. font-size: 14px;
  200. color: #606266;
  201. margin-bottom: 10px;
  202. }
  203. .statistics-value {
  204. font-size: 20px;
  205. font-weight: bold;
  206. color: #303133;
  207. }
  208. </style>