index.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. // 登录成功后要跳转的点餐页参数(手机号授权完成后再跳转)
  31. const pendingNavigate = ref(null);
  32. const addDiners = () => {
  33. diners.value = 16
  34. };
  35. const selectDiners = (item) => {
  36. currentDiners.value = item;
  37. };
  38. // 手机号授权登录成功:再跳转点餐页
  39. const handleLoginSuccess = () => {
  40. if (pendingNavigate.value) {
  41. const { tableid, dinersVal } = pendingNavigate.value;
  42. pendingNavigate.value = null;
  43. go(`/pages/orderFood/index?tableid=${tableid}&diners=${dinersVal}`);
  44. }
  45. };
  46. const handleLoginCancel = () => {
  47. pendingNavigate.value = null;
  48. };
  49. const toOrderFood = () => {
  50. uni.setStorageSync('currentDiners', currentDiners.value);
  51. // 桌号来自二维码缓存(App 启动时 s=店铺id t=桌号id 已写入 currentTableId)
  52. const tableid = uni.getStorageSync('currentTableId') || '';
  53. const dinersVal = currentDiners.value;
  54. if (tableid) uni.setStorageSync('currentTableId', String(tableid));
  55. if (!userStore.getToken) {
  56. // 未登录:弹出手机号授权一键登录弹窗,登录成功后再跳转
  57. pendingNavigate.value = { tableid, dinersVal };
  58. showLoginModal.value = true;
  59. return;
  60. }
  61. uni.reLaunch({
  62. url: `/pages/orderFood/index?tableid=${tableid}&diners=${dinersVal}`
  63. });
  64. }
  65. onLoad(async (e) => {
  66. const tableid = uni.getStorageSync('currentTableId') || '';
  67. if (!tableid) return;
  68. try {
  69. const res = await diningApi.GetTableDiningStatus(tableid);
  70. const raw = (res && typeof res === 'object') ? res : {};
  71. const inDining = raw?.inDining === true;
  72. const dinerCount = raw?.dinerCount ?? raw?.diner ?? uni.getStorageSync('currentDiners') ?? 1;
  73. if (inDining) {
  74. uni.setStorageSync('currentDiners', dinerCount);
  75. uni.reLaunch({
  76. url: `/pages/orderFood/index?tableid=${encodeURIComponent(tableid)}&diners=${encodeURIComponent(dinerCount)}`
  77. });
  78. return;
  79. }
  80. } catch (err) {
  81. console.warn('查询桌位就餐状态失败,按正常流程', err);
  82. }
  83. });
  84. </script>
  85. <style lang="scss" scoped>
  86. .title {
  87. font-size: 32rpx;
  88. font-weight: bold;
  89. text-align: center;
  90. margin-bottom: 20rpx;
  91. margin-top: 60rpx;
  92. }
  93. .number-list {
  94. display: flex;
  95. flex-wrap: wrap;
  96. justify-content: center;
  97. align-items: center;
  98. gap: 20rpx;
  99. margin-top: 60rpx;
  100. .number-item {
  101. width: 160rpx;
  102. height: 160rpx;
  103. background-color: #f0f0f0;
  104. border-radius: 8rpx;
  105. display: flex;
  106. justify-content: center;
  107. align-items: center;
  108. font-size: 32rpx;
  109. transition: all 0.3s ease;
  110. &.current {
  111. background: linear-gradient(180deg, #FCB73F 0%, #FC743D 100%);
  112. color: #fff;
  113. box-shadow: 0 8rpx 24rpx rgba(252, 183, 63, 0.4);
  114. }
  115. &.hover-active {
  116. opacity: 0.8;
  117. }
  118. }
  119. }
  120. .more-number {
  121. font-size: 28rpx;
  122. color: #aaa;
  123. text-align: center;
  124. margin-top: 20rpx;
  125. margin-top: 30rpx;
  126. }
  127. .confirm-button {
  128. width: 90%;
  129. height: 80rpx;
  130. background: linear-gradient(180deg, #FCB73F 0%, #FC743D 100%);
  131. color: #fff;
  132. text-align: center;
  133. line-height: 80rpx;
  134. border-radius: 24rpx;
  135. position: fixed;
  136. bottom: 80rpx;
  137. left: 50%;
  138. transform: translateX(-50%);
  139. font-size: 32rpx;
  140. }
  141. </style>