detail.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  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 {
  291. error,
  292. data
  293. } = await sheep.$api.order.confirm(orderId);
  294. if (error === 0) {
  295. getOrderDetail(data.order_sn);
  296. }
  297. }
  298. // #ifdef MP-WEIXIN
  299. // 小程序确认收货组件
  300. function mpConfirm(orderId) {
  301. if (!wx.openBusinessView) {
  302. sheep.$helper.toast(`请升级微信版本`);
  303. return;
  304. }
  305. wx.openBusinessView({
  306. businessType: 'weappOrderConfirm',
  307. extraData: {
  308. merchant_trade_no: state.orderInfo.wechat_extra_data.merchant_trade_no,
  309. transaction_id: state.orderInfo.wechat_extra_data.transaction_id,
  310. },
  311. success(response) {
  312. console.log('success:', response);
  313. if (response.errMsg === 'openBusinessView:ok') {
  314. if (response.extraData.status === 'success') {
  315. onConfirm(orderId, true);
  316. }
  317. }
  318. },
  319. fail(error) {
  320. console.log('error:', error);
  321. },
  322. complete(result) {
  323. console.log('result:', result);
  324. },
  325. });
  326. }
  327. // #endif
  328. // 配送方式详情
  329. function onDetail(item) {
  330. sheep.$router.go('/pages/order/dispatch/content', {
  331. id: item.order_id,
  332. item_id: item.id,
  333. });
  334. }
  335. // 评价
  336. function onComment(orderSN, orderId) {
  337. console.log(orderId);
  338. // return;
  339. uni.$once('SELECT_INVOICE', (e) => {
  340. state.invoiceInfo = e.invoiceInfo;
  341. });
  342. sheep.$router.go('/pages/goods/comment/add', {
  343. orderSN,
  344. orderId
  345. });
  346. }
  347. async function getOrderDetail(id) {
  348. // 对详情数据进行适配
  349. let res;
  350. if (state.comeinType === 'wechat') {
  351. res = await sheep.$api.order.detail(id, {
  352. merchant_trade_no: state.merchantTradeNo,
  353. });
  354. } else {
  355. res = await sheep.$api.order.detail(id);
  356. }
  357. if (res.code === 0) {
  358. state.orderInfo = res.data;
  359. handleOrderButtons(state.orderInfo)
  360. } else {
  361. sheep.$router.back();
  362. }
  363. }
  364. onLoad(async (options) => {
  365. let id = 0;
  366. if (options.id) {
  367. id = options.id;
  368. }
  369. // TODO 芋艿:下面两个变量,后续接入
  370. state.comeinType = options.comein_type;
  371. if (state.comeinType === 'wechat') {
  372. state.merchantTradeNo = options.merchant_trade_no;
  373. }
  374. await getOrderDetail(id);
  375. });
  376. </script>
  377. <style lang="scss" scoped>
  378. .score-img {
  379. width: 36rpx;
  380. height: 36rpx;
  381. margin: 0 4rpx;
  382. }
  383. .apply-btn {
  384. width: 140rpx;
  385. height: 50rpx;
  386. border-radius: 25rpx;
  387. font-size: 24rpx;
  388. border: 2rpx solid #dcdcdc;
  389. line-height: normal;
  390. margin-left: 16rpx;
  391. }
  392. .state-box {
  393. color: rgba(#fff, 0.9);
  394. width: 100%;
  395. background: v-bind(headerBg) no-repeat,
  396. linear-gradient(90deg, var(--ui-BG-Main), var(--ui-BG-Main-gradient));
  397. background-size: 750rpx 100%;
  398. box-sizing: border-box;
  399. .state-img {
  400. width: 60rpx;
  401. height: 60rpx;
  402. margin-right: 20rpx;
  403. }
  404. }
  405. .order-address-box {
  406. background-color: #fff;
  407. border-radius: 10rpx;
  408. margin: -50rpx 20rpx 16rpx 20rpx;
  409. padding: 44rpx 34rpx 42rpx 20rpx;
  410. font-size: 30rpx;
  411. box-sizing: border-box;
  412. font-weight: 500;
  413. color: rgba(51, 51, 51, 1);
  414. .address-username {
  415. margin-right: 20rpx;
  416. }
  417. .address-detail {
  418. font-size: 26rpx;
  419. font-weight: 500;
  420. color: rgba(153, 153, 153, 1);
  421. margin-top: 20rpx;
  422. }
  423. }
  424. .detail-goods {
  425. border-radius: 10rpx;
  426. margin: 0 20rpx 20rpx 20rpx;
  427. .order-list {
  428. margin-bottom: 20rpx;
  429. background-color: #fff;
  430. .order-card {
  431. padding: 20rpx 0;
  432. .order-sku {
  433. font-size: 24rpx;
  434. font-weight: 400;
  435. color: rgba(153, 153, 153, 1);
  436. width: 450rpx;
  437. margin-bottom: 20rpx;
  438. .order-num {
  439. margin-right: 10rpx;
  440. }
  441. }
  442. .tag-btn {
  443. margin-left: 16rpx;
  444. font-size: 24rpx;
  445. height: 36rpx;
  446. color: var(--ui-BG-Main);
  447. border: 2rpx solid var(--ui-BG-Main);
  448. border-radius: 14rpx;
  449. padding: 0 4rpx;
  450. }
  451. }
  452. }
  453. }
  454. // 订单信息。
  455. .notice-box {
  456. background: #fff;
  457. border-radius: 10rpx;
  458. margin: 0 20rpx 20rpx 20rpx;
  459. .notice-box__head {
  460. font-size: 30rpx;
  461. font-weight: 500;
  462. color: rgba(51, 51, 51, 1);
  463. line-height: 80rpx;
  464. border-bottom: 1rpx solid #dfdfdf;
  465. padding: 0 25rpx;
  466. }
  467. .notice-box__content {
  468. padding: 20rpx;
  469. .self-pickup-box {
  470. width: 100%;
  471. .self-pickup--img {
  472. width: 200rpx;
  473. height: 200rpx;
  474. margin: 40rpx 0;
  475. }
  476. }
  477. }
  478. .notice-item,
  479. .notice-item--center {
  480. display: flex;
  481. align-items: center;
  482. line-height: normal;
  483. margin-bottom: 24rpx;
  484. .title {
  485. font-size: 28rpx;
  486. color: #999;
  487. }
  488. .detail {
  489. font-size: 28rpx;
  490. color: #333;
  491. flex: 1;
  492. }
  493. }
  494. }
  495. .copy-btn {
  496. width: 100rpx;
  497. line-height: 50rpx;
  498. border-radius: 25rpx;
  499. padding: 0;
  500. background: rgba(238, 238, 238, 1);
  501. font-size: 22rpx;
  502. font-weight: 400;
  503. color: rgba(51, 51, 51, 1);
  504. }
  505. // 订单价格信息
  506. .order-price-box {
  507. background-color: #fff;
  508. border-radius: 10rpx;
  509. padding: 20rpx;
  510. margin: 0 20rpx 20rpx 20rpx;
  511. .notice-item {
  512. line-height: 70rpx;
  513. .title {
  514. font-size: 28rpx;
  515. color: #999;
  516. }
  517. .detail {
  518. font-size: 28rpx;
  519. color: #333;
  520. font-family: OPPOSANS;
  521. }
  522. }
  523. .all-rpice-item {
  524. justify-content: flex-end;
  525. align-items: center;
  526. .title {
  527. font-size: 26rpx;
  528. font-weight: 500;
  529. color: #333333;
  530. line-height: normal;
  531. }
  532. .all-price {
  533. font-size: 26rpx;
  534. font-family: OPPOSANS;
  535. line-height: normal;
  536. color: $red;
  537. }
  538. }
  539. }
  540. // 底部
  541. .footer-box {
  542. height: 100rpx;
  543. width: 100%;
  544. box-sizing: border-box;
  545. border-radius: 10rpx;
  546. padding-right: 20rpx;
  547. .cancel-btn {
  548. width: 160rpx;
  549. height: 60rpx;
  550. background: #eeeeee;
  551. border-radius: 30rpx;
  552. margin-right: 20rpx;
  553. font-size: 26rpx;
  554. font-weight: 400;
  555. color: #333333;
  556. }
  557. .pay-btn {
  558. width: 160rpx;
  559. height: 60rpx;
  560. font-size: 26rpx;
  561. border-radius: 30rpx;
  562. font-weight: 500;
  563. color: #fff;
  564. }
  565. }
  566. </style>