orderDetail.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603
  1. <template>
  2. <view class="container">
  3. <!-- 加载中 -->
  4. <view v-if="loading" class="loading-wrapper">
  5. <text>加载中...</text>
  6. </view>
  7. <!-- 订单详情 -->
  8. <view v-else-if="order">
  9. <!-- 订单状态 -->
  10. <view class="card status-card">
  11. <view class="status-left">
  12. <view class="status-icon-wrapper" :class="getStatusClass(order.status)">
  13. <text class="status-icon">✓</text>
  14. </view>
  15. <text class="status-text">{{ order.statusText || getStatusText(order.status) }}</text>
  16. </view>
  17. <text class="invoice-status">未开票</text>
  18. </view>
  19. <!-- 订单明细 -->
  20. <view class="card detail-card">
  21. <view class="card-header">
  22. <text class="card-title">订单明细</text>
  23. </view>
  24. <!-- 商品列表 -->
  25. <view v-for="(product, index) in order.products" :key="index" class="product-item">
  26. <view class="product-image">
  27. <image v-if="product.image" :src="product.image" mode="aspectFill"></image>
  28. <view v-else class="image-placeholder"></view>
  29. </view>
  30. <view class="product-info">
  31. <text class="product-name">{{ product.name }}</text>
  32. <text class="product-price">销售单价 ¥{{ product.price.toFixed(2) }}</text>
  33. </view>
  34. <text class="product-quantity">x{{ product.quantity }}</text>
  35. </view>
  36. <!-- 总价 -->
  37. <view class="amount-row">
  38. <text class="amount-label">实付款</text>
  39. <view class="amount-value-wrapper">
  40. <text class="amount-prefix">合计</text>
  41. <text class="amount-symbol">¥</text>
  42. <text class="amount-integer">{{ order.totalAmount.toFixed(2) }}</text>
  43. </view>
  44. </view>
  45. <!-- 操作按钮 -->
  46. <view class="card-footer-actions">
  47. <button v-if="canRefund(order)" class="action-btn-outline" @click="applyRefund">申请退款</button>
  48. <!-- <button class="action-btn-primary" @click="printOrder">打印订单</button>-->
  49. <!-- <button class="action-btn-primary" @click="exportImage">导出图片</button>-->
  50. </view>
  51. </view>
  52. <!-- 订单信息 -->
  53. <view class="card info-card">
  54. <view class="card-header">
  55. <text class="card-title">订单信息</text>
  56. </view>
  57. <view class="info-list">
  58. <view class="info-row" v-if="order.orderName">
  59. <text class="info-label">订单名称</text>
  60. <text class="info-value">{{ order.orderName }}</text>
  61. </view>
  62. <view class="info-row">
  63. <text class="info-label">订单编号</text>
  64. <view class="info-value-group">
  65. <text class="info-value">{{ order.orderNo }}</text>
  66. <view class="copy-btn" @click="copyText(order.orderNo)">
  67. <view class="copy-icon-box"></view>
  68. </view>
  69. </view>
  70. </view>
  71. <view class="info-row" v-if="order.hahaOrderNo">
  72. <text class="info-label">哈哈订单号</text>
  73. <view class="info-value-group">
  74. <text class="info-value">{{ order.hahaOrderNo }}</text>
  75. <view class="copy-btn" @click="copyText(order.hahaOrderNo)">
  76. <view class="copy-icon-box"></view>
  77. </view>
  78. </view>
  79. </view>
  80. <view class="info-row">
  81. <text class="info-label">下单时间</text>
  82. <text class="info-value">{{ formatTime(order.createTime) }}</text>
  83. </view>
  84. <view class="info-row" v-if="order.payTime">
  85. <text class="info-label">支付时间</text>
  86. <text class="info-value">{{ formatTime(order.payTime) }}</text>
  87. </view>
  88. <view class="info-row">
  89. <text class="info-label">支付方式</text>
  90. <text class="info-value">微信</text>
  91. </view>
  92. <view class="info-row">
  93. <text class="info-label">设备编号</text>
  94. <text class="info-value">{{ order.deviceId }}</text>
  95. </view>
  96. <view class="info-row" v-if="order.confidence">
  97. <text class="info-label">AI识别置信度</text>
  98. <text class="info-value">{{ (order.confidence * 100).toFixed(1) }}%</text>
  99. </view>
  100. <view class="info-row" v-if="order.videoUrl">
  101. <text class="info-label">识别视频</text>
  102. <view class="info-link" @click="viewVideo(order.videoUrl)">
  103. <text class="link-text">查看视频</text>
  104. <text class="link-arrow">></text>
  105. </view>
  106. </view>
  107. </view>
  108. </view>
  109. </view>
  110. <!-- 底部提示 -->
  111. <view class="footer-note">
  112. <text>如有疑问,请联系客服</text>
  113. </view>
  114. </view>
  115. </template>
  116. <script setup lang="ts">
  117. import { ref, onMounted } from 'vue';
  118. import { getOrderDetail } from '../../api/order';
  119. import type { OrderInfo } from '../../api/order';
  120. import { checkAuth } from '../../utils/auth';
  121. const order = ref<OrderInfo | null>(null);
  122. const loading = ref(false);
  123. const orderId = ref<number | null>(null);
  124. /**
  125. * 获取订单状态文本
  126. */
  127. const getStatusText = (status: number) => {
  128. const statusMap: any = {
  129. 0: '待支付',
  130. 1: '已完成',
  131. 2: '已取消'
  132. };
  133. return statusMap[status] || '未知';
  134. };
  135. /**
  136. * 获取状态样式
  137. */
  138. const getStatusClass = (status: number) => {
  139. if (status === 1) return 'status-success';
  140. if (status === 0) return 'status-pending';
  141. if (status === 2) return 'status-cancelled';
  142. return '';
  143. };
  144. /**
  145. * 判断是否可以退款
  146. */
  147. const canRefund = (order: OrderInfo) => {
  148. return order.status === 1; // 只有已完成的订单可以退款
  149. };
  150. /**
  151. * 格式化时间
  152. */
  153. const formatTime = (time: string | undefined) => {
  154. if (!time) return '-';
  155. // 如果已经是格式化的时间字符串,直接返回
  156. if (typeof time === 'string' && time.includes('-')) {
  157. return time.replace('T', ' ').substring(0, 19);
  158. }
  159. return time;
  160. };
  161. /**
  162. * 加载订单详情
  163. */
  164. const loadOrderDetail = async () => {
  165. if (!orderId.value) {
  166. uni.showToast({
  167. title: '订单ID不存在',
  168. icon: 'none'
  169. });
  170. return;
  171. }
  172. loading.value = true;
  173. try {
  174. uni.showLoading({
  175. title: '加载中...',
  176. mask: true
  177. });
  178. // 调用真实接口获取订单详情
  179. const orderDetail = await getOrderDetail({ orderId: orderId.value });
  180. order.value = orderDetail;
  181. uni.hideLoading();
  182. } catch (error: any) {
  183. uni.hideLoading();
  184. console.error('加载订单详情失败:', error);
  185. // 错误已在request工具中显示
  186. setTimeout(() => {
  187. uni.navigateBack();
  188. }, 1500);
  189. } finally {
  190. loading.value = false;
  191. }
  192. };
  193. /**
  194. * 页面加载时检查登录状态并获取订单详情
  195. */
  196. onMounted(() => {
  197. // 检查登录状态
  198. if (!checkAuth()) {
  199. return;
  200. }
  201. const pages = getCurrentPages();
  202. const currentPage = pages[pages.length - 1] as any;
  203. const options = currentPage.options || {};
  204. if (options.orderId) {
  205. orderId.value = parseInt(options.orderId);
  206. loadOrderDetail();
  207. } else {
  208. uni.showToast({
  209. title: '订单ID不存在',
  210. icon: 'none'
  211. });
  212. setTimeout(() => {
  213. uni.navigateBack();
  214. }, 1500);
  215. }
  216. });
  217. /**
  218. * 申请退款
  219. */
  220. const applyRefund = () => {
  221. if (!order.value) return;
  222. uni.navigateTo({
  223. url: '/pages/refund/refund?orderId=' + order.value.id
  224. });
  225. };
  226. /**
  227. * 打印订单
  228. */
  229. const printOrder = () => {
  230. uni.showToast({
  231. title: '打印订单功能开发中',
  232. icon: 'none'
  233. });
  234. };
  235. /**
  236. * 导出图片
  237. */
  238. const exportImage = () => {
  239. uni.showToast({
  240. title: '导出图片功能开发中',
  241. icon: 'none'
  242. });
  243. };
  244. /**
  245. * 复制文本
  246. */
  247. const copyText = (text: string) => {
  248. uni.setClipboardData({
  249. data: text,
  250. success: () => {
  251. uni.showToast({
  252. title: '复制成功',
  253. icon: 'success'
  254. });
  255. }
  256. });
  257. };
  258. /**
  259. * 查看视频
  260. */
  261. const viewVideo = (url: string) => {
  262. // TODO: 实现视频播放功能
  263. uni.showToast({
  264. title: '视频播放功能开发中',
  265. icon: 'none'
  266. });
  267. };
  268. </script>
  269. <style>
  270. .container {
  271. min-height: 100vh;
  272. background-color: #f8f8f8;
  273. padding: 20rpx;
  274. box-sizing: border-box;
  275. }
  276. .loading-wrapper {
  277. display: flex;
  278. align-items: center;
  279. justify-content: center;
  280. min-height: 400rpx;
  281. font-size: 28rpx;
  282. color: #999;
  283. }
  284. /* 通用卡片样式 */
  285. .card {
  286. background-color: #ffffff;
  287. border-radius: 16rpx;
  288. padding: 30rpx;
  289. margin-bottom: 20rpx;
  290. box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);
  291. }
  292. /* 订单状态卡片 */
  293. .status-card {
  294. display: flex;
  295. justify-content: space-between;
  296. align-items: center;
  297. }
  298. .status-left {
  299. display: flex;
  300. align-items: center;
  301. }
  302. .status-icon-wrapper {
  303. width: 44rpx;
  304. height: 44rpx;
  305. background-color: #7ED321;
  306. border-radius: 50%;
  307. display: flex;
  308. align-items: center;
  309. justify-content: center;
  310. margin-right: 16rpx;
  311. }
  312. .status-icon-wrapper.status-success {
  313. background-color: #7ED321;
  314. }
  315. .status-icon-wrapper.status-pending {
  316. background-color: #FF9100;
  317. }
  318. .status-icon-wrapper.status-cancelled {
  319. background-color: #999999;
  320. }
  321. .status-icon {
  322. color: #ffffff;
  323. font-size: 28rpx;
  324. font-weight: bold;
  325. }
  326. .status-text {
  327. font-size: 32rpx;
  328. color: #333333;
  329. font-weight: 500;
  330. }
  331. .invoice-status {
  332. font-size: 28rpx;
  333. color: #FF6B6B;
  334. }
  335. /* 订单明细卡片 */
  336. .detail-card {
  337. padding: 0;
  338. overflow: hidden;
  339. }
  340. .card-header {
  341. padding: 30rpx;
  342. border-bottom: 1rpx solid #f5f5f5;
  343. }
  344. .card-title {
  345. font-size: 32rpx;
  346. font-weight: bold;
  347. color: #333333;
  348. }
  349. .product-item {
  350. display: flex;
  351. padding: 30rpx;
  352. align-items: flex-start;
  353. }
  354. .product-image {
  355. width: 140rpx;
  356. height: 140rpx;
  357. background-color: #f9f9f9;
  358. border-radius: 8rpx;
  359. margin-right: 20rpx;
  360. border: 1rpx solid #eeeeee;
  361. }
  362. .product-image image {
  363. width: 100%;
  364. height: 100%;
  365. border-radius: 8rpx;
  366. }
  367. .image-placeholder {
  368. width: 100%;
  369. height: 100%;
  370. background-color: #f5f5f5;
  371. border-radius: 8rpx;
  372. display: flex;
  373. align-items: center;
  374. justify-content: center;
  375. }
  376. .product-info {
  377. flex: 1;
  378. }
  379. .product-name {
  380. font-size: 30rpx;
  381. color: #333333;
  382. margin-bottom: 16rpx;
  383. display: block;
  384. }
  385. .product-price {
  386. font-size: 26rpx;
  387. color: #999999;
  388. }
  389. .product-quantity {
  390. font-size: 26rpx;
  391. color: #999999;
  392. margin-top: 60rpx;
  393. }
  394. .amount-row {
  395. display: flex;
  396. justify-content: space-between;
  397. align-items: center;
  398. padding: 30rpx;
  399. border-top: 1rpx solid #f5f5f5;
  400. }
  401. .amount-label {
  402. font-size: 28rpx;
  403. color: #999999;
  404. }
  405. .amount-value-wrapper {
  406. display: flex;
  407. align-items: baseline;
  408. }
  409. .amount-prefix {
  410. font-size: 26rpx;
  411. color: #333333;
  412. margin-right: 10rpx;
  413. }
  414. .amount-symbol {
  415. font-size: 26rpx;
  416. color: #333333;
  417. font-weight: bold;
  418. }
  419. .amount-integer {
  420. font-size: 36rpx;
  421. color: #333333;
  422. font-weight: bold;
  423. }
  424. .card-footer-actions {
  425. display: flex;
  426. justify-content: flex-end;
  427. padding: 20rpx 30rpx 30rpx;
  428. }
  429. .action-btn-outline {
  430. background-color: #f8f8f8;
  431. border: 1rpx solid #e0e0e0;
  432. border-radius: 12rpx;
  433. font-size: 26rpx;
  434. color: #666666;
  435. margin: 0 0 0 20rpx;
  436. padding: 10rpx 24rpx;
  437. line-height: 1.5;
  438. }
  439. .action-btn-outline::after {
  440. border: none;
  441. }
  442. .action-btn-primary {
  443. background-color: #FFD200;
  444. border-radius: 12rpx;
  445. font-size: 26rpx;
  446. color: #333333;
  447. margin: 0 0 0 20rpx;
  448. padding: 10rpx 24rpx;
  449. line-height: 1.5;
  450. font-weight: 500;
  451. }
  452. .action-btn-primary::after {
  453. border: none;
  454. }
  455. /* 订单信息卡片 */
  456. .info-card {
  457. padding: 0;
  458. }
  459. .info-list {
  460. padding: 10rpx 30rpx 30rpx;
  461. }
  462. .info-row {
  463. display: flex;
  464. justify-content: space-between;
  465. align-items: center;
  466. padding: 24rpx 0;
  467. border-bottom: 1rpx solid #f9f9f9;
  468. }
  469. .info-row:last-child {
  470. border-bottom: none;
  471. }
  472. .info-label {
  473. font-size: 28rpx;
  474. color: #666666;
  475. }
  476. .info-value-group {
  477. display: flex;
  478. align-items: center;
  479. }
  480. .info-value {
  481. font-size: 28rpx;
  482. color: #333333;
  483. }
  484. .copy-btn {
  485. margin-left: 10rpx;
  486. padding: 4rpx;
  487. }
  488. .copy-icon-box {
  489. width: 28rpx;
  490. height: 32rpx;
  491. border: 3rpx solid #999999;
  492. position: relative;
  493. border-radius: 4rpx;
  494. }
  495. .copy-icon-box::after {
  496. content: '';
  497. position: absolute;
  498. width: 20rpx;
  499. height: 24rpx;
  500. border: 3rpx solid #999999;
  501. background-color: #ffffff;
  502. top: -8rpx;
  503. right: -8rpx;
  504. border-radius: 4rpx;
  505. }
  506. .info-link {
  507. display: flex;
  508. align-items: center;
  509. }
  510. .link-text {
  511. font-size: 28rpx;
  512. color: #999999;
  513. margin-right: 6rpx;
  514. }
  515. .link-arrow {
  516. font-size: 28rpx;
  517. color: #cccccc;
  518. }
  519. /* 底部提示 */
  520. .footer-note {
  521. text-align: center;
  522. padding: 40rpx 0;
  523. }
  524. .footer-note text {
  525. font-size: 26rpx;
  526. color: #cccccc;
  527. }
  528. </style>