index.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. // 页面加载时仅同步参数到 storage,不自动弹出登录框;未登录时只能在点击「确定」时弹出登录框
  69. onLoad((options) => {
  70. const tableid = options?.tableid || uni.getStorageSync('currentTableId') || '';
  71. const dinersVal = options?.diners || uni.getStorageSync('currentDiners') || 1;
  72. if (tableid) uni.setStorageSync('currentTableId', tableid);
  73. if (dinersVal) {
  74. uni.setStorageSync('currentDiners', dinersVal);
  75. currentDiners.value = Number(dinersVal) || 1;
  76. }
  77. });
  78. </script>
  79. <style lang="scss" scoped>
  80. .title {
  81. font-size: 32rpx;
  82. font-weight: bold;
  83. text-align: center;
  84. margin-bottom: 20rpx;
  85. margin-top: 60rpx;
  86. }
  87. .number-list {
  88. display: flex;
  89. flex-wrap: wrap;
  90. justify-content: center;
  91. align-items: center;
  92. gap: 20rpx;
  93. margin-top: 60rpx;
  94. .number-item {
  95. width: 160rpx;
  96. height: 160rpx;
  97. background-color: #f0f0f0;
  98. border-radius: 8rpx;
  99. display: flex;
  100. justify-content: center;
  101. align-items: center;
  102. font-size: 32rpx;
  103. transition: all 0.3s ease;
  104. &.current {
  105. background: linear-gradient(180deg, #FCB73F 0%, #FC743D 100%);
  106. color: #fff;
  107. box-shadow: 0 8rpx 24rpx rgba(252, 183, 63, 0.4);
  108. }
  109. &.hover-active {
  110. opacity: 0.8;
  111. }
  112. }
  113. }
  114. .more-number {
  115. font-size: 28rpx;
  116. color: #aaa;
  117. text-align: center;
  118. margin-top: 20rpx;
  119. margin-top: 30rpx;
  120. }
  121. .confirm-button {
  122. width: 90%;
  123. height: 80rpx;
  124. background: linear-gradient(180deg, #FCB73F 0%, #FC743D 100%);
  125. color: #fff;
  126. text-align: center;
  127. line-height: 80rpx;
  128. border-radius: 24rpx;
  129. position: fixed;
  130. bottom: 80rpx;
  131. left: 50%;
  132. transform: translateX(-50%);
  133. font-size: 32rpx;
  134. z-index: 100;
  135. }
  136. /* 登录弹窗层级(与 index 一致,确保弹窗可显示) */
  137. .login-modal-wrapper {
  138. position: relative;
  139. z-index: 99999;
  140. :deep(.uni-popup) {
  141. z-index: 99999 !important;
  142. top: 0 !important;
  143. left: 0 !important;
  144. right: 0 !important;
  145. bottom: 0 !important;
  146. }
  147. :deep(.uni-popup__wrapper) {
  148. z-index: 99999 !important;
  149. }
  150. }
  151. </style>