src/views/procureMent/index.vue
@@ -20,9 +20,9 @@
        <el-button type="primary" :icon="Plus" @click="handleAdd"
          >新建
        </el-button>
        <el-button type="danger" :icon="Delete" @click="handleDelete"
        <!-- <el-button type="danger" :icon="Delete" @click="handleDelete"
          >删除
        </el-button>
        </el-button> -->
      </el-row>
      <!-- 表格组件 -->
      <data-table
@@ -73,9 +73,15 @@
  purchaseRegistration,
  getSupplyList,
  getCoalInfoList,
  delPR
} from "@/api/procureMent";
import { useDelete } from "@/hooks/useDelete";
const userStore = useUserStore();
import useUserStore from "@/store/modules/user";
let userList = ref([]);
userStore.getUserList().then((res) => {
  userList.value = res;
});
// 引入字典数据
const { proxy } = getCurrentInstance();
const dialogFormVisible = ref(false);
@@ -107,7 +113,7 @@
  // 这里添加实际的查询逻辑
  getList();
};
const userStore = useUserStore();
// 获取用户信息
const userInfo = ref({});
onMounted(async () => {
@@ -146,7 +152,13 @@
  { prop: "totalPriceIncludingTax", label: "总价(含税)", minWidth: 100 },
  { prop: "taxRate", label: "税率", minWidth: 100 },
  { prop: "priceExcludingTax", label: "不含税单价", minWidth: 100 },
  { prop: "registrantId", label: "登记人", minWidth: 100 },
  { prop: "registrantId", label: "登记人", minWidth: 100,
    formatter: (row) => {
      // 匹配用户信息
      const user = userList.value.find((user) => user.userId === row.registrantId);
      return user ? user.nickName : "未知用户";
    },
  },
  { prop: "registrationDate", label: "登记日期", minWidth: 100 },
]);
@@ -194,6 +206,7 @@
    // 触发ref里面的方法
    return;
  }
  console.log(userInfo.value)
  // 新建时初始化表单
  form.value = {
    supplierName: "",
@@ -205,7 +218,7 @@
    priceIncludingTax: "",
    totalPriceIncludingTax: "",
    taxRate: "",
    registrantId: userInfo.value.userName,
    registrantId: userInfo.value.userId,
    registrationDate: new Date().toISOString().split("T")[0],
  };
  // 新建时也需要设置 copyForm 用于重置功能
@@ -238,28 +251,15 @@
  addOrEdit.value = "viewRow";
  handleAddEdit();
};
const handleDelete = () => {
  if (selectedRows.value.length === 0) {
    ElMessage.warning("请选择要删除的数据");
    return;
  }
  ElMessageBox.confirm(`确定删除选中的数据吗?`, "提示", {
    confirmButtonText: "确定",
    cancelButtonText: "取消",
    type: "warning",
  })
    .then(() => {
      // 模拟删除操作
      tableData.value = tableData.value.filter(
        (item) => !selectedRows.value.includes(item)
      );
      total.value = tableData.value.length;
      ElMessage.success("删除成功");
    })
    .catch(() => {
      ElMessage.info("已取消删除");
    });
};
// 使用删除组合式函数 - 简化版本
const { handleDeleteBatch: handleDelete } = useDelete({
  deleteApi: delPR,
  selectedRows,
  tableData,
  total,
  confirmText: "确定删除选中的采购记录吗?",
  useLocalUpdate: true
});
const handleDeleteSuccess = (row) => {
  ElMessage.success("删除成功:" + row.supplierName);
};