list.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  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.id)"
  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. const pagination = {
  233. data: [],
  234. current_page: 1,
  235. total: 1,
  236. last_page: 1,
  237. };
  238. // 数据
  239. const state = reactive({
  240. currentTab: 0,
  241. pagination: {
  242. data: [],
  243. current_page: 1,
  244. total: 1,
  245. last_page: 1,
  246. },
  247. loadStatus: '',
  248. deleteOrderId: 0,
  249. error: 0,
  250. });
  251. const tabMaps = [
  252. {
  253. name: '全部',
  254. value: 'all',
  255. },
  256. {
  257. name: '待付款',
  258. value: 'unpaid',
  259. },
  260. {
  261. name: '待发货',
  262. value: 'nosend',
  263. },
  264. {
  265. name: '待收货',
  266. value: 'noget',
  267. },
  268. {
  269. name: '待评价',
  270. value: 'nocomment',
  271. },
  272. ];
  273. // 切换选项卡
  274. function onTabsChange(e) {
  275. if (state.currentTab === e.index) return;
  276. state.pagination = pagination;
  277. state.currentTab = e.index;
  278. getOrderList();
  279. }
  280. // 订单详情
  281. function onOrderDetail(orderSN) {
  282. sheep.$router.go('/pages/order/detail', {
  283. orderSN,
  284. });
  285. }
  286. // 分享拼团
  287. function onOrderGroupon(order) {
  288. sheep.$router.go('/pages/activity/groupon/detail', {
  289. id: order.ext.groupon_id,
  290. });
  291. }
  292. // 查看发票
  293. function onOrderInvoice(invoiceId) {
  294. sheep.$router.go('/pages/order/invoice', {
  295. invoiceId,
  296. });
  297. }
  298. // 继续支付
  299. function onPay(orderSN) {
  300. sheep.$router.go('/pages/pay/index', {
  301. orderSN,
  302. });
  303. }
  304. // 评价
  305. function onComment(orderSN) {
  306. sheep.$router.go('/pages/goods/comment/add', {
  307. orderSN,
  308. });
  309. }
  310. // 确认收货
  311. async function onConfirm(orderId) {
  312. uni.showModal({
  313. title: '提示',
  314. content: '请确认包裹全部到达后再确认收货',
  315. success: async function (res) {
  316. if (res.confirm) {
  317. const { error, data } = await sheep.$api.order.confirm(orderId);
  318. if (error === 0) {
  319. let index = state.pagination.data.findIndex((order) => order.id === orderId);
  320. state.pagination.data[index] = data;
  321. }
  322. }
  323. },
  324. });
  325. }
  326. // 查看物流
  327. async function onExpress(orderId) {
  328. sheep.$router.go('/pages/order/express/list', {
  329. orderId,
  330. });
  331. }
  332. // 取消订单
  333. async function onCancel(orderId) {
  334. uni.showModal({
  335. title: '提示',
  336. content: '确定要取消订单吗?',
  337. success: async function (res) {
  338. if (res.confirm) {
  339. const { error, data } = await sheep.$api.order.cancel(orderId);
  340. if (error === 0) {
  341. let index = state.pagination.data.findIndex((order) => order.id === orderId);
  342. state.pagination.data[index] = data;
  343. }
  344. }
  345. },
  346. });
  347. }
  348. // 删除订单
  349. function onDelete(orderId) {
  350. uni.showModal({
  351. title: '提示',
  352. content: '确定要删除订单吗?',
  353. success: async function (res) {
  354. if (res.confirm) {
  355. const { error, data } = await sheep.$api.order.delete(orderId);
  356. if (error === 0) {
  357. let index = state.pagination.data.findIndex((order) => order.id === orderId);
  358. state.pagination.data.splice(index, 1);
  359. }
  360. }
  361. },
  362. });
  363. }
  364. // 申请退款
  365. async function onRefund(orderId) {
  366. uni.showModal({
  367. title: '提示',
  368. content: '确定要申请退款吗?',
  369. success: async function (res) {
  370. if (res.confirm) {
  371. // #ifdef MP
  372. sheep.$platform.useProvider('wechat').subscribeMessage('order_apply_refund');
  373. // #endif
  374. const { error, data } = await sheep.$api.order.applyRefund(orderId);
  375. if (error === 0) {
  376. let index = state.pagination.data.findIndex((order) => order.id === orderId);
  377. state.pagination.data[index] = data;
  378. }
  379. }
  380. },
  381. });
  382. }
  383. // 获取订单列表
  384. async function getOrderList(page = 1, list_rows = 5) {
  385. state.loadStatus = 'loading';
  386. let res = await sheep.$api.order.list({
  387. type: tabMaps[state.currentTab].value,
  388. list_rows,
  389. page,
  390. });
  391. state.error = res.error;
  392. if (res.error === 0) {
  393. let orderList = _.concat(state.pagination.data, res.data.data);
  394. state.pagination = {
  395. ...res.data,
  396. data: orderList,
  397. };
  398. if (state.pagination.current_page < state.pagination.last_page) {
  399. state.loadStatus = 'more';
  400. } else {
  401. state.loadStatus = 'noMore';
  402. }
  403. }
  404. }
  405. onLoad(async (options) => {
  406. if (options.type) {
  407. state.currentTab = options.type;
  408. }
  409. getOrderList();
  410. });
  411. // 加载更多
  412. function loadmore() {
  413. if (state.loadStatus !== 'noMore') {
  414. getOrderList(state.pagination.current_page + 1);
  415. }
  416. }
  417. // 上拉加载更多
  418. onReachBottom(() => {
  419. loadmore();
  420. });
  421. //下拉刷新
  422. onPullDownRefresh(() => {
  423. state.pagination = pagination;
  424. getOrderList();
  425. setTimeout(function () {
  426. uni.stopPullDownRefresh();
  427. }, 800);
  428. });
  429. </script>
  430. <style lang="scss" scoped>
  431. .score-img {
  432. width: 36rpx;
  433. height: 36rpx;
  434. margin: 0 4rpx;
  435. }
  436. .tool-btn {
  437. width: 160rpx;
  438. height: 60rpx;
  439. background: #f6f6f6;
  440. font-size: 26rpx;
  441. border-radius: 30rpx;
  442. margin-right: 10rpx;
  443. &:last-of-type {
  444. margin-right: 0;
  445. }
  446. }
  447. .delete-btn {
  448. width: 160rpx;
  449. height: 56rpx;
  450. color: #ff3000;
  451. background: #fee;
  452. border-radius: 28rpx;
  453. font-size: 26rpx;
  454. margin-right: 10rpx;
  455. line-height: normal;
  456. &:last-of-type {
  457. margin-right: 0;
  458. }
  459. }
  460. .apply-btn {
  461. width: 140rpx;
  462. height: 50rpx;
  463. border-radius: 25rpx;
  464. font-size: 24rpx;
  465. border: 2rpx solid #dcdcdc;
  466. line-height: normal;
  467. margin-left: 16rpx;
  468. }
  469. .swiper-box {
  470. flex: 1;
  471. .swiper-item {
  472. height: 100%;
  473. width: 100%;
  474. }
  475. }
  476. .order-list-card-box {
  477. .order-card-header {
  478. height: 80rpx;
  479. .order-no {
  480. font-size: 26rpx;
  481. font-weight: 500;
  482. }
  483. .order-state {
  484. }
  485. }
  486. .pay-box {
  487. .discounts-title {
  488. font-size: 24rpx;
  489. line-height: normal;
  490. color: #999999;
  491. }
  492. .discounts-money {
  493. font-size: 24rpx;
  494. line-height: normal;
  495. color: #999;
  496. font-family: OPPOSANS;
  497. }
  498. .pay-color {
  499. color: #333;
  500. }
  501. }
  502. .order-card-footer {
  503. height: 100rpx;
  504. .more-item-box {
  505. padding: 20rpx;
  506. .more-item {
  507. height: 60rpx;
  508. .title {
  509. font-size: 26rpx;
  510. }
  511. }
  512. }
  513. .more-btn {
  514. color: $dark-9;
  515. font-size: 24rpx;
  516. }
  517. .content {
  518. width: 154rpx;
  519. color: #333333;
  520. font-size: 26rpx;
  521. font-weight: 500;
  522. }
  523. }
  524. }
  525. :deep(.uni-tooltip-popup) {
  526. background: var(--ui-BG);
  527. }
  528. .warning-color {
  529. color: #faad14;
  530. }
  531. .danger-color {
  532. color: #ff3000;
  533. }
  534. .success-color {
  535. color: #52c41a;
  536. }
  537. .info-color {
  538. color: #999999;
  539. }
  540. </style>