order-details.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  1. <template>
  2. <view class="page">
  3. <u-navbar title="订单明细" :autoBack="true" :placeholder="true" :border-bottom="false"></u-navbar>
  4. <view v-if="loading" class="loading">加载中...</view>
  5. <view v-else-if="!detail.hostOrderId" class="empty">暂无订单详情</view>
  6. <scroll-view v-else class="content" scroll-y>
  7. <view class="detail-card">
  8. <view class="location-info">
  9. <view class="location-top">
  10. <view class="location-title">
  11. <u-icon name="map" color="#1d2129" size="30"></u-icon>
  12. <text>{{ detail.deliveryAddress || '暂无地址' }}</text>
  13. </view>
  14. <text v-if="statusText" class="status-badge">{{ statusText }}</text>
  15. <text class="copies">合计:<text class="copies-number">{{ detail.totalCopies || 0 }}</text>份</text>
  16. </view>
  17. <text class="location-region">{{ detail.region || '' }}</text>
  18. </view>
  19. <view
  20. v-for="(item, index) in items"
  21. :key="item.merchantOrderPackageId || index"
  22. class="detail-item"
  23. >
  24. <view
  25. v-if="showRefundActions"
  26. class="select-circle"
  27. :class="{ checked: isSelected(item, index) }"
  28. @click.stop="toggleItem(item, index)"
  29. >
  30. <u-icon v-if="isSelected(item, index)" name="checkmark" color="#fff" size="22"></u-icon>
  31. </view>
  32. <view class="item-content">
  33. <view class="contact-row">
  34. <view class="contact-info">
  35. <text>{{ item.linkName || '--' }}</text>
  36. <text>{{ item.maskedPhone || '--' }}</text>
  37. </view>
  38. <image
  39. class="call-icon"
  40. src="/static/merchantDish/call.png"
  41. mode="aspectFit"
  42. @click.stop="makePhoneCall(item.maskedPhone)"
  43. ></image>
  44. </view>
  45. <view class="product-row">
  46. <u-image
  47. width="120rpx"
  48. height="120rpx"
  49. border-radius="12rpx"
  50. :src="getProductImage(item.productImage)"
  51. mode="aspectFill"
  52. ></u-image>
  53. <view class="product-info">
  54. <text class="product-name">{{ item.packageName || '团餐套餐' }}</text>
  55. <text class="product-desc">{{ item.dishName || '暂无菜品信息' }}</text>
  56. <view class="product-meta">
  57. <text>{{ getItemCopies(item) }}份</text>
  58. <text>餐盒费:{{ formatMoney(item.containerFee) }}元</text>
  59. <text>成团价:<text class="price">¥{{ formatMoney(item.groupPrice) }}</text></text>
  60. </view>
  61. </view>
  62. </view>
  63. </view>
  64. </view>
  65. <view v-if="!items.length" class="no-items">暂无套餐明细</view>
  66. <view class="card-footer">
  67. <text>合计餐盒费: <text class="amount">¥{{ formatMoney(detail.containerFeeTotal) }}</text></text>
  68. <text>合计金额: <text class="amount total-amount">¥{{ formatMoney(detail.amountTotal) }}</text></text>
  69. </view>
  70. </view>
  71. </scroll-view>
  72. <view v-if="showRefundActions && !loading && detail.hostOrderId" class="footer-bar">
  73. <view class="select-all" @click="toggleAll">
  74. <view class="select-circle" :class="{ checked: isAllSelected }">
  75. <u-icon v-if="isAllSelected" name="checkmark" color="#fff" size="22"></u-icon>
  76. </view>
  77. <text>全选</text>
  78. </view>
  79. <view class="refund-button" @click="handleRefund">退款</view>
  80. </view>
  81. <view v-if="refundVisible" class="refund-mask" @click.self="closeRefundModal">
  82. <view class="refund-dialog" @click.stop>
  83. <text class="refund-title">提示</text>
  84. <text class="refund-message">确认对{{ refundTargets.length }}个用户订单发起退款吗</text>
  85. <view class="refund-actions">
  86. <view class="refund-action cancel" @click="closeRefundModal">取消</view>
  87. <view class="refund-action confirm" @click="confirmRefund">确定</view>
  88. </view>
  89. </view>
  90. </view>
  91. </view>
  92. </template>
  93. <script>
  94. import merchantDishApi from '@/api/merchantDish.js'
  95. export default {
  96. data() {
  97. return {
  98. hostOrderId: '',
  99. detail: {},
  100. loading: true,
  101. selectedKeys: [],
  102. showRefundActions: false,
  103. refundVisible: false,
  104. refundTargets: [],
  105. refundSubmitting: false
  106. }
  107. },
  108. computed: {
  109. items() {
  110. return Array.isArray(this.detail.items) ? this.detail.items : []
  111. },
  112. statusText() {
  113. const status = this.detail.orderStatusName || this.detail.statusName || this.detail.orderStatus
  114. if (typeof status === 'string' && status && Number.isNaN(Number(status))) return status
  115. return ({ 0: '待支付', 1: '待成团', 2: '已成团', 3: '已出餐', 4: '已送达', 5: '已取消', 6: '售后' })[status] || ''
  116. },
  117. isAllSelected() {
  118. return this.items.length > 0 && this.items.every((item, index) => this.isSelected(item, index))
  119. }
  120. },
  121. onLoad(query) {
  122. this.hostOrderId = (query && query.hostOrderId) || ''
  123. this.showRefundActions = String((query && query.isReservation) || '') === '1'
  124. this.loadDetail()
  125. },
  126. methods: {
  127. loadDetail() {
  128. if (!this.hostOrderId) {
  129. this.loading = false
  130. uni.showToast({ title: '缺少主订单号', icon: 'none' })
  131. return
  132. }
  133. merchantDishApi.packageOrderDetail(this.hostOrderId).then((res) => {
  134. if (res.data.code !== 200) {
  135. uni.showToast({ title: res.data.message || '详情加载失败', icon: 'none' })
  136. return
  137. }
  138. this.detail = res.data.result || {}
  139. }).catch(() => {
  140. uni.showToast({ title: '详情加载失败', icon: 'none' })
  141. }).finally(() => {
  142. this.loading = false
  143. })
  144. },
  145. getItemKey(item, index) {
  146. // 预约单退款的业务粒度是用户子订单;同一用户有多个套餐时必须一起选中。
  147. return item.userOrderId || item.merchantOrderPackageId || item.packageId || `item-${index}`
  148. },
  149. isSelected(item, index) {
  150. return this.selectedKeys.includes(this.getItemKey(item, index))
  151. },
  152. toggleItem(item, index) {
  153. const key = this.getItemKey(item, index)
  154. const selectedIndex = this.selectedKeys.indexOf(key)
  155. if (selectedIndex >= 0) this.selectedKeys.splice(selectedIndex, 1)
  156. else this.selectedKeys.push(key)
  157. },
  158. toggleAll() {
  159. if (this.isAllSelected) {
  160. this.selectedKeys = []
  161. return
  162. }
  163. this.selectedKeys = [...new Set(this.items.map((item, index) => this.getItemKey(item, index)))]
  164. },
  165. handleRefund() {
  166. const selected = this.items.filter((item, index) => this.isSelected(item, index))
  167. if (!selected.length) {
  168. uni.showToast({ title: '请选择要退款的用户订单', icon: 'none' })
  169. return
  170. }
  171. if (selected.some((item) => !item.userOrderId)) {
  172. uni.showToast({ title: '退款缺少用户子订单号', icon: 'none' })
  173. return
  174. }
  175. this.refundTargets = [...new Set(selected.map((item) => item.userOrderId))]
  176. this.refundVisible = true
  177. },
  178. closeRefundModal() {
  179. if (this.refundSubmitting) return
  180. this.refundVisible = false
  181. this.refundTargets = []
  182. },
  183. confirmRefund() {
  184. if (!this.refundTargets.length || this.refundSubmitting) return
  185. this.refundSubmitting = true
  186. merchantDishApi.packageOrderReservationDirectRefundBatch(
  187. this.hostOrderId,
  188. this.refundTargets
  189. ).then((res) => {
  190. if (res.data.code !== 200) {
  191. uni.showToast({ title: res.data.message || '退款失败', icon: 'none' })
  192. return
  193. }
  194. const result = res.data.result || {}
  195. this.refundVisible = false
  196. this.refundTargets = []
  197. this.selectedKeys = []
  198. uni.showToast({
  199. title: res.data.message || '退款已受理',
  200. icon: Number(result.rejectedCount || 0) > 0 ? 'none' : 'success'
  201. })
  202. this.loadDetail()
  203. }).catch(() => {
  204. uni.showToast({ title: '退款失败', icon: 'none' })
  205. }).finally(() => {
  206. this.refundSubmitting = false
  207. })
  208. },
  209. getItemCopies(item) {
  210. return item.packageNumber || 0
  211. },
  212. makePhoneCall(phone) {
  213. const phoneNumber = String(phone || '')
  214. if (!phoneNumber || phoneNumber.includes('*')) {
  215. uni.showToast({ title: '手机号暂不可拨打', icon: 'none' })
  216. return
  217. }
  218. uni.makePhoneCall({
  219. phoneNumber
  220. })
  221. },
  222. formatMoney(value) {
  223. if (value == null || value === '') return '0.00'
  224. const number = Number(value)
  225. return Number.isFinite(number) ? number.toFixed(2) : '0.00'
  226. },
  227. getProductImage(value) {
  228. const image = String(value || '').split(',').filter(Boolean)[0] || ''
  229. if (!image || /^https?:\/\//.test(image)) return image
  230. return this.$config && this.$config.apiUrl ? `${this.$config.apiUrl}/${image}` : image
  231. }
  232. }
  233. }
  234. </script>
  235. <style lang="scss" scoped>
  236. .page {
  237. display: flex;
  238. flex-direction: column;
  239. height: 100vh;
  240. background: #f7f8fc;
  241. }
  242. .content {
  243. flex: 1;
  244. height: 0;
  245. box-sizing: border-box;
  246. padding: 20rpx 32rpx 140rpx;
  247. }
  248. .loading,
  249. .empty {
  250. padding: 80rpx 24rpx;
  251. color: #999;
  252. text-align: center;
  253. }
  254. .detail-card {
  255. padding: 24rpx;
  256. border-radius: 16rpx;
  257. background: #fff;
  258. }
  259. .location-info {
  260. padding-bottom: 20rpx;
  261. border-bottom: 1rpx solid #eee;
  262. }
  263. .location-top {
  264. display: flex;
  265. align-items: center;
  266. min-height: 34rpx;
  267. }
  268. .location-title {
  269. display: flex;
  270. flex: 1;
  271. align-items: center;
  272. min-width: 0;
  273. gap: 10rpx;
  274. color: #1d2129;
  275. font-size: 30rpx;
  276. font-weight: 600;
  277. }
  278. .location-title text {
  279. overflow: hidden;
  280. text-overflow: ellipsis;
  281. white-space: nowrap;
  282. }
  283. .status-badge {
  284. flex-shrink: 0;
  285. margin: 0 10rpx;
  286. padding: 4rpx 10rpx;
  287. border-radius: 4rpx;
  288. background: #43c28c;
  289. color: #fff;
  290. font-size: 24rpx;
  291. }
  292. .copies {
  293. flex-shrink: 0;
  294. color: #999;
  295. font-size: 26rpx;
  296. }
  297. .copies-number {
  298. color: #388bf9;
  299. }
  300. .location-region {
  301. display: block;
  302. margin-top: 10rpx;
  303. color: #666;
  304. font-size: 26rpx;
  305. }
  306. .detail-item {
  307. display: flex;
  308. align-items: flex-start;
  309. gap: 20rpx;
  310. padding-top: 24rpx;
  311. }
  312. .select-circle {
  313. display: flex;
  314. flex-shrink: 0;
  315. align-items: center;
  316. justify-content: center;
  317. width: 32rpx;
  318. height: 32rpx;
  319. margin-top: 8rpx;
  320. box-sizing: border-box;
  321. border: 1rpx solid #d9d9d9;
  322. border-radius: 50%;
  323. background: #fff;
  324. }
  325. .select-circle.checked {
  326. border-color: #388bf9;
  327. background: #388bf9;
  328. }
  329. .item-content {
  330. flex: 1;
  331. min-width: 0;
  332. }
  333. .contact-row {
  334. display: flex;
  335. align-items: center;
  336. justify-content: space-between;
  337. box-sizing: border-box;
  338. min-height: 48rpx;
  339. padding: 10rpx;
  340. border-radius: 8rpx;
  341. background: #f8f8f8;
  342. image{
  343. width: 40rpx;
  344. height: 40rpx;
  345. }
  346. }
  347. .contact-info {
  348. display: flex;
  349. align-items: center;
  350. gap: 24rpx;
  351. min-width: 0;
  352. color: #333;
  353. font-size: 30rpx;
  354. }
  355. .contact-info text {
  356. overflow: hidden;
  357. text-overflow: ellipsis;
  358. white-space: nowrap;
  359. }
  360. .call-icon {
  361. flex-shrink: 0;
  362. width: 40rpx;
  363. height: 40rpx;
  364. }
  365. .product-row {
  366. display: flex;
  367. align-items: stretch;
  368. gap: 12rpx;
  369. margin-top: 16rpx;
  370. }
  371. .product-info {
  372. display: flex;
  373. flex: 1;
  374. min-width: 0;
  375. flex-direction: column;
  376. justify-content: space-between;
  377. }
  378. .product-name,
  379. .product-desc {
  380. display: block;
  381. overflow: hidden;
  382. text-overflow: ellipsis;
  383. white-space: nowrap;
  384. }
  385. .product-name {
  386. color: #1d2129;
  387. font-size: 28rpx;
  388. }
  389. .product-desc {
  390. margin-top: 6rpx;
  391. color: #86909c;
  392. font-size: 24rpx;
  393. line-height: 32rpx;
  394. }
  395. .product-meta {
  396. display: flex;
  397. align-items: center;
  398. justify-content: space-between;
  399. gap: 8rpx;
  400. margin-top: 8rpx;
  401. color: #4e5969;
  402. font-size: 24rpx;
  403. white-space: nowrap;
  404. }
  405. .price,
  406. .amount {
  407. color: #ff004e;
  408. }
  409. .price {
  410. font-size: 32rpx;
  411. }
  412. .card-footer {
  413. display: flex;
  414. align-items: center;
  415. justify-content: space-between;
  416. margin-top: 24rpx;
  417. padding-top: 20rpx;
  418. border-top: 1rpx solid #eee;
  419. color: #86909c;
  420. font-size: 26rpx;
  421. }
  422. .total-amount {
  423. font-size: 40rpx;
  424. }
  425. .no-items {
  426. padding: 30rpx 0;
  427. color: #999;
  428. text-align: center;
  429. }
  430. .footer-bar {
  431. position: fixed;
  432. left: 0;
  433. right: 0;
  434. bottom: 0;
  435. z-index: 10;
  436. display: flex;
  437. align-items: center;
  438. justify-content: space-between;
  439. box-sizing: border-box;
  440. min-height: 88rpx;
  441. padding: 24rpx 48rpx calc(24rpx + env(safe-area-inset-bottom));
  442. background: rgba(255, 255, 255, 0.96);
  443. box-shadow: 0 -2rpx 8rpx rgba(0, 0, 0, 0.06);
  444. }
  445. .select-all {
  446. display: flex;
  447. align-items: center;
  448. gap: 16rpx;
  449. color: #1d2129;
  450. font-size: 28rpx;
  451. }
  452. .select-all .select-circle {
  453. margin-top: 0;
  454. }
  455. .refund-button {
  456. display: flex;
  457. align-items: center;
  458. justify-content: center;
  459. width: 240rpx;
  460. height: 80rpx;
  461. border-radius: 80rpx;
  462. background: linear-gradient(93deg, #10abfe 0%, #2260f6 100%);
  463. color: #fff;
  464. font-size: 32rpx;
  465. }
  466. .refund-mask {
  467. position: fixed;
  468. left: 0;
  469. right: 0;
  470. top: 0;
  471. bottom: 0;
  472. z-index: 20;
  473. display: flex;
  474. align-items: center;
  475. justify-content: center;
  476. background: rgba(0, 0, 0, 0.6);
  477. }
  478. .refund-dialog {
  479. display: flex;
  480. width: 590rpx;
  481. flex-direction: column;
  482. align-items: center;
  483. border-radius: 16rpx;
  484. background: #fff;
  485. overflow: hidden;
  486. }
  487. .refund-title {
  488. padding-top: 32rpx;
  489. color: #1d2129;
  490. font-size: 32rpx;
  491. font-weight: 600;
  492. line-height: 44rpx;
  493. margin-bottom: 32rpx;
  494. }
  495. .refund-message {
  496. color: #4e5969;
  497. font-size: 30rpx;
  498. line-height: 42rpx;
  499. text-align: center;
  500. margin-bottom: 32rpx;
  501. }
  502. .refund-actions {
  503. display: flex;
  504. width: 100%;
  505. border-top: 1rpx solid #e7e7e7;
  506. }
  507. .refund-action {
  508. display: flex;
  509. align-items: center;
  510. justify-content: center;
  511. width: 50%;
  512. height: 90rpx;
  513. box-sizing: border-box;
  514. font-size: 30rpx;
  515. line-height: 42rpx;
  516. }
  517. .refund-action.cancel {
  518. border-right: 1rpx solid #e7e7e7;
  519. color: #86909c;
  520. }
  521. .refund-action.confirm {
  522. color: #1d2129;
  523. }
  524. </style>