orderDetail.vue 13 KB

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