detail.vue 16 KB

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