orderDetail.vue 19 KB

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