index.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <script setup lang="ts">
  2. /**
  3. * 分账页(views/academic/divide/index.vue)—— 分账树(菜单「分账」,端点 38,树形非分页)。
  4. * el-table tree-props 渲染上级→下线层级(最多 3 层);quota 为金额(每次分成金额)。
  5. */
  6. import { getDivideTree, type DivideNodeDTO } from '@/api/academic/divide-into';
  7. import { useScope } from '@/store/scope';
  8. import { formatMoney } from '@/utils/format';
  9. const scope = useScope();
  10. const tree = ref<DivideNodeDTO[]>([]);
  11. const loading = ref(false);
  12. const error = ref('');
  13. async function load(): Promise<void> {
  14. loading.value = true;
  15. error.value = '';
  16. try {
  17. const r = await getDivideTree(scope.toQuery());
  18. if (r.code === 200 && r.data) tree.value = r.data.tree;
  19. else error.value = r.message || '加载失败';
  20. } catch {
  21. error.value = '网络连接异常';
  22. } finally {
  23. loading.value = false;
  24. }
  25. }
  26. onMounted(() => {
  27. void load();
  28. });
  29. </script>
  30. <template>
  31. <div class="divide-page">
  32. <div class="divide-page__bar">
  33. <el-button @click="load" :loading="loading">刷新</el-button>
  34. <span class="divide-page__hint">分账树:上级 → 下线(最多 3 层);额度 0.00 = 该链不分成</span>
  35. </div>
  36. <el-alert v-if="error" :title="error" type="error" show-icon class="divide-page__error" />
  37. <el-table v-else :data="tree" :loading="loading" row-key="userId" :default-expand-all="true" :tree-props="{ children: 'children' }" border>
  38. <el-table-column prop="realName" label="成员" min-width="160" />
  39. <el-table-column label="分成额度(元)" min-width="130">
  40. <template #default="{ row }">¥ {{ formatMoney(parseFloat(row.quota)) }}</template>
  41. </el-table-column>
  42. <el-table-column label="累计收入(元)" min-width="130">
  43. <template #default="{ row }">¥ {{ formatMoney(parseFloat(row.cumulativeIncome)) }}</template>
  44. </el-table-column>
  45. </el-table>
  46. </div>
  47. </template>
  48. <style scoped>
  49. .divide-page {
  50. width: 100%;
  51. }
  52. .divide-page__bar {
  53. display: flex;
  54. align-items: center;
  55. gap: 12px;
  56. margin-bottom: 12px;
  57. }
  58. .divide-page__hint {
  59. font-size: var(--app-font-md);
  60. color: var(--app-text-secondary, #8a8f9c);
  61. }
  62. </style>