account.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. <script setup lang="ts">
  2. import { reactive, onMounted, ref, nextTick } from "vue";
  3. import { getStationAccount, applyWithdrawn, getStationList } from "@/api/station";
  4. import { useRenderIcon } from "@/components/ReIcon/src/hooks";
  5. import { useStationScope } from "@/hooks/useStationScope";
  6. import { ElMessage, ElMessageBox } from "element-plus";
  7. defineOptions({
  8. name: "AdminStationAccount"
  9. });
  10. const queryRef = ref();
  11. const tableRef = ref();
  12. const state = reactive({
  13. formQuery: {
  14. stationId: ""
  15. },
  16. pageQuery: {
  17. pageNum: 1,
  18. pageSize: 10,
  19. total: 0
  20. },
  21. tableData: {
  22. height: 500,
  23. data: [] as Array<any>,
  24. loading: false,
  25. columns: [
  26. { label: "站点名称", prop: "stationName", width: 200 },
  27. { label: "可提现金额(元)", prop: "availableBalance", width: 180 },
  28. { label: "已提现金额(元)", prop: "withdrawnAmount", width: 180 },
  29. { label: "提现中金额(元)", prop: "withdrawnFrozenAmount", width: 180 },
  30. { label: "创建时间", prop: "createTime", width: 180 },
  31. { label: "更新时间", prop: "updateTime", width: 180 }
  32. ]
  33. },
  34. stationOptions: [] as Array<{ stationId: string; stationName: string }>
  35. });
  36. //站点筛选与全局当前站点联动(回调懒引用,规避 loadData 声明顺序的 TDZ 错误)
  37. useStationScope(state.formQuery, (refresh?: boolean) => loadData(refresh));
  38. onMounted(() => {
  39. loadStationOptions();
  40. loadData();
  41. nextTick(() => {
  42. const bodyHeight = document.body.clientHeight;
  43. const queryHeight = queryRef.value?.$el?.clientHeight || 0;
  44. state.tableData.height = bodyHeight - queryHeight - 230;
  45. });
  46. });
  47. const loadStationOptions = () => {
  48. getStationList({ pageSize: 1000 }).then((res: any) => {
  49. const { list } = res || {};
  50. state.stationOptions = list || [];
  51. });
  52. };
  53. const loadData = (refresh: boolean = false) => {
  54. if (refresh) {
  55. state.pageQuery.pageNum = 1;
  56. }
  57. state.tableData.loading = true;
  58. getStationAccount({ ...state.formQuery, ...state.pageQuery })
  59. .then((res: any) => {
  60. const { list, count } = res || {};
  61. state.tableData.data = list || [];
  62. state.pageQuery.total = count || 0;
  63. })
  64. .catch(() => {
  65. state.tableData.data = [];
  66. ElMessage.error("加载账户列表失败");
  67. })
  68. .finally(() => {
  69. state.tableData.loading = false;
  70. });
  71. };
  72. const withdrawLoading = ref(false);
  73. const handleWithdrawApply = (row: any) => {
  74. ElMessageBox.prompt(
  75. `站点「${row.stationName}」可提现 ${formatMoney(row.availableBalance)} 元`,
  76. "提现申请",
  77. {
  78. confirmButtonText: "确认提现",
  79. cancelButtonText: "取消",
  80. inputPattern: /^[0-9]+(\.[0-9]{1,2})?$/,
  81. inputErrorMessage: "请输入有效的金额",
  82. inputPlaceholder: "请输入提现金额(元)"
  83. }
  84. ).then(({ value }) => {
  85. const amount = Number(value) * 100;
  86. withdrawLoading.value = true;
  87. applyWithdrawn({ stationId: row.stationId, amount })
  88. .then(() => {
  89. ElMessage.success("提现已发起");
  90. loadData(true);
  91. })
  92. .catch(() => {
  93. ElMessage.error("提现申请失败,请稍后重试");
  94. })
  95. .finally(() => {
  96. withdrawLoading.value = false;
  97. });
  98. });
  99. };
  100. const handleSizeChange = (size: number) => {
  101. state.pageQuery.pageSize = size;
  102. loadData(true);
  103. };
  104. const handleCurrentChange = (page: number) => {
  105. state.pageQuery.pageNum = page;
  106. loadData();
  107. };
  108. const handleSearch = () => {
  109. loadData(true);
  110. };
  111. const handleReset = () => {
  112. state.formQuery = {
  113. stationId: ""
  114. };
  115. loadData(true);
  116. };
  117. const formatMoney = (value: number) => {
  118. if (value === null || value === undefined) return "¥0.00";
  119. return `¥${(value / 100).toFixed(2)}`;
  120. };
  121. </script>
  122. <template>
  123. <div class="page-container">
  124. <el-card shadow="hover">
  125. <template #header>
  126. <span class="card-header">站点账户</span>
  127. </template>
  128. <el-form
  129. ref="queryRef"
  130. :model="state.formQuery"
  131. inline
  132. class="search-form"
  133. >
  134. <el-form-item label="站点">
  135. <el-select
  136. v-model="state.formQuery.stationId"
  137. placeholder="请选择站点"
  138. clearable
  139. filterable
  140. @change="handleSearch"
  141. >
  142. <el-option
  143. v-for="item in state.stationOptions"
  144. :key="item.stationId"
  145. :label="item.stationName"
  146. :value="item.stationId"
  147. />
  148. </el-select>
  149. </el-form-item>
  150. <el-form-item>
  151. <el-button
  152. type="primary"
  153. :icon="useRenderIcon('ri/search-line')"
  154. @click="handleSearch"
  155. >
  156. 查询
  157. </el-button>
  158. <el-button
  159. :icon="useRenderIcon('ri/refresh-line')"
  160. @click="handleReset"
  161. >
  162. 重置
  163. </el-button>
  164. </el-form-item>
  165. </el-form>
  166. <el-table
  167. ref="tableRef"
  168. v-loading="state.tableData.loading"
  169. :data="state.tableData.data"
  170. :height="state.tableData.height"
  171. border
  172. stripe
  173. >
  174. <template #empty>
  175. <el-empty description="暂无账户数据,请选择站点后查询" />
  176. </template>
  177. <el-table-column
  178. v-for="col in state.tableData.columns"
  179. :key="col.prop"
  180. :prop="col.prop"
  181. :label="col.label"
  182. :width="col.width"
  183. show-overflow-tooltip
  184. >
  185. <template #default="{ row }">
  186. <template
  187. v-if="['availableBalance', 'withdrawnAmount', 'withdrawnFrozenAmount'].includes(col.prop)"
  188. >
  189. {{ formatMoney(row[col.prop]) }}
  190. </template>
  191. <template v-else>
  192. {{ row[col.prop] }}
  193. </template>
  194. </template>
  195. </el-table-column>
  196. <el-table-column label="操作" width="120" fixed="right">
  197. <template #default="{ row }">
  198. <el-button type="primary" link size="small" @click="handleWithdrawApply(row)">
  199. 提现申请
  200. </el-button>
  201. </template>
  202. </el-table-column>
  203. </el-table>
  204. <div class="pagination-container">
  205. <el-pagination
  206. v-model:current-page="state.pageQuery.pageNum"
  207. v-model:page-size="state.pageQuery.pageSize"
  208. :total="state.pageQuery.total"
  209. :page-sizes="[10, 20, 50, 100]"
  210. layout="total, sizes, prev, pager, next, jumper"
  211. @size-change="handleSizeChange"
  212. @current-change="handleCurrentChange"
  213. />
  214. </div>
  215. </el-card>
  216. </div>
  217. </template>
  218. <style scoped lang="scss">
  219. .page-container {
  220. padding: 20px;
  221. }
  222. .search-form {
  223. margin-bottom: 16px;
  224. }
  225. .card-header {
  226. font-size: 16px;
  227. font-weight: 600;
  228. }
  229. .pagination-container {
  230. display: flex;
  231. justify-content: flex-end;
  232. margin-top: 20px;
  233. }
  234. </style>