index.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <template>
  2. <!-- 扫码点餐-选择就餐人数 -->
  3. <view class="content">
  4. <view class="title">请选择就餐人数</view>
  5. <view class="number-list">
  6. <view class="number-item" :class="{ 'current': currentDiners === item }" v-for="item in diners" :key="item"
  7. @click="selectDiners(item)" hover-class="hover-active">
  8. <view class="number-item-content">
  9. <view class="number-item-content-title">{{ item }}</view>
  10. </view>
  11. </view>
  12. </view>
  13. <view class="more-number" @click="addDiners" v-if="diners < 16">查看更多</view>
  14. <view class="confirm-button" @tap.stop="toOrderFood" hover-class="hover-active">确定</view>
  15. <!-- 未登录时弹出:手机号授权一键登录(需高 z-index 盖住其他内容) -->
  16. <view class="login-modal-wrapper">
  17. <LoginModal v-model:open="showLoginModal" @success="handleLoginSuccess" @cancel="handleLoginCancel" />
  18. </view>
  19. </view>
  20. </template>
  21. <script setup>
  22. import { onLoad } from "@dcloudio/uni-app";
  23. import { ref } from "vue";
  24. import { useUserStore } from "@/store/user.js";
  25. import LoginModal from "@/pages/components/LoginModal.vue";
  26. import { TOKEN } from "@/settings/enums.js";
  27. const userStore = useUserStore();
  28. const diners = ref(12);
  29. const currentDiners = ref(1);
  30. const showLoginModal = ref(false);
  31. // 登录成功后进入点餐页所需参数(手机号授权完成后再 navigate)
  32. const pendingNavigate = ref(null);
  33. const addDiners = () => {
  34. diners.value = 16
  35. };
  36. const selectDiners = (item) => {
  37. currentDiners.value = item;
  38. };
  39. /** 本版本不上预约:选完人数直接进入点餐页 */
  40. function navigateToOrderFood(tableid, dinersVal) {
  41. const q = [];
  42. if (tableid) q.push(`tableid=${encodeURIComponent(String(tableid))}`);
  43. q.push(`diners=${encodeURIComponent(String(dinersVal ?? currentDiners.value))}`);
  44. uni.navigateTo({
  45. url: `/pages/orderFood/index?${q.join('&')}`
  46. });
  47. }
  48. // 手机号授权登录成功:本版本不上预约,原「就餐信息页 diningInfo」流程已注释
  49. const handleLoginSuccess = () => {
  50. const pending = pendingNavigate.value;
  51. pendingNavigate.value = null;
  52. if (!pending) return;
  53. const { tableid, dinersVal } = pending;
  54. navigateToOrderFood(tableid, dinersVal);
  55. // go('/pages/diningInfo/index');
  56. };
  57. const handleLoginCancel = () => {
  58. pendingNavigate.value = null;
  59. };
  60. const toOrderFood = () => {
  61. uni.setStorageSync('currentDiners', currentDiners.value);
  62. // 桌号来自二维码缓存(App 启动时 s=店铺id t=桌号id 已写入 currentTableId)
  63. const tableid = uni.getStorageSync('currentTableId') || '';
  64. const dinersVal = currentDiners.value;
  65. if (tableid) uni.setStorageSync('currentTableId', String(tableid));
  66. const token = userStore.getToken || uni.getStorageSync(TOKEN) || '';
  67. if (!token) {
  68. // 未登录:授权成功后与已登录一致,直接进入点餐页(不上预约 / diningInfo)
  69. pendingNavigate.value = { tableid, dinersVal };
  70. showLoginModal.value = true;
  71. return;
  72. }
  73. // 本版本不上预约:不到 diningInfo,选毕人数直接去点餐
  74. // uni.navigateTo({ url: '/pages/diningInfo/index' });
  75. navigateToOrderFood(tableid, dinersVal);
  76. }
  77. // 页面加载时仅同步参数到 storage,不自动弹出登录框;未登录时只能在点击「确定」时弹出登录框
  78. onLoad((options) => {
  79. const tableid = options?.tableid || uni.getStorageSync('currentTableId') || '';
  80. const dinersVal = options?.diners || uni.getStorageSync('currentDiners') || 1;
  81. if (tableid) uni.setStorageSync('currentTableId', tableid);
  82. if (dinersVal) {
  83. uni.setStorageSync('currentDiners', dinersVal);
  84. currentDiners.value = Number(dinersVal) || 1;
  85. }
  86. });
  87. </script>
  88. <style lang="scss" scoped>
  89. .title {
  90. font-size: 32rpx;
  91. font-weight: bold;
  92. text-align: center;
  93. margin-bottom: 20rpx;
  94. margin-top: 60rpx;
  95. }
  96. .number-list {
  97. display: flex;
  98. flex-wrap: wrap;
  99. justify-content: center;
  100. align-items: center;
  101. gap: 20rpx;
  102. margin-top: 60rpx;
  103. .number-item {
  104. width: 160rpx;
  105. height: 160rpx;
  106. background-color: #f0f0f0;
  107. border-radius: 8rpx;
  108. display: flex;
  109. justify-content: center;
  110. align-items: center;
  111. font-size: 32rpx;
  112. transition: all 0.3s ease;
  113. &.current {
  114. background: linear-gradient(180deg, #FCB73F 0%, #FC743D 100%);
  115. color: #fff;
  116. box-shadow: 0 8rpx 24rpx rgba(252, 183, 63, 0.4);
  117. }
  118. &.hover-active {
  119. opacity: 0.8;
  120. }
  121. }
  122. }
  123. .more-number {
  124. font-size: 28rpx;
  125. color: #aaa;
  126. text-align: center;
  127. margin-top: 20rpx;
  128. margin-top: 30rpx;
  129. }
  130. .confirm-button {
  131. width: 90%;
  132. height: 80rpx;
  133. background: linear-gradient(180deg, #FCB73F 0%, #FC743D 100%);
  134. color: #fff;
  135. text-align: center;
  136. line-height: 80rpx;
  137. border-radius: 24rpx;
  138. position: fixed;
  139. bottom: 80rpx;
  140. left: 50%;
  141. transform: translateX(-50%);
  142. font-size: 32rpx;
  143. z-index: 100;
  144. }
  145. /* 登录弹窗层级(与 index 一致,确保弹窗可显示) */
  146. .login-modal-wrapper {
  147. position: relative;
  148. z-index: 99999;
  149. :deep(.uni-popup) {
  150. z-index: 99999 !important;
  151. top: 0 !important;
  152. left: 0 !important;
  153. right: 0 !important;
  154. bottom: 0 !important;
  155. }
  156. :deep(.uni-popup__wrapper) {
  157. z-index: 99999 !important;
  158. }
  159. }
  160. </style>