orderDetail.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  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 foodList" :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 } 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. // 金额保留两位小数
  130. const formatPrice = (price) => {
  131. if (price === '' || price === null || price === undefined) return '0.00';
  132. const num = Number(price);
  133. return Number.isNaN(num) ? '0.00' : num.toFixed(2);
  134. };
  135. // 将接口订单项转为列表项
  136. function normalizeOrderItem(item) {
  137. const tags = item?.tags ?? [];
  138. const tagArr = Array.isArray(tags) ? tags : [];
  139. const images = item?.images;
  140. const imageUrl = Array.isArray(images) ? images[0] : images;
  141. return {
  142. id: item?.id ?? item?.cuisineId,
  143. name: item?.cuisineName ?? item?.name ?? '',
  144. price: item?.totalPrice ?? item?.unitPrice ?? item?.price ?? 0,
  145. image: imageUrl ?? item?.image ?? item?.cuisineImage ?? 'img/icon/shop.png',
  146. quantity: item?.quantity ?? 1,
  147. tags: tagArr.map((t) => (typeof t === 'string' ? { text: t } : { text: t?.text ?? t?.tagName ?? '' }))
  148. };
  149. }
  150. // 从接口数据填充 orderDetail、priceDetail、foodList
  151. function applyOrderData(data) {
  152. const raw = data?.data ?? data ?? {};
  153. const store = raw?.storeInfo ?? raw?.store ?? {};
  154. orderDetail.value = {
  155. storeName: store?.storeName ?? raw?.storeName ?? '',
  156. storeAddress: store?.storeAddress ?? store?.address ?? raw?.storeAddress ?? raw?.address ?? '',
  157. orderNo: raw?.orderNo ?? raw?.orderId ?? '',
  158. tableId: raw?.tableId ?? raw?.tableNumber ?? '', // 加餐跳转用
  159. tableNo: raw?.tableNumber ?? raw?.tableNo ?? raw?.tableName ?? '',
  160. dinerCount: raw?.dinerCount ?? '',
  161. createTime: raw?.createdTime ?? raw?.createTime ?? raw?.orderTime ?? '',
  162. contactPhone: raw?.contactPhone ?? raw?.phone ?? '',
  163. remark: raw?.remark ?? ''
  164. };
  165. const dishTotal = raw?.dishTotal ?? raw?.orderAmount ?? raw?.foodAmount ?? 0;
  166. const tablewareFee = raw?.tablewareFee ?? raw?.tablewareAmount ?? 0;
  167. const couponDiscount = raw?.couponAmount ?? raw?.couponDiscount ?? 0;
  168. const total = raw?.totalAmount ?? raw?.totalPrice ?? raw?.payAmount ?? 0;
  169. priceDetail.value = {
  170. dishTotal: formatPrice(dishTotal),
  171. tablewareFee: formatPrice(tablewareFee),
  172. couponDiscount: formatPrice(couponDiscount),
  173. total: formatPrice(total)
  174. };
  175. const list = raw?.orderItemList ?? raw?.orderItems ?? raw?.items ?? raw?.detailList ?? [];
  176. foodList.value = (Array.isArray(list) ? list : []).map(normalizeOrderItem);
  177. }
  178. // 去加餐:跳转点餐页,携带桌号与就餐人数
  179. const handleConfirmOrder = () => {
  180. const tableid = orderDetail.value?.tableId || orderDetail.value?.tableNo || '';
  181. const diners = orderDetail.value?.dinerCount ?? '';
  182. const q = [];
  183. if (tableid !== '') q.push(`tableid=${encodeURIComponent(String(tableid))}`);
  184. if (diners !== '') q.push(`diners=${encodeURIComponent(String(diners))}`);
  185. go(q.length ? `/pages/orderFood/index?${q.join('&')}` : '/pages/orderFood/index');
  186. };
  187. // 去结算:跳转确认订单页,携带订单ID、订单号、桌号、就餐人数、订单金额(用于调起支付)
  188. const handleConfirmPay = () => {
  189. const orderId = detailOrderId.value || '';
  190. const orderNo = orderDetail.value?.orderNo ?? '';
  191. const tableId = orderDetail.value?.tableId || orderDetail.value?.tableNo || '';
  192. const diners = orderDetail.value?.dinerCount ?? '';
  193. const totalAmount = priceDetail.value?.total ?? '';
  194. const remark = (orderDetail.value?.remark ?? '').trim().slice(0, 30);
  195. const q = [];
  196. if (orderId !== '') q.push(`orderId=${encodeURIComponent(String(orderId))}`);
  197. if (orderNo !== '') q.push(`orderNo=${encodeURIComponent(String(orderNo))}`);
  198. if (tableId !== '') q.push(`tableId=${encodeURIComponent(String(tableId))}`);
  199. if (diners !== '') q.push(`diners=${encodeURIComponent(String(diners))}`);
  200. if (totalAmount !== '' && totalAmount != null) q.push(`totalAmount=${encodeURIComponent(String(totalAmount))}`);
  201. if (remark !== '') q.push(`remark=${encodeURIComponent(remark)}`);
  202. go(q.length ? `/pages/placeOrder/index?${q.join('&')}` : '/pages/placeOrder/index');
  203. };
  204. onLoad(async (e) => {
  205. if (e.payType) payType.value = e.payType;
  206. const orderId = e?.orderId ?? e?.id ?? '';
  207. detailOrderId.value = orderId;
  208. if (!orderId) {
  209. uni.showToast({ title: '缺少订单ID', icon: 'none' });
  210. return;
  211. }
  212. try {
  213. const res = await GetOrderInfo(orderId);
  214. applyOrderData(res);
  215. } catch (err) {
  216. console.error('订单详情加载失败:', err);
  217. uni.showToast({ title: '加载失败', icon: 'none' });
  218. }
  219. });
  220. </script>
  221. <style lang="scss" scoped>
  222. .content {
  223. padding: 0 30rpx 300rpx;
  224. }
  225. .card {
  226. background-color: #fff;
  227. border-radius: 24rpx;
  228. padding: 30rpx 0;
  229. margin-top: 20rpx;
  230. .card-header {
  231. display: flex;
  232. justify-content: space-between;
  233. align-items: center;
  234. padding: 0 30rpx;
  235. height: 40rpx;
  236. position: relative;
  237. font-size: 27rpx;
  238. color: #151515;
  239. font-weight: bold;
  240. }
  241. .tag {
  242. width: 10rpx;
  243. height: 42rpx;
  244. background: linear-gradient(35deg, #FCB73F 0%, #FC733D 100%);
  245. border-radius: 0rpx 0rpx 0rpx 0rpx;
  246. position: absolute;
  247. left: 0;
  248. top: 0;
  249. }
  250. .card-content {
  251. padding: 0 30rpx;
  252. }
  253. .info-item {
  254. display: flex;
  255. justify-content: space-between;
  256. align-items: center;
  257. margin-top: 20rpx;
  258. font-size: 27rpx;
  259. .info-item-label {
  260. color: #666666;
  261. }
  262. .info-item-value {
  263. color: #151515;
  264. }
  265. }
  266. .info-item-textarea {
  267. width: 100%;
  268. height: 115rpx;
  269. border-radius: 8rpx;
  270. border: 1rpx solid #F2F2F2;
  271. margin-top: 20rpx;
  272. font-size: 23rpx;
  273. color: #AAAAAA;
  274. box-sizing: border-box;
  275. padding: 20rpx;
  276. }
  277. .info-food {
  278. margin-top: 20rpx;
  279. }
  280. .food-item {
  281. display: flex;
  282. align-items: center;
  283. padding: 20rpx 0;
  284. &:last-child {
  285. border-bottom: none;
  286. }
  287. &__image {
  288. width: 118rpx;
  289. height: 118rpx;
  290. border-radius: 8rpx;
  291. flex-shrink: 0;
  292. background-color: #f5f5f5;
  293. }
  294. &__info {
  295. flex: 1;
  296. margin-left: 20rpx;
  297. display: flex;
  298. flex-direction: column;
  299. justify-content: center;
  300. }
  301. &__name {
  302. font-size: 28rpx;
  303. font-weight: bold;
  304. color: #151515;
  305. margin-bottom: 8rpx;
  306. }
  307. &__desc {
  308. font-size: 24rpx;
  309. color: #666666;
  310. line-height: 1.5;
  311. }
  312. &__tag {
  313. font-size: 24rpx;
  314. color: #666666;
  315. }
  316. &__right {
  317. display: flex;
  318. flex-direction: column;
  319. align-items: flex-end;
  320. justify-content: center;
  321. margin-left: 20rpx;
  322. }
  323. &__price {
  324. display: flex;
  325. align-items: baseline;
  326. color: #151515;
  327. font-weight: bold;
  328. margin-bottom: 8rpx;
  329. .price-symbol {
  330. font-size: 20rpx;
  331. margin-right: 2rpx;
  332. }
  333. .price-main {
  334. font-size: 28rpx;
  335. }
  336. .price-decimal {
  337. font-size: 24rpx;
  338. }
  339. }
  340. &__quantity {
  341. font-size: 24rpx;
  342. color: #797979;
  343. }
  344. }
  345. .price-line {
  346. display: flex;
  347. justify-content: space-between;
  348. align-items: center;
  349. margin-top: 20rpx;
  350. font-size: 27rpx;
  351. color: #151515;
  352. border-top: 1rpx solid rgba(170, 170, 170, 0.15);
  353. font-weight: bold;
  354. padding-top: 20rpx;
  355. }
  356. }
  357. .bottom-button {
  358. width: 100%;
  359. background-color: #fff;
  360. padding: 20rpx 30rpx;
  361. box-sizing: border-box;
  362. position: fixed;
  363. bottom: 0;
  364. left: 0;
  365. right: 0;
  366. z-index: 999;
  367. padding-bottom: env(safe-area-inset-bottom);
  368. box-shadow: 0rpx -11rpx 46rpx 0rpx rgba(0, 0, 0, 0.05);
  369. display: flex;
  370. justify-content: space-between;
  371. align-items: center;
  372. .bottom-button-text1 {
  373. font-size: 32rpx;
  374. font-weight: bold;
  375. color: #fff;
  376. width: 324rpx;
  377. height: 80rpx;
  378. border-radius: 23rpx 23rpx 23rpx 23rpx;
  379. border: 2rpx solid #F47D1F;
  380. display: flex;
  381. align-items: center;
  382. color: #F47D1F;
  383. justify-content: center;
  384. }
  385. .bottom-button-text {
  386. font-size: 32rpx;
  387. font-weight: bold;
  388. color: #fff;
  389. background: linear-gradient(90deg, #FCB73F 0%, #FC743D 100%);
  390. border-radius: 23rpx 23rpx 23rpx 23rpx;
  391. display: flex;
  392. align-items: center;
  393. justify-content: center;
  394. width: 324rpx;
  395. height: 80rpx;
  396. }
  397. }
  398. .store-info {
  399. border-bottom: 1rpx solid rgba(170, 170, 170, 0.15);
  400. box-sizing: border-box;
  401. margin: 0 30rpx 30rpx;
  402. .store-info-title {
  403. font-size: 27rpx;
  404. color: #151515;
  405. font-weight: bold;
  406. margin-bottom: 10rpx;
  407. }
  408. .store-info-address {
  409. font-size: 23rpx;
  410. color: #AAAAAA;
  411. margin-bottom: 30rpx;
  412. }
  413. }
  414. </style>