index.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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" @click="toOrderFood" hover-class="hover-active">确定</view>
  15. <!-- 未登录时弹出:手机号授权一键登录 -->
  16. <LoginModal v-model:open="showLoginModal" @success="handleLoginSuccess" @cancel="handleLoginCancel" />
  17. </view>
  18. </template>
  19. <script setup>
  20. import { onLoad } from "@dcloudio/uni-app";
  21. import { ref } from "vue";
  22. import { go } from "@/utils/utils.js";
  23. import { useUserStore } from "@/store/user.js";
  24. import LoginModal from "@/pages/components/LoginModal.vue";
  25. import * as diningApi from "@/api/dining.js";
  26. const userStore = useUserStore();
  27. const diners = ref(12);
  28. const currentDiners = ref(1);
  29. const showLoginModal = ref(false);
  30. const checking = ref(false); // 是否正在查询桌位就餐状态
  31. // 登录成功后要跳转的点餐页参数(手机号授权完成后再跳转)
  32. const pendingNavigate = ref(null);
  33. const addDiners = () => {
  34. diners.value = 16
  35. };
  36. const selectDiners = (item) => {
  37. currentDiners.value = item;
  38. };
  39. // 手机号授权登录成功:再跳转点餐页
  40. const handleLoginSuccess = () => {
  41. if (pendingNavigate.value) {
  42. const { tableid, dinersVal } = pendingNavigate.value;
  43. pendingNavigate.value = null;
  44. go(`/pages/orderFood/index?tableid=${tableid}&diners=${dinersVal}`);
  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. if (!userStore.getToken) {
  57. // 未登录:弹出手机号授权一键登录弹窗,登录成功后再跳转
  58. pendingNavigate.value = { tableid, dinersVal };
  59. showLoginModal.value = true;
  60. return;
  61. }
  62. uni.reLaunch({
  63. url: `/pages/orderFood/index?tableid=${tableid}&diners=${dinersVal}`
  64. });
  65. }
  66. // 接口由 App.vue 统一调用;App.vue 在 inDining 为 true 且未登录时会重定向到本页并带 inDining=1,此时需弹出登录
  67. onLoad((options) => {
  68. const inDining = options?.inDining === '1' || options?.inDining === 1;
  69. const tableid = options?.tableid || uni.getStorageSync('currentTableId') || '';
  70. const dinersVal = options?.diners || uni.getStorageSync('currentDiners') || 1;
  71. if (inDining && tableid && !userStore.getToken) {
  72. uni.setStorageSync('currentTableId', tableid);
  73. uni.setStorageSync('currentDiners', dinersVal);
  74. pendingNavigate.value = { tableid, dinersVal };
  75. showLoginModal.value = true;
  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. }
  135. </style>