|
|
@@ -0,0 +1,86 @@
|
|
|
+// 审核中心:服务角色申请与各 Tab 原有列表行的统一映射/合并工具
|
|
|
+
|
|
|
+const ROLE_LABELS = {
|
|
|
+ planner: '规划师',
|
|
|
+ nutritionist: '营养师',
|
|
|
+ butler: '管家',
|
|
|
+ vendor: '服务商',
|
|
|
+ activity_provider: '活动提供商',
|
|
|
+ article_admin: '知识管理员'
|
|
|
+}
|
|
|
+
|
|
|
+const SERVICE_ROLE_STATUS = { 0: 'pending', 1: 'approved', 2: 'rejected' }
|
|
|
+
|
|
|
+// 解析后端 JSON 字符串字段(roles / images),容错返回数组
|
|
|
+export function parseJsonArray(value) {
|
|
|
+ if (Array.isArray(value)) return value
|
|
|
+ if (!value) return []
|
|
|
+ try {
|
|
|
+ const arr = JSON.parse(value)
|
|
|
+ return Array.isArray(arr) ? arr : []
|
|
|
+ } catch (e) {
|
|
|
+ return []
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+export function parseRoles(roles) {
|
|
|
+ return parseJsonArray(roles)
|
|
|
+}
|
|
|
+
|
|
|
+export function roleLabel(role, roleLabels = {}) {
|
|
|
+ const labels = { ...ROLE_LABELS, ...roleLabels }
|
|
|
+ return labels[role] || role
|
|
|
+}
|
|
|
+
|
|
|
+// 服务角色申请 → 统一审核行
|
|
|
+export function mapServiceRoleRow(app, roleLabels = {}) {
|
|
|
+ if (!app) return null
|
|
|
+ const roles = parseRoles(app.roles)
|
|
|
+ return {
|
|
|
+ source: 'service_role',
|
|
|
+ applyId: app.id,
|
|
|
+ id: app.id,
|
|
|
+ userId: app.userId,
|
|
|
+ nickname: app.userName,
|
|
|
+ realName: app.realName,
|
|
|
+ phone: app.phone,
|
|
|
+ roles,
|
|
|
+ roleLabel: roles.map(r => roleLabel(r, roleLabels)).join('、'),
|
|
|
+ status: SERVICE_ROLE_STATUS[app.status] || 'pending',
|
|
|
+ rejected: app.status === 2,
|
|
|
+ rejectReason: app.rejectReason,
|
|
|
+ submittedAt: app.createdAt,
|
|
|
+ reviewedAt: app.reviewedAt,
|
|
|
+ idCard: app.idCard,
|
|
|
+ idCardImages: parseJsonArray(app.idCardImages),
|
|
|
+ certificateImages: parseJsonArray(app.certificateImages),
|
|
|
+ province: app.province,
|
|
|
+ city: app.city,
|
|
|
+ district: app.district,
|
|
|
+ street: app.street,
|
|
|
+ addressDetail: app.addressDetail,
|
|
|
+ raw: app
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+function submittedTime(row) {
|
|
|
+ const t = row.submittedAt || row.createdAt || 0
|
|
|
+ const parsed = new Date(t).getTime()
|
|
|
+ return isNaN(parsed) ? 0 : parsed
|
|
|
+}
|
|
|
+
|
|
|
+// 合并原 Tab 行与服务角色申请行:同 userId 去重(服务角色优先),按提交时间倒序
|
|
|
+export function mergeAuditRows(userRows = [], serviceRoleRows = []) {
|
|
|
+ const map = new Map()
|
|
|
+ for (const row of userRows) {
|
|
|
+ if (!row) continue
|
|
|
+ const key = String(row.userId != null ? row.userId : row.id)
|
|
|
+ map.set(key, { source: 'user', ...row })
|
|
|
+ }
|
|
|
+ for (const row of serviceRoleRows) {
|
|
|
+ if (!row) continue
|
|
|
+ const key = String(row.userId != null ? row.userId : row.applyId)
|
|
|
+ map.set(key, { source: 'service_role', ...row })
|
|
|
+ }
|
|
|
+ return Array.from(map.values()).sort((a, b) => submittedTime(b) - submittedTime(a))
|
|
|
+}
|