index.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. pendingNavigate.value = null;
  44. go('/pages/diningInfo/index');
  45. }
  46. };
  47. const handleLoginCancel = () => {
  48. pendingNavigate.value = null;
  49. };
  50. const toOrderFood = () => {
  51. uni.setStorageSync('currentDiners', currentDiners.value);
  52. // 桌号来自二维码缓存(App 启动时 s=店铺id t=桌号id 已写入 currentTableId)
  53. const tableid = uni.getStorageSync('currentTableId') || '';
  54. const dinersVal = currentDiners.value;
  55. if (tableid) uni.setStorageSync('currentTableId', String(tableid));
  56. const token = userStore.getToken || uni.getStorageSync(TOKEN) || '';
  57. if (!token) {
  58. // 未登录:弹出手机号授权一键登录弹窗,登录成功后再跳转就餐信息页
  59. pendingNavigate.value = { tableid, dinersVal };
  60. showLoginModal.value = true;
  61. return;
  62. }
  63. uni.navigateTo({
  64. url: '/pages/diningInfo/index'
  65. });
  66. }
  67. // 页面加载时仅同步参数到 storage,不自动弹出登录框;未登录时只能在点击「确定」时弹出登录框
  68. onLoad((options) => {
  69. const tableid = options?.tableid || uni.getStorageSync('currentTableId') || '';
  70. const dinersVal = options?.diners || uni.getStorageSync('currentDiners') || 1;
  71. if (tableid) uni.setStorageSync('currentTableId', tableid);
  72. if (dinersVal) {
  73. uni.setStorageSync('currentDiners', dinersVal);
  74. currentDiners.value = Number(dinersVal) || 1;
  75. }
  76. });
  77. </script>
  78. <style lang="scss" scoped>
  79. .title {
  80. font-size: 32rpx;
  81. font-weight: bold;
  82. text-align: center;
  83. margin-bottom: 20rpx;
  84. margin-top: 60rpx;
  85. }
  86. .number-list {
  87. display: flex;
  88. flex-wrap: wrap;
  89. justify-content: center;
  90. align-items: center;
  91. gap: 20rpx;
  92. margin-top: 60rpx;
  93. .number-item {
  94. width: 160rpx;
  95. height: 160rpx;
  96. background-color: #f0f0f0;
  97. border-radius: 8rpx;
  98. display: flex;
  99. justify-content: center;
  100. align-items: center;
  101. font-size: 32rpx;
  102. transition: all 0.3s ease;
  103. &.current {
  104. background: linear-gradient(180deg, #FCB73F 0%, #FC743D 100%);
  105. color: #fff;
  106. box-shadow: 0 8rpx 24rpx rgba(252, 183, 63, 0.4);
  107. }
  108. &.hover-active {
  109. opacity: 0.8;
  110. }
  111. }
  112. }
  113. .more-number {
  114. font-size: 28rpx;
  115. color: #aaa;
  116. text-align: center;
  117. margin-top: 20rpx;
  118. margin-top: 30rpx;
  119. }
  120. .confirm-button {
  121. width: 90%;
  122. height: 80rpx;
  123. background: linear-gradient(180deg, #FCB73F 0%, #FC743D 100%);
  124. color: #fff;
  125. text-align: center;
  126. line-height: 80rpx;
  127. border-radius: 24rpx;
  128. position: fixed;
  129. bottom: 80rpx;
  130. left: 50%;
  131. transform: translateX(-50%);
  132. font-size: 32rpx;
  133. z-index: 100;
  134. }
  135. /* 登录弹窗层级(与 index 一致,确保弹窗可显示) */
  136. .login-modal-wrapper {
  137. position: relative;
  138. z-index: 99999;
  139. :deep(.uni-popup) {
  140. z-index: 99999 !important;
  141. top: 0 !important;
  142. left: 0 !important;
  143. right: 0 !important;
  144. bottom: 0 !important;
  145. }
  146. :deep(.uni-popup__wrapper) {
  147. z-index: 99999 !important;
  148. }
  149. }
  150. </style>