detail.vue 18 KB

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