FinancialPlanAccountTreeNode.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <template>
  2. <q-expansion-item
  3. v-if="hasChildren"
  4. v-model="expanded"
  5. dense
  6. expand-separator
  7. header-class="account-tree-row"
  8. :style="{ '--account-depth': depth }"
  9. >
  10. <template #header>
  11. <q-item-section class="account-code">{{ node.code }}</q-item-section>
  12. <q-item-section class="account-name text-weight-medium">
  13. {{ node.description }}
  14. </q-item-section>
  15. <q-item-section class="account-type">{{ node.chart_type }}</q-item-section>
  16. </template>
  17. <FinancialPlanAccountTreeNode
  18. v-for="child in node.children"
  19. :key="child.id"
  20. :node="child"
  21. :depth="depth + 1"
  22. :force-expanded="forceExpanded"
  23. />
  24. </q-expansion-item>
  25. <q-item
  26. v-else
  27. dense
  28. class="account-tree-row account-tree-leaf"
  29. :style="{ '--account-depth': depth }"
  30. >
  31. <q-item-section class="account-code">{{ node.code }}</q-item-section>
  32. <q-item-section class="account-name">{{ node.description }}</q-item-section>
  33. <q-item-section class="account-type">{{ node.chart_type }}</q-item-section>
  34. </q-item>
  35. </template>
  36. <script setup>
  37. import { computed, ref, watch } from "vue";
  38. defineOptions({ name: "FinancialPlanAccountTreeNode" });
  39. const props = defineProps({
  40. node: { type: Object, required: true },
  41. depth: { type: Number, default: 0 },
  42. forceExpanded: { type: Boolean, default: false },
  43. });
  44. const hasChildren = computed(() => props.node.children?.length > 0);
  45. const expanded = ref(props.depth === 0);
  46. watch(
  47. () => props.forceExpanded,
  48. (value) => {
  49. if (value) expanded.value = true;
  50. },
  51. { immediate: true },
  52. );
  53. </script>
  54. <style scoped>
  55. :deep(.account-tree-row) {
  56. min-height: 48px;
  57. padding-left: calc(16px + (var(--account-depth) * 28px));
  58. border-bottom: 1px solid #dedede;
  59. }
  60. :deep(.account-tree-leaf) {
  61. padding-right: 56px;
  62. }
  63. :deep(.account-code) {
  64. flex: 0 0 18%;
  65. min-width: 80px;
  66. }
  67. :deep(.account-name) {
  68. flex: 1 1 auto;
  69. min-width: 0;
  70. }
  71. :deep(.account-type) {
  72. flex: 0 0 18%;
  73. min-width: 90px;
  74. align-items: flex-start;
  75. }
  76. @media (max-width: 599px) {
  77. :deep(.account-tree-row) {
  78. padding-left: calc(8px + (var(--account-depth) * 16px));
  79. }
  80. :deep(.account-code),
  81. :deep(.account-type) {
  82. flex-basis: 25%;
  83. min-width: 64px;
  84. }
  85. }
  86. </style>