detail.vue 18 KB

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