detail.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  1. <!-- 订单详情 -->
  2. <template>
  3. <s-layout title="订单详情" class="index-wrap" navbar="inner">
  4. <!-- 订单状态 TODO -->
  5. <view
  6. class="state-box ss-flex-col ss-col-center ss-row-right"
  7. :style="[
  8. {
  9. marginTop: '-' + Number(statusBarHeight + 88) + 'rpx',
  10. paddingTop: Number(statusBarHeight + 88) + 'rpx',
  11. },
  12. ]"
  13. >
  14. <view class="ss-flex ss-m-t-32 ss-m-b-20">
  15. <image
  16. v-if="
  17. state.orderInfo.status_code == 'unpaid' ||
  18. state.orderInfo.status === 10 || // 待发货
  19. state.orderInfo.status_code == 'nocomment'
  20. "
  21. class="state-img"
  22. :src="sheep.$url.static('/static/img/shop/order/order_loading.png')"
  23. >
  24. </image>
  25. <image
  26. v-if="
  27. state.orderInfo.status_code == 'completed' ||
  28. state.orderInfo.status_code == 'refund_agree'
  29. "
  30. class="state-img"
  31. :src="sheep.$url.static('/static/img/shop/order/order_success.png')"
  32. >
  33. </image>
  34. <image
  35. v-if="state.orderInfo.status_code == 'cancel' || state.orderInfo.status_code == 'closed'"
  36. class="state-img"
  37. :src="sheep.$url.static('/static/img/shop/order/order_close.png')"
  38. >
  39. </image>
  40. <image
  41. v-if="state.orderInfo.status_code == 'noget'"
  42. class="state-img"
  43. :src="sheep.$url.static('/static/img/shop/order/order_express.png')"
  44. >
  45. </image>
  46. <view class="ss-font-30">{{ formatOrderStatus(state.orderInfo) }}</view>
  47. </view>
  48. <view class="ss-font-26 ss-m-x-20 ss-m-b-70">{{
  49. formatOrderStatusDescription(state.orderInfo)
  50. }}</view>
  51. </view>
  52. <!-- 收货地址 -->
  53. <view class="order-address-box" v-if="state.orderInfo.receiverAreaId > 0">
  54. <view class="ss-flex ss-col-center">
  55. <text class="address-username">
  56. {{ state.orderInfo.receiverName }}
  57. </text>
  58. <text class="address-phone">{{ state.orderInfo.receiverMobile }}</text>
  59. </view>
  60. <view class="address-detail">
  61. {{ state.orderInfo.receiverAreaName }} {{ state.orderInfo.receiverDetailAddress }}
  62. </view>
  63. </view>
  64. <view
  65. class="detail-goods"
  66. :style="[{ marginTop: state.orderInfo.receiverAreaId > 0 ? '0' : '-40rpx' }]"
  67. >
  68. <!-- 订单信 -->
  69. <view class="order-list" v-for="item in state.orderInfo.items" :key="item.goods_id">
  70. <view class="order-card">
  71. <s-goods-item
  72. @tap="onGoodsDetail(item.skuId)"
  73. :img="item.picUrl"
  74. :title="item.spuName"
  75. :skuText="item.properties.map((property) => property.valueName).join(' ')"
  76. :price="item.price"
  77. :num="item.count"
  78. >
  79. <template #tool>
  80. <view class="ss-flex">
  81. <button
  82. class="ss-reset-button apply-btn"
  83. v-if="[10, 20, 30].includes(state.orderInfo.status) && item.afterSaleStatus === 0"
  84. @tap.stop="
  85. sheep.$router.go('/pages/order/aftersale/apply', {
  86. orderId: state.orderInfo.id,
  87. itemId: item.id,
  88. })
  89. "
  90. >
  91. 申请售后
  92. </button>
  93. <button
  94. class="ss-reset-button apply-btn"
  95. v-if="item.afterSaleStatus === 10"
  96. @tap.stop="
  97. sheep.$router.go('/pages/order/aftersale/detail', {
  98. id: item.afterSaleId,
  99. })
  100. "
  101. >
  102. 退款中
  103. </button>
  104. <button
  105. class="ss-reset-button apply-btn"
  106. v-if="item.afterSaleStatus === 20"
  107. @tap.stop="
  108. sheep.$router.go('/pages/order/aftersale/detail', {
  109. id: item.afterSaleId,
  110. })
  111. "
  112. >
  113. 退款成功
  114. </button>
  115. </view>
  116. </template>
  117. <template #priceSuffix>
  118. <button class="ss-reset-button tag-btn" v-if="item.status_text">
  119. {{ item.status_text }}
  120. </button>
  121. </template>
  122. </s-goods-item>
  123. </view>
  124. </view>
  125. </view>
  126. <!-- 订单信息 -->
  127. <view class="notice-box">
  128. <view class="notice-box__content">
  129. <view class="notice-item--center">
  130. <view class="ss-flex ss-flex-1">
  131. <text class="title">订单编号:</text>
  132. <text class="detail">{{ state.orderInfo.no }}</text>
  133. </view>
  134. <button class="ss-reset-button copy-btn" @tap="onCopy">复制</button>
  135. </view>
  136. <view class="notice-item">
  137. <text class="title">下单时间:</text>
  138. <text class="detail">
  139. {{ sheep.$helper.timeFormat(state.orderInfo.createTime, 'yyyy-mm-dd hh:MM:ss') }}
  140. </text>
  141. </view>
  142. <view class="notice-item" v-if="state.orderInfo.payTime">
  143. <text class="title">支付时间:</text>
  144. <text class="detail">
  145. {{ sheep.$helper.timeFormat(state.orderInfo.payTime, 'yyyy-mm-dd hh:MM:ss') }}
  146. </text>
  147. </view>
  148. <view class="notice-item">
  149. <text class="title">支付方式:</text>
  150. <text class="detail">{{ state.orderInfo.payChannelName || '-' }}</text>
  151. </view>
  152. </view>
  153. </view>
  154. <!-- 价格信息 -->
  155. <view class="order-price-box">
  156. <view class="notice-item ss-flex ss-row-between">
  157. <text class="title">商品总额</text>
  158. <view class="ss-flex">
  159. <text class="detail">¥{{ fen2yuan(state.orderInfo.totalPrice) }}</text>
  160. </view>
  161. </view>
  162. <view class="notice-item ss-flex ss-row-between">
  163. <text class="title">运费</text>
  164. <text class="detail">¥{{ fen2yuan(state.orderInfo.deliveryPrice) }}</text>
  165. </view>
  166. <!-- TODO 芋艿:优惠劵抵扣、积分抵扣 -->
  167. <view class="notice-item ss-flex ss-row-between" v-if="state.orderInfo.couponPrice > 0">
  168. <text class="title">优惠劵金额</text>
  169. <text class="detail">-¥{{ fen2yuan(state.orderInfo.couponPrice) }}</text>
  170. </view>
  171. <view class="notice-item ss-flex ss-row-between" v-if="state.orderInfo.discountPrice > 0">
  172. <text class="title">活动优惠</text>
  173. <text class="detail">¥{{ fen2yuan(state.orderInfo.discountPrice) }}</text>
  174. </view>
  175. <view class="notice-item ss-flex ss-row-between" v-if="state.orderInfo.vipPrice > 0">
  176. <text class="title">会员优惠</text>
  177. <text class="detail">-¥{{ fen2yuan(state.orderInfo.vipPrice) }}</text>
  178. </view>
  179. <view class="notice-item all-rpice-item ss-flex ss-m-t-20">
  180. <text class="title">{{ state.orderInfo.payStatus ? '已付款' : '需付款' }}</text>
  181. <text class="detail all-price">¥{{ fen2yuan(state.orderInfo.payPrice) }}</text>
  182. </view>
  183. <view
  184. class="notice-item all-rpice-item ss-flex ss-m-t-20"
  185. v-if="state.orderInfo.refundPrice > 0"
  186. >
  187. <text class="title">已退款</text>
  188. <text class="detail all-price">¥{{ fen2yuan(state.orderInfo.refundPrice) }}</text>
  189. </view>
  190. </view>
  191. <!-- 底部按钮 -->
  192. <!-- TODO: 查看物流、等待成团、评价完后返回页面没刷新页面 -->
  193. <su-fixed bottom placeholder bg="bg-white" v-if="state.orderInfo.buttons?.length">
  194. <view class="footer-box ss-flex ss-col-center ss-row-right">
  195. <button
  196. class="ss-reset-button cancel-btn"
  197. v-if="state.orderInfo.buttons?.includes('cancel')"
  198. @tap="onCancel(state.orderInfo.id)"
  199. >
  200. 取消订单
  201. </button>
  202. <button
  203. class="ss-reset-button pay-btn ui-BG-Main-Gradient"
  204. v-if="state.orderInfo.buttons?.includes('pay')"
  205. @tap="onPay(state.orderInfo.payOrderId)"
  206. >
  207. 继续支付
  208. </button>
  209. <!-- TODO 芋艿:拼团接入 -->
  210. <button
  211. class="ss-reset-button cancel-btn"
  212. v-if="state.orderInfo.buttons?.includes('combination')"
  213. @tap="
  214. sheep.$router.go('/pages/activity/groupon/detail', {
  215. id: state.orderInfo.ext.groupon_id,
  216. })
  217. "
  218. >
  219. 拼团详情
  220. </button>
  221. <button
  222. class="ss-reset-button cancel-btn"
  223. v-if="state.orderInfo.buttons?.includes('express')"
  224. @tap="onExpress(state.orderInfo.id)"
  225. >
  226. 查看物流
  227. </button>
  228. <button
  229. class="ss-reset-button cancel-btn"
  230. v-if="state.orderInfo.buttons?.includes('confirm')"
  231. @tap="onConfirm(state.orderInfo.id)"
  232. >
  233. 确认收货
  234. </button>
  235. <button
  236. class="ss-reset-button cancel-btn"
  237. v-if="state.orderInfo.buttons?.includes('comment')"
  238. @tap="onComment(state.orderInfo.id)"
  239. >
  240. 评价
  241. </button>
  242. </view>
  243. </su-fixed>
  244. </s-layout>
  245. </template>
  246. <script setup>
  247. import sheep from '@/sheep';
  248. import { onLoad } from '@dcloudio/uni-app';
  249. import { reactive } from 'vue';
  250. import { isEmpty } from 'lodash';
  251. import {
  252. fen2yuan,
  253. formatOrderStatus,
  254. formatOrderStatusDescription,
  255. handleOrderButtons,
  256. } from '@/sheep/hooks/useGoods';
  257. import OrderApi from '@/sheep/api/trade/order';
  258. const statusBarHeight = sheep.$platform.device.statusBarHeight * 2;
  259. const headerBg = sheep.$url.css('/static/img/shop/order/order_bg.png');
  260. const state = reactive({
  261. orderInfo: {},
  262. merchantTradeNo: '', // 商户订单号
  263. comeinType: '', // 进入订单详情的来源类型
  264. });
  265. // 复制
  266. const onCopy = () => {
  267. sheep.$helper.copyText(state.orderInfo.sn);
  268. };
  269. // 去支付
  270. function onPay(payOrderId) {
  271. sheep.$router.go('/pages/pay/index', {
  272. id: payOrderId,
  273. });
  274. }
  275. // 查看商品
  276. function onGoodsDetail(id) {
  277. sheep.$router.go('/pages/goods/index', {
  278. id,
  279. });
  280. }
  281. // 取消订单
  282. async function onCancel(orderId) {
  283. uni.showModal({
  284. title: '提示',
  285. content: '确定要取消订单吗?',
  286. success: async function (res) {
  287. if (!res.confirm) {
  288. return;
  289. }
  290. const { code } = await OrderApi.cancelOrder(orderId);
  291. if (code === 0) {
  292. await getOrderDetail(orderId);
  293. }
  294. },
  295. });
  296. }
  297. // 查看物流
  298. async function onExpress(id) {
  299. sheep.$router.go('/pages/order/express/log', {
  300. id,
  301. });
  302. }
  303. // 确认收货 TODO 芋艿:待测试
  304. async function onConfirm(orderId, ignore = false) {
  305. // 需开启确认收货组件
  306. // todo: 芋艿:待接入微信
  307. // 1.怎么检测是否开启了发货组件功能?如果没有开启的话就不能在这里return出去
  308. // 2.如果开启了走mpConfirm方法,需要在App.vue的show方法中拿到确认收货结果
  309. let isOpenBusinessView = true;
  310. if (
  311. sheep.$platform.name === 'WechatMiniProgram' &&
  312. !isEmpty(state.orderInfo.wechat_extra_data) &&
  313. isOpenBusinessView &&
  314. !ignore
  315. ) {
  316. mpConfirm(orderId);
  317. return;
  318. }
  319. // 正常的确认收货流程
  320. const { code } = await OrderApi.receiveOrder(orderId);
  321. if (code === 0) {
  322. await getOrderDetail(orderId);
  323. }
  324. }
  325. // #ifdef MP-WEIXIN
  326. // 小程序确认收货组件
  327. function mpConfirm(orderId) {
  328. if (!wx.openBusinessView) {
  329. sheep.$helper.toast(`请升级微信版本`);
  330. return;
  331. }
  332. wx.openBusinessView({
  333. businessType: 'weappOrderConfirm',
  334. extraData: {
  335. merchant_trade_no: state.orderInfo.wechat_extra_data.merchant_trade_no,
  336. transaction_id: state.orderInfo.wechat_extra_data.transaction_id,
  337. },
  338. success(response) {
  339. console.log('success:', response);
  340. if (response.errMsg === 'openBusinessView:ok') {
  341. if (response.extraData.status === 'success') {
  342. onConfirm(orderId, true);
  343. }
  344. }
  345. },
  346. fail(error) {
  347. console.log('error:', error);
  348. },
  349. complete(result) {
  350. console.log('result:', result);
  351. },
  352. });
  353. }
  354. // #endif
  355. // 评价
  356. function onComment(id) {
  357. sheep.$router.go('/pages/goods/comment/add', {
  358. id
  359. });
  360. }
  361. async function getOrderDetail(id) {
  362. // 对详情数据进行适配
  363. let res;
  364. if (state.comeinType === 'wechat') {
  365. // TODO 芋艿:微信场景下
  366. res = await OrderApi.getOrder(id, {
  367. merchant_trade_no: state.merchantTradeNo,
  368. });
  369. } else {
  370. res = await OrderApi.getOrder(id);
  371. }
  372. if (res.code === 0) {
  373. state.orderInfo = res.data;
  374. handleOrderButtons(state.orderInfo);
  375. } else {
  376. sheep.$router.back();
  377. }
  378. }
  379. onLoad(async (options) => {
  380. let id = 0;
  381. if (options.id) {
  382. id = options.id;
  383. }
  384. // TODO 芋艿:下面两个变量,后续接入
  385. state.comeinType = options.comein_type;
  386. if (state.comeinType === 'wechat') {
  387. state.merchantTradeNo = options.merchant_trade_no;
  388. }
  389. await getOrderDetail(id);
  390. });
  391. </script>
  392. <style lang="scss" scoped>
  393. .score-img {
  394. width: 36rpx;
  395. height: 36rpx;
  396. margin: 0 4rpx;
  397. }
  398. .apply-btn {
  399. width: 140rpx;
  400. height: 50rpx;
  401. border-radius: 25rpx;
  402. font-size: 24rpx;
  403. border: 2rpx solid #dcdcdc;
  404. line-height: normal;
  405. margin-left: 16rpx;
  406. }
  407. .state-box {
  408. color: rgba(#fff, 0.9);
  409. width: 100%;
  410. background: v-bind(headerBg) no-repeat,
  411. linear-gradient(90deg, var(--ui-BG-Main), var(--ui-BG-Main-gradient));
  412. background-size: 750rpx 100%;
  413. box-sizing: border-box;
  414. .state-img {
  415. width: 60rpx;
  416. height: 60rpx;
  417. margin-right: 20rpx;
  418. }
  419. }
  420. .order-address-box {
  421. background-color: #fff;
  422. border-radius: 10rpx;
  423. margin: -50rpx 20rpx 16rpx 20rpx;
  424. padding: 44rpx 34rpx 42rpx 20rpx;
  425. font-size: 30rpx;
  426. box-sizing: border-box;
  427. font-weight: 500;
  428. color: rgba(51, 51, 51, 1);
  429. .address-username {
  430. margin-right: 20rpx;
  431. }
  432. .address-detail {
  433. font-size: 26rpx;
  434. font-weight: 500;
  435. color: rgba(153, 153, 153, 1);
  436. margin-top: 20rpx;
  437. }
  438. }
  439. .detail-goods {
  440. border-radius: 10rpx;
  441. margin: 0 20rpx 20rpx 20rpx;
  442. .order-list {
  443. margin-bottom: 20rpx;
  444. background-color: #fff;
  445. .order-card {
  446. padding: 20rpx 0;
  447. .order-sku {
  448. font-size: 24rpx;
  449. font-weight: 400;
  450. color: rgba(153, 153, 153, 1);
  451. width: 450rpx;
  452. margin-bottom: 20rpx;
  453. .order-num {
  454. margin-right: 10rpx;
  455. }
  456. }
  457. .tag-btn {
  458. margin-left: 16rpx;
  459. font-size: 24rpx;
  460. height: 36rpx;
  461. color: var(--ui-BG-Main);
  462. border: 2rpx solid var(--ui-BG-Main);
  463. border-radius: 14rpx;
  464. padding: 0 4rpx;
  465. }
  466. }
  467. }
  468. }
  469. // 订单信息。
  470. .notice-box {
  471. background: #fff;
  472. border-radius: 10rpx;
  473. margin: 0 20rpx 20rpx 20rpx;
  474. .notice-box__head {
  475. font-size: 30rpx;
  476. font-weight: 500;
  477. color: rgba(51, 51, 51, 1);
  478. line-height: 80rpx;
  479. border-bottom: 1rpx solid #dfdfdf;
  480. padding: 0 25rpx;
  481. }
  482. .notice-box__content {
  483. padding: 20rpx;
  484. .self-pickup-box {
  485. width: 100%;
  486. .self-pickup--img {
  487. width: 200rpx;
  488. height: 200rpx;
  489. margin: 40rpx 0;
  490. }
  491. }
  492. }
  493. .notice-item,
  494. .notice-item--center {
  495. display: flex;
  496. align-items: center;
  497. line-height: normal;
  498. margin-bottom: 24rpx;
  499. .title {
  500. font-size: 28rpx;
  501. color: #999;
  502. }
  503. .detail {
  504. font-size: 28rpx;
  505. color: #333;
  506. flex: 1;
  507. }
  508. }
  509. }
  510. .copy-btn {
  511. width: 100rpx;
  512. line-height: 50rpx;
  513. border-radius: 25rpx;
  514. padding: 0;
  515. background: rgba(238, 238, 238, 1);
  516. font-size: 22rpx;
  517. font-weight: 400;
  518. color: rgba(51, 51, 51, 1);
  519. }
  520. // 订单价格信息
  521. .order-price-box {
  522. background-color: #fff;
  523. border-radius: 10rpx;
  524. padding: 20rpx;
  525. margin: 0 20rpx 20rpx 20rpx;
  526. .notice-item {
  527. line-height: 70rpx;
  528. .title {
  529. font-size: 28rpx;
  530. color: #999;
  531. }
  532. .detail {
  533. font-size: 28rpx;
  534. color: #333;
  535. font-family: OPPOSANS;
  536. }
  537. }
  538. .all-rpice-item {
  539. justify-content: flex-end;
  540. align-items: center;
  541. .title {
  542. font-size: 26rpx;
  543. font-weight: 500;
  544. color: #333333;
  545. line-height: normal;
  546. }
  547. .all-price {
  548. font-size: 26rpx;
  549. font-family: OPPOSANS;
  550. line-height: normal;
  551. color: $red;
  552. }
  553. }
  554. }
  555. // 底部
  556. .footer-box {
  557. height: 100rpx;
  558. width: 100%;
  559. box-sizing: border-box;
  560. border-radius: 10rpx;
  561. padding-right: 20rpx;
  562. .cancel-btn {
  563. width: 160rpx;
  564. height: 60rpx;
  565. background: #eeeeee;
  566. border-radius: 30rpx;
  567. margin-right: 20rpx;
  568. font-size: 26rpx;
  569. font-weight: 400;
  570. color: #333333;
  571. }
  572. .pay-btn {
  573. width: 160rpx;
  574. height: 60rpx;
  575. font-size: 26rpx;
  576. border-radius: 30rpx;
  577. font-weight: 500;
  578. color: #fff;
  579. }
  580. }
  581. </style>