select.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. <template>
  2. <div class="buffet-select">
  3. <van-nav-bar :title="$t('buffet.select.title')" left-arrow @click-left="$router.back()" fixed placeholder />
  4. <div class="intro-banner">
  5. <van-icon name="fire-o" size="36" color="#ff6b6b" />
  6. <h2>{{ $t('buffet.select.subtitle') }}</h2>
  7. <p>{{ $t('buffet.select.description') }}</p>
  8. </div>
  9. <div class="plans-container">
  10. <div
  11. v-for="plan in activePlans"
  12. :key="plan.id"
  13. class="plan-option"
  14. :class="{ selected: selectedPlan === plan.id }"
  15. @click="selectPlan(plan)"
  16. >
  17. <div class="plan-badge" v-if="plan.duration >= 120">
  18. <van-tag type="danger">{{ $t('buffet.select.recommended') }}</van-tag>
  19. </div>
  20. <div class="plan-header">
  21. <h3>{{ plan.name }}</h3>
  22. <div class="plan-price">
  23. <span class="currency">¥</span>
  24. <span class="amount">{{ plan.price }}</span>
  25. <span class="unit">{{ $t('buffet.select.perPerson') }}</span>
  26. </div>
  27. </div>
  28. <div class="plan-duration">
  29. <van-icon name="clock-o" />
  30. <span>{{ plan.duration }}{{ $t('buffet.select.minutes') }}</span>
  31. </div>
  32. <div class="plan-description" v-if="plan.description">
  33. {{ plan.description }}
  34. </div>
  35. <div class="plan-features">
  36. <div class="feature-item">
  37. <van-icon name="success" color="#07c160" />
  38. <span>{{ $t('buffet.select.unlimitedOrder') }}</span>
  39. </div>
  40. <div class="feature-item" v-if="plan.maxOrders">
  41. <van-icon name="success" color="#07c160" />
  42. <span>{{ $t('buffet.select.maxOrders', { count: plan.maxOrders }) }}</span>
  43. </div>
  44. <div class="feature-item">
  45. <van-icon name="success" color="#07c160" />
  46. <span>{{ $t('buffet.select.drinksIncluded') }}</span>
  47. </div>
  48. </div>
  49. <van-icon name="checked" class="check-icon" v-if="selectedPlan === plan.id" />
  50. </div>
  51. </div>
  52. <div class="guest-selector">
  53. <div class="selector-label">{{ $t('buffet.select.guestCount') }}</div>
  54. <van-stepper v-model="guestCount" min="1" max="20" integer />
  55. </div>
  56. <div class="total-price">
  57. <div class="price-breakdown">
  58. <span>{{ $t('buffet.select.subtotal') }}</span>
  59. <span>¥{{ subtotal }}</span>
  60. </div>
  61. <div class="price-breakdown total">
  62. <span>{{ $t('buffet.select.total') }}</span>
  63. <span>¥{{ totalAmount }}</span>
  64. </div>
  65. </div>
  66. <div class="action-bar">
  67. <van-button type="primary" block round size="large" @click="confirmSelection" :disabled="!selectedPlan">
  68. {{ $t('buffet.select.startBuffet') }}
  69. </van-button>
  70. </div>
  71. </div>
  72. </template>
  73. <script setup lang="ts">
  74. import { ref, computed, onMounted } from 'vue'
  75. import { useRoute, useRouter } from 'vue-router'
  76. import { useI18n } from 'vue-i18n'
  77. import { showToast, showConfirmDialog } from 'vant'
  78. import { useBuffetStore, type BuffetPlan } from '@/store/modules/buffet'
  79. const { t } = useI18n()
  80. const route = useRoute()
  81. const router = useRouter()
  82. const buffetStore = useBuffetStore()
  83. const selectedPlan = ref('')
  84. const guestCount = ref(2)
  85. const activePlans = computed(() => buffetStore.activePlans)
  86. const selectedPlanData = computed(() =>
  87. activePlans.value.find(p => p.id === selectedPlan.value)
  88. )
  89. const subtotal = computed(() =>
  90. selectedPlanData.value ? selectedPlanData.value.price * guestCount.value : 0
  91. )
  92. const totalAmount = computed(() => subtotal.value)
  93. const selectPlan = (plan: BuffetPlan) => {
  94. selectedPlan.value = plan.id
  95. }
  96. const confirmSelection = async () => {
  97. if (!selectedPlanData.value) return
  98. try {
  99. await showConfirmDialog({
  100. title: t('buffet.select.confirmTitle'),
  101. message: t('buffet.select.confirmMessage', {
  102. plan: selectedPlanData.value.name,
  103. count: guestCount.value,
  104. amount: totalAmount.value
  105. })
  106. })
  107. // 获取桌位信息(从路由或store)
  108. const tableId = route.query.tableId as string || 'table_1'
  109. const tableName = route.query.tableName as string || 'A1'
  110. // 开始放题会话
  111. buffetStore.startSession(selectedPlanData.value, tableId, tableName)
  112. showToast(t('buffet.orderSuccess'))
  113. // 跳转到菜单页面
  114. router.push({
  115. path: '/menu',
  116. query: { buffet: '1' }
  117. })
  118. } catch {
  119. // 用户取消
  120. }
  121. }
  122. onMounted(() => {
  123. buffetStore.loadPlans()
  124. })
  125. </script>
  126. <style scoped>
  127. .buffet-select {
  128. min-height: 100vh;
  129. background: #f5f5f5;
  130. padding-bottom: 100px;
  131. }
  132. .intro-banner {
  133. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  134. color: #fff;
  135. text-align: center;
  136. padding: 30px 20px;
  137. }
  138. .intro-banner h2 {
  139. margin: 12px 0 8px;
  140. font-size: 22px;
  141. }
  142. .intro-banner p {
  143. margin: 0;
  144. font-size: 14px;
  145. opacity: 0.9;
  146. }
  147. .plans-container {
  148. padding: 16px 12px;
  149. }
  150. .plan-option {
  151. position: relative;
  152. background: #fff;
  153. border-radius: 16px;
  154. padding: 20px;
  155. margin-bottom: 16px;
  156. border: 2px solid transparent;
  157. transition: all 0.3s;
  158. cursor: pointer;
  159. }
  160. .plan-option.selected {
  161. border-color: #1989fa;
  162. box-shadow: 0 4px 12px rgba(25, 137, 250, 0.2);
  163. }
  164. .plan-badge {
  165. position: absolute;
  166. top: 12px;
  167. right: 12px;
  168. }
  169. .plan-header {
  170. display: flex;
  171. justify-content: space-between;
  172. align-items: center;
  173. margin-bottom: 12px;
  174. }
  175. .plan-header h3 {
  176. margin: 0;
  177. font-size: 18px;
  178. font-weight: bold;
  179. }
  180. .plan-price {
  181. display: flex;
  182. align-items: baseline;
  183. }
  184. .plan-price .currency {
  185. font-size: 14px;
  186. color: #ee0a24;
  187. }
  188. .plan-price .amount {
  189. font-size: 24px;
  190. font-weight: bold;
  191. color: #ee0a24;
  192. margin: 0 2px;
  193. }
  194. .plan-price .unit {
  195. font-size: 12px;
  196. color: #999;
  197. }
  198. .plan-duration {
  199. display: flex;
  200. align-items: center;
  201. gap: 4px;
  202. font-size: 14px;
  203. color: #666;
  204. margin-bottom: 12px;
  205. }
  206. .plan-description {
  207. font-size: 13px;
  208. color: #999;
  209. margin-bottom: 12px;
  210. line-height: 1.5;
  211. }
  212. .plan-features {
  213. display: flex;
  214. flex-wrap: wrap;
  215. gap: 12px;
  216. }
  217. .feature-item {
  218. display: flex;
  219. align-items: center;
  220. gap: 4px;
  221. font-size: 13px;
  222. color: #666;
  223. }
  224. .check-icon {
  225. position: absolute;
  226. bottom: 16px;
  227. right: 16px;
  228. font-size: 24px;
  229. color: #1989fa;
  230. }
  231. .guest-selector {
  232. background: #fff;
  233. display: flex;
  234. justify-content: space-between;
  235. align-items: center;
  236. padding: 16px;
  237. margin: 0 12px 16px;
  238. border-radius: 12px;
  239. }
  240. .selector-label {
  241. font-size: 15px;
  242. font-weight: 500;
  243. }
  244. .total-price {
  245. background: #fff;
  246. padding: 16px;
  247. margin: 0 12px 16px;
  248. border-radius: 12px;
  249. }
  250. .price-breakdown {
  251. display: flex;
  252. justify-content: space-between;
  253. font-size: 14px;
  254. margin-bottom: 8px;
  255. }
  256. .price-breakdown.total {
  257. font-size: 18px;
  258. font-weight: bold;
  259. color: #ee0a24;
  260. padding-top: 8px;
  261. border-top: 1px dashed #eee;
  262. margin-bottom: 0;
  263. }
  264. .action-bar {
  265. position: fixed;
  266. bottom: 0;
  267. left: 0;
  268. right: 0;
  269. background: #fff;
  270. padding: 12px 16px;
  271. box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.05);
  272. }
  273. </style>