orderDetail.vue 12 KB

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