list.vue 15 KB

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