list.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632
  1. <!-- 页面 -->
  2. <template>
  3. <s-layout title="我的订单">
  4. <su-sticky bgColor="#fff">
  5. <su-tabs
  6. :list="tabMaps"
  7. :scrollable="false"
  8. @change="onTabsChange"
  9. :current="state.currentTab"
  10. ></su-tabs>
  11. </su-sticky>
  12. <s-empty
  13. v-if="state.pagination.total === 0"
  14. icon="/static/order-empty.png"
  15. text="暂无订单"
  16. ></s-empty>
  17. <view v-if="state.pagination.total > 0">
  18. <view
  19. class="bg-white order-list-card-box ss-r-10 ss-m-t-14 ss-m-20"
  20. v-for="order in state.pagination.data"
  21. :key="order.id"
  22. @tap="onOrderDetail(order.order_sn)"
  23. >
  24. <view class="order-card-header ss-flex ss-col-center ss-row-between ss-p-x-20">
  25. <view class="order-no">订单号:{{ order.order_sn }}</view>
  26. <view class="order-state ss-font-26" :class="formatOrderColor(order.status_code)">{{
  27. order.status_text
  28. }}</view>
  29. </view>
  30. <view class="border-bottom" v-for="item in order.items" :key="item.id">
  31. <s-goods-item
  32. :img="item.goods_image"
  33. :title="item.goods_title"
  34. :skuText="item.goods_sku_text"
  35. :price="item.goods_price"
  36. :score="order.score_amount"
  37. :num="item.goods_num"
  38. >
  39. <template #tool>
  40. <view class="ss-flex">
  41. <button
  42. class="ss-reset-button apply-btn"
  43. v-if="item.btns.includes('aftersale')"
  44. @tap.stop="
  45. sheep.$router.go('/pages/order/aftersale/apply', {
  46. item: JSON.stringify(item),
  47. })
  48. "
  49. >
  50. 申请售后
  51. </button>
  52. <button
  53. class="ss-reset-button apply-btn"
  54. v-if="item.btns.includes('re_aftersale')"
  55. @tap.stop="
  56. sheep.$router.go('/pages/order/aftersale/apply', {
  57. item: JSON.stringify(item),
  58. })
  59. "
  60. >
  61. 重新售后
  62. </button>
  63. <button
  64. class="ss-reset-button apply-btn"
  65. v-if="item.btns.includes('aftersale_info')"
  66. @tap.stop="
  67. sheep.$router.go('/pages/order/aftersale/detail', {
  68. id: item.ext.aftersale_id,
  69. })
  70. "
  71. >
  72. 售后详情
  73. </button>
  74. <button
  75. class="ss-reset-button apply-btn"
  76. v-if="item.btns.includes('buy_again')"
  77. @tap.stop="
  78. sheep.$router.go('/pages/goods/index', {
  79. id: item.goods_id,
  80. })
  81. "
  82. >
  83. 再次购买
  84. </button>
  85. </view>
  86. </template>
  87. </s-goods-item>
  88. </view>
  89. <view class="pay-box ss-m-t-30 ss-flex ss-row-right ss-p-r-20">
  90. <view v-if="order.total_discount_fee > 0" class="ss-flex ss-col-center ss-m-r-8">
  91. <view class="discounts-title">优惠:¥</view>
  92. <view class="discounts-money">{{ order.total_discount_fee }}</view>
  93. </view>
  94. <view class="ss-flex ss-col-center ss-m-r-8">
  95. <view class="discounts-title">运费:¥</view>
  96. <view class="discounts-money">{{ order.dispatch_amount }}</view>
  97. </view>
  98. <view class="ss-flex ss-col-center">
  99. <view class="discounts-title pay-color">总金额:</view>
  100. <view class="discounts-money pay-color" v-if="Number(order.order_amount) > 0"
  101. >¥{{ order.order_amount }}</view
  102. >
  103. <view v-if="order.score_amount && Number(order.order_amount) > 0">+</view>
  104. <view class="discounts-money pay-color ss-flex ss-col-center" v-if="order.score_amount">
  105. <image
  106. :src="sheep.$url.static('/static/img/shop/goods/score1.svg')"
  107. class="score-img"
  108. ></image>
  109. <view>{{ order.score_amount }}</view>
  110. </view>
  111. </view>
  112. </view>
  113. <view
  114. class="order-card-footer ss-flex ss-col-center ss-p-x-20"
  115. :class="order.btns.length > 3 ? 'ss-row-between' : 'ss-row-right'"
  116. >
  117. <!-- <su-popover>
  118. <button class="more-btn ss-reset-button" @click.stop>更多</button>
  119. <template #content>
  120. <view class="more-item-box">
  121. <view class="more-item ss-flex ss-col-center ss-reset-button">
  122. <view class="item-title">删除订单</view>
  123. </view>
  124. <view class="more-item ss-flex ss-col-center ss-reset-button">
  125. <view class="item-title">查看发票</view>
  126. </view>
  127. <view class="more-item ss-flex ss-col-center ss-reset-button">
  128. <view class="item-title">评价晒单</view>
  129. </view>
  130. </view>
  131. </template>
  132. </su-popover> -->
  133. <view class="ss-flex ss-col-center">
  134. <button
  135. v-if="order.btns.includes('groupon')"
  136. class="tool-btn ss-reset-button"
  137. @tap.stop="onOrderGroupon(order)"
  138. >
  139. {{ order.status_code === 'groupon_ing' ? '邀请拼团' : '拼团详情' }}
  140. </button>
  141. <button
  142. v-if="order.btns.includes('invoice')"
  143. class="tool-btn ss-reset-button"
  144. @tap.stop="onOrderInvoice(order.invoice?.id)"
  145. >
  146. 查看发票
  147. </button>
  148. <button
  149. v-if="order.btns.length === 0"
  150. class="tool-btn ss-reset-button"
  151. @tap.stop="onOrderDetail(order.order_sn)"
  152. >
  153. 查看详情
  154. </button>
  155. <button
  156. v-if="order.btns.includes('confirm')"
  157. class="tool-btn ss-reset-button"
  158. @tap.stop="onConfirm(order)"
  159. >
  160. 确认收货
  161. </button>
  162. <button
  163. v-if="order.btns.includes('express')"
  164. class="tool-btn ss-reset-button"
  165. @tap.stop="onExpress(order.id)"
  166. >
  167. 查看物流
  168. </button>
  169. <button
  170. v-if="order.btns.includes('apply_refund')"
  171. class="tool-btn ss-reset-button"
  172. @tap.stop="onRefund(order.id)"
  173. >
  174. 申请退款
  175. </button>
  176. <button
  177. v-if="order.btns.includes('re_apply_refund')"
  178. class="tool-btn ss-reset-button"
  179. @tap.stop="onRefund(order.id)"
  180. >
  181. 重新退款
  182. </button>
  183. <button
  184. v-if="order.btns.includes('cancel')"
  185. class="tool-btn ss-reset-button"
  186. @tap.stop="onCancel(order.id)"
  187. >
  188. 取消订单
  189. </button>
  190. <button
  191. v-if="order.btns.includes('comment')"
  192. class="tool-btn ss-reset-button"
  193. @tap.stop="onComment(order.order_sn)"
  194. >
  195. 评价晒单
  196. </button>
  197. <button
  198. v-if="order.btns.includes('delete')"
  199. class="delete-btn ss-reset-button"
  200. @tap.stop="onDelete(order.id)"
  201. >
  202. 删除订单
  203. </button>
  204. <button
  205. v-if="order.btns.includes('pay')"
  206. class="tool-btn ss-reset-button ui-BG-Main-Gradient"
  207. @tap.stop="onPay(order.order_sn)"
  208. >
  209. 继续支付
  210. </button>
  211. </view>
  212. </view>
  213. </view>
  214. </view>
  215. <!-- 加载更多 -->
  216. <uni-load-more
  217. v-if="state.pagination.total > 0"
  218. :status="state.loadStatus"
  219. :content-text="{
  220. contentdown: '上拉加载更多',
  221. }"
  222. @tap="loadmore"
  223. />
  224. </s-layout>
  225. </template>
  226. <script setup>
  227. import { computed, reactive } from 'vue';
  228. import { onLoad, onReachBottom, onPullDownRefresh } from '@dcloudio/uni-app';
  229. import { formatOrderColor } from '@/sheep/hooks/useGoods';
  230. import sheep from '@/sheep';
  231. import _ from 'lodash';
  232. import { isEmpty } from 'lodash';
  233. const pagination = {
  234. data: [],
  235. current_page: 1,
  236. total: 1,
  237. last_page: 1,
  238. };
  239. // 数据
  240. const state = reactive({
  241. currentTab: 0,
  242. pagination: {
  243. data: [],
  244. current_page: 1,
  245. total: 1,
  246. last_page: 1,
  247. },
  248. loadStatus: '',
  249. deleteOrderId: 0,
  250. error: 0,
  251. });
  252. const tabMaps = [
  253. {
  254. name: '全部',
  255. value: 'all',
  256. },
  257. {
  258. name: '待付款',
  259. value: 'unpaid',
  260. },
  261. {
  262. name: '待发货',
  263. value: 'nosend',
  264. },
  265. {
  266. name: '待收货',
  267. value: 'noget',
  268. },
  269. {
  270. name: '待评价',
  271. value: 'nocomment',
  272. },
  273. ];
  274. // 切换选项卡
  275. function onTabsChange(e) {
  276. if (state.currentTab === e.index) return;
  277. state.pagination = pagination;
  278. state.currentTab = e.index;
  279. getOrderList();
  280. }
  281. // 订单详情
  282. function onOrderDetail(orderSN) {
  283. sheep.$router.go('/pages/order/detail', {
  284. orderSN,
  285. });
  286. }
  287. // 分享拼团
  288. function onOrderGroupon(order) {
  289. sheep.$router.go('/pages/activity/groupon/detail', {
  290. id: order.ext.groupon_id,
  291. });
  292. }
  293. // 查看发票
  294. function onOrderInvoice(invoiceId) {
  295. sheep.$router.go('/pages/order/invoice', {
  296. invoiceId,
  297. });
  298. }
  299. // 继续支付
  300. function onPay(orderSN) {
  301. sheep.$router.go('/pages/pay/index', {
  302. orderSN,
  303. });
  304. }
  305. // 评价
  306. function onComment(orderSN) {
  307. sheep.$router.go('/pages/goods/comment/add', {
  308. orderSN,
  309. });
  310. }
  311. // 确认收货
  312. async function onConfirm(order, ignore = false) {
  313. // 需开启确认收货组件
  314. // todo:
  315. // 1.怎么检测是否开启了发货组件功能?如果没有开启的话就不能在这里return出去
  316. // 2.如果开启了走mpConfirm方法,需要在App.vue的show方法中拿到确认收货结果
  317. let isOpenBusinessView = true;
  318. if (
  319. sheep.$platform.name === 'WechatMiniProgram' &&
  320. !isEmpty(order.wechat_extra_data) &&
  321. isOpenBusinessView &&
  322. !ignore
  323. ) {
  324. mpConfirm(order);
  325. return;
  326. }
  327. // 正常的确认收货流程
  328. const { error } = await sheep.$api.order.confirm(order.id);
  329. if (error === 0) {
  330. state.pagination = pagination;
  331. getOrderList();
  332. }
  333. }
  334. // #ifdef MP-WEIXIN
  335. // 小程序确认收货组件
  336. function mpConfirm(order) {
  337. if (!wx.openBusinessView) {
  338. sheep.$helper.toast(`请升级微信版本`);
  339. return;
  340. }
  341. wx.openBusinessView({
  342. businessType: 'weappOrderConfirm',
  343. extraData: {
  344. merchant_id: '1481069012',
  345. merchant_trade_no: order.wechat_extra_data.merchant_trade_no,
  346. transaction_id: order.wechat_extra_data.transaction_id,
  347. },
  348. success(response) {
  349. console.log('success:', response);
  350. if (response.errMsg === 'openBusinessView:ok') {
  351. if (response.extraData.status === 'success') {
  352. onConfirm(order, true);
  353. }
  354. }
  355. },
  356. fail(error) {
  357. console.log('error:', error);
  358. },
  359. complete(result) {
  360. console.log('result:', result);
  361. },
  362. });
  363. }
  364. // #endif
  365. // 查看物流
  366. async function onExpress(orderId) {
  367. sheep.$router.go('/pages/order/express/list', {
  368. orderId,
  369. });
  370. }
  371. // 取消订单
  372. async function onCancel(orderId) {
  373. uni.showModal({
  374. title: '提示',
  375. content: '确定要取消订单吗?',
  376. success: async function (res) {
  377. if (res.confirm) {
  378. const { error, data } = await sheep.$api.order.cancel(orderId);
  379. if (error === 0) {
  380. let index = state.pagination.data.findIndex((order) => order.id === orderId);
  381. state.pagination.data[index] = data;
  382. }
  383. }
  384. },
  385. });
  386. }
  387. // 删除订单
  388. function onDelete(orderId) {
  389. uni.showModal({
  390. title: '提示',
  391. content: '确定要删除订单吗?',
  392. success: async function (res) {
  393. if (res.confirm) {
  394. const { error, data } = await sheep.$api.order.delete(orderId);
  395. if (error === 0) {
  396. let index = state.pagination.data.findIndex((order) => order.id === orderId);
  397. state.pagination.data.splice(index, 1);
  398. }
  399. }
  400. },
  401. });
  402. }
  403. // 申请退款
  404. async function onRefund(orderId) {
  405. uni.showModal({
  406. title: '提示',
  407. content: '确定要申请退款吗?',
  408. success: async function (res) {
  409. if (res.confirm) {
  410. // #ifdef MP
  411. sheep.$platform.useProvider('wechat').subscribeMessage('order_refund');
  412. // #endif
  413. const { error, data } = await sheep.$api.order.applyRefund(orderId);
  414. if (error === 0) {
  415. let index = state.pagination.data.findIndex((order) => order.id === orderId);
  416. state.pagination.data[index] = data;
  417. }
  418. }
  419. },
  420. });
  421. }
  422. // 获取订单列表
  423. async function getOrderList(page = 1, list_rows = 5) {
  424. state.loadStatus = 'loading';
  425. let res = await sheep.$api.order.list({
  426. type: tabMaps[state.currentTab].value,
  427. list_rows,
  428. page,
  429. });
  430. state.error = res.error;
  431. if (res.error === 0) {
  432. let orderList = _.concat(state.pagination.data, res.data.data);
  433. state.pagination = {
  434. ...res.data,
  435. data: orderList,
  436. };
  437. if (state.pagination.current_page < state.pagination.last_page) {
  438. state.loadStatus = 'more';
  439. } else {
  440. state.loadStatus = 'noMore';
  441. }
  442. }
  443. }
  444. onLoad(async (options) => {
  445. if (options.type) {
  446. state.currentTab = options.type;
  447. }
  448. getOrderList();
  449. });
  450. // 加载更多
  451. function loadmore() {
  452. if (state.loadStatus !== 'noMore') {
  453. getOrderList(state.pagination.current_page + 1);
  454. }
  455. }
  456. // 上拉加载更多
  457. onReachBottom(() => {
  458. loadmore();
  459. });
  460. //下拉刷新
  461. onPullDownRefresh(() => {
  462. state.pagination = pagination;
  463. getOrderList();
  464. setTimeout(function () {
  465. uni.stopPullDownRefresh();
  466. }, 800);
  467. });
  468. </script>
  469. <style lang="scss" scoped>
  470. .score-img {
  471. width: 36rpx;
  472. height: 36rpx;
  473. margin: 0 4rpx;
  474. }
  475. .tool-btn {
  476. width: 160rpx;
  477. height: 60rpx;
  478. background: #f6f6f6;
  479. font-size: 26rpx;
  480. border-radius: 30rpx;
  481. margin-right: 10rpx;
  482. &:last-of-type {
  483. margin-right: 0;
  484. }
  485. }
  486. .delete-btn {
  487. width: 160rpx;
  488. height: 56rpx;
  489. color: #ff3000;
  490. background: #fee;
  491. border-radius: 28rpx;
  492. font-size: 26rpx;
  493. margin-right: 10rpx;
  494. line-height: normal;
  495. &:last-of-type {
  496. margin-right: 0;
  497. }
  498. }
  499. .apply-btn {
  500. width: 140rpx;
  501. height: 50rpx;
  502. border-radius: 25rpx;
  503. font-size: 24rpx;
  504. border: 2rpx solid #dcdcdc;
  505. line-height: normal;
  506. margin-left: 16rpx;
  507. }
  508. .swiper-box {
  509. flex: 1;
  510. .swiper-item {
  511. height: 100%;
  512. width: 100%;
  513. }
  514. }
  515. .order-list-card-box {
  516. .order-card-header {
  517. height: 80rpx;
  518. .order-no {
  519. font-size: 26rpx;
  520. font-weight: 500;
  521. }
  522. .order-state {
  523. }
  524. }
  525. .pay-box {
  526. .discounts-title {
  527. font-size: 24rpx;
  528. line-height: normal;
  529. color: #999999;
  530. }
  531. .discounts-money {
  532. font-size: 24rpx;
  533. line-height: normal;
  534. color: #999;
  535. font-family: OPPOSANS;
  536. }
  537. .pay-color {
  538. color: #333;
  539. }
  540. }
  541. .order-card-footer {
  542. height: 100rpx;
  543. .more-item-box {
  544. padding: 20rpx;
  545. .more-item {
  546. height: 60rpx;
  547. .title {
  548. font-size: 26rpx;
  549. }
  550. }
  551. }
  552. .more-btn {
  553. color: $dark-9;
  554. font-size: 24rpx;
  555. }
  556. .content {
  557. width: 154rpx;
  558. color: #333333;
  559. font-size: 26rpx;
  560. font-weight: 500;
  561. }
  562. }
  563. }
  564. :deep(.uni-tooltip-popup) {
  565. background: var(--ui-BG);
  566. }
  567. .warning-color {
  568. color: #faad14;
  569. }
  570. .danger-color {
  571. color: #ff3000;
  572. }
  573. .success-color {
  574. color: #52c41a;
  575. }
  576. .info-color {
  577. color: #999999;
  578. }
  579. </style>