order-details.vue 12 KB

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