index.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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 { go } from "@/utils/utils.js";
  25. import { useUserStore } from "@/store/user.js";
  26. import LoginModal from "@/pages/components/LoginModal.vue";
  27. import { TOKEN } from "@/settings/enums.js";
  28. const userStore = useUserStore();
  29. const diners = ref(12);
  30. const currentDiners = ref(1);
  31. const showLoginModal = ref(false);
  32. // 登录成功后要跳转的点餐页参数(手机号授权完成后再跳转)
  33. const pendingNavigate = ref(null);
  34. const addDiners = () => {
  35. diners.value = 16
  36. };
  37. const selectDiners = (item) => {
  38. currentDiners.value = item;
  39. };
  40. // 手机号授权登录成功:再跳转点餐页
  41. const handleLoginSuccess = () => {
  42. if (pendingNavigate.value) {
  43. const { tableid, dinersVal } = pendingNavigate.value;
  44. pendingNavigate.value = null;
  45. go(`/pages/orderFood/index?tableid=${tableid}&diners=${dinersVal}`);
  46. }
  47. };
  48. const handleLoginCancel = () => {
  49. pendingNavigate.value = null;
  50. };
  51. const toOrderFood = () => {
  52. uni.setStorageSync('currentDiners', currentDiners.value);
  53. // 桌号来自二维码缓存(App 启动时 s=店铺id t=桌号id 已写入 currentTableId)
  54. const tableid = uni.getStorageSync('currentTableId') || '';
  55. const dinersVal = currentDiners.value;
  56. if (tableid) uni.setStorageSync('currentTableId', String(tableid));
  57. const token = userStore.getToken || uni.getStorageSync(TOKEN) || '';
  58. if (!token) {
  59. // 未登录:弹出手机号授权一键登录弹窗,登录成功后再跳转
  60. pendingNavigate.value = { tableid, dinersVal };
  61. showLoginModal.value = true;
  62. return;
  63. }
  64. uni.reLaunch({
  65. url: `/pages/orderFood/index?tableid=${tableid}&diners=${dinersVal}`
  66. });
  67. }
  68. // 接口由 App.vue 统一调用;App.vue 在 inDining 为 true 且未登录时会重定向到本页并带 inDining=1,此时需弹出登录
  69. onLoad((options) => {
  70. const inDining = options?.inDining === '1' || options?.inDining === 1;
  71. const tableid = options?.tableid || uni.getStorageSync('currentTableId') || '';
  72. const dinersVal = options?.diners || uni.getStorageSync('currentDiners') || 1;
  73. const token = userStore.getToken || uni.getStorageSync(TOKEN) || '';
  74. if (inDining && tableid && !token) {
  75. uni.setStorageSync('currentTableId', tableid);
  76. uni.setStorageSync('currentDiners', dinersVal);
  77. pendingNavigate.value = { tableid, dinersVal };
  78. showLoginModal.value = true;
  79. }
  80. });
  81. </script>
  82. <style lang="scss" scoped>
  83. .title {
  84. font-size: 32rpx;
  85. font-weight: bold;
  86. text-align: center;
  87. margin-bottom: 20rpx;
  88. margin-top: 60rpx;
  89. }
  90. .number-list {
  91. display: flex;
  92. flex-wrap: wrap;
  93. justify-content: center;
  94. align-items: center;
  95. gap: 20rpx;
  96. margin-top: 60rpx;
  97. .number-item {
  98. width: 160rpx;
  99. height: 160rpx;
  100. background-color: #f0f0f0;
  101. border-radius: 8rpx;
  102. display: flex;
  103. justify-content: center;
  104. align-items: center;
  105. font-size: 32rpx;
  106. transition: all 0.3s ease;
  107. &.current {
  108. background: linear-gradient(180deg, #FCB73F 0%, #FC743D 100%);
  109. color: #fff;
  110. box-shadow: 0 8rpx 24rpx rgba(252, 183, 63, 0.4);
  111. }
  112. &.hover-active {
  113. opacity: 0.8;
  114. }
  115. }
  116. }
  117. .more-number {
  118. font-size: 28rpx;
  119. color: #aaa;
  120. text-align: center;
  121. margin-top: 20rpx;
  122. margin-top: 30rpx;
  123. }
  124. .confirm-button {
  125. width: 90%;
  126. height: 80rpx;
  127. background: linear-gradient(180deg, #FCB73F 0%, #FC743D 100%);
  128. color: #fff;
  129. text-align: center;
  130. line-height: 80rpx;
  131. border-radius: 24rpx;
  132. position: fixed;
  133. bottom: 80rpx;
  134. left: 50%;
  135. transform: translateX(-50%);
  136. font-size: 32rpx;
  137. z-index: 100;
  138. }
  139. /* 登录弹窗层级(与 index 一致,确保弹窗可显示) */
  140. .login-modal-wrapper {
  141. position: relative;
  142. z-index: 99999;
  143. :deep(.uni-popup) {
  144. z-index: 99999 !important;
  145. top: 0 !important;
  146. left: 0 !important;
  147. right: 0 !important;
  148. bottom: 0 !important;
  149. }
  150. :deep(.uni-popup__wrapper) {
  151. z-index: 99999 !important;
  152. }
  153. }
  154. </style>