ZBLOG

要在传递 customerId 的同时也传递 customerName,您可以对现有代码做一些调整。在 batchCustomerTags 函数中,您需要确保将 customerName 包含在调用的参数中。为了实现这一点,您可以从所选行中提取必要的信息。

以下是修改后的示例代码:

<template>
  <a-table
    :columns="columns"
    :data-source="data"
    :scroll="{
      x: columns.reduce((sum, col) => sum + (col.width || 0), 0) > 1800 ? 'max-content' : undefined
    }"
    :pagination="{
      current: currentPage,
      pageSize: pageSize,
      total: totalRecords,
      pageSizeOptions: ['10', '20', '30', '40', '100'],
      onShowSizeChange: handlePageSizeChange,
      onChange: handlePageChange,
      showQuickJumper: true,
      showSizeChanger: true,
      showTotal: (total, range) => `显示 ${range[0]} ~ ${range[1]} 条记录,共 ${total} 条记录`
    }"
    :custom-row="customRow"
    style="padding: 5px"
    bordered
    :row-selection="rowSelection"
    :rowKey="record => record.customerId" <!-- Assuming customerId is unique -->
  />
</template>

<script setup>
import { reactive, ref } from 'vue';
import { message } from 'ant-design-vue';

const columns = [
  // Define your columns here
];

const data = ref([]); // Your data source
const currentPage = ref(1);
const pageSize = ref(10);
const totalRecords = ref(0);

const rowSelection = reactive({
  preserveSelectedRowKeys: true,
  selectedRowKeys: [],
  onChange(selectedRowKeys, selectedRows) {
    newSelectedRowKeys.value = selectedRowKeys;
    
    // Update the names of the selected customers
    newSelectedCustomerNames.value = selectedRows.map(row => row.customerName);
    
    console.log('Selected Row Keys:', selectedRowKeys);
  }
});

const handlePageSizeChange = (current, size) => {
  pageSize.value = size;
};

const handlePageChange = (page, size) => {
  currentPage.value = page;
};

const customRow = (record) => {
  return {
    onClick: () => {
      console.log('Clicked row:', record);
    }
  };
};

// Add other necessary methods and API calls

// Example for batch customer tags function
const batchCustomerTags = async ({ tagsId, customerIds, customerNames }) => {
   // Implement your API call here and return a promise
   console.log("Batch processing for IDs:", customerIds);
   console.log("Batch processing for Names:", customerNames);
};

// To simulate handling of selected customers and displaying messages after an operation.
const newSelectedRowKeys = ref([]);
const newSelectedCustomerNames = ref([]);

function processBatchAction() {
   const targetKeys = { value }; // Obtain this based on your implementation context
   
   batchCustomerTags({ 
     tagsId: targetKeys.value, 
     customerIds:newSelectedRowKeys.value, 
     customerNames:newSelectedCustomerNames.value 
   }).then(response => {
     if(response.success){
       message.success(response.message);
     } else {
       message.error(response.message);
     }
   });
}

</script>

修改说明:

  1. 新增变量

    • 增加了一个响应式引用 newSelectedCustomerNames 用于存储所选客户的名称。
  2. 更新选择事件处理函数

    • onChange 中,除了更新所选的 selectedRowKeys 外,也通过映射选择的行来获取每个顾客的名字,并将其存储到 newSelectedCustomerNames.
  3. 更新批处理函数

    • 修改了 batchCustomerTags 函数,使其接收一个包含客户 ID 和姓名的新对象。

现在,当您调用 processBatchAction 函数时,它会同时传递选中的客户 ID 和姓名。这样就能满足新的需求。


内容由零声教学AI助手提供,问题来源于学员提问

本站部分文章来源于网络,版权归原作者所有,如有侵权请联系站长删除。
转载请注明出处:https://golang.0voice.com/?id=21743

分享:
扫描分享到社交APP
上一篇
下一篇
发表列表
游客 游客
此处应有掌声~
评论列表

还没有评论,快来说点什么吧~

联系我们

在线咨询: 点击这里给我发消息

微信号:3007537140

上班时间: 10:30-22:30

关注我们
x

注册

已经有帐号?