orderDetail.vue 14 KB

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