month-stat.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <style scoped lang="scss">
  2. .system-container {
  3. :deep(.el-card__body) {
  4. display: flex;
  5. flex-direction: column;
  6. justify-content: space-between;
  7. flex: 1;
  8. overflow: auto;
  9. .el-table {
  10. flex: 1;
  11. }
  12. }
  13. }
  14. .page-pager {
  15. background-color: var(--el-color-white);
  16. height: 24px;
  17. }
  18. </style>
  19. <template>
  20. <div class="system-container layout-padding">
  21. <el-card shadow="hover" class="layout-padding-auto">
  22. <el-form
  23. :model="state.formQuery"
  24. ref="queryRef"
  25. size="default" label-width="0px" class="mt5 mb5">
  26. <ext-select
  27. v-model="state.formQuery.stationId"
  28. placeholder="站点"
  29. url="washStation/list"
  30. url-method="post"
  31. label-key="stationName"
  32. value-key="stationId"
  33. data-key="list"
  34. clearable
  35. class="wd200 ml10"/>
  36. <el-input
  37. v-model="state.formQuery.statMonth"
  38. placeholder="统计月份 如 2026-05"
  39. clearable
  40. class="wd200 ml10"/>
  41. <el-button class="ml10" plain size="default" type="success" @click="loadData(true)">
  42. <SvgIcon name="ele-Search"/>
  43. 查询
  44. </el-button>
  45. <el-input
  46. v-model="state.syncMonth"
  47. placeholder="同步月份 如 2026-05"
  48. clearable
  49. class="wd180 ml10"/>
  50. <el-button class="ml10" plain size="default" type="warning" @click="handleSyncMonthStat">
  51. <SvgIcon name="ele-RefreshRight"/>
  52. 重新同步
  53. </el-button>
  54. </el-form>
  55. <el-table
  56. border
  57. stripe="stripe"
  58. :height="state.tableData.height"
  59. :data="state.tableData.data"
  60. v-loading="state.tableData.loading">
  61. <template #empty>
  62. <el-empty></el-empty>
  63. </template>
  64. <el-table-column
  65. v-for="field in state.columns"
  66. :key="field.prop"
  67. :label="field.label"
  68. :column-key="field.prop"
  69. :width="field.width"
  70. :min-width="field.minWidth"
  71. :fixed="field.fixed"
  72. :show-overflow-tooltip="!field.fixed&&field.width>150">
  73. <template #default="{row}">
  74. <template v-if="['totalIncome','totalRefund','crossIncome','crossExpend','consumption','platformFee'].includes(field.prop)">
  75. {{ u.fmt.fmtMoney(row[field.prop]) }}
  76. </template>
  77. <template v-else-if="['createTime','updateTime'].includes(field.prop)">
  78. {{ u.fmt.fmtDateTime(row[field.prop]) }}
  79. </template>
  80. <template v-else>
  81. <div>{{ row[field.prop] }}</div>
  82. </template>
  83. </template>
  84. </el-table-column>
  85. </el-table>
  86. <ext-page class="page-pager" v-model:value="state.pageQuery" @change="loadData(false)"/>
  87. </el-card>
  88. </div>
  89. </template>
  90. <script setup lang="ts" name="adminStatisticsMonthStat">
  91. import {reactive, onMounted, ref, nextTick} from 'vue';
  92. import {$body} from "/@/utils/request";
  93. import u from '/@/utils/u'
  94. import {Msg} from "/@/utils/message";
  95. import ExtPage from '/@/components/form/ExtPage.vue'
  96. import ExtSelect from "/@/components/form/ExtSelect.vue";
  97. const queryRef = ref();
  98. const state = reactive({
  99. syncMonth: '',
  100. formQuery: {
  101. stationId: '',
  102. statMonth: ''
  103. },
  104. pageQuery: {
  105. pageNum: 1,
  106. pageSize: 10,
  107. total: 0
  108. },
  109. tableData: {
  110. height: 500,
  111. data: [] as Array<any>,
  112. loading: false
  113. },
  114. columns: [
  115. {label: '统计月份', width: 120, prop: 'statMonth', fixed: 'left', resizable: true},
  116. {label: '站点名称', width: 180, prop: 'stationName', resizable: true},
  117. {label: '总收入(元)', width: 140, prop: 'totalIncome', resizable: true},
  118. {label: '退款金额(元)', width: 140, prop: 'totalRefund', resizable: true},
  119. {label: '跨店收入(元)', width: 140, prop: 'crossIncome', resizable: true},
  120. {label: '跨店支出(元)', width: 140, prop: 'crossExpend', resizable: true},
  121. {label: '消费金额(元)', width: 140, prop: 'consumption', resizable: true},
  122. {label: '平台服务费(元)', width: 150, prop: 'platformFee', resizable: true},
  123. {label: '充值笔数', width: 100, prop: 'rechargeCount', resizable: true},
  124. {label: '退款笔数', width: 100, prop: 'refundCount', resizable: true},
  125. {label: '注册人数', width: 100, prop: 'registrations', resizable: true},
  126. {label: '活跃用户数', width: 110, prop: 'activeUserCount', resizable: true},
  127. {label: '订单数量', width: 100, prop: 'ordersCount', resizable: true},
  128. {label: '创建时间', width: 180, prop: 'createTime', resizable: true},
  129. ],
  130. })
  131. onMounted(() => {
  132. // 默认查询上月数据
  133. const now = new Date();
  134. const lastMonth = new Date(now.getFullYear(), now.getMonth() - 1, 1);
  135. const lastMonthStr = lastMonth.getFullYear() + '-' + String(lastMonth.getMonth() + 1).padStart(2, '0');
  136. state.formQuery.statMonth = lastMonthStr;
  137. state.syncMonth = lastMonthStr;
  138. loadData();
  139. nextTick(() => {
  140. let bodyHeight = document.body.clientHeight;
  141. let queryHeight = queryRef.value.$el.clientHeight;
  142. state.tableData.height = bodyHeight - queryHeight - 320
  143. })
  144. });
  145. const loadData = (refresh: boolean = false) => {
  146. if (refresh) {
  147. state.pageQuery.pageNum = 1;
  148. }
  149. state.tableData.loading = true;
  150. $body(`/month-stat/list`, {...state.formQuery, ...state.pageQuery}).then((res: any) => {
  151. let {list, total} = res;
  152. state.tableData.data = list || [];
  153. state.pageQuery.total = total || 0;
  154. state.tableData.loading = false;
  155. }).catch(e => {
  156. console.error(e)
  157. state.tableData.loading = false;
  158. })
  159. };
  160. const handleSyncMonthStat = () => {
  161. if (!state.syncMonth) {
  162. Msg.message('请输入同步月份', 'warning');
  163. return;
  164. }
  165. Msg.confirm(`确认重新同步 ${state.syncMonth} 的统计数据吗?将同步所有站点的数据。`, '重新同步月统计').then(() => {
  166. Msg.showLoading('同步中...');
  167. $body(`/month-stat/sync`, {statMonth: state.syncMonth}).then(() => {
  168. Msg.message("同步完成");
  169. Msg.hideLoading();
  170. loadData(true);
  171. }).catch(e => {
  172. Msg.hideLoading();
  173. })
  174. })
  175. };
  176. </script>