首页 > 其他分享 >elementUI实现el-table分页多选功能,解决点击分页之后还可以选中

elementUI实现el-table分页多选功能,解决点击分页之后还可以选中

时间:2023-05-19 14:56:48浏览次数:37  
标签:el 分页 elementUI page item newArray ... data userFrom

<template>
  <div>
    <el-dialog
      title="批量下载推广码"
      :visible.sync="dialogVisibleDownCodeAll"
      width="900px"
      :before-close="close"
    >
      <div class="container">
        <el-form size="small">
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item>
                <el-input
                  v-model="userFrom.keyword"
                  @keyup.enter.native="onChanges"
                  placeholder="请输入姓名、电话、UID"
                  class="selWidth"
                  size="small"
                >
                  <el-button
                    slot="append"
                    icon="el-icon-search"
                    class="el-button-solt"
                    size="small"
                    @click="onChanges"
                  />
                </el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>
      <template>
        <el-checkbox
          v-model="allcheckUser"
          label="全选"
          border
          style="margin-bottom: 20px;"
        ></el-checkbox>
        <el-table
          :key="tableKey1"
          :data="userData.data"
          :selection="userSelection"
          row-key="uid"
          @selection-change="handleSelectionChangeUser"
          style="width: 100%"
          size="mini"
          class="table"
          highlight-current-row
          ref="table1"
          v-loading="loading"
          :element-loading-text="`正在下载中:`+percentage + '%'"
          element-loading-spinner="el-icon-loading"
          element-loading-background="rgba(0, 0, 0, 0.8)"
        >
          <el-table-column type="selection" width="55"> </el-table-column>
          <el-table-column label="ID" min-width="120" prop="uid" />
          <el-table-column label="用户姓名" min-width="120" prop="real_name" />
          <el-table-column label="用户昵称" min-width="120" prop="nickname" />
          <el-table-column label="用户电话" min-width="120" prop="phone" />
        </el-table>
        <div class="block">
          <el-pagination
            :page-sizes="[10, 20]"
            :page-size="userFrom.limit"
            :current-page="userFrom.page"
            layout="total, sizes, prev, pager, next, jumper"
            :total="userData.total"
            @size-change="handleSizeChangeUser"
            @current-change="pageChangeUser"
          />
        </div>
      </template>
      <span v-if="!loading" slot="footer" class="dialog-footer">
        <el-button type="primary" style="margin-top: 12px;" @click="next"
          >下 载</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>

<script>
import axios from "axios";

import { getToken } from "@/utils/auth";

import {
  promoterListApi
} from "@/api/promoter";

export default {
  name: "DownCode",
  props: {},
  data() {
    return {
      newAllArray: [],
      newAllArrayCheck: [],
      myHeaders: { "X-Token": getToken() },
      tableKey1: 0,
      allcheckUser: false,
      dialogVisibleDownCodeAll: false,
      selection: [],
      userSelection: [],
      userData: {
        data: [],
        total: 0
      },
      userFrom: {
        page: 1,
        limit: 10,
        keyword: ""
      },
      page: 2,
      percentage: 0,
      loading: false
    };
  },
  watch: {},
  methods: {
    next() {
      const newArray = [].concat(...Object.values(this.newAllArray));
      newArray.filter(item => item !== undefined);
      if (newArray.length == 0 && !this.allcheckUser) {
        this.$message.error("请先选择分销员");
        return;
      }
      this.down(1);
    },
    down(page) {
      this.loading = true;
      const newArray = [].concat(...Object.values(this.newAllArray));
      newArray.filter(item => item !== undefined);
      var uid_Array = newArray.map(function(obj) {
        return obj.uid;
      });
      axios({
        url:
          process.env.VUE_APP_BASE_API +
          "/mer/user/promoter/code/batch_download",
        method: "POST",
        data: {
          uid: this.allcheckUser ? "-1" : uid_Array.join(","),
          page: page
        },
        responseType: "json",
        headers: {
          "X-Token": getToken()
        }
      }).then(response => {
        this.percentage = response.data.progress;
        if (response.data.url == "") {
          this.down(this.page++);
        } else if (response.data.status == 400) {
          this.loading = false;
          this.$message.error(response.data.message);
        } else {
          this.loading = false;
          window.open(response.data.url);
        }
      });
    },
    close() {
      this.dialogVisibleDownCodeAll = false;
    },
    open() {
      this.dialogVisibleDownCodeAll = true;
    },
    onChanges() {
      this.getListUser(1);
    },
    // 分销员列表
    getListUser(num) {
      this.userFrom.page = num ? num : this.userFrom.page;
      promoterListApi({ ...this.userFrom })
        .then(res => {
          this.userData.data = res.data.list;
          this.userData.total = res.data.count;

          this.newAllArrayCheck = [...this.newAllArray];
          const newArray = [].concat(...Object.values(this.newAllArrayCheck));
          newArray.filter(item => item !== undefined);

          // 赋值选中的数据
          // 赋值选中缓存的数据
          const selectedRow = newArray;
          this.$nextTick(() => {
            if (selectedRow) {
              const table = this.$refs.table1;
              selectedRow.forEach(row => {
                if (row != undefined) {
                  const selectedRowIndex = this.userData.data.findIndex(
                    item => item["uid"] === row["uid"]
                  );
                  if (selectedRowIndex > -1) {
                    table.toggleRowSelection(
                      this.userData.data[selectedRowIndex],
                      true
                    );
                  }
                }
              });
            }
          });
        })
        .catch(res => {
          this.$message.error(res.message);
        });
    },
    handleSizeChangeUser(val) {
      this.userFrom.limit = val;
      this.getListUser();
    },
    pageChangeUser(page) {
      this.userFrom.page = page;
      this.getListUser();
    },
    handleSelectionChangeUser(val) {
      // 判断选中行数据的变化
      this.userSelection = val;
      if (this.newAllArray[this.userFrom.page] == undefined) {
        this.newAllArray[this.userFrom.page] = [...val];
      } else {
        this.newAllArray[this.userFrom.page] = [...val] || [
          ...this.newAllArray[this.userFrom.page],
          ...val
        ];
      }
    }
  }
};
</script>

<style scoped lang="scss"></style>

 

标签:el,分页,elementUI,page,item,newArray,...,data,userFrom
From: https://www.cnblogs.com/zcm1688/p/17415107.html

相关文章

  • Excel的开发工具中模块等含义
    如图:      ......
  • DCC32命令行方式编译delphi工程源码
    本文链接地址:http://blog.csdn.net/sushengmiyan/article/details/10284879作者:苏生米沿 一、首先找到这个可执行文件,熟悉delphi的人应该很容易就找到,打开你安装delphi的目录,如我的路径C:\ProgramFiles\Delphi_2007\bin\DCC32.EXE二、拷贝一份出来,我将其放在了我的测试目录下......
  • python使用exchangelib读取、保存exchange邮件
    importosfromdatetimeimportdatetimeimportpytzfromexchangelibimportCredentials,Account,Configuration,DELEGATE,Q,FileAttachmentdefreceived_exchange_message():"""接收exchange邮件,保存邮件到本地:return:""......
  • Shell常用命令
    Shell常用命令shell字符!:执行历史命令!!:执行上一条命令$:变量中取内容符+-*/%:对应数学运算加减乘除取余数&:后台执行;:分号可以在shell中一行执行多个命令,命令之......
  • elementui 表单验证
    ————————————————版权声明:本文为CSDN博主「橙-极纪元」的原创文章,遵循CC4.0BY-SA版权协议,转载请附上原文出处链接及本声明。原文链接:https://blog.csdn.net/cplvfx/article/details/125329481介绍Form组件提供了表单验证的功能,只需要通过rules属性传入......
  • STI比赛任务一:【智能问答baseline】
    比赛简介百度搜索首届技术创新挑战赛:赛道一答案抽取STI比赛任务一:【比赛数据分析与长尾发现】STI比赛任务一:【NLP常见优化算法和上分Trick】STI比赛任务一:【智能问答baseline】任务定义本赛题任务是:给定一个用户搜索问题集合Q,基于每个搜索问题q,给定搜索引擎检索得到的网页文档集合......
  • ExtJs GridPanel 自定义汇总
    {text:'订单金额',dataIndex:'amount',renderer:function(value){returnExt.util.Format.number(value,'0.00');},summaryType:function(records){varamount=0;varlength=records.length;for(var......
  • 近8万条谜语灯谜大全ACCESS\EXCEL数据库
    其实互联网上关于谜语和灯谜的资料仍然是挺多的,但是要想数据量以万来计算并且是接近10万的量来看的话,就只能是《近8万条谜语灯谜大全ACCESS数据库》了。而且《近8万条谜语灯谜大全ACCESS数据库》的数据表字段中也包含分类字段,可以根据分类字段有针对性的给出谜语。分类情况包含:......
  • 2万5千多条经典名言语录ACCESS\EXCEL数据库
    语录之类的数据库之前也发现过几个,比如《用自制的采集程序采集的经典语录》、《从网上采集下来的那些优美的句子》等,但是这些感觉都比较现代,比较时尚,而今天发现的这个《2万5千多条经典名言语录ACCESS数据库》则比较正规、是属于那种收集完整的传统经典谚语类的ACCESS数据库。---......
  • 报表控件FastReport VCL v2023.2 - 将Delphi 产品整合到单一系统
    FastReport 是功能齐全的报表控件,可以帮助开发者可以快速并高效地为.NET,VCL,COM,ActiveX应用程序添加报表支持,由于其独特的编程原则,现在已经成为了Delphi平台最优秀的报表控件,支持将编程开发中的报表信息输出为TXT、PDF等多种文件格式,是编程开发人员必备的报表工具。FastReportVC......