index.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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(2);
  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. const tableid = 1;
  51. const dinersVal = currentDiners.value;
  52. if (!userStore.getToken) {
  53. // 未登录:弹出手机号授权一键登录弹窗,登录成功后再跳转
  54. pendingNavigate.value = { tableid, dinersVal };
  55. showLoginModal.value = true;
  56. return;
  57. }
  58. go(`/pages/orderFood/index?tableid=${tableid}&diners=${dinersVal}`);
  59. };
  60. onLoad((e) => {
  61. // let currentDiners = uni.getStorageSync('currentDiners');
  62. // if (currentDiners) currentDiners.value = currentDiners;
  63. });
  64. </script>
  65. <style lang="scss" scoped>
  66. .title {
  67. font-size: 32rpx;
  68. font-weight: bold;
  69. text-align: center;
  70. margin-bottom: 20rpx;
  71. margin-top: 60rpx;
  72. }
  73. .number-list {
  74. display: flex;
  75. flex-wrap: wrap;
  76. justify-content: center;
  77. align-items: center;
  78. gap: 20rpx;
  79. margin-top: 60rpx;
  80. .number-item {
  81. width: 160rpx;
  82. height: 160rpx;
  83. background-color: #f0f0f0;
  84. border-radius: 8rpx;
  85. display: flex;
  86. justify-content: center;
  87. align-items: center;
  88. font-size: 32rpx;
  89. transition: all 0.3s ease;
  90. &.current {
  91. background: linear-gradient(180deg, #FCB73F 0%, #FC743D 100%);
  92. color: #fff;
  93. box-shadow: 0 8rpx 24rpx rgba(252, 183, 63, 0.4);
  94. }
  95. &.hover-active {
  96. opacity: 0.8;
  97. }
  98. }
  99. }
  100. .more-number {
  101. font-size: 28rpx;
  102. color: #aaa;
  103. text-align: center;
  104. margin-top: 20rpx;
  105. margin-top: 30rpx;
  106. }
  107. .confirm-button {
  108. width: 90%;
  109. height: 80rpx;
  110. background: linear-gradient(180deg, #FCB73F 0%, #FC743D 100%);
  111. color: #fff;
  112. text-align: center;
  113. line-height: 80rpx;
  114. border-radius: 24rpx;
  115. position: fixed;
  116. bottom: 80rpx;
  117. left: 50%;
  118. transform: translateX(-50%);
  119. font-size: 32rpx;
  120. }
  121. </style>