settlement.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. <script setup lang="ts">
  2. import { reactive, onMounted, ref, nextTick } from "vue";
  3. import { getSettlementList, triggerSettlement } from "@/api/finance";
  4. import { getStationList } from "@/api/station";
  5. import { useRenderIcon } from "@/components/ReIcon/src/hooks";
  6. import { ElMessage } from "element-plus";
  7. import { getDictOptions, formatDict, getDictColor } from "@/utils/dict";
  8. defineOptions({
  9. name: "AdminFinanceSettlement"
  10. });
  11. const queryRef = ref();
  12. const tableRef = ref();
  13. const state = reactive({
  14. formQuery: {
  15. stationId: "",
  16. settlementPeriod: "",
  17. status: ""
  18. },
  19. pageQuery: {
  20. pageNum: 1,
  21. pageSize: 10,
  22. total: 0
  23. },
  24. tableData: {
  25. height: 500,
  26. data: [] as Array<any>,
  27. loading: false,
  28. columns: [
  29. { label: "站点", prop: "stationId", width: 180 },
  30. { label: "结算周期", prop: "settlementPeriod", width: 120 },
  31. { label: "期初余额(元)", prop: "openingPendingBalance", width: 150 },
  32. { label: "总充值(元)", prop: "totalRecharge", width: 140 },
  33. { label: "总退款(元)", prop: "totalRefund", width: 140 },
  34. { label: "跨店收入(元)", prop: "totalCrossIncome", width: 140 },
  35. { label: "跨店支出(元)", prop: "totalCrossExpend", width: 140 },
  36. { label: "平台费基数(元)", prop: "platformFeeBase", width: 150 },
  37. { label: "平台费(元)", prop: "platformFee", width: 130 },
  38. { label: "提现手续费(元)", prop: "withdrawalFee", width: 150 },
  39. { label: "结算金额(元)", prop: "settlementAmount", width: 150 },
  40. { label: "期末余额(元)", prop: "closingPendingBalance", width: 150 },
  41. { label: "状态", prop: "status", width: 100 },
  42. { label: "备注", prop: "remark", width: 180 },
  43. { label: "创建时间", prop: "createTime", width: 180 }
  44. ]
  45. },
  46. stationOptions: [] as Array<{ stationId: string; stationName: string }>,
  47. get statusOptions() { return getDictOptions("Settlement.status"); }
  48. });
  49. onMounted(() => {
  50. loadStationOptions();
  51. loadData();
  52. nextTick(() => {
  53. const bodyHeight = document.body.clientHeight;
  54. const queryHeight = queryRef.value?.$el?.clientHeight || 0;
  55. state.tableData.height = bodyHeight - queryHeight - 230;
  56. });
  57. });
  58. const loadStationOptions = () => {
  59. getStationList({ pageSize: 1000 }).then((res: any) => {
  60. const { list } = res || {};
  61. state.stationOptions = list || [];
  62. });
  63. };
  64. const loadData = (refresh: boolean = false) => {
  65. if (refresh) {
  66. state.pageQuery.pageNum = 1;
  67. }
  68. state.tableData.loading = true;
  69. getSettlementList({ ...state.formQuery, ...state.pageQuery })
  70. .then((res: any) => {
  71. const { list, total } = res || {};
  72. state.tableData.data = list || [];
  73. state.pageQuery.total = total || 0;
  74. })
  75. .catch(() => {
  76. state.tableData.data = [];
  77. ElMessage.error("加载结算记录失败");
  78. })
  79. .finally(() => {
  80. state.tableData.loading = false;
  81. });
  82. };
  83. const settlementLoading = ref(false);
  84. const handleTriggerSettlement = () => {
  85. settlementLoading.value = true;
  86. triggerSettlement()
  87. .then(() => {
  88. ElMessage.success("结算已完成");
  89. loadData(true);
  90. })
  91. .catch(() => {
  92. ElMessage.error("结算执行失败,请稍后重试");
  93. })
  94. .finally(() => {
  95. settlementLoading.value = false;
  96. });
  97. };
  98. const handleSizeChange = (size: number) => {
  99. state.pageQuery.pageSize = size;
  100. loadData(true);
  101. };
  102. const handleCurrentChange = (page: number) => {
  103. state.pageQuery.pageNum = page;
  104. loadData();
  105. };
  106. const handleSearch = () => {
  107. loadData(true);
  108. };
  109. const handleReset = () => {
  110. state.formQuery = { stationId: "", settlementPeriod: "", status: "" };
  111. loadData(true);
  112. };
  113. const formatMoney = (value: number) => {
  114. if (value === null || value === undefined) return "¥0.00";
  115. return `¥${(value / 100).toFixed(2)}`;
  116. };
  117. </script>
  118. <template>
  119. <div class="page-container">
  120. <el-card shadow="hover">
  121. <template #header>
  122. <span class="card-header">结算记录</span>
  123. </template>
  124. <el-form ref="queryRef" :model="state.formQuery" inline class="search-form">
  125. <el-form-item label="站点">
  126. <el-select v-model="state.formQuery.stationId" placeholder="请选择站点" clearable filterable @change="handleSearch">
  127. <el-option v-for="item in state.stationOptions" :key="item.stationId" :label="item.stationName" :value="item.stationId" />
  128. </el-select>
  129. </el-form-item>
  130. <el-form-item label="结算周期">
  131. <el-input v-model="state.formQuery.settlementPeriod" placeholder="如 2026-05" clearable @change="handleSearch" />
  132. </el-form-item>
  133. <el-form-item label="状态">
  134. <el-select v-model="state.formQuery.status" placeholder="请选择状态" clearable @change="handleSearch">
  135. <el-option v-for="item in getDictOptions('Settlement.status')" :key="item.value" :label="item.label" :value="item.value" />
  136. </el-select>
  137. </el-form-item>
  138. <el-form-item>
  139. <el-button type="primary" :icon="useRenderIcon('ri/search-line')" @click="handleSearch">查询</el-button>
  140. <el-button :icon="useRenderIcon('ri/refresh-line')" @click="handleReset">重置</el-button>
  141. <el-button type="warning" :loading="settlementLoading" :icon="useRenderIcon('ri/money-cny-circle-line')" @click="handleTriggerSettlement">手动触发结算</el-button>
  142. </el-form-item>
  143. </el-form>
  144. <el-table ref="tableRef" v-loading="state.tableData.loading" :data="state.tableData.data" :height="state.tableData.height" border stripe>
  145. <template #empty>
  146. <el-empty description="暂无结算记录" />
  147. </template>
  148. <el-table-column v-for="col in state.tableData.columns" :key="col.prop" :prop="col.prop" :label="col.label" :width="col.width" show-overflow-tooltip>
  149. <template #default="{ row }">
  150. <template v-if="col.prop === 'stationId'">
  151. <div class="station-name-cell">
  152. <span class="station-id">{{ row.stationId }}</span>
  153. <span class="station-divider"></span>
  154. <span class="station-name">{{ row.stationName }}</span>
  155. </div>
  156. </template>
  157. <template v-else-if="col.prop === 'status'">
  158. <el-tag :type="getDictColor('Settlement.status', row.status)" size="small">
  159. {{ formatDict('Settlement.status', row.status) }}
  160. </el-tag>
  161. </template>
  162. <template v-else-if="['openingPendingBalance', 'totalRecharge', 'totalRefund', 'totalCrossIncome', 'totalCrossExpend', 'platformFeeBase', 'platformFee', 'withdrawalFee', 'settlementAmount', 'closingPendingBalance'].includes(col.prop)">
  163. {{ formatMoney(row[col.prop]) }}
  164. </template>
  165. <template v-else>
  166. {{ row[col.prop] }}
  167. </template>
  168. </template>
  169. </el-table-column>
  170. </el-table>
  171. <div class="pagination-container">
  172. <el-pagination
  173. v-model:current-page="state.pageQuery.pageNum"
  174. v-model:page-size="state.pageQuery.pageSize"
  175. :total="state.pageQuery.total"
  176. :page-sizes="[10, 20, 50, 100]"
  177. layout="total, sizes, prev, pager, next, jumper"
  178. @size-change="handleSizeChange"
  179. @current-change="handleCurrentChange"
  180. />
  181. </div>
  182. </el-card>
  183. </div>
  184. </template>
  185. <style scoped lang="scss">
  186. .page-container {
  187. padding: 20px;
  188. }
  189. .card-header {
  190. font-size: 16px;
  191. font-weight: 600;
  192. }
  193. .search-form {
  194. margin-bottom: 16px;
  195. }
  196. .station-name-cell {
  197. display: flex;
  198. flex-direction: column;
  199. align-items: center;
  200. gap: 4px;
  201. .station-name {
  202. font-weight: 500;
  203. }
  204. .station-divider {
  205. display: block;
  206. width: 40px;
  207. height: 1px;
  208. background: var(--el-border-color-light);
  209. }
  210. .station-id {
  211. color: var(--el-text-color-secondary);
  212. font-size: 12px;
  213. }
  214. }
  215. .pagination-container {
  216. display: flex;
  217. justify-content: flex-end;
  218. margin-top: 20px;
  219. }
  220. </style>