orderDetail.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  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 info-item--coupon">
  51. <view class="info-item-label">优惠券</view>
  52. <view class="info-item-value coupon-value">
  53. <text v-if="priceDetail.discountRate != null && priceDetail.discountRate !== ''" class="coupon-amount">{{ priceDetail.discountRate }}折</text>
  54. <text v-else class="coupon-placeholder">—</text>
  55. </view>
  56. </view>
  57. <view v-if="(priceDetail.discountAmount ?? 0) > 0" class="info-item info-item--coupon">
  58. <view class="info-item-label">优惠金额</view>
  59. <view class="info-item-value coupon-value">
  60. <text class="coupon-amount">-¥{{ formatPrice(priceDetail.discountAmount) }}</text>
  61. </view>
  62. </view>
  63. <view class="price-line">
  64. <view class="price-line-label">合计</view>
  65. <view class="price-line-value">¥{{ priceDetail.total }}</view>
  66. </view>
  67. </view>
  68. </view>
  69. <!-- 订单卡片 -->
  70. <view class="card">
  71. <view class="card-header">
  72. <view class="card-header-title">订单信息</view>
  73. </view>
  74. <view class="card-content">
  75. <view class="info-item">
  76. <view class="info-item-label">订单编号</view>
  77. <view class="info-item-value">{{ orderDetail.orderNo || '—' }}</view>
  78. </view>
  79. <view class="info-item">
  80. <view class="info-item-label">就餐桌号</view>
  81. <view class="info-item-value">{{ orderDetail.tableNo || '—' }}</view>
  82. </view>
  83. <view class="info-item">
  84. <view class="info-item-label">用餐人数</view>
  85. <view class="info-item-value">{{ orderDetail.dinerCount != null && orderDetail.dinerCount !== '' ? orderDetail.dinerCount + '人' : '—' }}</view>
  86. </view>
  87. <view class="info-item">
  88. <view class="info-item-label">下单时间</view>
  89. <view class="info-item-value">{{ orderDetail.createTime || '—' }}</view>
  90. </view>
  91. <view class="info-item">
  92. <view class="info-item-label">联系电话</view>
  93. <view class="info-item-value">{{ orderDetail.contactPhone || '—' }}</view>
  94. </view>
  95. <view class="info-item">
  96. <view class="info-item-label">备注信息</view>
  97. <view class="info-item-value">{{ orderDetail.remark || '—' }}</view>
  98. </view>
  99. </view>
  100. </view>
  101. <!-- 底部按钮 -->
  102. <view class="bottom-button">
  103. <view class="bottom-button-text1 " hover-class="hover-active" @click="handleConfirmOrder">去加餐</view>
  104. <view class="bottom-button-text" hover-class="hover-active" @click="handleConfirmPay">去结算</view>
  105. </view>
  106. </view>
  107. </template>
  108. <script setup>
  109. import { onLoad } from "@dcloudio/uni-app";
  110. import { ref, computed } from "vue";
  111. import { getFileUrl } from "@/utils/file.js";
  112. import { GetOrderInfo } from "@/api/dining.js";
  113. const payType = ref('confirmOrder'); // confirmOrder 确认下单 confirmPay 确认支付
  114. /** 当前订单ID,用于「去结算」传参 */
  115. const detailOrderId = ref('');
  116. // 订单详情(店铺、订单信息)
  117. const orderDetail = ref({
  118. storeName: '',
  119. storeAddress: '',
  120. storeId: '',
  121. orderNo: '',
  122. tableId: '', // 桌号ID,用于跳转加餐
  123. tableNo: '', // 桌号展示(tableNumber)
  124. dinerCount: '',
  125. createTime: '',
  126. contactPhone: '',
  127. remark: ''
  128. });
  129. // 价格明细(两位小数)
  130. const priceDetail = ref({
  131. dishTotal: '0.00',
  132. tablewareFee: '0.00',
  133. couponDiscount: '0.00',
  134. discountAmount: 0,
  135. couponName: '',
  136. couponType: null,
  137. nominalValue: null,
  138. discountRate: null,
  139. total: '0.00'
  140. });
  141. // 优惠券展示:满减券显示 nominalValue+元,折扣券显示 discountRate+折,否则显示 couponName 或 已使用优惠券(与 checkout 一致)
  142. const couponDisplayText = computed(() => {
  143. const p = priceDetail.value;
  144. const amount = Number(p.discountAmount ?? p.couponDiscount ?? 0) || 0;
  145. if (amount <= 0) return '—';
  146. const type = Number(p.couponType);
  147. if (type === 1 && (p.nominalValue != null && p.nominalValue !== '')) {
  148. const val = Number(p.nominalValue);
  149. return Number.isNaN(val) ? (p.couponName || '已使用优惠券') : val + '元';
  150. }
  151. if (type === 2 && (p.discountRate != null && p.discountRate !== '')) {
  152. const rate = Number(p.discountRate);
  153. return Number.isNaN(rate) ? (p.couponName || '已使用优惠券') : rate + '折';
  154. }
  155. return p.couponName || '已使用优惠券';
  156. });
  157. // 菜品列表(接口订单明细)
  158. const foodList = ref([]);
  159. // 菜品详情展示:包含所有项(含餐具 id/cuisineId === -1)
  160. const displayFoodList = computed(() => foodList.value ?? []);
  161. // 菜品图片:餐具(id/cuisineId=-1)用本地图
  162. function getItemImage(item) {
  163. if (Number(item?.id ?? item?.cuisineId) === -1) return '/static/utensilFee.png';
  164. const raw = item?.image ?? item?.cuisineImage ?? item?.imageUrl ?? '';
  165. if (typeof raw === 'string' && (raw.startsWith('http') || raw.startsWith('//'))) return raw;
  166. return getFileUrl(raw || 'img/icon/shop.png');
  167. }
  168. // 金额保留两位小数
  169. const formatPrice = (price) => {
  170. if (price === '' || price === null || price === undefined) return '0.00';
  171. const num = Number(price);
  172. return Number.isNaN(num) ? '0.00' : num.toFixed(2);
  173. };
  174. // 将 tags 统一为 [{ text, type }] 格式
  175. function normalizeTags(raw) {
  176. if (raw == null) return [];
  177. let arr = [];
  178. if (Array.isArray(raw)) arr = raw;
  179. else if (typeof raw === 'string') {
  180. const t = raw.trim();
  181. if (t.startsWith('[')) { try { arr = JSON.parse(t); if (!Array.isArray(arr)) arr = []; } catch { arr = t ? [t] : []; } }
  182. else arr = t ? t.split(/[,,、\s]+/).map(s => s.trim()).filter(Boolean) : [];
  183. } else if (raw && typeof raw === 'object') arr = Array.isArray(raw.list) ? raw.list : Array.isArray(raw.items) ? raw.items : [];
  184. return arr.map((it) => {
  185. if (it == null) return { text: '', type: '' };
  186. if (typeof it === 'string') return { text: it, type: '' };
  187. if (typeof it === 'number') return { text: String(it), type: '' };
  188. return { text: it.text ?? it.tagName ?? it.name ?? it.label ?? it.title ?? '', type: it.type ?? it.tagType ?? '' };
  189. }).filter((t) => t.text !== '' && t.text != null);
  190. }
  191. // 将接口订单项转为列表项
  192. function normalizeOrderItem(item) {
  193. const rawTags = item?.tags ?? item?.tagList ?? item?.tagNames ?? item?.labels ?? item?.tag;
  194. const images = item?.images ?? item?.image;
  195. const imageUrl = Array.isArray(images) ? images[0] : images;
  196. return {
  197. id: item?.id ?? item?.cuisineId,
  198. name: item?.cuisineName ?? item?.name ?? '',
  199. price: item?.totalPrice ?? item?.unitPrice ?? item?.price ?? 0,
  200. image: imageUrl ?? item?.image ?? item?.cuisineImage ?? 'img/icon/shop.png',
  201. quantity: item?.quantity ?? 1,
  202. tags: normalizeTags(rawTags)
  203. };
  204. }
  205. // 从接口数据填充 orderDetail、priceDetail、foodList
  206. function applyOrderData(data) {
  207. const raw = data?.data ?? data ?? {};
  208. const store = raw?.storeInfo ?? raw?.store ?? {};
  209. orderDetail.value = {
  210. storeName: store?.storeName ?? raw?.storeName ?? '',
  211. storeAddress: store?.storeAddress ?? store?.address ?? raw?.storeAddress ?? raw?.address ?? '',
  212. storeId: store?.storeId ?? store?.id ?? raw?.storeId ?? raw?.store_id ?? '',
  213. orderNo: raw?.orderNo ?? raw?.orderId ?? '',
  214. tableId: raw?.tableId ?? raw?.tableNumber ?? '', // 加餐跳转用
  215. tableNo: raw?.tableNumber ?? raw?.tableNo ?? raw?.tableName ?? '',
  216. dinerCount: raw?.dinerCount ?? '',
  217. createTime: raw?.createdTime ?? raw?.createTime ?? raw?.orderTime ?? '',
  218. contactPhone: raw?.contactPhone ?? raw?.phone ?? '',
  219. remark: raw?.remark ?? ''
  220. };
  221. const dishTotal = raw?.totalAmount ?? raw?.dishTotal ?? raw?.orderAmount ?? raw?.foodAmount ?? 0;
  222. const tablewareFee = raw?.tablewareFee ?? raw?.tablewareAmount ?? 0;
  223. const couponDiscount = raw?.couponAmount ?? raw?.couponDiscount ?? 0;
  224. const discountAmountVal = Number(raw?.discountAmount ?? raw?.couponAmount ?? raw?.couponDiscount ?? 0) || 0;
  225. const total = raw?.payAmount ?? raw?.totalAmount ?? raw?.totalPrice ?? 0;
  226. const rawDiscountRate = raw?.discountRate ?? raw?.couponInfo?.discountRate ?? raw?.coupon?.discountRate;
  227. const discountRateVal = rawDiscountRate != null && rawDiscountRate !== '' ? (Number(rawDiscountRate) || 0) / 10 : null;
  228. priceDetail.value = {
  229. dishTotal: formatPrice(dishTotal),
  230. tablewareFee: formatPrice(tablewareFee),
  231. couponDiscount: formatPrice(couponDiscount),
  232. discountAmount: discountAmountVal,
  233. couponName: raw?.couponName ?? '',
  234. couponType: raw?.couponType ?? null,
  235. nominalValue: raw?.nominalValue ?? null,
  236. discountRate: discountRateVal,
  237. total: formatPrice(total)
  238. };
  239. const list = raw?.orderItemList ?? raw?.orderItems ?? raw?.items ?? raw?.detailList ?? [];
  240. foodList.value = (Array.isArray(list) ? list : []).map(normalizeOrderItem);
  241. }
  242. // 去加餐:跳转点餐页,携带桌号与就餐人数
  243. const handleConfirmOrder = () => {
  244. const tableid = uni.getStorageSync('currentTableId');
  245. const diners = orderDetail.value?.dinerCount ?? '';
  246. const storeId = orderDetail.value?.storeId ?? '';
  247. if (!tableid) {
  248. uni.showToast({ title: '订单缺少桌号信息,无法加餐', icon: 'none' });
  249. return;
  250. }
  251. const q = [];
  252. q.push(`tableid=${encodeURIComponent(String(tableid))}`);
  253. if (diners !== '' && diners != null) q.push(`diners=${encodeURIComponent(String(diners))}`);
  254. if (storeId !== '' && storeId != null) q.push(`storeId=${encodeURIComponent(String(storeId))}`);
  255. uni.navigateTo({ url: `/pages/orderFood/index?${q.join('&')}` });
  256. };
  257. // 去结算:跳转确认订单页,携带订单ID、订单号、桌号、就餐人数、订单金额(用于调起支付)
  258. const handleConfirmPay = () => {
  259. const orderId = detailOrderId.value || '';
  260. const orderNo = orderDetail.value?.orderNo ?? '';
  261. const tableId = orderDetail.value?.tableId || orderDetail.value?.tableNo || '';
  262. const tableNumber = orderDetail.value?.tableNo ?? orderDetail.value?.tableNumber ?? '';
  263. const diners = orderDetail.value?.dinerCount ?? '';
  264. const totalAmount = priceDetail.value?.total ?? '';
  265. const remark = (orderDetail.value?.remark ?? '').trim().slice(0, 30);
  266. const q = [];
  267. if (orderId !== '') q.push(`orderId=${encodeURIComponent(String(orderId))}`);
  268. if (orderNo !== '') q.push(`orderNo=${encodeURIComponent(String(orderNo))}`);
  269. if (tableId !== '') q.push(`tableId=${encodeURIComponent(String(tableId))}`);
  270. if (tableNumber !== '') q.push(`tableNumber=${encodeURIComponent(String(tableNumber))}`);
  271. if (diners !== '') q.push(`diners=${encodeURIComponent(String(diners))}`);
  272. if (totalAmount !== '' && totalAmount != null) q.push(`totalAmount=${encodeURIComponent(String(totalAmount))}`);
  273. if (remark !== '') q.push(`remark=${encodeURIComponent(remark)}`);
  274. uni.navigateTo({ url: q.length ? `/pages/checkout/index?${q.join('&')}` : '/pages/checkout/index' });
  275. };
  276. onLoad(async (e) => {
  277. if (e.payType) payType.value = e.payType;
  278. const orderId = e?.orderId ?? e?.id ?? '';
  279. detailOrderId.value = orderId;
  280. if (!orderId) {
  281. uni.showToast({ title: '缺少订单ID', icon: 'none' });
  282. return;
  283. }
  284. try {
  285. const res = await GetOrderInfo(orderId);
  286. applyOrderData(res);
  287. } catch (err) {
  288. console.error('订单详情加载失败:', err);
  289. uni.showToast({ title: '加载失败', icon: 'none' });
  290. }
  291. });
  292. </script>
  293. <style lang="scss" scoped>
  294. .content {
  295. padding: 0 30rpx 300rpx;
  296. }
  297. .card {
  298. background-color: #fff;
  299. border-radius: 24rpx;
  300. padding: 30rpx 0;
  301. margin-top: 20rpx;
  302. .card-header {
  303. display: flex;
  304. justify-content: space-between;
  305. align-items: center;
  306. padding: 0 30rpx;
  307. height: 40rpx;
  308. position: relative;
  309. font-size: 27rpx;
  310. color: #151515;
  311. font-weight: bold;
  312. }
  313. .tag {
  314. width: 10rpx;
  315. height: 42rpx;
  316. background: linear-gradient(35deg, #FCB73F 0%, #FC733D 100%);
  317. border-radius: 0rpx 0rpx 0rpx 0rpx;
  318. position: absolute;
  319. left: 0;
  320. top: 0;
  321. }
  322. .card-content {
  323. padding: 0 30rpx;
  324. }
  325. .info-item {
  326. display: flex;
  327. justify-content: space-between;
  328. align-items: center;
  329. margin-top: 20rpx;
  330. font-size: 27rpx;
  331. .info-item-label {
  332. color: #666666;
  333. }
  334. .info-item-value {
  335. color: #151515;
  336. }
  337. &--coupon .coupon-value {
  338. display: flex;
  339. align-items: center;
  340. gap: 8rpx;
  341. }
  342. .coupon-amount {
  343. color: #E61F19;
  344. }
  345. .coupon-placeholder {
  346. color: #999999;
  347. }
  348. }
  349. .info-item-textarea {
  350. width: 100%;
  351. height: 115rpx;
  352. border-radius: 8rpx;
  353. border: 1rpx solid #F2F2F2;
  354. margin-top: 20rpx;
  355. font-size: 23rpx;
  356. color: #AAAAAA;
  357. box-sizing: border-box;
  358. padding: 20rpx;
  359. }
  360. .info-food {
  361. margin-top: 20rpx;
  362. }
  363. .food-item {
  364. display: flex;
  365. align-items: center;
  366. padding: 20rpx 0;
  367. &:last-child {
  368. border-bottom: none;
  369. }
  370. &__image {
  371. width: 118rpx;
  372. height: 118rpx;
  373. border-radius: 8rpx;
  374. flex-shrink: 0;
  375. background-color: #f5f5f5;
  376. }
  377. &__info {
  378. flex: 1;
  379. margin-left: 20rpx;
  380. display: flex;
  381. flex-direction: column;
  382. justify-content: center;
  383. }
  384. &__name {
  385. font-size: 28rpx;
  386. font-weight: bold;
  387. color: #151515;
  388. margin-bottom: 8rpx;
  389. }
  390. &__desc {
  391. font-size: 24rpx;
  392. color: #666666;
  393. line-height: 1.5;
  394. }
  395. &__tag {
  396. font-size: 24rpx;
  397. color: #666666;
  398. &.signature {
  399. color: #FC793D;
  400. }
  401. &.spicy {
  402. color: #2E2E2E;
  403. }
  404. }
  405. &__right {
  406. display: flex;
  407. flex-direction: column;
  408. align-items: flex-end;
  409. justify-content: center;
  410. margin-left: 20rpx;
  411. }
  412. &__price {
  413. display: flex;
  414. align-items: baseline;
  415. color: #151515;
  416. font-weight: bold;
  417. margin-bottom: 8rpx;
  418. .price-symbol {
  419. font-size: 20rpx;
  420. margin-right: 2rpx;
  421. }
  422. .price-main {
  423. font-size: 28rpx;
  424. }
  425. .price-decimal {
  426. font-size: 24rpx;
  427. }
  428. }
  429. &__quantity {
  430. font-size: 24rpx;
  431. color: #797979;
  432. }
  433. }
  434. .price-line {
  435. display: flex;
  436. justify-content: space-between;
  437. align-items: center;
  438. margin-top: 20rpx;
  439. font-size: 27rpx;
  440. color: #151515;
  441. border-top: 1rpx solid rgba(170, 170, 170, 0.15);
  442. font-weight: bold;
  443. padding-top: 20rpx;
  444. }
  445. }
  446. .bottom-button {
  447. width: 100%;
  448. background-color: #fff;
  449. padding: 20rpx 30rpx;
  450. box-sizing: border-box;
  451. position: fixed;
  452. bottom: 0;
  453. left: 0;
  454. right: 0;
  455. z-index: 999;
  456. padding-bottom: env(safe-area-inset-bottom);
  457. box-shadow: 0rpx -11rpx 46rpx 0rpx rgba(0, 0, 0, 0.05);
  458. display: flex;
  459. justify-content: space-between;
  460. align-items: center;
  461. .bottom-button-text1 {
  462. font-size: 32rpx;
  463. font-weight: bold;
  464. color: #fff;
  465. width: 324rpx;
  466. height: 80rpx;
  467. border-radius: 23rpx 23rpx 23rpx 23rpx;
  468. border: 2rpx solid #F47D1F;
  469. display: flex;
  470. align-items: center;
  471. color: #F47D1F;
  472. justify-content: center;
  473. }
  474. .bottom-button-text {
  475. font-size: 32rpx;
  476. font-weight: bold;
  477. color: #fff;
  478. background: linear-gradient(90deg, #FCB73F 0%, #FC743D 100%);
  479. border-radius: 23rpx 23rpx 23rpx 23rpx;
  480. display: flex;
  481. align-items: center;
  482. justify-content: center;
  483. width: 324rpx;
  484. height: 80rpx;
  485. }
  486. }
  487. .store-info {
  488. border-bottom: 1rpx solid rgba(170, 170, 170, 0.15);
  489. box-sizing: border-box;
  490. margin: 0 30rpx 30rpx;
  491. .store-info-title {
  492. font-size: 27rpx;
  493. color: #151515;
  494. font-weight: bold;
  495. margin-bottom: 10rpx;
  496. }
  497. .store-info-address {
  498. font-size: 23rpx;
  499. color: #AAAAAA;
  500. margin-bottom: 30rpx;
  501. }
  502. }
  503. </style>