删除客户

This commit is contained in:
WindowBird 2025-11-08 15:58:45 +08:00
parent dd0ad2b34d
commit 1b53149d88
4 changed files with 115 additions and 11 deletions

View File

@ -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 认证
}
});
};

View File

@ -129,10 +129,10 @@
</template>
<script setup>
import { ref, computed, onMounted, watch } from 'vue';
import { ref, computed, onMounted, onUnmounted, watch } from 'vue';
import FabPlus from '@/components/FabPlus.vue';
import { usePagination } from '@/composables/usePagination';
import { getCustomerList } from '@/common/api/customer';
import { getCustomerList, deleteCustomer } from '@/common/api/customer';
//
const showFilter = ref(false);
@ -280,10 +280,34 @@ const handleMore = (customer) => {
uni.showModal({
title: '确认删除',
content: `确定要删除客户"${customer.name}"吗?`,
success: (modalRes) => {
success: async (modalRes) => {
if (modalRes.confirm) {
// TODO: API
uni.$uv.toast('删除功能待实现');
try {
//
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);
});
//
const handleCustomerListRefresh = () => {
console.log('收到客户列表刷新事件');
refresh();
// onShow
uni.removeStorageSync('customerListNeedRefresh');
};
//
onMounted(() => {
const params = buildQueryParams();
// updateParams getList()
updateParams(params);
//
uni.$on('customerListRefresh', handleCustomerListRefresh);
});
//
onUnmounted(() => {
uni.$off('customerListRefresh', handleCustomerListRefresh);
});
// onReachBottom
@ -329,7 +369,8 @@ const winB_LoadMore = () => {
// 使 defineExpose
defineExpose({
winB_LoadMore
winB_LoadMore,
refresh // refresh
});
</script>

View File

@ -125,7 +125,7 @@
<script setup>
import { ref, onMounted } from 'vue';
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 ProjectsTab from '@/components/customer-detail/ProjectsTab.vue';
import InfoTab from '@/components/customer-detail/InfoTab.vue';
@ -327,11 +327,46 @@ const handleMore = () => {
//
uni.showModal({
title: '确认删除',
content: '确定要删除该客户吗?',
success: (modalRes) => {
content: `确定要删除客户"${customerDetail.value.name || '该客户'}"吗?`,
success: async (modalRes) => {
if (modalRes.confirm) {
// TODO:
uni.$uv.toast('删除功能待实现');
try {
//
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 || '删除失败,请重试');
}
}
}
});

View File

@ -163,6 +163,18 @@ onShow(() => {
} catch (e) {
console.error('读取新日程数据失败:', e);
}
//
if (value.value === 3 && customerManagementRef.value) {
//
const needRefresh = uni.getStorageSync('customerListNeedRefresh');
if (needRefresh) {
//
customerManagementRef.value.refresh();
//
uni.removeStorageSync('customerListNeedRefresh');
}
}
});
//