redPacketProjectReport.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="90px">
  4. <el-form-item label="日期" prop="createTime">
  5. <el-date-picker v-model="createTime" size="small" style="width: 220px" value-format="yyyy-MM-dd"
  6. type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"
  7. @change="xdChange"></el-date-picker>
  8. </el-form-item>
  9. <el-form-item>
  10. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  11. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  12. </el-form-item>
  13. </el-form>
  14. <el-row :gutter="10" class="mb8">
  15. <el-col :span="1.5">
  16. <el-button
  17. type="warning"
  18. plain
  19. icon="el-icon-download"
  20. size="mini"
  21. :loading="exportLoading"
  22. @click="handleExport"
  23. v-hasPermi="['course:courseRedPacketLog:exportMoneyList']"
  24. >导出</el-button>
  25. </el-col>
  26. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  27. </el-row>
  28. <el-table v-loading="loading" border :data="projectRedPacketList" v-hasPermi="['course:courseRedPacketLog:moneyList']">
  29. <el-table-column label="项目名称" align="center" prop="projectName" />
  30. <el-table-column label="红包消耗金额(元)" align="center" prop="money">
  31. <template slot-scope="{ row }">
  32. {{ row.money ? row.money.toFixed(2) : '0.00' }}
  33. </template>
  34. </el-table-column>
  35. </el-table>
  36. <div class="total-summary" v-hasPermi="['course:courseRedPacketLog:moneyList']">
  37. <span class="total-title">总计:</span>
  38. <span class="total-item">红包消耗金额: {{ calculatedTotalData.money.toFixed(2) }} 元</span>
  39. </div>
  40. <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
  41. @pagination="getList" v-hasPermi="['course:courseRedPacketLog:moneyList']" />
  42. </div>
  43. </template>
  44. <script>
  45. import {exportProjectRedPacketMoney, getProjectRedPacketMoney} from "@/api/course/courseRedPacketLog";
  46. import rightToolbar from "@/components/RightToolbar";
  47. import Pagination from "@/components/Pagination";
  48. export default {
  49. name: "ProjectRedPacketReport",
  50. components: {
  51. rightToolbar,
  52. Pagination
  53. },
  54. data() {
  55. return {
  56. calculatedTotalData: {
  57. money: 0
  58. },
  59. // 遮罩层
  60. loading: true,
  61. // 导出遮罩层
  62. exportLoading: false,
  63. // 总条数
  64. total: 0,
  65. createTime: [],
  66. // 项目红包消耗列表数据
  67. projectRedPacketList: [],
  68. // 显示搜索条件
  69. showSearch: true,
  70. startTime: null,
  71. endTime: null,
  72. // 查询参数
  73. queryParams: {
  74. pageNum: 1,
  75. pageSize: 10,
  76. startTime: null, // 修改为startTime
  77. endTime: null // 修改为endTime
  78. },
  79. };
  80. },
  81. created() {
  82. this.createTime = this.getDefaultDateRange();
  83. this.queryParams.startTime = this.createTime[0];
  84. this.queryParams.endTime = this.createTime[1];
  85. this.getList()
  86. },
  87. methods: {
  88. // 获取前一天日期范围
  89. getDefaultDateRange() {
  90. const yesterday = new Date();
  91. yesterday.setDate(yesterday.getDate() - 1);
  92. const year = yesterday.getFullYear();
  93. const month = String(yesterday.getMonth() + 1).padStart(2, '0');
  94. const day = String(yesterday.getDate()).padStart(2, '0');
  95. const yesterdayStr = `${year}-${month}-${day}`;
  96. return [yesterdayStr, yesterdayStr]; // 前一天开始和结束是同一天
  97. },
  98. calculateTotals() {
  99. // 重置总计数据
  100. this.calculatedTotalData = {
  101. money: 0
  102. };
  103. // 遍历当前页数据计算总和
  104. this.projectRedPacketList.forEach(item => {
  105. this.calculatedTotalData.money += Number(item.money) || 0;
  106. });
  107. },
  108. /** 查询项目红包消耗列表 */
  109. getList() {
  110. this.loading = true;
  111. getProjectRedPacketMoney(this.queryParams).then(response => {
  112. this.projectRedPacketList = response.rows;
  113. this.total = response.total;
  114. this.calculateTotals();
  115. this.loading = false;
  116. });
  117. },
  118. // 取消按钮
  119. cancel() {
  120. this.open = false;
  121. this.reset();
  122. },
  123. // 表单重置
  124. reset() {
  125. this.resetForm("form");
  126. },
  127. /** 搜索按钮操作 */
  128. handleQuery() {
  129. this.queryParams.pageNum = 1;
  130. this.getList();
  131. },
  132. /** 重置按钮操作 */
  133. resetQuery() {
  134. this.resetForm("queryForm");
  135. this.handleQuery();
  136. // 清空所有时间相关变量
  137. this.createTime = null;
  138. this.startTime = null;
  139. this.endTime = null;
  140. this.queryParams.startTime = null; // 重置时间参数
  141. this.queryParams.endTime = null; // 重置时间参数
  142. },
  143. handleExport() {
  144. this.$confirm('是否确认导出项目红包消耗数据?', "警告", {
  145. confirmButtonText: "确定",
  146. cancelButtonText: "取消",
  147. type: "warning"
  148. }).then(() => {
  149. this.exportLoading = true;
  150. // 调用导出API,传入查询参数
  151. exportProjectRedPacketMoney(this.queryParams)
  152. .then(response => {
  153. this.download(response.msg);
  154. this.msgSuccess('导出成功');
  155. })
  156. .catch(error => {
  157. console.error('导出失败:', error);
  158. this.msgError('导出失败');
  159. })
  160. .finally(() => {
  161. this.exportLoading = false;
  162. });
  163. }).catch(() => {
  164. // 用户取消导出,不执行任何操作
  165. });
  166. },
  167. xdChange() {
  168. if (this.createTime != null && this.createTime.length === 2) {
  169. this.queryParams.startTime = this.createTime[0];
  170. this.queryParams.endTime = this.createTime[1];
  171. } else {
  172. this.queryParams.startTime = null;
  173. this.queryParams.endTime = null;
  174. }
  175. }
  176. }
  177. };
  178. </script>
  179. <style scoped>
  180. .total-summary {
  181. margin-top: 15px;
  182. padding: 15px 20px;
  183. background: linear-gradient(135deg, #f5f7fa 0%, #e4e7f4 100%);
  184. border: 1px solid #dcdfe6;
  185. border-radius: 4px;
  186. box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
  187. display: flex;
  188. flex-wrap: wrap;
  189. align-items: center;
  190. }
  191. .total-title {
  192. font-weight: bold;
  193. font-size: 16px;
  194. color: #303133;
  195. margin-right: 20px;
  196. }
  197. .total-item {
  198. margin-right: 20px;
  199. font-size: 14px;
  200. color: #606266;
  201. }
  202. </style>