orderDetail.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  1. <template>
  2. <!-- 订单详情页面 -->
  3. <view class="content">
  4. <!-- 菜品清单 -->
  5. <view class="card">
  6. <!-- 店铺信息 -->
  7. <view class="store-info">
  8. <view class="store-info-title">{{ orderDetail.storeName || '店铺名称' }}</view>
  9. <view class="store-info-address">{{ orderDetail.storeAddress || '—' }}</view>
  10. </view>
  11. <view class="card-header">
  12. <view class="card-header-title">菜品详情</view>
  13. </view>
  14. <view class="card-content">
  15. <view class="info-food">
  16. <view v-for="(item, index) in displayFoodList" :key="item.id || index" class="food-item">
  17. <!-- 菜品图片 -->
  18. <image :src="getFileUrl(item.image)" mode="aspectFill" class="food-item__image"></image>
  19. <!-- 菜品信息 -->
  20. <view class="food-item__info">
  21. <view class="food-item__name">{{ item.name }}</view>
  22. <view class="food-item__desc" v-if="item.tags && item.tags.length > 0">
  23. <text v-for="(tag, tagIndex) in item.tags" :key="tagIndex" class="food-item__tag">
  24. {{ tag.text }}<text v-if="tagIndex < item.tags.length - 1">,</text>
  25. </text>
  26. </view>
  27. </view>
  28. <!-- 价格和数量 -->
  29. <view class="food-item__right">
  30. <view class="food-item__price">
  31. <text class="price-main">¥{{ formatPrice(item.price) }}</text>
  32. </view>
  33. <view class="food-item__quantity">{{ item.quantity || 1 }}份</view>
  34. </view>
  35. </view>
  36. </view>
  37. </view>
  38. <view class="card-header">
  39. <view class="card-header-title">价格明细</view>
  40. </view>
  41. <view class="card-content">
  42. <view class="info-item">
  43. <view class="info-item-label">菜品总价</view>
  44. <view class="info-item-value">¥{{ priceDetail.dishTotal }}</view>
  45. </view>
  46. <view class="info-item">
  47. <view class="info-item-label">餐具费</view>
  48. <view class="info-item-value">¥{{ priceDetail.tablewareFee }}</view>
  49. </view>
  50. <view class="info-item">
  51. <view class="info-item-label">优惠券</view>
  52. <view class="info-item-value">¥{{ priceDetail.couponDiscount }}</view>
  53. </view>
  54. <view class="price-line">
  55. <view class="price-line-label">合计</view>
  56. <view class="price-line-value">¥{{ priceDetail.total }}</view>
  57. </view>
  58. </view>
  59. </view>
  60. <!-- 订单卡片 -->
  61. <view class="card">
  62. <view class="card-header">
  63. <view class="card-header-title">订单信息</view>
  64. </view>
  65. <view class="card-content">
  66. <view class="info-item">
  67. <view class="info-item-label">订单编号</view>
  68. <view class="info-item-value">{{ orderDetail.orderNo || '—' }}</view>
  69. </view>
  70. <view class="info-item">
  71. <view class="info-item-label">就餐桌号</view>
  72. <view class="info-item-value">{{ orderDetail.tableNo || '—' }}</view>
  73. </view>
  74. <view class="info-item">
  75. <view class="info-item-label">用餐人数</view>
  76. <view class="info-item-value">{{ orderDetail.dinerCount ?? '—' }}</view>
  77. </view>
  78. <view class="info-item">
  79. <view class="info-item-label">下单时间</view>
  80. <view class="info-item-value">{{ orderDetail.createTime || '—' }}</view>
  81. </view>
  82. <view class="info-item">
  83. <view class="info-item-label">联系电话</view>
  84. <view class="info-item-value">{{ orderDetail.contactPhone || '—' }}</view>
  85. </view>
  86. <view class="info-item">
  87. <view class="info-item-label">备注信息</view>
  88. <view class="info-item-value">{{ orderDetail.remark || '—' }}</view>
  89. </view>
  90. </view>
  91. </view>
  92. <!-- 底部按钮 -->
  93. <view class="bottom-button">
  94. <view class="bottom-button-text1 " hover-class="hover-active" @click="handleConfirmOrder">去加餐</view>
  95. <view class="bottom-button-text" hover-class="hover-active" @click="handleConfirmPay">去结算</view>
  96. </view>
  97. </view>
  98. </template>
  99. <script setup>
  100. import { onLoad } from "@dcloudio/uni-app";
  101. import { ref, computed } from "vue";
  102. import { go } from "@/utils/utils.js";
  103. import { getFileUrl } from "@/utils/file.js";
  104. import { GetOrderInfo } from "@/api/dining.js";
  105. const payType = ref('confirmOrder'); // confirmOrder 确认下单 confirmPay 确认支付
  106. /** 当前订单ID,用于「去结算」传参 */
  107. const detailOrderId = ref('');
  108. // 订单详情(店铺、订单信息)
  109. const orderDetail = ref({
  110. storeName: '',
  111. storeAddress: '',
  112. orderNo: '',
  113. tableId: '', // 桌号ID,用于跳转加餐
  114. tableNo: '', // 桌号展示(tableNumber)
  115. dinerCount: '',
  116. createTime: '',
  117. contactPhone: '',
  118. remark: ''
  119. });
  120. // 价格明细(两位小数)
  121. const priceDetail = ref({
  122. dishTotal: '0.00',
  123. tablewareFee: '0.00',
  124. couponDiscount: '0.00',
  125. total: '0.00'
  126. });
  127. // 菜品列表(接口订单明细)
  128. const foodList = ref([]);
  129. // 菜品详情展示:排除餐具(id/cuisineId === -1)
  130. const displayFoodList = computed(() => {
  131. return (foodList.value ?? []).filter((it) => Number(it?.id ?? it?.cuisineId) !== -1);
  132. });
  133. // 金额保留两位小数
  134. const formatPrice = (price) => {
  135. if (price === '' || price === null || price === undefined) return '0.00';
  136. const num = Number(price);
  137. return Number.isNaN(num) ? '0.00' : num.toFixed(2);
  138. };
  139. // 将接口订单项转为列表项
  140. function normalizeOrderItem(item) {
  141. const tags = item?.tags ?? [];
  142. const tagArr = Array.isArray(tags) ? tags : [];
  143. const images = item?.images;
  144. const imageUrl = Array.isArray(images) ? images[0] : images;
  145. return {
  146. id: item?.id ?? item?.cuisineId,
  147. name: item?.cuisineName ?? item?.name ?? '',
  148. price: item?.totalPrice ?? item?.unitPrice ?? item?.price ?? 0,
  149. image: imageUrl ?? item?.image ?? item?.cuisineImage ?? 'img/icon/shop.png',
  150. quantity: item?.quantity ?? 1,
  151. tags: tagArr.map((t) => (typeof t === 'string' ? { text: t } : { text: t?.text ?? t?.tagName ?? '' }))
  152. };
  153. }
  154. // 从接口数据填充 orderDetail、priceDetail、foodList
  155. function applyOrderData(data) {
  156. const raw = data?.data ?? data ?? {};
  157. const store = raw?.storeInfo ?? raw?.store ?? {};
  158. orderDetail.value = {
  159. storeName: store?.storeName ?? raw?.storeName ?? '',
  160. storeAddress: store?.storeAddress ?? store?.address ?? raw?.storeAddress ?? raw?.address ?? '',
  161. orderNo: raw?.orderNo ?? raw?.orderId ?? '',
  162. tableId: raw?.tableId ?? raw?.tableNumber ?? '', // 加餐跳转用
  163. tableNo: raw?.tableNumber ?? raw?.tableNo ?? raw?.tableName ?? '',
  164. dinerCount: raw?.dinerCount ?? '',
  165. createTime: raw?.createdTime ?? raw?.createTime ?? raw?.orderTime ?? '',
  166. contactPhone: raw?.contactPhone ?? raw?.phone ?? '',
  167. remark: raw?.remark ?? ''
  168. };
  169. const dishTotal = raw?.totalAmount ?? raw?.dishTotal ?? raw?.orderAmount ?? raw?.foodAmount ?? 0;
  170. const tablewareFee = raw?.tablewareFee ?? raw?.tablewareAmount ?? 0;
  171. const couponDiscount = raw?.couponAmount ?? raw?.couponDiscount ?? 0;
  172. const total = raw?.totalAmount ?? raw?.totalPrice ?? raw?.payAmount ?? 0;
  173. priceDetail.value = {
  174. dishTotal: formatPrice(dishTotal),
  175. tablewareFee: formatPrice(tablewareFee),
  176. couponDiscount: formatPrice(couponDiscount),
  177. total: formatPrice(total)
  178. };
  179. const list = raw?.orderItemList ?? raw?.orderItems ?? raw?.items ?? raw?.detailList ?? [];
  180. foodList.value = (Array.isArray(list) ? list : []).map(normalizeOrderItem);
  181. }
  182. // 去加餐:跳转点餐页,携带桌号与就餐人数
  183. const handleConfirmOrder = () => {
  184. const tableid = orderDetail.value?.tableId || orderDetail.value?.tableNo || '';
  185. const diners = orderDetail.value?.dinerCount ?? '';
  186. const q = [];
  187. if (tableid !== '') q.push(`tableid=${encodeURIComponent(String(tableid))}`);
  188. if (diners !== '') q.push(`diners=${encodeURIComponent(String(diners))}`);
  189. go(q.length ? `/pages/orderFood/index?${q.join('&')}` : '/pages/orderFood/index');
  190. };
  191. // 去结算:跳转确认订单页,携带订单ID、订单号、桌号、就餐人数、订单金额(用于调起支付)
  192. const handleConfirmPay = () => {
  193. const orderId = detailOrderId.value || '';
  194. const orderNo = orderDetail.value?.orderNo ?? '';
  195. const tableId = orderDetail.value?.tableId || orderDetail.value?.tableNo || '';
  196. const tableNumber = orderDetail.value?.tableNo ?? orderDetail.value?.tableNumber ?? '';
  197. const diners = orderDetail.value?.dinerCount ?? '';
  198. const totalAmount = priceDetail.value?.total ?? '';
  199. const remark = (orderDetail.value?.remark ?? '').trim().slice(0, 30);
  200. const q = [];
  201. if (orderId !== '') q.push(`orderId=${encodeURIComponent(String(orderId))}`);
  202. if (orderNo !== '') q.push(`orderNo=${encodeURIComponent(String(orderNo))}`);
  203. if (tableId !== '') q.push(`tableId=${encodeURIComponent(String(tableId))}`);
  204. if (tableNumber !== '') q.push(`tableNumber=${encodeURIComponent(String(tableNumber))}`);
  205. if (diners !== '') q.push(`diners=${encodeURIComponent(String(diners))}`);
  206. if (totalAmount !== '' && totalAmount != null) q.push(`totalAmount=${encodeURIComponent(String(totalAmount))}`);
  207. if (remark !== '') q.push(`remark=${encodeURIComponent(remark)}`);
  208. go(q.length ? `/pages/checkout/index?${q.join('&')}` : '/pages/checkout/index');
  209. };
  210. onLoad(async (e) => {
  211. if (e.payType) payType.value = e.payType;
  212. const orderId = e?.orderId ?? e?.id ?? '';
  213. detailOrderId.value = orderId;
  214. if (!orderId) {
  215. uni.showToast({ title: '缺少订单ID', icon: 'none' });
  216. return;
  217. }
  218. try {
  219. const res = await GetOrderInfo(orderId);
  220. applyOrderData(res);
  221. } catch (err) {
  222. console.error('订单详情加载失败:', err);
  223. uni.showToast({ title: '加载失败', icon: 'none' });
  224. }
  225. });
  226. </script>
  227. <style lang="scss" scoped>
  228. .content {
  229. padding: 0 30rpx 300rpx;
  230. }
  231. .card {
  232. background-color: #fff;
  233. border-radius: 24rpx;
  234. padding: 30rpx 0;
  235. margin-top: 20rpx;
  236. .card-header {
  237. display: flex;
  238. justify-content: space-between;
  239. align-items: center;
  240. padding: 0 30rpx;
  241. height: 40rpx;
  242. position: relative;
  243. font-size: 27rpx;
  244. color: #151515;
  245. font-weight: bold;
  246. }
  247. .tag {
  248. width: 10rpx;
  249. height: 42rpx;
  250. background: linear-gradient(35deg, #FCB73F 0%, #FC733D 100%);
  251. border-radius: 0rpx 0rpx 0rpx 0rpx;
  252. position: absolute;
  253. left: 0;
  254. top: 0;
  255. }
  256. .card-content {
  257. padding: 0 30rpx;
  258. }
  259. .info-item {
  260. display: flex;
  261. justify-content: space-between;
  262. align-items: center;
  263. margin-top: 20rpx;
  264. font-size: 27rpx;
  265. .info-item-label {
  266. color: #666666;
  267. }
  268. .info-item-value {
  269. color: #151515;
  270. }
  271. }
  272. .info-item-textarea {
  273. width: 100%;
  274. height: 115rpx;
  275. border-radius: 8rpx;
  276. border: 1rpx solid #F2F2F2;
  277. margin-top: 20rpx;
  278. font-size: 23rpx;
  279. color: #AAAAAA;
  280. box-sizing: border-box;
  281. padding: 20rpx;
  282. }
  283. .info-food {
  284. margin-top: 20rpx;
  285. }
  286. .food-item {
  287. display: flex;
  288. align-items: center;
  289. padding: 20rpx 0;
  290. &:last-child {
  291. border-bottom: none;
  292. }
  293. &__image {
  294. width: 118rpx;
  295. height: 118rpx;
  296. border-radius: 8rpx;
  297. flex-shrink: 0;
  298. background-color: #f5f5f5;
  299. }
  300. &__info {
  301. flex: 1;
  302. margin-left: 20rpx;
  303. display: flex;
  304. flex-direction: column;
  305. justify-content: center;
  306. }
  307. &__name {
  308. font-size: 28rpx;
  309. font-weight: bold;
  310. color: #151515;
  311. margin-bottom: 8rpx;
  312. }
  313. &__desc {
  314. font-size: 24rpx;
  315. color: #666666;
  316. line-height: 1.5;
  317. }
  318. &__tag {
  319. font-size: 24rpx;
  320. color: #666666;
  321. }
  322. &__right {
  323. display: flex;
  324. flex-direction: column;
  325. align-items: flex-end;
  326. justify-content: center;
  327. margin-left: 20rpx;
  328. }
  329. &__price {
  330. display: flex;
  331. align-items: baseline;
  332. color: #151515;
  333. font-weight: bold;
  334. margin-bottom: 8rpx;
  335. .price-symbol {
  336. font-size: 20rpx;
  337. margin-right: 2rpx;
  338. }
  339. .price-main {
  340. font-size: 28rpx;
  341. }
  342. .price-decimal {
  343. font-size: 24rpx;
  344. }
  345. }
  346. &__quantity {
  347. font-size: 24rpx;
  348. color: #797979;
  349. }
  350. }
  351. .price-line {
  352. display: flex;
  353. justify-content: space-between;
  354. align-items: center;
  355. margin-top: 20rpx;
  356. font-size: 27rpx;
  357. color: #151515;
  358. border-top: 1rpx solid rgba(170, 170, 170, 0.15);
  359. font-weight: bold;
  360. padding-top: 20rpx;
  361. }
  362. }
  363. .bottom-button {
  364. width: 100%;
  365. background-color: #fff;
  366. padding: 20rpx 30rpx;
  367. box-sizing: border-box;
  368. position: fixed;
  369. bottom: 0;
  370. left: 0;
  371. right: 0;
  372. z-index: 999;
  373. padding-bottom: env(safe-area-inset-bottom);
  374. box-shadow: 0rpx -11rpx 46rpx 0rpx rgba(0, 0, 0, 0.05);
  375. display: flex;
  376. justify-content: space-between;
  377. align-items: center;
  378. .bottom-button-text1 {
  379. font-size: 32rpx;
  380. font-weight: bold;
  381. color: #fff;
  382. width: 324rpx;
  383. height: 80rpx;
  384. border-radius: 23rpx 23rpx 23rpx 23rpx;
  385. border: 2rpx solid #F47D1F;
  386. display: flex;
  387. align-items: center;
  388. color: #F47D1F;
  389. justify-content: center;
  390. }
  391. .bottom-button-text {
  392. font-size: 32rpx;
  393. font-weight: bold;
  394. color: #fff;
  395. background: linear-gradient(90deg, #FCB73F 0%, #FC743D 100%);
  396. border-radius: 23rpx 23rpx 23rpx 23rpx;
  397. display: flex;
  398. align-items: center;
  399. justify-content: center;
  400. width: 324rpx;
  401. height: 80rpx;
  402. }
  403. }
  404. .store-info {
  405. border-bottom: 1rpx solid rgba(170, 170, 170, 0.15);
  406. box-sizing: border-box;
  407. margin: 0 30rpx 30rpx;
  408. .store-info-title {
  409. font-size: 27rpx;
  410. color: #151515;
  411. font-weight: bold;
  412. margin-bottom: 10rpx;
  413. }
  414. .store-info-address {
  415. font-size: 23rpx;
  416. color: #AAAAAA;
  417. margin-bottom: 30rpx;
  418. }
  419. }
  420. </style>