detail.vue 19 KB

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