wujianwei
1 天以前 d14994e10797ce5bc0d29668d358f7c5274dcc5b
ui/admin-ui3/src/views/cwgl/voucherSubjectFee/index.vue
@@ -20,8 +20,8 @@
          v-hasPermi="['cwgl:voucherSubjectFee:export']">导出
        </el-button>
      </template>
          <template #menu="{ row, index, size }">
      <template #menu="{ row, index, size }">
        <el-button type="text" icon="View" @click="handleFlow(row)"
          v-hasPermi="['cwgl:voucherSubjectFee:flow']">日志</el-button>
      </template>
@@ -33,7 +33,7 @@
<script setup name="voucherSubjectFee" lang="ts">
import { listVoucherSubjectSetting } from "@/api/cwgl/voucherSubjectSetting";
  import { listVoucherSubjectFeeLog, } from "@/api/cwgl/voucherSubjectFeeLog";
import { listVoucherSubjectFeeLog, } from "@/api/cwgl/voucherSubjectFeeLog";
import { VoucherSubjectFeeI, addVoucherSubjectFee, delVoucherSubjectFee, exportVoucherSubjectFee, getVoucherSubjectFee, listVoucherSubjectFee, updateVoucherSubjectFee } from "@/api/cwgl/voucherSubjectFee";
import useCurrentInstance from "@/utils/useCurrentInstance";
@@ -69,12 +69,12 @@
const option = ref({
  pageKey: 'VoucherSubjectFee',
  rowKey: 'id',
    viewBtn: false,
  viewBtn: false,
  column: {
    // id: {
    //   label: 'ID',
    // },
    accountSet: {
    type: {
      label: '账套',
      minWidth: 120,
      addDisabled: true,
@@ -89,28 +89,29 @@
    },
    subjectName: {
      label: '科目名称',
      type: 'select', // 如果需要树形可以改为 'tree'
      type: 'tree',
      search: true,
      props: {
        label: 'subjectName',
        value: 'subjectName' // 建议绑定 ID 作为 value
        label: 'subjectName', // 下拉树里依然只显示单名(如:差旅费)
        value: 'subjectName'
      },
      // 关键:监听选中值的变化
    change: ({ value, column, item }) => {
  // 关键:只有明确有选中的对象 item 时才执行赋值
  if (item && Object.keys(item).length > 0) {
    form.value.subjectCode = item.subjectCode;
    form.value.subjectType = item.subjectType;
    form.value.feeName = item.expenseName;
  }
  // 只有当用户手动清除选择(value 为空)时,才清空其他字段
  else if (!value) {
    form.value.subjectCode = '';
    form.value.subjectType = '';
    form.value.feeName = '';
  }
  // 如果是有 value 但没 item(通常是回显瞬间),什么都不做,保护已有数据
},
      change: ({ value, column, item }) => {
        if (item && Object.keys(item).length > 0) {
          form.value.subjectCode = item.subjectCode;
          form.value.subjectType = item.subjectType;
          form.value.feeName = item.expenseName;
          // 【修改点】在选中时,获取隐藏的 fullName(带 / 的全路径)
          // 如果没有 fullName(顶级),则使用原始名称
          form.value.fullPathName = item.fullName || item.subjectName;
        }
        else if (!value) {
          form.value.subjectCode = '';
          form.value.subjectType = '';
          form.value.feeName = '';
          form.value.fullPathName = '';
        }
      },
      rules: [{ required: true, message: "科目名称不能为空", trigger: "change" }],
    },
@@ -236,26 +237,60 @@
      selectionList.value = selection;
    },
    // --- 关键修改:处理弹窗打开前的逻辑 ---
    // --- 核心逻辑 1:保存前拦截 ---
    // 在 usePagePlus 的配置对象中
    rowSaveBegin: (row, done) => {
      // 提交时,将 subjectName 替换为我们在 change 时拿到的全路径
      if (row.fullPathName) {
        row.subjectName = row.fullPathName;
      }
      delete row.fullPathName; // 清理临时变量
      done(row);
    },
    rowUpdateBegin: (row, done) => {
      if (row.fullPathName) {
        row.subjectName = row.fullPathName;
      }
      delete row.fullPathName;
      done(row);
    },
    // --- 核心逻辑 3:打开弹窗前加载并处理字典 ---
    handleBeforeOpenFunc: (type: string) => {
      if (type === 'add') {
        form.value.accountSet = activeAccountSet.value;
        form.value.type = activeAccountSet.value;
      }
      listVoucherSubjectSetting({ type: activeAccountSet.value }).then(res => {
        const subjectNameCol = option.value.column.subjectName;
        if (subjectNameCol) {
          // 假设接口返回的数据在 res.data 或 res.rows 中
          const listData = res.rows  || [];
          const listData = res.rows || [];
          // 如果你需要树形展示,可以使用 handleTree 转换
          subjectNameCol.type = 'tree';
          subjectNameCol.dicData = proxy.handleTree(listData, "id");
          // 递归函数:计算全路径,使用 / 分隔
          const injectFullPath = (list: any[], parentPath = '') => {
            return list.map(item => {
              // 【核心修改点】将拼接符改为 /
              const currentPath = parentPath ? `${parentPath}/${item.subjectName}` : item.subjectName;
              const newItem = {
                ...item,
                fullName: currentPath // 此时 fullName 格式为 "管理费用/差旅费"
              };
              if (newItem.children && newItem.children.length > 0) {
                newItem.children = injectFullPath(newItem.children, currentPath);
              }
              return newItem;
            });
          };
          const treeData = proxy.handleTree(listData, "id");
          subjectNameCol.dicData = injectFullPath(treeData);
        }
      });
    },
    // ... 其他钩子如 handleUpdateFunc, getBeginListFunc 保持不变 ...
  })
const activeAccountSet = ref('0');
@@ -280,7 +315,7 @@
  // 示例模拟数据
  listVoucherSubjectFeeLog({ subjectId: row.id }).then((res) => {
    if (res.code == 200) {
      logModalRef.value.open(res.rows,'payable');
      logModalRef.value.open(res.rows, 'payable');
    }
  });