storePicker.helpers.js 1.11 KB
/**
 * @file storePicker 纯逻辑 — confirm/toast 与 show 重置
 * 供全局 storePicker 合并 staffDaily 副本后单测。
 */

/**
 * 未选时的 toast 文案
 * @param {string|undefined} pickerType - 'merchant' | 'staff'
 * @returns {string}
 */
export function getConfirmToast(pickerType) {
  if (pickerType === 'staff') return '请选择员工'
  return '请选择门店'
}

/**
 * confirm 时是否额外 trigger search(operatingShow 默认 true)
 * @param {string|undefined} pickerType
 * @returns {boolean}
 */
export function shouldEmitSearchOnConfirm(pickerType) {
  return !pickerType
}

/**
 * show=true 时是否清空搜索并 emit search
 * @param {boolean} show
 * @returns {{ searchValue: string, shouldEmitSearch: boolean }|null}
 */
export function getShowResetSearchState(show) {
  if (!show) return null
  return { searchValue: '', shouldEmitSearch: true }
}

/**
 * 搜索 confirm 时是否重置 picker 选中索引为 0(staffDaily 行为)
 * @param {string} type - input 事件 type
 * @returns {boolean}
 */
export function shouldResetSelectOnSearchConfirm(type) {
  return type === 'confirm'
}