129 lines
3.5 KiB
JavaScript
129 lines
3.5 KiB
JavaScript
/**
|
|||
|
|
* 红娘工作台主页
|
||
|
|
*
|
||
|
|
* 展示待处理服务、工作台数据概览
|
||
|
|
*/
|
||
|
|
const api = require('../../utils/api');
|
||
|
|
|
||
|
|
Page({
|
||
|
|
data: {
|
||
|
|
operatorName: '',
|
||
|
|
pendingCount: 0,
|
||
|
|
inProgressCount: 0,
|
||
|
|
todayCount: 0,
|
||
|
|
completedCount: 0,
|
||
|
|
pendingServices: [],
|
||
|
|
loading: true,
|
||
|
|
currentDate: '',
|
||
|
|
},
|
||
|
|
|
||
|
|
onLoad() {
|
||
|
|
wx.setNavigationBarTitle({ title: '红娘工作台' });
|
||
|
|
// 获取操作员信息
|
||
|
|
const operatorName = wx.getStorageSync('operatorName') || '红娘';
|
||
|
|
this.setData({ operatorName });
|
||
|
|
|
||
|
|
// 设置当前日期
|
||
|
|
const now = new Date();
|
||
|
|
const dateStr = `${now.getFullYear()}年${now.getMonth() + 1}月${now.getDate()}日`;
|
||
|
|
this.setData({ currentDate: dateStr });
|
||
|
|
|
||
|
|
this.loadDashboard();
|
||
|
|
},
|
||
|
|
|
||
|
|
onShow() {
|
||
|
|
// 每次显示刷新数据
|
||
|
|
this.loadDashboard();
|
||
|
|
},
|
||
|
|
|
||
|
|
async loadDashboard() {
|
||
|
|
this.setData({ loading: true });
|
||
|
|
try {
|
||
|
|
const token = wx.getStorageSync('operatorToken');
|
||
|
|
if (!token) {
|
||
|
|
wx.redirectTo({ url: '/pages/matchmaker-login/matchmaker-login' });
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 加载工作台数据
|
||
|
|
const [dashRes, pendingRes] = await Promise.all([
|
||
|
|
api.get('/operator/matchmaker/dashboard', {}, { Authorization: `Bearer ${token}` }),
|
||
|
|
api.get('/operator/matchmaker/pending', {}, { Authorization: `Bearer ${token}` }),
|
||
|
|
]);
|
||
|
|
|
||
|
|
if (dashRes.success) {
|
||
|
|
this.setData({
|
||
|
|
pendingCount: dashRes.data.pendingCount || 0,
|
||
|
|
inProgressCount: dashRes.data.inProgressCount || 0,
|
||
|
|
todayCount: dashRes.data.todayCount || 0,
|
||
|
|
completedCount: dashRes.data.completedCount || 0,
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
if (pendingRes.success) {
|
||
|
|
this.setData({
|
||
|
|
pendingServices: pendingRes.data || [],
|
||
|
|
});
|
||
|
|
}
|
||
|
|
} catch (err) {
|
||
|
|
console.error('加载工作台数据失败:', err);
|
||
|
|
} finally {
|
||
|
|
this.setData({ loading: false });
|
||
|
|
}
|
||
|
|
},
|
||
|
|
|
||
|
|
onViewService(e) {
|
||
|
|
const serviceId = e.currentTarget.dataset.id;
|
||
|
|
wx.navigateTo({ url: `/pages/matchmaker-service-detail/matchmaker-service-detail?id=${serviceId}` });
|
||
|
|
},
|
||
|
|
|
||
|
|
onClaimService(e) {
|
||
|
|
const serviceId = e.currentTarget.dataset.id;
|
||
|
|
wx.showLoading({ title: '接单中...' });
|
||
|
|
|
||
|
|
const token = wx.getStorageSync('operatorToken');
|
||
|
|
api.post(`/operator/matchmaker/services/${serviceId}/claim`, {}, {}, { Authorization: `Bearer ${token}` })
|
||
|
|
.then(res => {
|
||
|
|
wx.hideLoading();
|
||
|
|
if (res.success) {
|
||
|
|
wx.showToast({ title: '接单成功', icon: 'success' });
|
||
|
|
this.loadDashboard();
|
||
|
|
} else {
|
||
|
|
wx.showToast({ title: res.message || '接单失败', icon: 'none' });
|
||
|
|
}
|
||
|
|
})
|
||
|
|
.catch(err => {
|
||
|
|
wx.hideLoading();
|
||
|
|
wx.showToast({ title: '网络错误', icon: 'none' });
|
||
|
|
});
|
||
|
|
},
|
||
|
|
|
||
|
|
formatTime(timeStr) {
|
||
|
|
if (!timeStr) return '';
|
||
|
|
const date = new Date(timeStr);
|
||
|
|
const now = new Date();
|
||
|
|
const diff = now - date;
|
||
|
|
const days = Math.floor(diff / 86400000);
|
||
|
|
if (days === 0) return '今天';
|
||
|
|
if (days === 1) return '昨天';
|
||
|
|
if (days < 7) return days + '天前';
|
||
|
|
const m = date.getMonth() + 1;
|
||
|
|
const d = date.getDate();
|
||
|
|
return m + '月' + d + '日';
|
||
|
|
},
|
||
|
|
|
||
|
|
onLogout() {
|
||
|
|
wx.showModal({
|
||
|
|
title: '退出登录',
|
||
|
|
content: '确定要退出登录吗?',
|
||
|
|
success: (res) => {
|
||
|
|
if (res.confirm) {
|
||
|
|
wx.removeStorageSync('operatorToken');
|
||
|
|
wx.removeStorageSync('operatorName');
|
||
|
|
wx.reLaunch({ url: '/pages/matchmaker-login/matchmaker-login' });
|
||
|
|
}
|
||
|
|
},
|
||
|
|
});
|
||
|
|
},
|
||
|
|
});
|