detail.vue 15 KB

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