Vue.js 表格多选数据更新功能实现:综合所得申报修改

本示例展示了如何在 Vue.js 中使用 el-table 组件实现表格多选数据更新功能,以修改综合所得申报信息为例,演示了如何通过 API 调用实现数据的更新和弹窗展示。

代码示例:

// 更新数据函数
handleUpdate(row) {
  this.reset(); //重置表单
  const reportingPeriodDate = this.selection.map((item) => item.reportingPeriodDate); //获取选中的报告期日期
  this.params.companyId = this.companyId; //设置请求参数
  this.params.incomeReportingCode = this.incomeReportingCode;
  
  editReportingDonationDeduction(this.params, reportingPeriodDate).then((response) => { //调用编辑综合所得申报接口
    this.form = response.data; //将返回的数据赋值给表单
    this.open = true; //打开弹窗
    this.title = '修改综合所得申报-稿酬所得'; //设置弹窗标题
  });
},

// 多选框选中数据
handleSelectionChange(selection) {
  this.selection = selection; //保存选中的数据
  this.ids = selection.map((item) => item.personId); //获取选中数据的id
  this.single = selection.length !== 1; //判断是否选中了单行数据
  this.multiple = !selection.length; //判断是否未选中数据
},

<el-table
    ref="multipleTable"
    :data="tableData"
    @selection-change="handleSelectionChange"
    border
    style="width: 100%; margin-top: 20px"
>
  <el-table-column type="selection" width="55" align="center" />
  <!-- 其他列 -->
</el-table>

功能说明:

  1. handleUpdate(row) 函数: 该函数负责处理更新操作。

    • 使用 this.reset() 重置表单。
    • 通过 this.selection.map((item) => item.reportingPeriodDate) 获取选中数据的报告期日期,并将其作为参数传递给 editReportingDonationDeduction 函数。
    • 设置请求参数 this.params.companyIdthis.params.incomeReportingCode
    • 调用 editReportingDonationDeduction 函数,该函数负责发送请求更新数据,并返回更新后的数据。
    • 将返回的数据赋值给 this.form,并将弹窗 this.open 设置为 true
    • 设置弹窗标题 this.title
  2. handleSelectionChange(selection) 函数: 该函数负责处理多选框的选中状态变化。

    • 将选中的数据保存在 this.selection 中。
    • 通过 this.selection.map((item) => item.personId) 获取选中数据的 personId
    • 根据选中数据数量判断是单选 (this.single) 还是多选 (this.multiple)。
  3. el-table 组件: 该组件用于展示表格数据。

    • 使用 @selection-change 事件绑定 handleSelectionChange 函数,监听多选框的选中状态变化。
    • 使用 <el-table-column type="selection" ... /> 添加多选列。

注意:

  • 本示例中的 editReportingDonationDeduction 函数是一个示例,具体的 API 调用方式需要根据实际情况进行调整。
  • 请根据实际需求修改代码中的数据字段和 API 接口名称。
  • 在实际应用中,还需要根据用户操作进行相应的提示和错误处理。

通过以上代码和说明,您可以轻松地实现 Vue.js 表格多选数据更新功能,并在实际项目中应用。

Vue.js 表格多选数据更新功能实现:综合所得申报修改

原文地址: https://www.cveoy.top/t/topic/pgpo 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录