orderDetail.vue 15 KB

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