huminmin
4 小时以前 cdf8190c92a536dabdbd3dfd6758cf67320ff6df
src/views/financialManagement/revenueManagement/index.vue
@@ -34,8 +34,8 @@
          <el-button
            type="danger"
            icon="Delete"
            :disabled="multipleList.length <= 0"
            @click="deleteRow(multipleList.map((item) => item.id))"
            :disabled="multipleList.length <= 0 || hasBusinessIdInSelection"
            @click="handleBatchDelete"
          >
            批量删除
          </el-button>
@@ -55,12 +55,17 @@
        @pagination="changePage"
      >
        <template #operation="{ row }">
          <el-button type="primary" text @click="edit(row.id)" icon="editPen">
          <el-button
            type="primary"
            link
            :disabled="!!row.businessId"
            @click="edit(row.id)"
          >
            编辑
          </el-button>
          <el-button
            type="primary"
            text
                  link
            @click="openFilesFormDia(row)"
          >
            附件
@@ -69,18 +74,27 @@
      </PIMTable>
    </div>
    <Modal ref="modalRef" @success="getTableData"></Modal>
    <files-dia ref="filesDia"></files-dia>
    <FileListDialog
      ref="fileListRef"
      v-model="fileListDialogVisible"
      :show-upload-button="true"
      :show-delete-button="true"
      :upload-method="handleUpload"
      :delete-method="handleFileDelete"
    />
  </div>
</template>
<script setup>
import { usePaginationApi } from "@/hooks/usePaginationApi";
import { listPage, delAccountIncome } from "@/api/financialManagement/revenueManagement";
import { onMounted, getCurrentInstance } from "vue";
import { listPage, delAccountIncome, fileListPage, fileAdd, fileDel } from "@/api/financialManagement/revenueManagement";
import { onMounted, getCurrentInstance, ref, computed } from "vue";
import Modal from "./Modal.vue";
import { ElMessageBox, ElMessage } from "element-plus";
import dayjs from "dayjs";
import FilesDia from "./filesDia.vue";
import FileListDialog from "@/components/Dialog/FileListDialog.vue";
import request from "@/utils/request";
import { getToken } from "@/utils/auth";
defineOptions({
  name: "收入管理",
@@ -92,7 +106,10 @@
const modalRef = ref();
const { payment_methods } = proxy.useDict("payment_methods");
const { income_types } = proxy.useDict("income_types");
const filesDia = ref()
const fileListRef = ref(null);
const fileListDialogVisible = ref(false);
const currentFileRow = ref(null);
const accountType = ref('收入');
const {
  filters,
@@ -111,12 +128,10 @@
  [
    {
      label: "收入日期",
      align: "center",
      prop: "incomeDate",
    },
    {
      label: "收入类型",
      align: "center",
      prop: "incomeType",
      dataType: "tag",
      formatData: (params) => {
@@ -129,26 +144,25 @@
    },
    {
      label: "客户名称",
      align: "center",
      prop: "customerName",
         width: '200'
    },
    {
      label: "收入金额",
      align: "center",
      prop: "incomeMoney",
    },
    {
      label: "收入描述",
      align: "center",
      prop: "incomeDescribed",
    },
    {
      label: "收款方式",
      align: "center",
      prop: "incomeMethod",
         align: 'center',
         width: '100',
      dataType: "tag",
      formatData: (params) => {
        if (payment_methods.value.find((m) => m.value == params)) {
@@ -160,24 +174,20 @@
    },
    {
      label: "发票号码",
      align: "center",
      prop: "invoiceNumber",
    },
    {
      label: "备注",
      align: "center",
      prop: "note",
    },
    {
      label: "录入人",
      align: "center",
      prop: "inputUser",
    },
    {
      label: "录入日期",
      align: "center",
      prop: "inputTime",
    },
@@ -187,7 +197,7 @@
      dataType: "slot",
      slot: "operation",
      align: "center",
      width: "200px",
      width: "160px",
    },
  ]
);
@@ -197,10 +207,21 @@
  multipleList.value = selectionList;
};
// 判断选中的项中是否有 businessId
const hasBusinessIdInSelection = computed(() => {
  return multipleList.value.some(item => item.businessId);
});
const add = () => {
  modalRef.value.openModal();
};
const edit = (id) => {
  // 检查当前行是否有 businessId
  const row = dataList.value.find(item => item.id === id);
  if (row && row.businessId) {
    proxy.$modal.msgWarning("该记录已关联业务,不能编辑");
    return;
  }
  modalRef.value.loadForm(id);
};
const changePage = ({ page, limit }) => {
@@ -209,6 +230,25 @@
  onCurrentChange(page);
};
const deleteRow = (id) => {
  // 如果是数组,检查是否有 businessId
  if (Array.isArray(id)) {
    const hasBusinessId = id.some(itemId => {
      const row = dataList.value.find(item => item.id === itemId);
      return row && row.businessId;
    });
    if (hasBusinessId) {
      proxy.$modal.msgWarning("选中的记录中包含已关联业务的记录,不能删除");
      return;
    }
  } else {
    // 单个删除,检查是否有 businessId
    const row = dataList.value.find(item => item.id === id);
    if (row && row.businessId) {
      proxy.$modal.msgWarning("该记录已关联业务,不能删除");
      return;
    }
  }
  ElMessageBox.confirm("此操作将永久删除该数据, 是否继续?", "提示", {
    confirmButtonText: "确定",
    cancelButtonText: "取消",
@@ -223,6 +263,23 @@
      getTableData();
    }
  });
};
// 批量删除
const handleBatchDelete = () => {
  if (multipleList.value.length === 0) {
    proxy.$modal.msgWarning("请选择要删除的数据");
    return;
  }
  // 检查是否有 businessId
  if (hasBusinessIdInSelection.value) {
    proxy.$modal.msgWarning("选中的记录中包含已关联业务的记录,不能删除");
    return;
  }
  const ids = multipleList.value.map((item) => item.id);
  deleteRow(ids);
};
const changeDaterange = (value) => {
@@ -252,10 +309,154 @@
    });
};
// 打开附件弹框
const openFilesFormDia = (row) => {
  nextTick(() => {
    filesDia.value?.openDialog( row,'收入')
  })
const openFilesFormDia = async (row) => {
  currentFileRow.value = row;
  accountType.value = '收入';
  try {
    const res = await fileListPage({
      accountId: row.id,
      accountType: accountType.value,
      current: 1,
      size: 100
    });
    if (res.code === 200 && fileListRef.value) {
      // 将数据转换为 FileListDialog 需要的格式
      const fileList = (res.data?.records || []).map(item => ({
        name: item.name,
        url: item.url,
        id: item.id,
        ...item
      }));
      fileListRef.value.open(fileList);
      fileListDialogVisible.value = true;
    }
  } catch (error) {
    proxy.$modal.msgError("获取附件列表失败");
  }
};
// 上传附件
const handleUpload = async () => {
  if (!currentFileRow.value) {
    proxy.$modal.msgWarning("请先选择数据");
    return null;
  }
  return new Promise((resolve) => {
    // 创建一个隐藏的文件输入元素
    const input = document.createElement('input');
    input.type = 'file';
    input.style.display = 'none';
    input.onchange = async (e) => {
      const file = e.target.files[0];
      if (!file) {
        resolve(null);
        return;
      }
      try {
        // 使用 FormData 上传文件
        const formData = new FormData();
        formData.append('file', file);
        const uploadRes = await request({
          url: '/file/upload',
          method: 'post',
          data: formData,
          headers: {
            'Content-Type': 'multipart/form-data',
            Authorization: `Bearer ${getToken()}`
          }
        });
        if (uploadRes.code === 200) {
          // 保存附件信息
          const fileData = {
            accountId: currentFileRow.value.id,
            accountType: accountType.value,
            name: uploadRes.data.originalName || file.name,
            url: uploadRes.data.tempPath || uploadRes.data.url
          };
          const saveRes = await fileAdd(fileData);
          if (saveRes.code === 200) {
            proxy.$modal.msgSuccess("文件上传成功");
            // 重新加载文件列表
            const listRes = await fileListPage({
              accountId: currentFileRow.value.id,
              accountType: accountType.value,
              current: 1,
              size: 100
            });
            if (listRes.code === 200 && fileListRef.value) {
              const fileList = (listRes.data?.records || []).map(item => ({
                name: item.name,
                url: item.url,
                id: item.id,
                ...item
              }));
              fileListRef.value.setList(fileList);
            }
            // 返回新文件信息
            resolve({
              name: fileData.name,
              url: fileData.url,
              id: saveRes.data?.id
            });
          } else {
            proxy.$modal.msgError(saveRes.msg || "文件保存失败");
            resolve(null);
          }
        } else {
          proxy.$modal.msgError(uploadRes.msg || "文件上传失败");
          resolve(null);
        }
      } catch (error) {
        proxy.$modal.msgError("文件上传失败");
        resolve(null);
      } finally {
        document.body.removeChild(input);
      }
    };
    document.body.appendChild(input);
    input.click();
  });
};
// 删除附件
const handleFileDelete = async (row) => {
  try {
    const res = await fileDel([row.id]);
    if (res.code === 200) {
      proxy.$modal.msgSuccess("删除成功");
      // 重新加载文件列表
      if (currentFileRow.value && fileListRef.value) {
        const listRes = await fileListPage({
          accountId: currentFileRow.value.id,
          accountType: accountType.value,
          current: 1,
          size: 100
        });
        if (listRes.code === 200) {
          const fileList = (listRes.data?.records || []).map(item => ({
            name: item.name,
            url: item.url,
            id: item.id,
            ...item
          }));
          fileListRef.value.setList(fileList);
        }
      }
      return true; // 返回 true 表示删除成功,组件会更新列表
    } else {
      proxy.$modal.msgError(res.msg || "删除失败");
      return false;
    }
  } catch (error) {
    proxy.$modal.msgError("删除失败");
    return false;
  }
};
onMounted(() => {