vue2批量操作

switch语句

  handleStatus(row, type) {
      getFairStatus({ ids: [row.id], issueStatus: type }).then(response => {
        this.$message.success(type == 1 ? '发布成功' : '取消发布成功');
        this.getList();
      });
    },
// 获取checked列表
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },

// 下拉框批量操作
   handleCommand(command) {
     if (this.multipleSelection.length === 0) {
       this.$message.error('至少选择一项操作')
       return
     }

    //三元表达式:逻辑较强 
         // let cmdText = '1' == command ? cmdText = "置顶" : '2'==command ?
         // "取消置顶" : '3' == command ? "发布" : "取消发布";

(switch语句自己很少用得多试试)
       Switch语句:
         switch (command) {
             case '1':
               cmdText = "置顶";
               break;
             case '2':
               cmdText = "取消置顶";
               break;
            case '3':
            cmdText = "发布";
            break;
            case '4':
            cmdText = "取消发布";
            break;
         }

       this.ids = [];
      this.multipleSelection.forEach(element => {
    // 如果command=1并且它的置顶状态为0 再把它的ID放入新的数组中。
         if ('1' == command && element.isTop === 0) {
           this.ids.push(element.id);
         } else if ('2' == command && element.isTop === 1) {
           this.ids.push(element.id);
         } else if ('3' == command && element.issueStatus === 0) {
           this.ids.push(element.id);
         } else if ('4' == command && element.issueStatus === 1) {
           this.ids.push(element.id);
         }
       });

       if (this.ids.length == 0) {
         this.$message.error('所选文章已' + cmdText + ',无需重复操作');
         return
       }

       if ('1' == command || '2' == command) {
         cntArticleTop({ ids: this.ids, isTop: '1' == command ? 1 : 0 }).then(response => {
           this.getList();
         });
       } else {
         cntArticleStatus({ ids: this.ids, issueStatus: '3' == command ? 1 : 0 }).then(response => {
           this.getList();
         });
       }
     },

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

flutter大佬

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值