js删除el-table删除新增项,有的已经保存有的未经保存

有时候在弹窗中的弹窗要删除数据,有的是刚新增进来的,没有经过保存就没有id,有的已经保存过就有id

根据情况设定是否为编辑模式,如果为编辑模式就需要进行筛选删除及接口,如果不是编辑模式,只需要进行筛选删除

复制代码
  this.editFlag = true; // 为编辑模式

   // 删除伤亡名单
    handelDel() {
      let that = this;
      if (!that.selectRow.length) {
        this.$message.error("请选择要删除的数据");
        return;
      }
      that
        .$confirm("是否确认删除?", "确认信息", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
        .then(() => {
          if (this.editFlag) {
            this.tableDel();
          } else {
            const result = this.tableData.filter((itemA) => {
              return !this.selectRow.some((itemB) => itemA.id === itemB.id); // some 判断是否存在相同 projectName 的对象
            });
            this.tableData = result;
          }
        })
        .catch(() => {
          that.$message.info("已取消删除");
        });
    },
    tableDel() {
      let arr1 = this.selectRow.filter((val) => !val.accidentUserId);
      if (arr1.length > 0) {
        const result = this.tableData.filter((itemA) => {
          return !this.selectRow.some((itemB) => itemA.id === itemB.id); // some 判断是否存在相同 projectName 的对象
        });
        this.tableData = result;
      }
      let arr = this.selectRow.filter((val) => val.accidentUserId);

      if (arr.length > 0) {
        let accidentRecordIds = this.selectRow.map(
          (item) => item.accidentUserId
        );
        delUser(accidentRecordIds)
          .then((res) => {
            const { code, data, msg } = res.data;
            if (code == 0) {
              this.$message.success(msg || "删除成功");
              this.getTableData();
              this.innerDrawer = false;
            } else {
              this.$message.error(msg || "删除失败,请稍后重试");
            }
          })
          .catch((err) => {
            console.log(err);
          });
      }
    },
相关推荐
JackieDYH2 分钟前
CSS滚动吸附详解:构建精准流畅的滚动体验-scroll-snap-type
前端·css
A-程序设计18 分钟前
基于Spring Boot+Vue的生活用品购物平台设计与实现-(源码+LW+可部署)
vue.js·spring boot·后端
CodeCraft Studio24 分钟前
纯前端文档编辑组件——Spire.WordJS全新发布
前端·javascript·word·office·spire.wordjs·web文档编辑·在线文档编辑器
前端一课28 分钟前
第 32 题:Vue3 Template 编译原理(Template → AST → Transform → Codegen → Render 函数)
前端·面试
前端一课31 分钟前
第 33 题:Vue3 v-model 原理(语法糖 → props + emit → modelValue → update:modelValue)
前端·面试
前端一课35 分钟前
第 25 题:说一下 Vue3 的 keep-alive 原理?缓存是怎么做的?
前端·面试
前端一课38 分钟前
第 30 题:Vue3 自定义渲染器(Custom Renderer)原理- 为什么 Vue 能渲染到 DOM / Canvas / WebGL / 三方平台
前端·面试
前端一课38 分钟前
【vue高频面试题】第 23 题:Vue3 自定义指令(directive)完整解析
前端·面试