修复bug
This commit is contained in:
1 parent
fc8c3ee3ad
commit
68617335f0
9 files changed
+645
-161
No files matched your search
@@ -7,14 +7,6 @@
|
||||
</div>
|
||||
<div class="header-actions">
|
||||
<el-button :icon="Refresh" @click="fetchList">刷新</el-button>
|
||||
<el-button
|
||||
type="warning"
|
||||
plain
|
||||
:disabled="!multipleSelection.length"
|
||||
@click="openMovePool(multipleSelection)"
|
||||
>
|
||||
移入公海
|
||||
</el-button>
|
||||
<el-button type="primary" :icon="Plus" @click="openCreate">新增客户</el-button>
|
||||
<el-button type="success" :icon="Cpu" @click="smartAddVisible = true">智能添加</el-button>
|
||||
</div>
|
||||
@@ -69,6 +61,26 @@
|
||||
</el-form>
|
||||
</div>
|
||||
|
||||
<!-- 批量操作:勾选行后出现,所有操作都按所选记录批量执行 -->
|
||||
<div v-if="multipleSelection.length" class="batch-bar">
|
||||
<span class="batch-tip">已选 {{ multipleSelection.length }} 项</span>
|
||||
<el-button size="small" type="primary" plain :loading="batchLoading" @click="handleBatchToggleStatus('1')">
|
||||
批量启用
|
||||
</el-button>
|
||||
<el-button size="small" type="info" plain :loading="batchLoading" @click="handleBatchToggleStatus('0')">
|
||||
批量禁用
|
||||
</el-button>
|
||||
<el-button size="small" type="success" plain :loading="batchLoading" @click="handleBatchConvertSupplier">
|
||||
批量转供应商
|
||||
</el-button>
|
||||
<el-button size="small" type="warning" plain @click="openMovePool(multipleSelection)">
|
||||
批量移入公海
|
||||
</el-button>
|
||||
<el-button size="small" type="danger" plain :loading="batchLoading" @click="handleBatchDelete">
|
||||
批量删除
|
||||
</el-button>
|
||||
</div>
|
||||
|
||||
<div class="table-container" v-loading="loading">
|
||||
<el-table
|
||||
:data="tableData"
|
||||
@@ -333,6 +345,7 @@ import { Plus, Search, Refresh, Cpu } from "@element-plus/icons-vue";
|
||||
import {
|
||||
getCrmCustomerList,
|
||||
deleteCrmCustomer,
|
||||
toggleCrmCustomerStatus,
|
||||
moveToPool,
|
||||
convertCustomerToSupplier,
|
||||
} from "@/api/crm";
|
||||
@@ -446,6 +459,82 @@ function handleSelectionChange(val) {
|
||||
multipleSelection.value = val;
|
||||
}
|
||||
|
||||
/* ------------------------------ 批量操作 ------------------------------ */
|
||||
|
||||
const batchLoading = ref(false);
|
||||
|
||||
/**
|
||||
* 批量执行:逐个复用单条接口,单行失败不影响其他行;
|
||||
* 结束后按成功 / 失败数量给出汇总提示,并刷新列表、清空选中。
|
||||
*/
|
||||
async function runBatch(rows, action, actionText) {
|
||||
if (!rows.length) return;
|
||||
batchLoading.value = true;
|
||||
try {
|
||||
const results = await Promise.allSettled(rows.map((row) => action(row)));
|
||||
const failed = results.filter((item) => item.status === "rejected");
|
||||
const okCount = rows.length - failed.length;
|
||||
if (failed.length === 0) {
|
||||
ElMessage.success(`${actionText}成功(${okCount} 条)`);
|
||||
} else if (okCount === 0) {
|
||||
ElMessage.error(`${actionText}失败:${failed[0].reason?.message || "请稍后重试"}`);
|
||||
} else {
|
||||
ElMessage.warning(`${actionText}完成:成功 ${okCount} 条,失败 ${failed.length} 条`);
|
||||
}
|
||||
multipleSelection.value = [];
|
||||
fetchList();
|
||||
} finally {
|
||||
batchLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
/** 批量启用 / 禁用 */
|
||||
async function handleBatchToggleStatus(status) {
|
||||
const rows = multipleSelection.value;
|
||||
if (!rows.length) return;
|
||||
const action = status === "1" ? "启用" : "禁用";
|
||||
try {
|
||||
await ElMessageBox.confirm(`确定要${action}选中的 ${rows.length} 个客户吗?`, `批量${action}`, {
|
||||
type: "warning",
|
||||
});
|
||||
} catch (e) {
|
||||
return; // 取消
|
||||
}
|
||||
await runBatch(rows, (row) => toggleCrmCustomerStatus(row.id, status), `批量${action}`);
|
||||
}
|
||||
|
||||
/** 批量删除(软删,不可恢复) */
|
||||
async function handleBatchDelete() {
|
||||
const rows = multipleSelection.value;
|
||||
if (!rows.length) return;
|
||||
try {
|
||||
await ElMessageBox.confirm(
|
||||
`确定要删除选中的 ${rows.length} 个客户吗?删除后不可恢复。`,
|
||||
"批量删除",
|
||||
{ type: "warning" }
|
||||
);
|
||||
} catch (e) {
|
||||
return; // 取消
|
||||
}
|
||||
await runBatch(rows, (row) => deleteCrmCustomer(row.id), "批量删除");
|
||||
}
|
||||
|
||||
/** 批量转供应商:同名企业后端只补同步联系人,原客户记录保留 */
|
||||
async function handleBatchConvertSupplier() {
|
||||
const rows = multipleSelection.value;
|
||||
if (!rows.length) return;
|
||||
try {
|
||||
await ElMessageBox.confirm(
|
||||
`将选中的 ${rows.length} 个客户的企业资料与联系人复制到供应商库?原客户记录会保留。`,
|
||||
"批量转供应商",
|
||||
{ type: "warning" }
|
||||
);
|
||||
} catch (e) {
|
||||
return; // 取消
|
||||
}
|
||||
await runBatch(rows, (row) => convertCustomerToSupplier(row.id), "批量转供应商");
|
||||
}
|
||||
|
||||
function openCreate() {
|
||||
currentEditData.value = null;
|
||||
editVisible.value = true;
|
||||
@@ -630,6 +719,25 @@ async function submitMovePool() {
|
||||
border: 1px solid var(--el-border-color-lighter);
|
||||
}
|
||||
|
||||
/* 批量操作栏:勾选行后出现 */
|
||||
.batch-bar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
flex-wrap: wrap;
|
||||
margin-bottom: 12px;
|
||||
padding: 10px 16px;
|
||||
border-radius: 6px;
|
||||
border: 1px solid var(--el-color-primary-light-7);
|
||||
background: var(--el-color-primary-light-9);
|
||||
|
||||
.batch-tip {
|
||||
margin-right: 8px;
|
||||
font-size: 13px;
|
||||
color: var(--el-text-color-regular);
|
||||
}
|
||||
}
|
||||
|
||||
.name-link {
|
||||
cursor: pointer;
|
||||
font-weight: 500;
|
||||
|
||||
Reference in new issue
Block a user