orderAddFoodNavigate.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /**
  2. * 订单「去加餐」:携带桌台主键跳转点餐页,与 pages/orderInfo/index 列表逻辑一致。
  3. */
  4. import { go } from '@/utils/utils.js';
  5. const STORAGE_STORE_ID = 'currentStoreId';
  6. const STORAGE_TABLE_ID = 'currentTableId';
  7. /**
  8. * @param {object} order 订单对象(列表项或详情 orderDetail)
  9. */
  10. export function navigateToAddFood(order) {
  11. let tableid =
  12. order?.tableId ??
  13. order?.storeTableId ??
  14. order?.diningTableId ??
  15. '';
  16. let tid = tableid != null && tableid !== '' ? String(tableid).trim() : '';
  17. // 详情接口可能只回展示桌号、不回主键;与当前点餐桌一致时用本地桌台主键兜底
  18. if (!tid) {
  19. const cached = uni.getStorageSync(STORAGE_TABLE_ID);
  20. if (cached != null && String(cached).trim() !== '') {
  21. tid = String(cached).trim();
  22. }
  23. }
  24. if (!tid) {
  25. uni.showToast({ title: '订单缺少桌台信息,无法加餐', icon: 'none' });
  26. return;
  27. }
  28. const diners = order?.dinerCount ?? order?.diners ?? uni.getStorageSync('currentDiners') ?? '';
  29. const storeId = order?.storeId ?? '';
  30. if (storeId !== '' && storeId != null) {
  31. uni.setStorageSync(STORAGE_STORE_ID, String(storeId));
  32. }
  33. uni.setStorageSync(STORAGE_TABLE_ID, tid);
  34. const q = [
  35. `tableid=${encodeURIComponent(tid)}`,
  36. `tableId=${encodeURIComponent(tid)}`
  37. ];
  38. if (diners !== '' && diners != null) q.push(`diners=${encodeURIComponent(String(diners))}`);
  39. if (storeId !== '' && storeId != null) q.push(`storeId=${encodeURIComponent(String(storeId))}`);
  40. go(`/pages/orderFood/index?${q.join('&')}`, 'redirectTo');
  41. }