detail.vue 15 KB

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