detail.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  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.spuId)"
  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. <PickUpVerify :order-info="state.orderInfo" :systemStore="systemStore" ref="pickUpVerifyRef"></PickUpVerify>
  128. <!-- 订单信息 -->
  129. <view class="notice-box">
  130. <view class="notice-box__content">
  131. <view class="notice-item--center">
  132. <view class="ss-flex ss-flex-1">
  133. <text class="title">订单编号:</text>
  134. <text class="detail">{{ state.orderInfo.no }}</text>
  135. </view>
  136. <button class="ss-reset-button copy-btn" @tap="onCopy">复制</button>
  137. </view>
  138. <view class="notice-item">
  139. <text class="title">下单时间:</text>
  140. <text class="detail">
  141. {{ sheep.$helper.timeFormat(state.orderInfo.createTime, 'yyyy-mm-dd hh:MM:ss') }}
  142. </text>
  143. </view>
  144. <view class="notice-item" v-if="state.orderInfo.payTime">
  145. <text class="title">支付时间:</text>
  146. <text class="detail">
  147. {{ sheep.$helper.timeFormat(state.orderInfo.payTime, 'yyyy-mm-dd hh:MM:ss') }}
  148. </text>
  149. </view>
  150. <view class="notice-item">
  151. <text class="title">支付方式:</text>
  152. <text class="detail">{{ state.orderInfo.payChannelName || '-' }}</text>
  153. </view>
  154. </view>
  155. </view>
  156. <!-- 价格信息 -->
  157. <view class="order-price-box">
  158. <view class="notice-item ss-flex ss-row-between">
  159. <text class="title">商品总额</text>
  160. <view class="ss-flex">
  161. <text class="detail">¥{{ fen2yuan(state.orderInfo.totalPrice) }}</text>
  162. </view>
  163. </view>
  164. <view class="notice-item ss-flex ss-row-between">
  165. <text class="title">运费</text>
  166. <text class="detail">¥{{ fen2yuan(state.orderInfo.deliveryPrice) }}</text>
  167. </view>
  168. <!-- TODO 芋艿:优惠劵抵扣、积分抵扣 -->
  169. <view class="notice-item ss-flex ss-row-between" v-if="state.orderInfo.couponPrice > 0">
  170. <text class="title">优惠劵金额</text>
  171. <text class="detail">-¥{{ fen2yuan(state.orderInfo.couponPrice) }}</text>
  172. </view>
  173. <view class="notice-item ss-flex ss-row-between" v-if="state.orderInfo.pointPrice > 0">
  174. <text class="title">积分抵扣</text>
  175. <text class="detail">-¥{{ fen2yuan(state.orderInfo.pointPrice) }}</text>
  176. </view>
  177. <view class="notice-item ss-flex ss-row-between" v-if="state.orderInfo.discountPrice > 0">
  178. <text class="title">活动优惠</text>
  179. <text class="detail">¥{{ fen2yuan(state.orderInfo.discountPrice) }}</text>
  180. </view>
  181. <view class="notice-item ss-flex ss-row-between" v-if="state.orderInfo.vipPrice > 0">
  182. <text class="title">会员优惠</text>
  183. <text class="detail">-¥{{ fen2yuan(state.orderInfo.vipPrice) }}</text>
  184. </view>
  185. <view class="notice-item all-rpice-item ss-flex ss-m-t-20">
  186. <text class="title">{{ state.orderInfo.payStatus ? '已付款' : '需付款' }}</text>
  187. <text class="detail all-price">¥{{ fen2yuan(state.orderInfo.payPrice) }}</text>
  188. </view>
  189. <view
  190. class="notice-item all-rpice-item ss-flex ss-m-t-20"
  191. v-if="state.orderInfo.refundPrice > 0"
  192. >
  193. <text class="title">已退款</text>
  194. <text class="detail all-price">¥{{ fen2yuan(state.orderInfo.refundPrice) }}</text>
  195. </view>
  196. </view>
  197. <!-- 底部按钮 -->
  198. <!-- TODO: 查看物流、等待成团、评价完后返回页面没刷新页面 -->
  199. <su-fixed bottom placeholder bg="bg-white" v-if="state.orderInfo.buttons?.length">
  200. <view class="footer-box ss-flex ss-col-center ss-row-right">
  201. <button
  202. class="ss-reset-button cancel-btn"
  203. v-if="state.orderInfo.buttons?.includes('cancel')"
  204. @tap="onCancel(state.orderInfo.id)"
  205. >
  206. 取消订单
  207. </button>
  208. <button
  209. class="ss-reset-button pay-btn ui-BG-Main-Gradient"
  210. v-if="state.orderInfo.buttons?.includes('pay')"
  211. @tap="onPay(state.orderInfo.payOrderId)"
  212. >
  213. 继续支付
  214. </button>
  215. <button
  216. class="ss-reset-button cancel-btn"
  217. v-if="state.orderInfo.buttons?.includes('combination')"
  218. @tap="
  219. sheep.$router.go('/pages/activity/groupon/detail', {
  220. id: state.orderInfo.combinationRecordId,
  221. })
  222. "
  223. >
  224. 拼团详情
  225. </button>
  226. <button
  227. class="ss-reset-button cancel-btn"
  228. v-if="state.orderInfo.buttons?.includes('express')"
  229. @tap="onExpress(state.orderInfo.id)"
  230. >
  231. 查看物流
  232. </button>
  233. <button
  234. class="ss-reset-button cancel-btn"
  235. v-if="state.orderInfo.buttons?.includes('confirm')"
  236. @tap="onConfirm(state.orderInfo.id)"
  237. >
  238. 确认收货
  239. </button>
  240. <button
  241. class="ss-reset-button cancel-btn"
  242. v-if="state.orderInfo.buttons?.includes('comment')"
  243. @tap="onComment(state.orderInfo.id)"
  244. >
  245. 评价
  246. </button>
  247. </view>
  248. </su-fixed>
  249. </s-layout>
  250. </template>
  251. <script setup>
  252. import sheep from '@/sheep';
  253. import { onLoad } from '@dcloudio/uni-app';
  254. import { reactive, ref } from 'vue';
  255. import { isEmpty } from 'lodash-es';
  256. import {
  257. fen2yuan,
  258. formatOrderStatus,
  259. formatOrderStatusDescription,
  260. handleOrderButtons,
  261. } from '@/sheep/hooks/useGoods';
  262. import OrderApi from '@/sheep/api/trade/order';
  263. import DeliveryApi from '@/sheep/api/trade/delivery';
  264. import PickUpVerify from '@/pages/order/pickUpVerify.vue';
  265. const statusBarHeight = sheep.$platform.device.statusBarHeight * 2;
  266. const headerBg = sheep.$url.css('/static/img/shop/order/order_bg.png');
  267. const state = reactive({
  268. orderInfo: {},
  269. merchantTradeNo: '', // 商户订单号
  270. comeinType: '', // 进入订单详情的来源类型
  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. // 确认收货 TODO 芋艿:待测试
  313. async function onConfirm(orderId, ignore = false) {
  314. // 需开启确认收货组件
  315. // todo: 芋艿:待接入微信
  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. // 正常的确认收货流程
  329. const { code } = await OrderApi.receiveOrder(orderId);
  330. if (code === 0) {
  331. await getOrderDetail(orderId);
  332. }
  333. }
  334. // #ifdef MP-WEIXIN
  335. // 小程序确认收货组件
  336. function mpConfirm(orderId) {
  337. if (!wx.openBusinessView) {
  338. sheep.$helper.toast(`请升级微信版本`);
  339. return;
  340. }
  341. wx.openBusinessView({
  342. businessType: 'weappOrderConfirm',
  343. extraData: {
  344. merchant_trade_no: state.orderInfo.wechat_extra_data.merchant_trade_no,
  345. transaction_id: state.orderInfo.wechat_extra_data.transaction_id,
  346. },
  347. success(response) {
  348. console.log('success:', response);
  349. if (response.errMsg === 'openBusinessView:ok') {
  350. if (response.extraData.status === 'success') {
  351. onConfirm(orderId, true);
  352. }
  353. }
  354. },
  355. fail(error) {
  356. console.log('error:', error);
  357. },
  358. complete(result) {
  359. console.log('result:', result);
  360. },
  361. });
  362. }
  363. // #endif
  364. // 评价
  365. function onComment(id) {
  366. sheep.$router.go('/pages/goods/comment/add', {
  367. id,
  368. });
  369. }
  370. const pickUpVerifyRef = ref();
  371. async function getOrderDetail(id) {
  372. // 对详情数据进行适配
  373. let res;
  374. if (state.comeinType === 'wechat') {
  375. // TODO 芋艿:微信场景下
  376. res = await OrderApi.getOrder(id, {
  377. merchant_trade_no: state.merchantTradeNo,
  378. });
  379. } else {
  380. res = await OrderApi.getOrder(id);
  381. }
  382. if (res.code === 0) {
  383. state.orderInfo = res.data;
  384. handleOrderButtons(state.orderInfo);
  385. // 配送方式:门店自提
  386. if (res.data.pickUpStoreId) {
  387. const { data } = await DeliveryApi.getDeliveryPickUpStore(res.data.pickUpStoreId);
  388. systemStore.value = data || {};
  389. }
  390. if (state.orderInfo.deliveryType === 2 && state.orderInfo.payStatus) {
  391. pickUpVerifyRef.value && pickUpVerifyRef.value.markCode(res.data.pickUpVerifyCode);
  392. }
  393. } else {
  394. sheep.$router.back();
  395. }
  396. }
  397. onLoad(async (options) => {
  398. let id = 0;
  399. if (options.id) {
  400. id = options.id;
  401. }
  402. // TODO 芋艿:下面两个变量,后续接入
  403. state.comeinType = options.comein_type;
  404. if (state.comeinType === 'wechat') {
  405. state.merchantTradeNo = options.merchant_trade_no;
  406. }
  407. await getOrderDetail(id);
  408. });
  409. </script>
  410. <style lang="scss" scoped>
  411. .score-img {
  412. width: 36rpx;
  413. height: 36rpx;
  414. margin: 0 4rpx;
  415. }
  416. .apply-btn {
  417. width: 140rpx;
  418. height: 50rpx;
  419. border-radius: 25rpx;
  420. font-size: 24rpx;
  421. border: 2rpx solid #dcdcdc;
  422. line-height: normal;
  423. margin-left: 16rpx;
  424. }
  425. .state-box {
  426. color: rgba(#fff, 0.9);
  427. width: 100%;
  428. background: v-bind(headerBg) no-repeat,
  429. linear-gradient(90deg, var(--ui-BG-Main), var(--ui-BG-Main-gradient));
  430. background-size: 750rpx 100%;
  431. box-sizing: border-box;
  432. .state-img {
  433. width: 60rpx;
  434. height: 60rpx;
  435. margin-right: 20rpx;
  436. }
  437. }
  438. .order-address-box {
  439. background-color: #fff;
  440. border-radius: 10rpx;
  441. margin: -50rpx 20rpx 16rpx 20rpx;
  442. padding: 44rpx 34rpx 42rpx 20rpx;
  443. font-size: 30rpx;
  444. box-sizing: border-box;
  445. font-weight: 500;
  446. color: rgba(51, 51, 51, 1);
  447. .address-username {
  448. margin-right: 20rpx;
  449. }
  450. .address-detail {
  451. font-size: 26rpx;
  452. font-weight: 500;
  453. color: rgba(153, 153, 153, 1);
  454. margin-top: 20rpx;
  455. }
  456. }
  457. .detail-goods {
  458. border-radius: 10rpx;
  459. margin: 0 20rpx 20rpx 20rpx;
  460. .order-list {
  461. margin-bottom: 20rpx;
  462. background-color: #fff;
  463. .order-card {
  464. padding: 20rpx 0;
  465. .order-sku {
  466. font-size: 24rpx;
  467. font-weight: 400;
  468. color: rgba(153, 153, 153, 1);
  469. width: 450rpx;
  470. margin-bottom: 20rpx;
  471. .order-num {
  472. margin-right: 10rpx;
  473. }
  474. }
  475. .tag-btn {
  476. margin-left: 16rpx;
  477. font-size: 24rpx;
  478. height: 36rpx;
  479. color: var(--ui-BG-Main);
  480. border: 2rpx solid var(--ui-BG-Main);
  481. border-radius: 14rpx;
  482. padding: 0 4rpx;
  483. }
  484. }
  485. }
  486. }
  487. // 订单信息。
  488. .notice-box {
  489. background: #fff;
  490. border-radius: 10rpx;
  491. margin: 0 20rpx 20rpx 20rpx;
  492. .notice-box__head {
  493. font-size: 30rpx;
  494. font-weight: 500;
  495. color: rgba(51, 51, 51, 1);
  496. line-height: 80rpx;
  497. border-bottom: 1rpx solid #dfdfdf;
  498. padding: 0 25rpx;
  499. }
  500. .notice-box__content {
  501. padding: 20rpx;
  502. .self-pickup-box {
  503. width: 100%;
  504. .self-pickup--img {
  505. width: 200rpx;
  506. height: 200rpx;
  507. margin: 40rpx 0;
  508. }
  509. }
  510. }
  511. .notice-item,
  512. .notice-item--center {
  513. display: flex;
  514. align-items: center;
  515. line-height: normal;
  516. margin-bottom: 24rpx;
  517. .title {
  518. font-size: 28rpx;
  519. color: #999;
  520. }
  521. .detail {
  522. font-size: 28rpx;
  523. color: #333;
  524. flex: 1;
  525. }
  526. }
  527. }
  528. .copy-btn {
  529. width: 100rpx;
  530. line-height: 50rpx;
  531. border-radius: 25rpx;
  532. padding: 0;
  533. background: rgba(238, 238, 238, 1);
  534. font-size: 22rpx;
  535. font-weight: 400;
  536. color: rgba(51, 51, 51, 1);
  537. }
  538. // 订单价格信息
  539. .order-price-box {
  540. background-color: #fff;
  541. border-radius: 10rpx;
  542. padding: 20rpx;
  543. margin: 0 20rpx 20rpx 20rpx;
  544. .notice-item {
  545. line-height: 70rpx;
  546. .title {
  547. font-size: 28rpx;
  548. color: #999;
  549. }
  550. .detail {
  551. font-size: 28rpx;
  552. color: #333;
  553. font-family: OPPOSANS;
  554. }
  555. }
  556. .all-rpice-item {
  557. justify-content: flex-end;
  558. align-items: center;
  559. .title {
  560. font-size: 26rpx;
  561. font-weight: 500;
  562. color: #333333;
  563. line-height: normal;
  564. }
  565. .all-price {
  566. font-size: 26rpx;
  567. font-family: OPPOSANS;
  568. line-height: normal;
  569. color: $red;
  570. }
  571. }
  572. }
  573. // 底部
  574. .footer-box {
  575. height: 100rpx;
  576. width: 100%;
  577. box-sizing: border-box;
  578. border-radius: 10rpx;
  579. padding-right: 20rpx;
  580. .cancel-btn {
  581. width: 160rpx;
  582. height: 60rpx;
  583. background: #eeeeee;
  584. border-radius: 30rpx;
  585. margin-right: 20rpx;
  586. font-size: 26rpx;
  587. font-weight: 400;
  588. color: #333333;
  589. }
  590. .pay-btn {
  591. width: 160rpx;
  592. height: 60rpx;
  593. font-size: 26rpx;
  594. border-radius: 30rpx;
  595. font-weight: 500;
  596. color: #fff;
  597. }
  598. }
  599. </style>