orderDetail.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  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 { getFileUrl } from "@/utils/file.js";
  103. import { GetOrderInfo } from "@/api/dining.js";
  104. const payType = ref('confirmOrder'); // confirmOrder 确认下单 confirmPay 确认支付
  105. /** 当前订单ID,用于「去结算」传参 */
  106. const detailOrderId = ref('');
  107. // 订单详情(店铺、订单信息)
  108. const orderDetail = ref({
  109. storeName: '',
  110. storeAddress: '',
  111. storeId: '',
  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. storeId: store?.storeId ?? store?.id ?? raw?.storeId ?? raw?.store_id ?? '',
  183. orderNo: raw?.orderNo ?? raw?.orderId ?? '',
  184. tableId: raw?.tableId ?? raw?.tableNumber ?? '', // 加餐跳转用
  185. tableNo: raw?.tableNumber ?? raw?.tableNo ?? raw?.tableName ?? '',
  186. dinerCount: raw?.dinerCount ?? '',
  187. createTime: raw?.createdTime ?? raw?.createTime ?? raw?.orderTime ?? '',
  188. contactPhone: raw?.contactPhone ?? raw?.phone ?? '',
  189. remark: raw?.remark ?? ''
  190. };
  191. const dishTotal = raw?.totalAmount ?? raw?.dishTotal ?? raw?.orderAmount ?? raw?.foodAmount ?? 0;
  192. const tablewareFee = raw?.tablewareFee ?? raw?.tablewareAmount ?? 0;
  193. const couponDiscount = raw?.couponAmount ?? raw?.couponDiscount ?? 0;
  194. const total = raw?.payAmount ?? raw?.totalAmount ?? raw?.totalPrice ?? 0;
  195. priceDetail.value = {
  196. dishTotal: formatPrice(dishTotal),
  197. tablewareFee: formatPrice(tablewareFee),
  198. couponDiscount: formatPrice(couponDiscount),
  199. total: formatPrice(total)
  200. };
  201. const list = raw?.orderItemList ?? raw?.orderItems ?? raw?.items ?? raw?.detailList ?? [];
  202. foodList.value = (Array.isArray(list) ? list : []).map(normalizeOrderItem);
  203. }
  204. // 去加餐:跳转点餐页,携带桌号与就餐人数
  205. const handleConfirmOrder = () => {
  206. const tableid = uni.getStorageSync('currentTableId');
  207. const diners = orderDetail.value?.dinerCount ?? '';
  208. const storeId = orderDetail.value?.storeId ?? '';
  209. if (!tableid) {
  210. uni.showToast({ title: '订单缺少桌号信息,无法加餐', icon: 'none' });
  211. return;
  212. }
  213. const q = [];
  214. q.push(`tableid=${encodeURIComponent(String(tableid))}`);
  215. if (diners !== '' && diners != null) q.push(`diners=${encodeURIComponent(String(diners))}`);
  216. if (storeId !== '' && storeId != null) q.push(`storeId=${encodeURIComponent(String(storeId))}`);
  217. uni.navigateTo({ url: `/pages/orderFood/index?${q.join('&')}` });
  218. };
  219. // 去结算:跳转确认订单页,携带订单ID、订单号、桌号、就餐人数、订单金额(用于调起支付)
  220. const handleConfirmPay = () => {
  221. const orderId = detailOrderId.value || '';
  222. const orderNo = orderDetail.value?.orderNo ?? '';
  223. const tableId = orderDetail.value?.tableId || orderDetail.value?.tableNo || '';
  224. const tableNumber = orderDetail.value?.tableNo ?? orderDetail.value?.tableNumber ?? '';
  225. const diners = orderDetail.value?.dinerCount ?? '';
  226. const totalAmount = priceDetail.value?.total ?? '';
  227. const remark = (orderDetail.value?.remark ?? '').trim().slice(0, 30);
  228. const q = [];
  229. if (orderId !== '') q.push(`orderId=${encodeURIComponent(String(orderId))}`);
  230. if (orderNo !== '') q.push(`orderNo=${encodeURIComponent(String(orderNo))}`);
  231. if (tableId !== '') q.push(`tableId=${encodeURIComponent(String(tableId))}`);
  232. if (tableNumber !== '') q.push(`tableNumber=${encodeURIComponent(String(tableNumber))}`);
  233. if (diners !== '') q.push(`diners=${encodeURIComponent(String(diners))}`);
  234. if (totalAmount !== '' && totalAmount != null) q.push(`totalAmount=${encodeURIComponent(String(totalAmount))}`);
  235. if (remark !== '') q.push(`remark=${encodeURIComponent(remark)}`);
  236. uni.navigateTo({ url: q.length ? `/pages/checkout/index?${q.join('&')}` : '/pages/checkout/index' });
  237. };
  238. onLoad(async (e) => {
  239. if (e.payType) payType.value = e.payType;
  240. const orderId = e?.orderId ?? e?.id ?? '';
  241. detailOrderId.value = orderId;
  242. if (!orderId) {
  243. uni.showToast({ title: '缺少订单ID', icon: 'none' });
  244. return;
  245. }
  246. try {
  247. const res = await GetOrderInfo(orderId);
  248. applyOrderData(res);
  249. } catch (err) {
  250. console.error('订单详情加载失败:', err);
  251. uni.showToast({ title: '加载失败', icon: 'none' });
  252. }
  253. });
  254. </script>
  255. <style lang="scss" scoped>
  256. .content {
  257. padding: 0 30rpx 300rpx;
  258. }
  259. .card {
  260. background-color: #fff;
  261. border-radius: 24rpx;
  262. padding: 30rpx 0;
  263. margin-top: 20rpx;
  264. .card-header {
  265. display: flex;
  266. justify-content: space-between;
  267. align-items: center;
  268. padding: 0 30rpx;
  269. height: 40rpx;
  270. position: relative;
  271. font-size: 27rpx;
  272. color: #151515;
  273. font-weight: bold;
  274. }
  275. .tag {
  276. width: 10rpx;
  277. height: 42rpx;
  278. background: linear-gradient(35deg, #FCB73F 0%, #FC733D 100%);
  279. border-radius: 0rpx 0rpx 0rpx 0rpx;
  280. position: absolute;
  281. left: 0;
  282. top: 0;
  283. }
  284. .card-content {
  285. padding: 0 30rpx;
  286. }
  287. .info-item {
  288. display: flex;
  289. justify-content: space-between;
  290. align-items: center;
  291. margin-top: 20rpx;
  292. font-size: 27rpx;
  293. .info-item-label {
  294. color: #666666;
  295. }
  296. .info-item-value {
  297. color: #151515;
  298. }
  299. }
  300. .info-item-textarea {
  301. width: 100%;
  302. height: 115rpx;
  303. border-radius: 8rpx;
  304. border: 1rpx solid #F2F2F2;
  305. margin-top: 20rpx;
  306. font-size: 23rpx;
  307. color: #AAAAAA;
  308. box-sizing: border-box;
  309. padding: 20rpx;
  310. }
  311. .info-food {
  312. margin-top: 20rpx;
  313. }
  314. .food-item {
  315. display: flex;
  316. align-items: center;
  317. padding: 20rpx 0;
  318. &:last-child {
  319. border-bottom: none;
  320. }
  321. &__image {
  322. width: 118rpx;
  323. height: 118rpx;
  324. border-radius: 8rpx;
  325. flex-shrink: 0;
  326. background-color: #f5f5f5;
  327. }
  328. &__info {
  329. flex: 1;
  330. margin-left: 20rpx;
  331. display: flex;
  332. flex-direction: column;
  333. justify-content: center;
  334. }
  335. &__name {
  336. font-size: 28rpx;
  337. font-weight: bold;
  338. color: #151515;
  339. margin-bottom: 8rpx;
  340. }
  341. &__desc {
  342. font-size: 24rpx;
  343. color: #666666;
  344. line-height: 1.5;
  345. }
  346. &__tag {
  347. font-size: 24rpx;
  348. color: #666666;
  349. &.signature {
  350. color: #FC793D;
  351. }
  352. &.spicy {
  353. color: #2E2E2E;
  354. }
  355. }
  356. &__right {
  357. display: flex;
  358. flex-direction: column;
  359. align-items: flex-end;
  360. justify-content: center;
  361. margin-left: 20rpx;
  362. }
  363. &__price {
  364. display: flex;
  365. align-items: baseline;
  366. color: #151515;
  367. font-weight: bold;
  368. margin-bottom: 8rpx;
  369. .price-symbol {
  370. font-size: 20rpx;
  371. margin-right: 2rpx;
  372. }
  373. .price-main {
  374. font-size: 28rpx;
  375. }
  376. .price-decimal {
  377. font-size: 24rpx;
  378. }
  379. }
  380. &__quantity {
  381. font-size: 24rpx;
  382. color: #797979;
  383. }
  384. }
  385. .price-line {
  386. display: flex;
  387. justify-content: space-between;
  388. align-items: center;
  389. margin-top: 20rpx;
  390. font-size: 27rpx;
  391. color: #151515;
  392. border-top: 1rpx solid rgba(170, 170, 170, 0.15);
  393. font-weight: bold;
  394. padding-top: 20rpx;
  395. }
  396. }
  397. .bottom-button {
  398. width: 100%;
  399. background-color: #fff;
  400. padding: 20rpx 30rpx;
  401. box-sizing: border-box;
  402. position: fixed;
  403. bottom: 0;
  404. left: 0;
  405. right: 0;
  406. z-index: 999;
  407. padding-bottom: env(safe-area-inset-bottom);
  408. box-shadow: 0rpx -11rpx 46rpx 0rpx rgba(0, 0, 0, 0.05);
  409. display: flex;
  410. justify-content: space-between;
  411. align-items: center;
  412. .bottom-button-text1 {
  413. font-size: 32rpx;
  414. font-weight: bold;
  415. color: #fff;
  416. width: 324rpx;
  417. height: 80rpx;
  418. border-radius: 23rpx 23rpx 23rpx 23rpx;
  419. border: 2rpx solid #F47D1F;
  420. display: flex;
  421. align-items: center;
  422. color: #F47D1F;
  423. justify-content: center;
  424. }
  425. .bottom-button-text {
  426. font-size: 32rpx;
  427. font-weight: bold;
  428. color: #fff;
  429. background: linear-gradient(90deg, #FCB73F 0%, #FC743D 100%);
  430. border-radius: 23rpx 23rpx 23rpx 23rpx;
  431. display: flex;
  432. align-items: center;
  433. justify-content: center;
  434. width: 324rpx;
  435. height: 80rpx;
  436. }
  437. }
  438. .store-info {
  439. border-bottom: 1rpx solid rgba(170, 170, 170, 0.15);
  440. box-sizing: border-box;
  441. margin: 0 30rpx 30rpx;
  442. .store-info-title {
  443. font-size: 27rpx;
  444. color: #151515;
  445. font-weight: bold;
  446. margin-bottom: 10rpx;
  447. }
  448. .store-info-address {
  449. font-size: 23rpx;
  450. color: #AAAAAA;
  451. margin-bottom: 30rpx;
  452. }
  453. }
  454. </style>