orderDetail.vue 18 KB

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