删除客户
This commit is contained in:
parent
dd0ad2b34d
commit
1b53149d88
|
|
@ -280,3 +280,19 @@ export const getWechatList = () => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除客户
|
||||||
|
* @param {string|string[]} ids 客户ID或ID数组(多个ID用逗号分隔或传入数组)
|
||||||
|
* @returns {Promise} 返回删除结果
|
||||||
|
*/
|
||||||
|
export const deleteCustomer = (ids) => {
|
||||||
|
// 如果传入的是数组,转换为逗号分隔的字符串
|
||||||
|
const idsParam = Array.isArray(ids) ? ids.join(',') : ids;
|
||||||
|
|
||||||
|
return uni.$uv.http.delete(`bst/customer/${idsParam}`,{}, {
|
||||||
|
custom: {
|
||||||
|
auth: true // 启用 token 认证
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -129,10 +129,10 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, computed, onMounted, watch } from 'vue';
|
import { ref, computed, onMounted, onUnmounted, watch } from 'vue';
|
||||||
import FabPlus from '@/components/FabPlus.vue';
|
import FabPlus from '@/components/FabPlus.vue';
|
||||||
import { usePagination } from '@/composables/usePagination';
|
import { usePagination } from '@/composables/usePagination';
|
||||||
import { getCustomerList } from '@/common/api/customer';
|
import { getCustomerList, deleteCustomer } from '@/common/api/customer';
|
||||||
|
|
||||||
// 筛选状态
|
// 筛选状态
|
||||||
const showFilter = ref(false);
|
const showFilter = ref(false);
|
||||||
|
|
@ -280,10 +280,34 @@ const handleMore = (customer) => {
|
||||||
uni.showModal({
|
uni.showModal({
|
||||||
title: '确认删除',
|
title: '确认删除',
|
||||||
content: `确定要删除客户"${customer.name}"吗?`,
|
content: `确定要删除客户"${customer.name}"吗?`,
|
||||||
success: (modalRes) => {
|
success: async (modalRes) => {
|
||||||
if (modalRes.confirm) {
|
if (modalRes.confirm) {
|
||||||
// TODO: 实现删除客户API调用
|
try {
|
||||||
uni.$uv.toast('删除功能待实现');
|
// 显示加载提示
|
||||||
|
uni.showLoading({
|
||||||
|
title: '删除中...',
|
||||||
|
mask: true
|
||||||
|
});
|
||||||
|
|
||||||
|
// 调用删除API
|
||||||
|
await deleteCustomer(customer.id);
|
||||||
|
|
||||||
|
// 隐藏加载提示
|
||||||
|
uni.hideLoading();
|
||||||
|
|
||||||
|
// 显示成功提示
|
||||||
|
uni.$uv.toast('删除成功');
|
||||||
|
|
||||||
|
// 刷新列表
|
||||||
|
refresh();
|
||||||
|
} catch (error) {
|
||||||
|
// 隐藏加载提示
|
||||||
|
uni.hideLoading();
|
||||||
|
|
||||||
|
// 显示错误提示
|
||||||
|
console.error('删除客户失败:', error);
|
||||||
|
uni.$uv.toast(error?.message || '删除失败,请重试');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -313,11 +337,27 @@ watch(filterStatus, () => {
|
||||||
updateParams(params);
|
updateParams(params);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 监听客户列表刷新事件
|
||||||
|
const handleCustomerListRefresh = () => {
|
||||||
|
console.log('收到客户列表刷新事件');
|
||||||
|
refresh();
|
||||||
|
// 清除存储标志,避免 onShow 时重复刷新
|
||||||
|
uni.removeStorageSync('customerListNeedRefresh');
|
||||||
|
};
|
||||||
|
|
||||||
// 组件挂载时加载数据
|
// 组件挂载时加载数据
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
const params = buildQueryParams();
|
const params = buildQueryParams();
|
||||||
// updateParams 内部会调用 getList(),所以不需要重复调用
|
// updateParams 内部会调用 getList(),所以不需要重复调用
|
||||||
updateParams(params);
|
updateParams(params);
|
||||||
|
|
||||||
|
// 监听客户列表刷新事件
|
||||||
|
uni.$on('customerListRefresh', handleCustomerListRefresh);
|
||||||
|
});
|
||||||
|
|
||||||
|
// 组件卸载时移除事件监听
|
||||||
|
onUnmounted(() => {
|
||||||
|
uni.$off('customerListRefresh', handleCustomerListRefresh);
|
||||||
});
|
});
|
||||||
|
|
||||||
// 暴露方法供父组件调用(用于 onReachBottom)
|
// 暴露方法供父组件调用(用于 onReachBottom)
|
||||||
|
|
@ -329,7 +369,8 @@ const winB_LoadMore = () => {
|
||||||
|
|
||||||
// 使用 defineExpose 暴露方法
|
// 使用 defineExpose 暴露方法
|
||||||
defineExpose({
|
defineExpose({
|
||||||
winB_LoadMore
|
winB_LoadMore,
|
||||||
|
refresh // 暴露 refresh 方法,供外部调用
|
||||||
});
|
});
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
|
||||||
|
|
@ -125,7 +125,7 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, onMounted } from 'vue';
|
import { ref, onMounted } from 'vue';
|
||||||
import { onLoad, onShow } from '@dcloudio/uni-app';
|
import { onLoad, onShow } from '@dcloudio/uni-app';
|
||||||
import { getCustomerDetail, getCustomerFollowupList, getCustomerProjects } from '@/common/api';
|
import { getCustomerDetail, getCustomerFollowupList, getCustomerProjects, deleteCustomer } from '@/common/api';
|
||||||
import FollowupTab from '@/components/customer-detail/FollowupTab.vue';
|
import FollowupTab from '@/components/customer-detail/FollowupTab.vue';
|
||||||
import ProjectsTab from '@/components/customer-detail/ProjectsTab.vue';
|
import ProjectsTab from '@/components/customer-detail/ProjectsTab.vue';
|
||||||
import InfoTab from '@/components/customer-detail/InfoTab.vue';
|
import InfoTab from '@/components/customer-detail/InfoTab.vue';
|
||||||
|
|
@ -327,11 +327,46 @@ const handleMore = () => {
|
||||||
// 删除客户
|
// 删除客户
|
||||||
uni.showModal({
|
uni.showModal({
|
||||||
title: '确认删除',
|
title: '确认删除',
|
||||||
content: '确定要删除该客户吗?',
|
content: `确定要删除客户"${customerDetail.value.name || '该客户'}"吗?`,
|
||||||
success: (modalRes) => {
|
success: async (modalRes) => {
|
||||||
if (modalRes.confirm) {
|
if (modalRes.confirm) {
|
||||||
// TODO: 实现删除客户功能
|
try {
|
||||||
uni.$uv.toast('删除功能待实现');
|
// 显示加载提示
|
||||||
|
uni.showLoading({
|
||||||
|
title: '删除中...',
|
||||||
|
mask: true
|
||||||
|
});
|
||||||
|
|
||||||
|
// 调用删除API
|
||||||
|
await deleteCustomer(customerId.value);
|
||||||
|
|
||||||
|
// 隐藏加载提示
|
||||||
|
uni.hideLoading();
|
||||||
|
|
||||||
|
// 显示成功提示
|
||||||
|
uni.$uv.toast('删除成功');
|
||||||
|
|
||||||
|
// 发送全局事件,通知客户列表刷新
|
||||||
|
uni.$emit('customerListRefresh');
|
||||||
|
|
||||||
|
// 设置刷新标志,确保返回页面时也能刷新
|
||||||
|
uni.setStorageSync('customerListNeedRefresh', true);
|
||||||
|
|
||||||
|
// 延迟一下再跳转,让用户看到成功提示
|
||||||
|
setTimeout(() => {
|
||||||
|
// 跳转回客户列表页面
|
||||||
|
uni.navigateBack({
|
||||||
|
delta: 999 // 返回到客户列表页面
|
||||||
|
});
|
||||||
|
}, 500);
|
||||||
|
} catch (error) {
|
||||||
|
// 隐藏加载提示
|
||||||
|
uni.hideLoading();
|
||||||
|
|
||||||
|
// 显示错误提示
|
||||||
|
console.error('删除客户失败:', error);
|
||||||
|
uni.$uv.toast(error?.message || '删除失败,请重试');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -163,6 +163,18 @@ onShow(() => {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('读取新日程数据失败:', e);
|
console.error('读取新日程数据失败:', e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 如果当前在客户管理页面,检查是否需要刷新客户列表
|
||||||
|
if (value.value === 3 && customerManagementRef.value) {
|
||||||
|
// 检查是否有刷新标志(从客户详情页删除后设置)
|
||||||
|
const needRefresh = uni.getStorageSync('customerListNeedRefresh');
|
||||||
|
if (needRefresh) {
|
||||||
|
// 刷新客户列表
|
||||||
|
customerManagementRef.value.refresh();
|
||||||
|
// 清除刷新标志
|
||||||
|
uni.removeStorageSync('customerListNeedRefresh');
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// 触底加载更多(仅在客户管理页面时生效)
|
// 触底加载更多(仅在客户管理页面时生效)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user