| | |
| | | </el-button> |
| | | </template> |
| | | <template #menu="{ row, index, size }"> |
| | | <el-button type="primary" text icon="Plus" @click="handleRowAdd(row)">新增子项</el-button> |
| | | <el-button type="primary" text icon="Plus" v-hasPermi="['cwgl:voucherSubjectSetting:addz']" |
| | | @click="handleRowAdd(row)">新增子项</el-button> |
| | | <el-button type="text" icon="View" @click="handleFlow(row)" |
| | | v-hasPermi="['cwgl:voucherSubjectSetting:flow']">日志</el-button> |
| | | </template> |
| | | </avue-crud> |
| | | </basicContainer> |
| | | |
| | | <OperationLogModal ref="logModalRef" /> |
| | | |
| | | </template> |
| | | |
| | | <script setup name="voucherSubjectSetting" lang="ts"> |
| | | import { listVoucherSubjectSettingLog, } from "@/api/cwgl/voucherSubjectSettingLog"; |
| | | |
| | | import { VoucherSubjectSettingI, addVoucherSubjectSetting, delVoucherSubjectSetting, exportVoucherSubjectSetting, getVoucherSubjectSetting, listVoucherSubjectSetting, updateVoucherSubjectSetting } from "@/api/cwgl/voucherSubjectSetting"; |
| | | import useCurrentInstance from "@/utils/useCurrentInstance"; |
| | | import { computed, reactive, ref, toRefs } from "vue"; |
| | | import { PagesInterface, PageQueryInterface } from "@/utils/globalInterface"; |
| | | import { usePagePlus } from "@/hooks/usePagePlus"; |
| | | import { hasPermission } from "@/utils/permissionUtils"; |
| | | import OperationLogModal from '@/components/OperationLogModal/index.vue'; |
| | | |
| | | const { proxy } = useCurrentInstance(); |
| | | const crudRef = ref(); |
| | |
| | | // ], |
| | | // }, |
| | | |
| | | accountSet: { |
| | | type: { |
| | | label: '账套', |
| | | minWidth: 220, |
| | | addDisabled: true, |
| | |
| | | // // } |
| | | // // ], |
| | | // }, |
| | | // 在 option.value.column 中找到 subjectName |
| | | // 找到 option 里的 subjectName 列 |
| | | subjectName: { |
| | | label: '科目名称', |
| | | minWidth: 150, |
| | | |
| | | prop: 'subjectName', // 保持原始 prop,这样弹窗里的输入框才是干净的名称 |
| | | minWidth: 250, // 拼接后会很长,建议调大宽度 |
| | | search: true, |
| | | overHidden: true, |
| | | // --- 使用 formatter 来控制表格界面的显示 --- |
| | | formatter: (row: any) => { |
| | | // 优先显示我们递归生成的拼接字段,如果没有(比如刚新增还没刷新的数据),显示原始名称 |
| | | return row.subjectNameWithParent || row.subjectName; |
| | | }, |
| | | rules: [ |
| | | { |
| | | required: true, |
| | | message: "科目名称不能为空", trigger: "blur" |
| | | } |
| | | { required: true, message: "科目名称不能为空", trigger: "blur" } |
| | | ], |
| | | }, |
| | | subjectCode: { |
| | |
| | | updateApi: updateVoucherSubjectSetting, |
| | | getListFunc: (res: any) => { |
| | | // 1. 转换树结构 |
| | | tableData.value = proxy.handleTree(res.rows, "id"); |
| | | const tree = proxy.handleTree(res.rows, "id"); |
| | | |
| | | // 2. 使用递归函数展开所有层级 |
| | | // 2. 递归拼接名称函数 (核心修改) |
| | | const recursionFormatName = (list: any[], pName = '') => { |
| | | list.forEach(item => { |
| | | // 这里的逻辑:如果有父级名称,拼在一起;否则只显示自己 |
| | | item.subjectNameWithParent = pName ? `${pName} / ${item.subjectName}` : item.subjectName; |
| | | |
| | | // 如果有子节点,继续递归,把当前的拼接结果传给子节点作为 pName |
| | | if (item.children && item.children.length > 0) { |
| | | recursionFormatName(item.children, item.subjectNameWithParent); |
| | | } |
| | | }); |
| | | }; |
| | | |
| | | // 执行递归 |
| | | recursionFormatName(tree); |
| | | |
| | | // 3. 赋值给表格数据 |
| | | tableData.value = tree; |
| | | |
| | | // 4. 递归展开所有层级 (你原有的逻辑) |
| | | nextTick(() => { |
| | | if (crudRef.value) { |
| | | const tableMethods = crudRef.value.$refs.table; |
| | | if (tableMethods && tableData.value) { |
| | | |
| | | // --- 定义递归展开函数 --- |
| | | const expandAllNodes = (list: any[]) => { |
| | | list.forEach(row => { |
| | | // 只要有子节点,就执行展开动作 |
| | | if (row.children && row.children.length > 0) { |
| | | tableMethods.toggleRowExpansion(row, true); |
| | | // 继续递归展开子节点的子节点 |
| | | expandAllNodes(row.children); |
| | | } |
| | | }); |
| | | }; |
| | | |
| | | // 执行递归 |
| | | expandAllNodes(tableData.value); |
| | | } |
| | | } |
| | |
| | | }; |
| | | const handleTabClick = (tab: any) => { |
| | | const selectedTabName = tab.props.name; |
| | | console.log("Tab点击的值:", selectedTabName); |
| | | activeAccountSet.value = selectedTabName; |
| | | queryParams.value.type = selectedTabName; |
| | | const nextParams = { |
| | | ...queryParams.value, |
| | | type: selectedTabName |
| | | }; |
| | | |
| | | // 4. 重置分页并加载 |
| | | // 先清空当前数据,防止旧数据的树结构影响新数据的渲染 |
| | | tableData.value = []; |
| | | |
| | | queryParams.value.type = selectedTabName; |
| | | page.value.currentPage = 1; |
| | | onLoad(page.value, nextParams); |
| | | onLoad(page.value, { type: selectedTabName }); |
| | | } |
| | | |
| | | /** |
| | |
| | | form.value.accountingItems = []; |
| | | }); |
| | | }; |
| | | |
| | | const logModalRef = ref(null); |
| | | const handleFlow = (row: any) => { |
| | | // 这里可以从 row 中直接获取日志,或者调用后端接口查询 |
| | | // 示例模拟数据 |
| | | listVoucherSubjectSettingLog({ subjectId: row.id }).then((res) => { |
| | | if (res.code == 200) { |
| | | logModalRef.value.open(res.rows, 'payable'); |
| | | |
| | | } |
| | | }); |
| | | } |
| | | </script> |