daily-stat.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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-date-picker
  37. v-model="state.formQuery.startDate"
  38. type="date"
  39. placeholder="开始日期"
  40. value-format="YYYY-MM-DD"
  41. clearable
  42. class="wd200 ml10"/>
  43. <el-date-picker
  44. v-model="state.formQuery.endDate"
  45. type="date"
  46. placeholder="结束日期"
  47. value-format="YYYY-MM-DD"
  48. clearable
  49. class="wd200 ml10"/>
  50. <el-button class="ml10" plain size="default" type="success" @click="loadData(true)">
  51. <SvgIcon name="ele-Search"/>
  52. 查询
  53. </el-button>
  54. <el-button class="ml10" plain size="default" type="warning" @click="handleSyncDailyStat">
  55. <SvgIcon name="ele-RefreshRight"/>
  56. 重新同步
  57. </el-button>
  58. </el-form>
  59. <el-table
  60. border
  61. stripe="stripe"
  62. :height="state.tableData.height"
  63. :data="state.tableData.data"
  64. v-loading="state.tableData.loading">
  65. <template #empty>
  66. <el-empty></el-empty>
  67. </template>
  68. <el-table-column
  69. v-for="field in state.columns"
  70. :key="field.prop"
  71. :label="field.label"
  72. :column-key="field.prop"
  73. :width="field.width"
  74. :min-width="field.minWidth"
  75. :fixed="field.fixed"
  76. :show-overflow-tooltip="!field.fixed&&field.width>150">
  77. <template #default="{row}">
  78. <template v-if="['totalIncome','totalRefund','crossIncome','crossExpend','consumption'].includes(field.prop)">
  79. {{ u.fmt.fmtMoney(row[field.prop]) }}
  80. </template>
  81. <template v-else-if="['createTime','updateTime'].includes(field.prop)">
  82. {{ u.fmt.fmtDateTime(row[field.prop]) }}
  83. </template>
  84. <template v-else>
  85. <div>{{ row[field.prop] }}</div>
  86. </template>
  87. </template>
  88. </el-table-column>
  89. </el-table>
  90. <ext-page class="page-pager" v-model:value="state.pageQuery" @change="loadData(false)"/>
  91. </el-card>
  92. </div>
  93. </template>
  94. <script setup lang="ts" name="adminStatisticsDailyStat">
  95. import {reactive, onMounted, ref, nextTick} from 'vue';
  96. import {$body} from "/@/utils/request";
  97. import u from '/@/utils/u'
  98. import {Msg} from "/@/utils/message";
  99. import ExtPage from '/@/components/form/ExtPage.vue'
  100. import ExtSelect from "/@/components/form/ExtSelect.vue";
  101. const queryRef = ref();
  102. const state = reactive({
  103. formQuery: {
  104. stationId: '',
  105. startDate: '',
  106. endDate: ''
  107. },
  108. pageQuery: {
  109. pageNum: 1,
  110. pageSize: 10,
  111. total: 0
  112. },
  113. tableData: {
  114. height: 500,
  115. data: [] as Array<any>,
  116. loading: false
  117. },
  118. columns: [
  119. {label: '统计日期', width: 120, prop: 'statDate', fixed: 'left', resizable: true},
  120. {label: '站点名称', width: 180, prop: 'stationName', resizable: true},
  121. {label: '总收入(元)', width: 140, prop: 'totalIncome', resizable: true},
  122. {label: '退款金额(元)', width: 140, prop: 'totalRefund', resizable: true},
  123. {label: '跨店收入(元)', width: 140, prop: 'crossIncome', resizable: true},
  124. {label: '跨店支出(元)', width: 140, prop: 'crossExpend', resizable: true},
  125. {label: '消费金额(元)', width: 140, prop: 'consumption', resizable: true},
  126. {label: '充值笔数', width: 100, prop: 'rechargeCount', resizable: true},
  127. {label: '退款笔数', width: 100, prop: 'refundCount', resizable: true},
  128. {label: '注册人数', width: 100, prop: 'registrations', resizable: true},
  129. {label: '活跃用户数', width: 110, prop: 'activeUserCount', resizable: true},
  130. {label: '订单数量', width: 100, prop: 'ordersCount', resizable: true},
  131. {label: '创建时间', width: 180, prop: 'createTime', resizable: true},
  132. ],
  133. })
  134. onMounted(() => {
  135. // 默认查询昨天数据
  136. const yesterday = new Date();
  137. yesterday.setDate(yesterday.getDate() - 1);
  138. state.formQuery.startDate = yesterday.toISOString().split('T')[0];
  139. state.formQuery.endDate = yesterday.toISOString().split('T')[0];
  140. loadData();
  141. nextTick(() => {
  142. let bodyHeight = document.body.clientHeight;
  143. let queryHeight = queryRef.value.$el.clientHeight;
  144. state.tableData.height = bodyHeight - queryHeight - 320
  145. })
  146. });
  147. const loadData = (refresh: boolean = false) => {
  148. if (refresh) {
  149. state.pageQuery.pageNum = 1;
  150. }
  151. state.tableData.loading = true;
  152. $body(`/daily-stat/list`, {...state.formQuery, ...state.pageQuery}).then((res: any) => {
  153. let {list, total} = res;
  154. state.tableData.data = list || [];
  155. state.pageQuery.total = total || 0;
  156. state.tableData.loading = false;
  157. }).catch(e => {
  158. console.error(e)
  159. state.tableData.loading = false;
  160. })
  161. };
  162. const handleSyncDailyStat = () => {
  163. Msg.confirm('确认重新同步该日期的统计数据吗?将同步所有站点的数据。', '重新同步日统计').then(() => {
  164. Msg.showLoading('同步中...');
  165. $body(`/daily-stat/sync`, {statDate: state.formQuery.startDate}).then(() => {
  166. Msg.message("同步完成");
  167. Msg.hideLoading();
  168. loadData(true);
  169. }).catch(e => {
  170. Msg.hideLoading();
  171. })
  172. })
  173. };
  174. </script>