campus-errand/miniapp/utils/chat-rules.js
2026-03-12 18:12:10 +08:00

57 lines
1.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 聊天页业务规则纯函数
* 提取自 chat.vue用于属性测试
*/
/**
* 获取聊天页应显示的对方手机号
* 单主看到跑腿认证手机号,跑腿看到单主下单手机号
*
* @param {Object} params
* @param {number} params.currentUserId - 当前用户 ID
* @param {number} params.ownerId - 单主用户 ID
* @param {number|null} params.runnerId - 跑腿用户 ID
* @param {string} params.ownerPhone - 单主下单手机号
* @param {string} params.runnerPhone - 跑腿认证手机号
* @returns {string} 应显示的手机号
*/
export function getChatTargetPhone({ currentUserId, ownerId, runnerId, ownerPhone, runnerPhone }) {
if (currentUserId === ownerId) {
// 当前用户是单主,显示跑腿认证手机号
return runnerPhone || ''
}
if (currentUserId === runnerId) {
// 当前用户是跑腿,显示单主下单手机号
return ownerPhone || ''
}
return ''
}
/**
* 获取聊天页更多功能按钮列表
* - 所有订单显示:发送图片、更改跑腿价格
* - 代购和美食街订单额外显示:更改商品价格
* - 仅跑腿用户可见:完成订单
*
* @param {Object} params
* @param {string} params.orderType - 订单类型Pickup, Delivery, Help, Purchase, Food
* @param {number} params.currentUserId - 当前用户 ID
* @param {number|null} params.runnerId - 跑腿用户 ID
* @returns {string[]} 按钮名称列表
*/
export function getChatMenuButtons({ orderType, currentUserId, runnerId }) {
const buttons = ['发送图片', '更改跑腿价格']
// 代购和美食街订单额外显示更改商品价格
if (orderType === 'Purchase' || orderType === 'Food') {
buttons.push('更改商品价格')
}
// 仅跑腿用户可见完成订单
if (currentUserId === runnerId && runnerId != null) {
buttons.push('完成订单')
}
return buttons
}