feat: 完善双端演示注册与红娘服务闭环
This commit is contained in:
@@ -11,6 +11,9 @@
|
||||
* 展示待处理服务、工作台数据概览
|
||||
*/
|
||||
const api = require('../../utils/api');
|
||||
const { authStore } = require('../../stores');
|
||||
const { matchmakerService } = require('../../services');
|
||||
const { IS_DEV } = require('../../env');
|
||||
|
||||
Page({
|
||||
data: {
|
||||
@@ -20,6 +23,13 @@ Page({
|
||||
todayCount: 0,
|
||||
completedCount: 0,
|
||||
myAssignments: [],
|
||||
serviceTabs: [{ value: 'pending', label: '待处理' }, { value: 'in_progress', label: '进行中' }, { value: 'completed', label: '已完成' }],
|
||||
activeServiceTab: 'pending',
|
||||
services: [],
|
||||
visibleServices: [],
|
||||
demoEnabled: IS_DEV,
|
||||
creatingDemoUser: false,
|
||||
assigningServiceId: '',
|
||||
assignmentCount: 0,
|
||||
loading: true,
|
||||
currentDate: '',
|
||||
@@ -92,7 +102,7 @@ Page({
|
||||
}
|
||||
|
||||
if (assignmentRes) {
|
||||
const assignments = assignmentRes || [];
|
||||
const assignments = Array.isArray(assignmentRes) ? assignmentRes : (assignmentRes.list || []);
|
||||
// 联系授权申请目标 = 本人生效中的分配对象(B1:只能对分配对象发起)
|
||||
const targets = assignments.map((a) => ({
|
||||
userId: a.userId,
|
||||
@@ -105,6 +115,7 @@ Page({
|
||||
contactTargetIndex: 0,
|
||||
});
|
||||
this.loadContactAuthorizations();
|
||||
await this.loadServices(token, assignments);
|
||||
}
|
||||
if (referralRes) {
|
||||
this.setData({
|
||||
@@ -132,8 +143,83 @@ Page({
|
||||
}
|
||||
},
|
||||
|
||||
async loadServices(token, assignments) {
|
||||
const headers = { Authorization: `Bearer ${token}` };
|
||||
const assigned = await Promise.allSettled(assignments.filter((item) => item.serviceId).map((item) =>
|
||||
api.get(`/operator/matchmaker/services/${encodeURIComponent(item.serviceId)}`, {}, headers)));
|
||||
const [pending, management] = await Promise.allSettled([
|
||||
api.get('/operator/matchmaker/pending', {}, headers),
|
||||
api.get('/operator/matchmaker/management/services', {}, headers),
|
||||
]);
|
||||
const services = new Map();
|
||||
assigned.forEach((result) => {
|
||||
if (result.status === 'fulfilled' && result.value) {
|
||||
const item = result.value;
|
||||
services.set(item.serviceId || item.id, { ...item, userDisplayName: item.userProfile && item.userProfile.displayName, source: 'assignment' });
|
||||
}
|
||||
});
|
||||
if (management.status === 'fulfilled') (management.value || []).forEach((item) =>
|
||||
services.set(item.serviceId || item.id, { ...item, source: item.status === 'submitted' || item.status === 'completed' ? 'management' : 'assignment' }));
|
||||
if (pending.status === 'fulfilled') (pending.value || []).forEach((item) =>
|
||||
services.set(item.serviceId || item.id, { ...item, source: 'management' }));
|
||||
this.setData({ services: [...services.values()].map((item) => ({
|
||||
...item,
|
||||
statusLabel: this.serviceStatusLabel(item.status),
|
||||
serviceTypeLabel: item.serviceType === 'recommend_partner' ? '推荐对象' : (item.serviceType || '公益红娘服务'),
|
||||
})) });
|
||||
this.selectServiceTab({ currentTarget: { dataset: { tab: this.data.activeServiceTab } } });
|
||||
},
|
||||
|
||||
selectServiceTab(e) {
|
||||
const tab = e.currentTarget.dataset.tab;
|
||||
const statuses = tab === 'pending' ? ['submitted', 'pending']
|
||||
: tab === 'in_progress' ? ['assigned', 'in_service', 'in_progress', 'waiting_user'] : ['completed'];
|
||||
this.setData({ activeServiceTab: tab, visibleServices: this.data.services.filter((item) => statuses.includes(item.status)) });
|
||||
},
|
||||
|
||||
serviceStatusLabel(status) {
|
||||
return { submitted: '待处理', assigned: '已接单', in_service: '服务中', waiting_user: '待用户确认', completed: '已完成' }[status] || status;
|
||||
},
|
||||
|
||||
async createDemoUser() {
|
||||
if (this.data.creatingDemoUser) return;
|
||||
this.setData({ creatingDemoUser: true });
|
||||
try {
|
||||
const code = `demo_openid_workbench_${Date.now()}`;
|
||||
await authStore.loginWithDemo(code, '演示服务用户');
|
||||
await matchmakerService.applyService({ serviceType: 'recommend_partner', description: '红娘演示服务申请' });
|
||||
wx.showToast({ title: '演示申请已创建', icon: 'success' });
|
||||
this.setData({ activeServiceTab: 'pending' });
|
||||
await this.loadDashboard();
|
||||
} catch (err) {
|
||||
wx.showToast({ title: err.message || '注册演示用户失败', icon: 'none' });
|
||||
} finally {
|
||||
this.setData({ creatingDemoUser: false });
|
||||
}
|
||||
},
|
||||
|
||||
async assignToSelf(e) {
|
||||
const serviceId = e.currentTarget.dataset.id;
|
||||
const operatorId = wx.getStorageSync('operatorId');
|
||||
if (!serviceId || !operatorId || this.data.assigningServiceId) return;
|
||||
this.setData({ assigningServiceId: serviceId });
|
||||
try {
|
||||
const token = wx.getStorageSync('operatorToken');
|
||||
await api.post(`/operator/matchmaker/services/${encodeURIComponent(serviceId)}/assign`,
|
||||
{ operatorId, reason: '演示分配' }, { Authorization: `Bearer ${token}` });
|
||||
wx.showToast({ title: '已接单', icon: 'success' });
|
||||
this.setData({ activeServiceTab: 'in_progress' });
|
||||
await this.loadDashboard();
|
||||
} catch (err) {
|
||||
wx.showToast({ title: err.message || '接单失败', icon: 'none' });
|
||||
} finally {
|
||||
this.setData({ assigningServiceId: '' });
|
||||
}
|
||||
},
|
||||
|
||||
onViewService(e) {
|
||||
const serviceId = e.currentTarget.dataset.id;
|
||||
const source = e.currentTarget.dataset.source || 'assignment';
|
||||
if (!serviceId) {
|
||||
const index = Number(e.currentTarget.dataset.index);
|
||||
const item = this.data.myAssignments[index] || {};
|
||||
@@ -144,7 +230,7 @@ Page({
|
||||
});
|
||||
return;
|
||||
}
|
||||
wx.navigateTo({ url: `/pages/matchmaker-service-detail/matchmaker-service-detail?id=${serviceId}` });
|
||||
wx.navigateTo({ url: `/pages/matchmaker-service-detail/matchmaker-service-detail?id=${serviceId}&source=${source}` });
|
||||
},
|
||||
|
||||
openReferral() {
|
||||
|
||||
Reference in New Issue
Block a user