detail.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  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/images/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/images/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/images/order_close.png')">
  25. </image>
  26. <image v-if="state.orderInfo.status_code == 'noget'" class="state-img"
  27. :src="sheep.$url.static('/static/images/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 @tap="onGoodsDetail(item.spuId)" :img="item.picUrl" :title="item.spuName"
  50. :skuText="item.properties.map((property) => property.valueName).join(' ')" :price="item.spuPayType === 2 ? item.highPrecisionPrice : item.price "
  51. :num="item.count" :virtualPirce="item.spuPayType === 2">
  52. <template #tool>
  53. <view class="ss-flex">
  54. <button class="ss-reset-button apply-btn"
  55. v-if="[30].includes(state.orderInfo.status) && item.afterSaleStatus === 0"
  56. @tap.stop="
  57. sheep.$router.go('/pages/order/aftersale/apply', {
  58. orderId: state.orderInfo.id,
  59. itemId: item.id,
  60. })
  61. ">
  62. 申请售后
  63. </button>
  64. <button class="ss-reset-button apply-btn" v-if="item.afterSaleStatus === 10" @tap.stop="
  65. sheep.$router.go('/pages/order/aftersale/detail', {
  66. id: item.afterSaleId,
  67. })
  68. ">
  69. 退款中
  70. </button>
  71. <button class="ss-reset-button apply-btn" v-if="item.afterSaleStatus === 20" @tap.stop="
  72. sheep.$router.go('/pages/order/aftersale/detail', {
  73. id: item.afterSaleId,
  74. })
  75. ">
  76. 退款成功
  77. </button>
  78. </view>
  79. </template>
  80. <template #priceSuffix>
  81. <button class="ss-reset-button tag-btn" v-if="item.status_text">
  82. {{ item.status_text }}
  83. </button>
  84. </template>
  85. </s-goods-item>
  86. </view>
  87. </view>
  88. </view>
  89. <!-- 订单信息 -->
  90. <view class="notice-box">
  91. <view class="notice-box__content">
  92. <view class="notice-item--center">
  93. <view class="ss-flex ss-flex-1">
  94. <text class="title">订单编号:</text>
  95. <text class="detail">{{ state.orderInfo.no }}</text>
  96. </view>
  97. <button class="ss-reset-button copy-btn" @tap="onCopy">复制</button>
  98. </view>
  99. <view class="notice-item">
  100. <text class="title">用户留言:</text>
  101. <text class="detail">
  102. {{ state.orderInfo.userRemark || '无' }}
  103. </text>
  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. <view class="notice-item ss-flex ss-row-between" v-if="state.orderInfo.payIntegral > 0">
  136. <text class="title">使用佣金</text>
  137. <text class="detail">{{ points2point(state.orderInfo.payIntegral) }}</text>
  138. </view>
  139. <view class="notice-item ss-flex ss-row-between" v-if="state.orderInfo.payConsumptionPoints > 0">
  140. <text class="title">使用消费分</text>
  141. <text class="detail">{{ points2point(state.orderInfo.payConsumptionPoints) }}</text>
  142. </view>
  143. <!-- TODO 非繁人:优惠劵抵扣、佣金抵扣 -->
  144. <view class="notice-item ss-flex ss-row-between" v-if="state.orderInfo.discountPrice > 0">
  145. <text class="title">优惠金额</text>
  146. <text class="detail">¥{{ fen2yuan(state.orderInfo.discountPrice) }}</text>
  147. </view>
  148. <view class="notice-item all-rpice-item ss-flex ss-m-t-20">
  149. <text class="title">{{ state.orderInfo.payStatus ? '已付款' : '需付款' }}</text>
  150. <text class="detail all-price">¥{{ fen2yuan(state.orderInfo.payPrice) }}</text>
  151. </view>
  152. <view class="notice-item all-rpice-item ss-flex ss-m-t-20" v-if="state.orderInfo.refundPrice > 0">
  153. <text class="title">已退款</text>
  154. <text class="detail all-price">¥{{ fen2yuan(state.orderInfo.refundPrice) }}</text>
  155. </view>
  156. </view>
  157. <!-- 底部按钮 -->
  158. <!-- TODO: 查看物流、等待成团、评价完后返回页面没刷新页面 -->
  159. <su-fixed bottom placeholder bg="bg-white" v-if="state.orderInfo.buttons?.length">
  160. <view class="footer-box ss-flex ss-col-center ss-row-right">
  161. <!-- {{state.orderInfo.buttons}} -->
  162. <button class="ss-reset-button cancel-btn" v-if="state.orderInfo.buttons?.includes('cancel')"
  163. @tap="onCancel(state.orderInfo.id)">
  164. 取消订单
  165. </button>
  166. <button class="ss-reset-button pay-btn ui-BG-Main-Gradient"
  167. v-if="state.orderInfo.buttons?.includes('pay')" @tap="onPay(state.orderInfo.payOrderId)">
  168. 继续支付
  169. </button>
  170. <!-- TODO 非繁人:拼团接入 -->
  171. <!-- <button class="ss-reset-button cancel-btn" v-if="state.orderInfo.buttons?.includes('combination')" @tap="
  172. sheep.$router.go('/pages/activity/groupon/detail', {
  173. id: state.orderInfo.ext.groupon_id,
  174. })
  175. ">
  176. 拼团详情
  177. </button> -->
  178. <!-- 商家发货&&用户不售后就能看到物流 -->
  179. <button class="ss-reset-button cancel-btn" v-if="state.orderInfo.buttons?.includes('express') && !state.orderInfo.items[0]?.refundStatus"
  180. @tap="onExpress(state.orderInfo.id)">
  181. 查看物流
  182. </button>
  183. <button class="ss-reset-button cancel-btn" v-if="state.orderInfo.buttons?.includes('confirm')"
  184. @tap="onConfirm(state.orderInfo.id)">
  185. 确认收货
  186. </button>
  187. <button class="ss-reset-button cancel-btn" v-if="state.orderInfo.buttons?.includes('comment')"
  188. @tap="onComment(state.orderInfo.id)">
  189. 评价
  190. </button>
  191. <!-- 售后用户退货 -->
  192. <button class="ss-reset-button cancel-btn" v-if="state.orderInfo.buttons?.includes('aftersaleCancel')"
  193. @tap="onApply(state.orderInfo.items[0].afterSaleId)">
  194. 取消申请
  195. </button>
  196. <button class="ss-reset-button cancel-btn" v-if="state.orderInfo.buttons?.includes('aftersaleDelivery')"
  197. @tap="sheep.$router.go('/pages/order/aftersale/return-delivery', { id: state.orderInfo.items[0].afterSaleId })">
  198. 填写退货
  199. </button>
  200. </view>
  201. </su-fixed>
  202. </s-layout>
  203. </template>
  204. <script setup>
  205. import sheep from '@/sheep';
  206. import {
  207. onLoad
  208. } from '@dcloudio/uni-app';
  209. import {
  210. reactive,
  211. computed,
  212. watch
  213. } from 'vue';
  214. import {
  215. isEmpty
  216. } from 'lodash';
  217. import {
  218. fen2yuan,
  219. formatOrderStatus,
  220. formatOrderStatusDescription,
  221. handleOrderButtons,
  222. points2point
  223. } from '@/sheep/hooks/useGoods';
  224. import OrderApi from '@/sheep/api/trade/order';
  225. import AfterSaleApi from '@/sheep/api/trade/afterSale';
  226. import {
  227. showAuthModal
  228. } from '@/sheep/hooks/useModal';
  229. const userInfo = sheep.$store('user').userInfo;
  230. const statusBarHeight = sheep.$platform.device.statusBarHeight * 2;
  231. const headerBg = sheep.$url.css('/static/images/order_bg.png');
  232. const state = reactive({
  233. orderInfo: {},
  234. merchantTradeNo: '', // 商户订单号
  235. comeinType: '', // 进入订单详情的来源类型
  236. });
  237. // 复制
  238. const onCopy = () => {
  239. sheep.$helper.copyText(state.orderInfo.no);
  240. };
  241. // 去支付
  242. function onPay(id) {
  243. sheep.$router.go('/pages/pay/index', {
  244. id: id,
  245. openType: 2,
  246. type:1,
  247. });
  248. }
  249. // 查看商品
  250. function onGoodsDetail(id) {
  251. // console.log(id)
  252. sheep.$router.go('/pages/goods/index', {
  253. id,
  254. });
  255. }
  256. // 取消订单
  257. async function onCancel(orderId) {
  258. uni.showModal({
  259. title: '提示',
  260. content: '确定要取消订单吗?',
  261. success: async function(res) {
  262. if (!res.confirm) {
  263. return;
  264. }
  265. const {
  266. code
  267. } = await OrderApi.cancelOrder(orderId);
  268. if (code === 0) {
  269. await getOrderDetail(orderId);
  270. }
  271. },
  272. });
  273. }
  274. // 查看物流
  275. async function onExpress(id) {
  276. sheep.$router.go('/pages/order/express/log', {
  277. id,
  278. });
  279. }
  280. // 确认收货 TODO 非繁人:待测试
  281. async function onConfirm(orderId, ignore = false) {
  282. // 需开启确认收货组件
  283. // todo: 非繁人:待接入微信
  284. // 1.怎么检测是否开启了发货组件功能?如果没有开启的话就不能在这里return出去
  285. // 2.如果开启了走mpConfirm方法,需要在App.vue的show方法中拿到确认收货结果
  286. let isOpenBusinessView = true;
  287. uni.showModal({
  288. title: '提示',
  289. content: '确认收货?',
  290. success: async function(res) {
  291. if (res.confirm) {
  292. if (
  293. sheep.$platform.name === 'WechatMiniProgram' &&
  294. !isEmpty(state.orderInfo.wechat_extra_data) &&
  295. isOpenBusinessView &&
  296. !ignore
  297. ) {
  298. mpConfirm(orderId);
  299. return;
  300. }
  301. // 正常的确认收货流程
  302. const {
  303. code
  304. } = await OrderApi.receiveOrder(orderId);
  305. if (code === 0) {
  306. await getOrderDetail(orderId);
  307. }
  308. }
  309. },
  310. });
  311. }
  312. // #ifdef MP-WEIXIN
  313. // 小程序确认收货组件
  314. function mpConfirm(orderId) {
  315. if (!wx.openBusinessView) {
  316. sheep.$helper.toast(`请升级微信版本`);
  317. return;
  318. }
  319. wx.openBusinessView({
  320. businessType: 'weappOrderConfirm',
  321. extraData: {
  322. merchant_trade_no: state.orderInfo.wechat_extra_data.merchant_trade_no,
  323. transaction_id: state.orderInfo.wechat_extra_data.transaction_id,
  324. },
  325. success(response) {
  326. console.log('success:', response);
  327. if (response.errMsg === 'openBusinessView:ok') {
  328. if (response.extraData.status === 'success') {
  329. onConfirm(orderId, true);
  330. }
  331. }
  332. },
  333. fail(error) {
  334. console.log('error:', error);
  335. },
  336. complete(result) {
  337. console.log('result:', result);
  338. },
  339. });
  340. }
  341. // #endif
  342. // 评价
  343. function onComment(id) {
  344. sheep.$router.go('/pages/goods/comment/add', {
  345. id
  346. });
  347. }
  348. // 取消售后申请
  349. function onApply(id) {
  350. uni.showModal({
  351. title: '提示',
  352. content: '确定要取消此申请吗?',
  353. success: async function(res) {
  354. if (!res.confirm) {
  355. return;
  356. }
  357. const {
  358. code
  359. } = await AfterSaleApi.cancelAfterSale(id);
  360. if (code === 0) {
  361. await getOrderDetail(id);
  362. }
  363. },
  364. });
  365. }
  366. async function getOrderDetail(id) {
  367. // 对详情数据进行适配
  368. let res;
  369. if (state.comeinType === 'wechat') {
  370. // TODO 非繁人:微信场景下
  371. res = await OrderApi.getOrder(id, {
  372. merchant_trade_no: state.merchantTradeNo,
  373. });
  374. } else {
  375. res = await OrderApi.getOrder(id);
  376. }
  377. if (res.code === 0) {
  378. state.orderInfo = res.data;
  379. handleOrderButtons(state.orderInfo);
  380. } else {
  381. sheep.$router.back();
  382. }
  383. }
  384. const isLogin = computed(() => sheep.$store('user').isLogin);
  385. // 监听到在这个页面登陆,并刷新页面
  386. watch(
  387. () => isLogin.value,
  388. (newVal) => {
  389. if (newVal) {
  390. window.location.reload()
  391. }
  392. }, {
  393. deep: true, // 深度监听
  394. },
  395. );
  396. onLoad(async (options) => {
  397. //如果没登陆就进来则有可能是在微信消息推送进来的 提示登陆
  398. if (!isLogin.value) {
  399. showAuthModal();
  400. sheep.$helper.toast("您尚未登录,请登录:" + options.username + "后再试", 3000);
  401. } else {
  402. // 如果
  403. if (options.username) {
  404. // 如果登陆了但不是该订单的账号,提示有问题
  405. console.log(JSON.parse(uni.getStorageSync("user-store")).userInfo.username)
  406. if (options.username != JSON.parse(uni.getStorageSync("user-store")).userInfo.username) {
  407. sheep.$helper.toast("您当前登录的账号是" + JSON.parse(uni.getStorageSync("user-store")).userInfo.username + ",请切换到" + options.username + "后再试",
  408. 3000);
  409. }
  410. }
  411. }
  412. let id = 0;
  413. if (options.id) {
  414. id = options.id;
  415. }
  416. // TODO 非繁人:下面两个变量,后续接入
  417. state.comeinType = options.comein_type;
  418. if (state.comeinType === 'wechat') {
  419. state.merchantTradeNo = options.merchant_trade_no;
  420. }
  421. await getOrderDetail(id);
  422. });
  423. </script>
  424. <style lang="scss" scoped>
  425. .score-img {
  426. width: 36rpx;
  427. height: 36rpx;
  428. margin: 0 4rpx;
  429. }
  430. .apply-btn {
  431. width: 140rpx;
  432. height: 50rpx;
  433. border-radius: 25rpx;
  434. font-size: 24rpx;
  435. border: 2rpx solid #dcdcdc;
  436. line-height: normal;
  437. margin-left: 16rpx;
  438. }
  439. .state-box {
  440. color: rgba(#fff, 0.9);
  441. width: 100%;
  442. background: v-bind(headerBg) no-repeat,
  443. linear-gradient(90deg, var(--ui-BG-Main), var(--ui-BG-Main-gradient));
  444. background-size: 750rpx 100%;
  445. box-sizing: border-box;
  446. .state-img {
  447. width: 60rpx;
  448. height: 60rpx;
  449. margin-right: 20rpx;
  450. }
  451. }
  452. .order-address-box {
  453. background-color: #fff;
  454. border-radius: 10rpx;
  455. margin: -50rpx 20rpx 16rpx 20rpx;
  456. padding: 44rpx 34rpx 42rpx 20rpx;
  457. font-size: 30rpx;
  458. box-sizing: border-box;
  459. font-weight: 500;
  460. color: rgba(51, 51, 51, 1);
  461. .address-username {
  462. margin-right: 20rpx;
  463. }
  464. .address-detail {
  465. font-size: 26rpx;
  466. font-weight: 500;
  467. color: rgba(153, 153, 153, 1);
  468. margin-top: 20rpx;
  469. }
  470. }
  471. .detail-goods {
  472. border-radius: 10rpx;
  473. margin: 0 20rpx 20rpx 20rpx;
  474. .order-list {
  475. margin-bottom: 20rpx;
  476. background-color: #fff;
  477. .order-card {
  478. padding: 20rpx 0;
  479. .order-sku {
  480. font-size: 24rpx;
  481. font-weight: 400;
  482. color: rgba(153, 153, 153, 1);
  483. width: 450rpx;
  484. margin-bottom: 20rpx;
  485. .order-num {
  486. margin-right: 10rpx;
  487. }
  488. }
  489. .tag-btn {
  490. margin-left: 16rpx;
  491. font-size: 24rpx;
  492. height: 36rpx;
  493. color: var(--ui-BG-Main);
  494. border: 2rpx solid var(--ui-BG-Main);
  495. border-radius: 14rpx;
  496. padding: 0 4rpx;
  497. }
  498. }
  499. }
  500. }
  501. // 订单信息。
  502. .notice-box {
  503. background: #fff;
  504. border-radius: 10rpx;
  505. margin: 0 20rpx 20rpx 20rpx;
  506. .notice-box__head {
  507. font-size: 30rpx;
  508. font-weight: 500;
  509. color: rgba(51, 51, 51, 1);
  510. line-height: 80rpx;
  511. border-bottom: 1rpx solid #dfdfdf;
  512. padding: 0 25rpx;
  513. }
  514. .notice-box__content {
  515. padding: 20rpx;
  516. .self-pickup-box {
  517. width: 100%;
  518. .self-pickup--img {
  519. width: 200rpx;
  520. height: 200rpx;
  521. margin: 40rpx 0;
  522. }
  523. }
  524. }
  525. .notice-item,
  526. .notice-item--center {
  527. display: flex;
  528. align-items: center;
  529. line-height: normal;
  530. margin-bottom: 24rpx;
  531. .title {
  532. font-size: 28rpx;
  533. color: #999;
  534. }
  535. .detail {
  536. font-size: 28rpx;
  537. color: #333;
  538. flex: 1;
  539. }
  540. }
  541. }
  542. .copy-btn {
  543. width: 100rpx;
  544. line-height: 50rpx;
  545. border-radius: 25rpx;
  546. padding: 0;
  547. background: rgba(238, 238, 238, 1);
  548. font-size: 22rpx;
  549. font-weight: 400;
  550. color: rgba(51, 51, 51, 1);
  551. }
  552. // 订单价格信息
  553. .order-price-box {
  554. background-color: #fff;
  555. border-radius: 10rpx;
  556. padding: 20rpx;
  557. margin: 0 20rpx 20rpx 20rpx;
  558. .notice-item {
  559. line-height: 70rpx;
  560. .title {
  561. font-size: 28rpx;
  562. color: #999;
  563. }
  564. .detail {
  565. font-size: 28rpx;
  566. color: #333;
  567. font-family: OPPOSANS;
  568. }
  569. }
  570. .all-rpice-item {
  571. justify-content: flex-end;
  572. align-items: center;
  573. .title {
  574. font-size: 26rpx;
  575. font-weight: 500;
  576. color: #333333;
  577. line-height: normal;
  578. }
  579. .all-price {
  580. font-size: 26rpx;
  581. font-family: OPPOSANS;
  582. line-height: normal;
  583. color: $red;
  584. }
  585. }
  586. }
  587. // 底部
  588. .footer-box {
  589. height: 100rpx;
  590. width: 100%;
  591. box-sizing: border-box;
  592. border-radius: 10rpx;
  593. padding-right: 20rpx;
  594. .cancel-btn {
  595. width: 160rpx;
  596. height: 60rpx;
  597. background: #eeeeee;
  598. border-radius: 30rpx;
  599. margin-right: 20rpx;
  600. font-size: 26rpx;
  601. font-weight: 400;
  602. color: #333333;
  603. }
  604. .pay-btn {
  605. width: 160rpx;
  606. height: 60rpx;
  607. font-size: 26rpx;
  608. border-radius: 30rpx;
  609. font-weight: 500;
  610. color: #fff;
  611. }
  612. }
  613. </style>