detail.vue 16 KB

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