index.vue 3.7 KB

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