|
|
|
@ -22,15 +22,16 @@ Page({ |
|
|
|
// 获取当前用户类型参数
|
|
|
|
const userType = this.data.userType || 'seller'; |
|
|
|
|
|
|
|
// 使用api.js中的请求工具,自动获取正确的服务器地址
|
|
|
|
const apiResponse = await api.request(`/api/managers?type=${userType}`, 'GET'); |
|
|
|
// 直接使用api.request函数,该函数已经配置了正确的BASE_URL
|
|
|
|
const res = await api.request(`/api/managers?type=${userType}`, 'GET', {}); |
|
|
|
|
|
|
|
console.log('API响应数据:', apiResponse ? JSON.stringify(apiResponse) : 'undefined'); |
|
|
|
console.log('API响应数据:', res ? JSON.stringify(res) : 'undefined'); |
|
|
|
|
|
|
|
// 更宽松的响应检查,确保能处理各种有效的响应格式
|
|
|
|
if (apiResponse) { |
|
|
|
// 无论success字段是否存在,只要有data字段就尝试处理
|
|
|
|
const dataSource = apiResponse.data || apiResponse; |
|
|
|
// 注意:api.request函数直接返回res.data,所以res已经是响应数据,不再有statusCode字段
|
|
|
|
if (res) { |
|
|
|
// 无论success字段是否存在,只要有数据就尝试处理
|
|
|
|
const dataSource = Array.isArray(res) ? res : (res.data || []); |
|
|
|
if (Array.isArray(dataSource)) { |
|
|
|
const processedData = dataSource.map(item => { |
|
|
|
// 解析information字段中的信息
|
|
|
|
@ -44,40 +45,64 @@ Page({ |
|
|
|
// 处理不同类型的换行符(\r\n和\n)
|
|
|
|
const lines = item.information.split(/\r?\n/).filter(line => line.trim()); |
|
|
|
|
|
|
|
// 解析第一行:服务平台X年 服务X+鸡场
|
|
|
|
// 解析第一行:服务平台X年 服务X家(或X+鸡场)
|
|
|
|
if (lines[0]) { |
|
|
|
const firstLine = lines[0].trim(); |
|
|
|
const experienceMatch = firstLine.match(/服务平台(.*?)年/); |
|
|
|
if (experienceMatch) { |
|
|
|
experience = experienceMatch[1].trim() + '年'; |
|
|
|
// 提取完整的经验信息,包括"服务平台"
|
|
|
|
const fullExperienceMatch = firstLine.match(/(服务平台.*?年|服务平台.*?月)/); |
|
|
|
if (fullExperienceMatch) { |
|
|
|
// 直接使用完整的经验信息,如"服务平台1年"或"服务平台2个月"
|
|
|
|
experience = fullExperienceMatch[1].trim(); |
|
|
|
} else { |
|
|
|
// 如果没有匹配到,使用默认格式
|
|
|
|
experience = '服务平台1年'; |
|
|
|
} |
|
|
|
|
|
|
|
const serviceCountMatch = firstLine.match(/服务(.*?)鸡场/); |
|
|
|
// 匹配服务数量,支持多种格式:服务66家、服务100+鸡场等
|
|
|
|
// 确保只匹配最后一个"服务"后面的数量
|
|
|
|
const serviceMatches = firstLine.match(/服务(.*?)(家|鸡场)/g); |
|
|
|
if (serviceMatches && serviceMatches.length > 0) { |
|
|
|
// 使用最后一个匹配项
|
|
|
|
const lastServiceMatch = serviceMatches[serviceMatches.length - 1]; |
|
|
|
const serviceCountMatch = lastServiceMatch.match(/服务(.*?)(家|鸡场)/); |
|
|
|
if (serviceCountMatch) { |
|
|
|
serviceCount = serviceCountMatch[1].trim(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 解析第二行:数字 数字 数字%
|
|
|
|
if (lines[1]) { |
|
|
|
const secondLine = lines[1].trim(); |
|
|
|
const numbers = secondLine.split(/\s+/).filter(num => num.trim()); |
|
|
|
if (numbers.length >= 3) { |
|
|
|
// 解析数字行:数字 数字% 或 数字 数字 数字%
|
|
|
|
for (let i = 1; i < lines.length; i++) { |
|
|
|
const line = lines[i].trim(); |
|
|
|
// 匹配数字序列
|
|
|
|
const numbers = line.split(/\s+/).filter(num => num.trim() && /\d/.test(num)); |
|
|
|
if (numbers.length >= 2) { |
|
|
|
// 销售相关数据:累计销售和客户满意度
|
|
|
|
purchaseCount = numbers[0].trim(); |
|
|
|
profitFarmCount = numbers[1].trim(); |
|
|
|
profitFarmCount = numbers[1].replace('%', '').trim(); |
|
|
|
// 如果有第三个数字,可能是其他数据
|
|
|
|
if (numbers.length >= 3) { |
|
|
|
profitIncreaseRate = numbers[2].replace('%', '').trim(); |
|
|
|
} |
|
|
|
break; // 只处理第一行数字
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 提取egg_section中的数字部分,去掉"鸡蛋分"后缀
|
|
|
|
let score = Math.floor(Math.random() * 20) + 980; |
|
|
|
// 处理鸡蛋分显示
|
|
|
|
let score = '新人暂无'; |
|
|
|
if (item.egg_section) { |
|
|
|
if (item.egg_section.trim() === '新人暂无') { |
|
|
|
// 新人暂无,直接显示
|
|
|
|
score = '新人暂无'; |
|
|
|
} else { |
|
|
|
// 提取egg_section中的数字部分,去掉"鸡蛋分"后缀
|
|
|
|
const scoreMatch = item.egg_section.match(/(\d+)/); |
|
|
|
if (scoreMatch) { |
|
|
|
score = scoreMatch[1]; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return { |
|
|
|
id: item.id || `id_${Date.now()}_${Math.random()}`, // 确保有id
|
|
|
|
@ -89,7 +114,33 @@ Page({ |
|
|
|
name: item.name || '未知', |
|
|
|
alias: item.alias || item.name || '未知', |
|
|
|
phoneNumber: item.phoneNumber || '', |
|
|
|
avatarUrl: item.avatar || item.avatarUrl || '', // 兼容avatar和avatarUrl
|
|
|
|
// 解析头像URL,处理JSON数组格式和多余字符
|
|
|
|
avatarUrl: function() { |
|
|
|
let url = ''; |
|
|
|
const avatarData = item.avatar || item.avatarUrl || ''; |
|
|
|
if (avatarData) { |
|
|
|
try { |
|
|
|
// 尝试解析JSON数组
|
|
|
|
const avatarArray = JSON.parse(avatarData); |
|
|
|
if (Array.isArray(avatarArray) && avatarArray.length > 0) { |
|
|
|
// 提取数组中的第一个URL,并清理多余字符
|
|
|
|
url = avatarArray[0].trim() |
|
|
|
.replace(/^`/, '') // 移除开头的反引号
|
|
|
|
.replace(/`$/, '') // 移除结尾的反引号
|
|
|
|
.replace(/^"/, '') // 移除开头的引号
|
|
|
|
.replace(/"$/, ''); // 移除结尾的引号
|
|
|
|
} |
|
|
|
} catch (e) { |
|
|
|
// 如果不是JSON数组,直接使用,并清理多余字符
|
|
|
|
url = avatarData.trim() |
|
|
|
.replace(/^`/, '') // 移除开头的反引号
|
|
|
|
.replace(/`$/, '') // 移除结尾的反引号
|
|
|
|
.replace(/^"/, '') // 移除开头的引号
|
|
|
|
.replace(/"$/, ''); // 移除结尾的引号
|
|
|
|
} |
|
|
|
} |
|
|
|
return url; |
|
|
|
}(), |
|
|
|
score: score, // 使用数据库中的鸡蛋分,提取数字部分
|
|
|
|
isOnline: !!item.online, // 转换为布尔值
|
|
|
|
responsibleArea: item.responsible_area || '', // 使用数据库中的负责区域
|
|
|
|
@ -104,13 +155,22 @@ Page({ |
|
|
|
}; |
|
|
|
}); |
|
|
|
console.log('处理后的数据数量:', processedData.length); |
|
|
|
|
|
|
|
// 按鸡蛋分从高到低排序
|
|
|
|
processedData.sort((a, b) => { |
|
|
|
const scoreA = parseInt(a.score) || 0; |
|
|
|
const scoreB = parseInt(b.score) || 0; |
|
|
|
return scoreB - scoreA; |
|
|
|
}); |
|
|
|
|
|
|
|
console.log('排序后的数据:', processedData.map(item => ({ id: item.id, name: item.name, score: item.score }))); |
|
|
|
return processedData; |
|
|
|
} else { |
|
|
|
console.error('响应数据格式错误,不是预期的数组格式:', dataSource); |
|
|
|
return []; |
|
|
|
} |
|
|
|
} else { |
|
|
|
console.error('获取客服列表失败,状态码:', res?.statusCode, '响应数据:', res?.data); |
|
|
|
console.error('获取客服列表失败,响应数据无效:', res); |
|
|
|
return []; |
|
|
|
} |
|
|
|
} catch (error) { |
|
|
|
@ -284,11 +344,11 @@ Page({ |
|
|
|
}, |
|
|
|
|
|
|
|
onAreaFilter: function () { |
|
|
|
// 区域筛选弹窗 - 鸡蛋采购区域
|
|
|
|
// 区域筛选弹窗 - 使用用户要求的具体省份
|
|
|
|
wx.showActionSheet({ |
|
|
|
itemList: ['全部', '华北区', '华东区', '华南区', '全国', '西南区', '西北区', '东北区'], |
|
|
|
itemList: ['全部', '全国', '云南', '四川', '贵州', '广西'], |
|
|
|
success: res => { |
|
|
|
const areas = ['全部', '华北区', '华东区', '华南区', '全国', '西南区', '西北区', '东北区']; |
|
|
|
const areas = ['全部', '全国', '云南', '四川', '贵州', '广西']; |
|
|
|
const selectedArea = areas[res.tapIndex]; |
|
|
|
this.setData({ |
|
|
|
selectedArea: selectedArea |
|
|
|
@ -301,9 +361,8 @@ Page({ |
|
|
|
filterServices: function () { |
|
|
|
const { customerServices, searchKeyword, selectedArea } = this.data; |
|
|
|
|
|
|
|
// 首先进行关键词搜索
|
|
|
|
let filtered = customerServices; |
|
|
|
|
|
|
|
// 关键词搜索
|
|
|
|
if (searchKeyword) { |
|
|
|
const keyword = searchKeyword.toLowerCase(); |
|
|
|
filtered = filtered.filter(item => { |
|
|
|
@ -314,10 +373,33 @@ Page({ |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
// 区域筛选
|
|
|
|
// 然后进行区域筛选和排序
|
|
|
|
if (selectedArea && selectedArea !== '全部') { |
|
|
|
// 筛选出符合条件的客服
|
|
|
|
filtered = filtered.filter(item => { |
|
|
|
return item.responsibleArea?.includes(selectedArea); |
|
|
|
return item.responsibleArea?.includes(selectedArea) || item.responsibleArea?.includes('全国'); |
|
|
|
}); |
|
|
|
|
|
|
|
// 按所选地区优先排序
|
|
|
|
filtered.sort((a, b) => { |
|
|
|
// 优先显示所选地区的客服
|
|
|
|
const aHasSelectedArea = a.responsibleArea?.includes(selectedArea); |
|
|
|
const bHasSelectedArea = b.responsibleArea?.includes(selectedArea); |
|
|
|
|
|
|
|
if (aHasSelectedArea && !bHasSelectedArea) return -1; |
|
|
|
if (!aHasSelectedArea && bHasSelectedArea) return 1; |
|
|
|
|
|
|
|
// 同一地区的客服按鸡蛋分排序
|
|
|
|
const scoreA = parseInt(a.score) || 0; |
|
|
|
const scoreB = parseInt(b.score) || 0; |
|
|
|
return scoreB - scoreA; |
|
|
|
}); |
|
|
|
} else { |
|
|
|
// 全部区域时,按鸡蛋分排序
|
|
|
|
filtered.sort((a, b) => { |
|
|
|
const scoreA = parseInt(a.score) || 0; |
|
|
|
const scoreB = parseInt(b.score) || 0; |
|
|
|
return scoreB - scoreA; |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
|