order-confirm.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. <template>
  2. <view class="hotel-customer-theme oc-page">
  3. <!-- 配送信息 -->
  4. <view class="oc-section">
  5. <view class="oc-section-title">📋 配送信息</view>
  6. <view class="oc-info-line">
  7. <text class="oc-label">房间号</text>
  8. <text class="oc-value">{{ roomNo }} {{ roomTypeName }}</text>
  9. </view>
  10. <view class="oc-info-line">
  11. <text class="oc-label">联系人</text>
  12. <input class="oc-input" v-model="contactName" placeholder="请输入姓名" />
  13. </view>
  14. <view class="oc-info-line">
  15. <text class="oc-label">联系电话</text>
  16. <input class="oc-input" v-model="contactPhone" placeholder="请输入手机号" type="number" :maxlength="11" />
  17. </view>
  18. </view>
  19. <!-- 送达时间 -->
  20. <view class="oc-section">
  21. <view class="oc-section-title">🕐 送达时间</view>
  22. <view class="oc-time-options">
  23. <view
  24. v-for="opt in timeOptions"
  25. :key="opt.value"
  26. class="oc-time-opt"
  27. :class="{ 'oc-time-opt--active': deliveryTimeType === opt.value }"
  28. @click="deliveryTimeType = opt.value"
  29. >{{ opt.label }}</view>
  30. </view>
  31. <view class="oc-time-hint">预计 {{ estimatedTime }} 左右送达</view>
  32. </view>
  33. <!-- 订单明细 -->
  34. <view class="oc-section">
  35. <view class="oc-section-title">📝 订单明细</view>
  36. <view v-for="(item, i) in cartItems" :key="i" class="oc-dish-mini">
  37. <text class="oc-dm-name">{{ item.dishName }} ×{{ item.quantity }}</text>
  38. <text class="oc-dm-price">¥{{ (item.unitPrice * item.quantity).toFixed(2) }}</text>
  39. </view>
  40. <view v-if="cartItems.length && (cartItems[0].specs?.length || cartItems[0].additions?.length)"
  41. class="oc-dish-spec-line">
  42. {{ formatSpecs(cartItems[0]) }}
  43. </view>
  44. <view class="oc-divider" />
  45. <view class="oc-info-line">
  46. <text class="oc-label">配送费</text>
  47. <text class="oc-value" style="color: var(--h-succ);">
  48. {{ deliveryFee > 0 ? '¥' + deliveryFee : '免配送费' }}
  49. </text>
  50. </view>
  51. <view class="oc-total-bar">
  52. <text class="oc-total-label">合计</text>
  53. <text class="oc-total-price">¥{{ grandTotal }}</text>
  54. </view>
  55. </view>
  56. <!-- 提交按钮 -->
  57. <view class="oc-submit-btn" @click="submitOrder">确认支付 ¥{{ grandTotal }}</view>
  58. </view>
  59. </template>
  60. <script setup>
  61. import { computed, ref, onMounted } from 'vue'
  62. import { useHotelOrderStore } from '@/store'
  63. import api from '@/api'
  64. const orderStore = useHotelOrderStore()
  65. const roomNo = computed(() => orderStore.roomInfo?.roomNo || '')
  66. const roomTypeName = computed(() => orderStore.roomInfo?.roomTypeName || '')
  67. const cartItems = computed(() => orderStore.cartItems)
  68. const deliveryFee = computed(() => orderStore.deliveryFee)
  69. const grandTotal = computed(() => (orderStore.cartTotal + deliveryFee.value).toFixed(2))
  70. // 从 Store 读取授权信息,自动填入
  71. const contactName = ref(orderStore.contactName || '')
  72. const contactPhone = ref(orderStore.contactPhone || '')
  73. const deliveryTimeType = ref('ASAP')
  74. const submitting = ref(false)
  75. const timeOptions = [
  76. { label: '立即送达', value: 'ASAP' },
  77. { label: '30分钟后', value: 'DELAY_30' },
  78. { label: '1小时后', value: 'DELAY_60' },
  79. ]
  80. const estimatedTime = computed(() => {
  81. const now = new Date()
  82. let minutes = 25
  83. if (deliveryTimeType.value === 'DELAY_30') minutes = 55
  84. else if (deliveryTimeType.value === 'DELAY_60') minutes = 85
  85. now.setMinutes(now.getMinutes() + minutes)
  86. const h = String(now.getHours()).padStart(2, '0')
  87. const m = String(now.getMinutes()).padStart(2, '0')
  88. return `${h}:${m}`
  89. })
  90. function formatSpecs(item) {
  91. const parts = []
  92. if (item.specs?.length) parts.push(item.specs.map(s => s.optionName).join('·'))
  93. if (item.additions?.length) parts.push(item.additions.map(a => '+' + a.name).join('·'))
  94. return parts.join(' / ')
  95. }
  96. async function submitOrder() {
  97. if (!contactName.value.trim()) {
  98. uni.showToast({ title: '请输入联系人姓名', icon: 'none' })
  99. return
  100. }
  101. if (!contactPhone.value.trim() || contactPhone.value.length < 11) {
  102. uni.showToast({ title: '请输入正确的手机号', icon: 'none' })
  103. return
  104. }
  105. if (submitting.value) return
  106. submitting.value = true
  107. try {
  108. const orderData = {
  109. roomNo: orderStore.roomInfo?.roomNo,
  110. roomId: orderStore.roomInfo?.roomId,
  111. contactName: contactName.value,
  112. contactPhone: contactPhone.value,
  113. deliveryFee: deliveryFee.value,
  114. deliveryTimeType: deliveryTimeType.value,
  115. note: orderStore.orderNote,
  116. items: cartItems.value.map(item => ({
  117. dishId: item.dishId,
  118. dishName: item.dishName,
  119. specDesc: item.specs?.map(s => s.optionName).join('·') || '',
  120. additionsDesc: item.additions?.map(a => a.name).join('·') || '',
  121. quantity: item.quantity,
  122. unitPrice: item.unitPrice,
  123. subtotal: item.unitPrice * item.quantity,
  124. note: item.note || '',
  125. })),
  126. }
  127. const res = await api.hotelOrderCreate(orderData, orderStore.tenantId)
  128. const orderId = res?.data || res
  129. // 清空购物车(订单已创建,进入支付流程)
  130. orderStore.clearCart()
  131. // 跳转到支付页
  132. uni.redirectTo({
  133. url: `/pages/hotel/customer/pay?orderId=${orderId}&amount=${grandTotal.value}&orderNo=${orderData.roomNo}`,
  134. })
  135. } catch (err) {
  136. uni.showToast({ title: err?.message || '下单失败', icon: 'none' })
  137. } finally {
  138. submitting.value = false
  139. }
  140. }
  141. </script>
  142. <style lang="scss" scoped>
  143. .oc-page {
  144. min-height: 100vh;
  145. background: var(--h-bg, #F7F7F7);
  146. padding: 24rpx 28rpx;
  147. padding-bottom: calc(140rpx + env(safe-area-inset-bottom));
  148. }
  149. .oc-section {
  150. background: #fff;
  151. border-radius: var(--h-rad, 20rpx);
  152. padding: 28rpx 24rpx;
  153. margin-bottom: 20rpx;
  154. box-shadow: var(--h-shd, 0 2rpx 8rpx rgba(0, 0, 0, 0.04));
  155. }
  156. .oc-section-title {
  157. font-size: 28rpx;
  158. font-weight: 600;
  159. color: var(--h-pri, #2D5016);
  160. margin-bottom: 20rpx;
  161. padding-bottom: 16rpx;
  162. border-bottom: 1rpx solid var(--h-bdr-lt, #F5F5F5);
  163. }
  164. .oc-info-line {
  165. display: flex;
  166. justify-content: space-between;
  167. align-items: center;
  168. padding: 10rpx 0;
  169. font-size: 26rpx;
  170. }
  171. .oc-label {
  172. color: var(--h-txt-sub, #666);
  173. flex-shrink: 0;
  174. width: 160rpx;
  175. }
  176. .oc-value {
  177. color: var(--h-txt, #1A1A1A);
  178. font-weight: 500;
  179. }
  180. .oc-input {
  181. flex: 1;
  182. text-align: right;
  183. border: none;
  184. font-size: 26rpx;
  185. color: var(--h-txt, #1A1A1A);
  186. background: transparent;
  187. }
  188. /* 送达时间 */
  189. .oc-time-options {
  190. display: flex;
  191. flex-wrap: wrap;
  192. gap: 16rpx;
  193. }
  194. .oc-time-opt {
  195. padding: 16rpx 32rpx;
  196. border: 1rpx solid var(--h-bdr, #eee);
  197. border-radius: 40rpx;
  198. font-size: 24rpx;
  199. color: var(--h-txt-sub, #666);
  200. background: #fff;
  201. }
  202. .oc-time-opt--active {
  203. background: var(--h-acc-lt, #E8F0E3);
  204. border-color: var(--h-pri, #2D5016);
  205. color: var(--h-pri, #2D5016);
  206. font-weight: 600;
  207. }
  208. .oc-time-hint {
  209. font-size: 22rpx;
  210. color: var(--h-txt-light, #999);
  211. margin-top: 16rpx;
  212. }
  213. /* 订单明细 */
  214. .oc-dish-mini {
  215. display: flex;
  216. justify-content: space-between;
  217. padding: 8rpx 0;
  218. font-size: 26rpx;
  219. }
  220. .oc-dm-name {
  221. flex: 1;
  222. color: var(--h-txt, #1A1A1A);
  223. }
  224. .oc-dm-price {
  225. color: var(--h-txt-sub, #666);
  226. }
  227. .oc-dish-spec-line {
  228. font-size: 22rpx;
  229. color: var(--h-txt-light, #999);
  230. padding: 0 0 12rpx;
  231. }
  232. .oc-divider {
  233. border-top: 1rpx dashed var(--h-bdr, #eee);
  234. margin: 12rpx 0;
  235. }
  236. .oc-total-bar {
  237. display: flex;
  238. justify-content: space-between;
  239. align-items: center;
  240. padding-top: 8rpx;
  241. }
  242. .oc-total-label {
  243. font-size: 26rpx;
  244. color: var(--h-txt-sub, #666);
  245. }
  246. .oc-total-price {
  247. font-size: 44rpx;
  248. font-weight: 700;
  249. color: var(--h-warn, #D97706);
  250. }
  251. /* 提交按钮 */
  252. .oc-submit-btn {
  253. width: 100%;
  254. box-sizing: border-box;
  255. padding: 28rpx;
  256. border-radius: 48rpx;
  257. background: var(--h-pri, #2D5016);
  258. color: #fff;
  259. font-size: 30rpx;
  260. font-weight: 700;
  261. text-align: center;
  262. box-shadow: 0 8rpx 24rpx rgba(45, 80, 22, 0.3);
  263. margin-top: 8rpx;
  264. }
  265. .oc-submit-btn:active {
  266. opacity: 0.85;
  267. }
  268. </style>