settlement.vue 9.2 KB

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