orderDetail.vue 19 KB

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