orderDetail.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  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 tableNumber = orderDetail.value?.tableNo ?? orderDetail.value?.tableNumber ?? '';
  193. const diners = orderDetail.value?.dinerCount ?? '';
  194. const totalAmount = priceDetail.value?.total ?? '';
  195. const remark = (orderDetail.value?.remark ?? '').trim().slice(0, 30);
  196. const q = [];
  197. if (orderId !== '') q.push(`orderId=${encodeURIComponent(String(orderId))}`);
  198. if (orderNo !== '') q.push(`orderNo=${encodeURIComponent(String(orderNo))}`);
  199. if (tableId !== '') q.push(`tableId=${encodeURIComponent(String(tableId))}`);
  200. if (tableNumber !== '') q.push(`tableNumber=${encodeURIComponent(String(tableNumber))}`);
  201. if (diners !== '') q.push(`diners=${encodeURIComponent(String(diners))}`);
  202. if (totalAmount !== '' && totalAmount != null) q.push(`totalAmount=${encodeURIComponent(String(totalAmount))}`);
  203. if (remark !== '') q.push(`remark=${encodeURIComponent(remark)}`);
  204. go(q.length ? `/pages/checkout/index?${q.join('&')}` : '/pages/checkout/index');
  205. };
  206. onLoad(async (e) => {
  207. if (e.payType) payType.value = e.payType;
  208. const orderId = e?.orderId ?? e?.id ?? '';
  209. detailOrderId.value = orderId;
  210. if (!orderId) {
  211. uni.showToast({ title: '缺少订单ID', icon: 'none' });
  212. return;
  213. }
  214. try {
  215. const res = await GetOrderInfo(orderId);
  216. applyOrderData(res);
  217. } catch (err) {
  218. console.error('订单详情加载失败:', err);
  219. uni.showToast({ title: '加载失败', icon: 'none' });
  220. }
  221. });
  222. </script>
  223. <style lang="scss" scoped>
  224. .content {
  225. padding: 0 30rpx 300rpx;
  226. }
  227. .card {
  228. background-color: #fff;
  229. border-radius: 24rpx;
  230. padding: 30rpx 0;
  231. margin-top: 20rpx;
  232. .card-header {
  233. display: flex;
  234. justify-content: space-between;
  235. align-items: center;
  236. padding: 0 30rpx;
  237. height: 40rpx;
  238. position: relative;
  239. font-size: 27rpx;
  240. color: #151515;
  241. font-weight: bold;
  242. }
  243. .tag {
  244. width: 10rpx;
  245. height: 42rpx;
  246. background: linear-gradient(35deg, #FCB73F 0%, #FC733D 100%);
  247. border-radius: 0rpx 0rpx 0rpx 0rpx;
  248. position: absolute;
  249. left: 0;
  250. top: 0;
  251. }
  252. .card-content {
  253. padding: 0 30rpx;
  254. }
  255. .info-item {
  256. display: flex;
  257. justify-content: space-between;
  258. align-items: center;
  259. margin-top: 20rpx;
  260. font-size: 27rpx;
  261. .info-item-label {
  262. color: #666666;
  263. }
  264. .info-item-value {
  265. color: #151515;
  266. }
  267. }
  268. .info-item-textarea {
  269. width: 100%;
  270. height: 115rpx;
  271. border-radius: 8rpx;
  272. border: 1rpx solid #F2F2F2;
  273. margin-top: 20rpx;
  274. font-size: 23rpx;
  275. color: #AAAAAA;
  276. box-sizing: border-box;
  277. padding: 20rpx;
  278. }
  279. .info-food {
  280. margin-top: 20rpx;
  281. }
  282. .food-item {
  283. display: flex;
  284. align-items: center;
  285. padding: 20rpx 0;
  286. &:last-child {
  287. border-bottom: none;
  288. }
  289. &__image {
  290. width: 118rpx;
  291. height: 118rpx;
  292. border-radius: 8rpx;
  293. flex-shrink: 0;
  294. background-color: #f5f5f5;
  295. }
  296. &__info {
  297. flex: 1;
  298. margin-left: 20rpx;
  299. display: flex;
  300. flex-direction: column;
  301. justify-content: center;
  302. }
  303. &__name {
  304. font-size: 28rpx;
  305. font-weight: bold;
  306. color: #151515;
  307. margin-bottom: 8rpx;
  308. }
  309. &__desc {
  310. font-size: 24rpx;
  311. color: #666666;
  312. line-height: 1.5;
  313. }
  314. &__tag {
  315. font-size: 24rpx;
  316. color: #666666;
  317. }
  318. &__right {
  319. display: flex;
  320. flex-direction: column;
  321. align-items: flex-end;
  322. justify-content: center;
  323. margin-left: 20rpx;
  324. }
  325. &__price {
  326. display: flex;
  327. align-items: baseline;
  328. color: #151515;
  329. font-weight: bold;
  330. margin-bottom: 8rpx;
  331. .price-symbol {
  332. font-size: 20rpx;
  333. margin-right: 2rpx;
  334. }
  335. .price-main {
  336. font-size: 28rpx;
  337. }
  338. .price-decimal {
  339. font-size: 24rpx;
  340. }
  341. }
  342. &__quantity {
  343. font-size: 24rpx;
  344. color: #797979;
  345. }
  346. }
  347. .price-line {
  348. display: flex;
  349. justify-content: space-between;
  350. align-items: center;
  351. margin-top: 20rpx;
  352. font-size: 27rpx;
  353. color: #151515;
  354. border-top: 1rpx solid rgba(170, 170, 170, 0.15);
  355. font-weight: bold;
  356. padding-top: 20rpx;
  357. }
  358. }
  359. .bottom-button {
  360. width: 100%;
  361. background-color: #fff;
  362. padding: 20rpx 30rpx;
  363. box-sizing: border-box;
  364. position: fixed;
  365. bottom: 0;
  366. left: 0;
  367. right: 0;
  368. z-index: 999;
  369. padding-bottom: env(safe-area-inset-bottom);
  370. box-shadow: 0rpx -11rpx 46rpx 0rpx rgba(0, 0, 0, 0.05);
  371. display: flex;
  372. justify-content: space-between;
  373. align-items: center;
  374. .bottom-button-text1 {
  375. font-size: 32rpx;
  376. font-weight: bold;
  377. color: #fff;
  378. width: 324rpx;
  379. height: 80rpx;
  380. border-radius: 23rpx 23rpx 23rpx 23rpx;
  381. border: 2rpx solid #F47D1F;
  382. display: flex;
  383. align-items: center;
  384. color: #F47D1F;
  385. justify-content: center;
  386. }
  387. .bottom-button-text {
  388. font-size: 32rpx;
  389. font-weight: bold;
  390. color: #fff;
  391. background: linear-gradient(90deg, #FCB73F 0%, #FC743D 100%);
  392. border-radius: 23rpx 23rpx 23rpx 23rpx;
  393. display: flex;
  394. align-items: center;
  395. justify-content: center;
  396. width: 324rpx;
  397. height: 80rpx;
  398. }
  399. }
  400. .store-info {
  401. border-bottom: 1rpx solid rgba(170, 170, 170, 0.15);
  402. box-sizing: border-box;
  403. margin: 0 30rpx 30rpx;
  404. .store-info-title {
  405. font-size: 27rpx;
  406. color: #151515;
  407. font-weight: bold;
  408. margin-bottom: 10rpx;
  409. }
  410. .store-info-address {
  411. font-size: 23rpx;
  412. color: #AAAAAA;
  413. margin-bottom: 30rpx;
  414. }
  415. }
  416. </style>