otherlist.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  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">¥{{ order.order_amount }}</view>
  101. <view v-if="order.score_amount">+</view>
  102. <view class="discounts-money pay-color ss-flex ss-col-center" v-if="order.score_amount">
  103. <image
  104. :src="sheep.$url.static('/static/images/score1.svg')"
  105. class="score-img"
  106. ></image>
  107. <view>{{ order.score_amount }}</view>
  108. </view>
  109. </view>
  110. </view>
  111. <view
  112. class="order-card-footer ss-flex ss-col-center ss-p-x-20"
  113. :class="order.btns.length > 3 ? 'ss-row-between' : 'ss-row-right'"
  114. >
  115. <!-- <su-popover>
  116. <button class="more-btn ss-reset-button" @click.stop>更多</button>
  117. <template #content>
  118. <view class="more-item-box">
  119. <view class="more-item ss-flex ss-col-center ss-reset-button">
  120. <view class="item-title">删除订单</view>
  121. </view>
  122. <view class="more-item ss-flex ss-col-center ss-reset-button">
  123. <view class="item-title">查看发票</view>
  124. </view>
  125. <view class="more-item ss-flex ss-col-center ss-reset-button">
  126. <view class="item-title">评价晒单</view>
  127. </view>
  128. </view>
  129. </template>
  130. </su-popover> -->
  131. <view class="ss-flex ss-col-center">
  132. <button
  133. v-if="order.btns.includes('groupon')"
  134. class="tool-btn ss-reset-button"
  135. @tap.stop="onOrderGroupon(order)"
  136. >
  137. {{ order.status_code === 'groupon_ing' ? '邀请拼团' : '拼团详情' }}
  138. </button>
  139. <button
  140. v-if="order.btns.includes('invoice')"
  141. class="tool-btn ss-reset-button"
  142. @tap.stop="onOrderInvoice(order.invoice?.id)"
  143. >
  144. 查看发票
  145. </button>
  146. <button
  147. v-if="order.btns.length === 0"
  148. class="tool-btn ss-reset-button"
  149. @tap.stop="onOrderDetail(order.order_sn)"
  150. >
  151. 查看详情
  152. </button>
  153. <button
  154. v-if="order.btns.includes('confirm')"
  155. class="tool-btn ss-reset-button"
  156. @tap.stop="onConfirm(order)"
  157. >
  158. 确认收货
  159. </button>
  160. <button
  161. v-if="order.btns.includes('express')"
  162. class="tool-btn ss-reset-button"
  163. @tap.stop="onExpress(order.id)"
  164. >
  165. 查看物流
  166. </button>
  167. <button
  168. v-if="order.btns.includes('apply_refund')"
  169. class="tool-btn ss-reset-button"
  170. @tap.stop="onRefund(order.id)"
  171. >
  172. 申请退款
  173. </button>
  174. <button
  175. v-if="order.btns.includes('re_apply_refund')"
  176. class="tool-btn ss-reset-button"
  177. @tap.stop="onRefund(order.id)"
  178. >
  179. 重新退款
  180. </button>
  181. <button
  182. v-if="order.btns.includes('cancel')"
  183. class="tool-btn ss-reset-button"
  184. @tap.stop="onCancel(order.id)"
  185. >
  186. 取消订单
  187. </button>
  188. <button
  189. v-if="order.btns.includes('comment')"
  190. class="tool-btn ss-reset-button"
  191. @tap.stop="onComment(order.order_sn)"
  192. >
  193. 评价晒单
  194. </button>
  195. <button
  196. v-if="order.btns.includes('delete')"
  197. class="delete-btn ss-reset-button"
  198. @tap.stop="onDelete(order.id)"
  199. >
  200. 删除订单
  201. </button>
  202. <button
  203. v-if="order.btns.includes('pay')"
  204. class="tool-btn ss-reset-button ui-BG-Main-Gradient"
  205. @tap.stop="onPay(order.order_sn)"
  206. >
  207. 继续支付
  208. </button>
  209. </view>
  210. </view>
  211. </view>
  212. </view>
  213. <!-- 加载更多 -->
  214. <uni-load-more
  215. v-if="state.pagination.total > 0"
  216. :status="state.loadStatus"
  217. :content-text="{
  218. contentdown: '上拉加载更多',
  219. }"
  220. @tap="loadmore"
  221. />
  222. </s-layout>
  223. </template>
  224. <script setup>
  225. import { computed, reactive } from 'vue';
  226. import { onLoad, onReachBottom, onPullDownRefresh } from '@dcloudio/uni-app';
  227. import { formatOrderColor } from '@/sheep/hooks/useGoods';
  228. import sheep from '@/sheep';
  229. import _ from 'lodash';
  230. import { isEmpty } from 'lodash';
  231. const tradeManaged = computed(() => sheep.$store('app').has_wechat_trade_managed);
  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(order, ignore = false) {
  312. // 需开启确认收货组件
  313. // todo:
  314. // 1.怎么检测是否开启了发货组件功能?如果没有开启的话就不能在这里return出去
  315. // 2.如果开启了走mpConfirm方法,需要在App.vue的show方法中拿到确认收货结果
  316. if (
  317. sheep.$platform.name === 'WechatMiniProgram' &&
  318. !isEmpty(order.wechat_extra_data) &&
  319. tradeManaged.value === 1 &&
  320. !ignore
  321. ) {
  322. mpConfirm(order);
  323. return;
  324. }
  325. // 正常的确认收货流程
  326. const { error } = await sheep.$api.order.confirm(order.id);
  327. if (error === 0) {
  328. state.pagination = pagination;
  329. getOrderList();
  330. }
  331. }
  332. // #ifdef MP-WEIXIN
  333. // 小程序确认收货组件
  334. function mpConfirm(order) {
  335. if (!wx.openBusinessView) {
  336. sheep.$helper.toast(`请升级微信版本`);
  337. return;
  338. }
  339. wx.openBusinessView({
  340. businessType: 'weappOrderConfirm',
  341. extraData: {
  342. merchant_trade_no: order.wechat_extra_data.merchant_trade_no,
  343. transaction_id: order.wechat_extra_data.transaction_id,
  344. },
  345. success(response) {
  346. console.log('success:', response);
  347. if (response.errMsg === 'openBusinessView:ok') {
  348. if (response.extraData.status === 'success') {
  349. onConfirm(order, true);
  350. }
  351. }
  352. },
  353. fail(error) {
  354. console.log('error:', error);
  355. },
  356. complete(result) {
  357. console.log('result:', result);
  358. },
  359. });
  360. }
  361. // #endif
  362. // 查看物流
  363. async function onExpress(orderId) {
  364. sheep.$router.go('/pages/order/express/list', {
  365. orderId,
  366. });
  367. }
  368. // 取消订单
  369. async function onCancel(orderId) {
  370. uni.showModal({
  371. title: '提示',
  372. content: '确定要取消订单吗?',
  373. success: async function (res) {
  374. if (res.confirm) {
  375. const { error, data } = await sheep.$api.order.cancel(orderId);
  376. if (error === 0) {
  377. let index = state.pagination.data.findIndex((order) => order.id === orderId);
  378. state.pagination.data[index] = data;
  379. }
  380. }
  381. },
  382. });
  383. }
  384. // 删除订单
  385. function onDelete(orderId) {
  386. uni.showModal({
  387. title: '提示',
  388. content: '确定要删除订单吗?',
  389. success: async function (res) {
  390. if (res.confirm) {
  391. const { error, data } = await sheep.$api.order.delete(orderId);
  392. if (error === 0) {
  393. let index = state.pagination.data.findIndex((order) => order.id === orderId);
  394. state.pagination.data.splice(index, 1);
  395. }
  396. }
  397. },
  398. });
  399. }
  400. // 申请退款
  401. async function onRefund(orderId) {
  402. uni.showModal({
  403. title: '提示',
  404. content: '确定要申请退款吗?',
  405. success: async function (res) {
  406. if (res.confirm) {
  407. // #ifdef MP
  408. sheep.$platform.useProvider('wechat').subscribeMessage('order_refund');
  409. // #endif
  410. const { error, data } = await sheep.$api.order.applyRefund(orderId);
  411. if (error === 0) {
  412. let index = state.pagination.data.findIndex((order) => order.id === orderId);
  413. state.pagination.data[index] = data;
  414. }
  415. }
  416. },
  417. });
  418. }
  419. // 获取订单列表
  420. async function getOrderList(page = 1, list_rows = 5) {
  421. state.loadStatus = 'loading';
  422. let res = await sheep.$api.order.list({
  423. type: tabMaps[state.currentTab].value,
  424. list_rows,
  425. page,
  426. });
  427. state.error = res.error;
  428. if (res.error === 0) {
  429. let orderList = _.concat(state.pagination.data, res.data.data);
  430. state.pagination = {
  431. ...res.data,
  432. data: orderList,
  433. };
  434. if (state.pagination.current_page < state.pagination.last_page) {
  435. state.loadStatus = 'more';
  436. } else {
  437. state.loadStatus = 'noMore';
  438. }
  439. }
  440. }
  441. onLoad(async (options) => {
  442. if (options.type) {
  443. state.currentTab = options.type;
  444. }
  445. getOrderList();
  446. });
  447. // 加载更多
  448. function loadmore() {
  449. if (state.loadStatus !== 'noMore') {
  450. getOrderList(state.pagination.current_page + 1);
  451. }
  452. }
  453. // 上拉加载更多
  454. onReachBottom(() => {
  455. loadmore();
  456. });
  457. //下拉刷新
  458. onPullDownRefresh(() => {
  459. state.pagination = pagination;
  460. getOrderList();
  461. setTimeout(function () {
  462. uni.stopPullDownRefresh();
  463. }, 800);
  464. });
  465. </script>
  466. <style lang="scss" scoped>
  467. .score-img {
  468. width: 36rpx;
  469. height: 36rpx;
  470. margin: 0 4rpx;
  471. }
  472. .tool-btn {
  473. width: 160rpx;
  474. height: 60rpx;
  475. background: #f6f6f6;
  476. font-size: 26rpx;
  477. border-radius: 30rpx;
  478. margin-right: 10rpx;
  479. &:last-of-type {
  480. margin-right: 0;
  481. }
  482. }
  483. .delete-btn {
  484. width: 160rpx;
  485. height: 56rpx;
  486. color: #ff3000;
  487. background: #fee;
  488. border-radius: 28rpx;
  489. font-size: 26rpx;
  490. margin-right: 10rpx;
  491. line-height: normal;
  492. &:last-of-type {
  493. margin-right: 0;
  494. }
  495. }
  496. .apply-btn {
  497. width: 140rpx;
  498. height: 50rpx;
  499. border-radius: 25rpx;
  500. font-size: 24rpx;
  501. border: 2rpx solid #dcdcdc;
  502. line-height: normal;
  503. margin-left: 16rpx;
  504. }
  505. .swiper-box {
  506. flex: 1;
  507. .swiper-item {
  508. height: 100%;
  509. width: 100%;
  510. }
  511. }
  512. .order-list-card-box {
  513. .order-card-header {
  514. height: 80rpx;
  515. .order-no {
  516. font-size: 26rpx;
  517. font-weight: 500;
  518. }
  519. .order-state {
  520. }
  521. }
  522. .pay-box {
  523. .discounts-title {
  524. font-size: 24rpx;
  525. line-height: normal;
  526. color: #999999;
  527. }
  528. .discounts-money {
  529. font-size: 24rpx;
  530. line-height: normal;
  531. color: #999;
  532. font-family: OPPOSANS;
  533. }
  534. .pay-color {
  535. color: #333;
  536. }
  537. }
  538. .order-card-footer {
  539. height: 100rpx;
  540. .more-item-box {
  541. padding: 20rpx;
  542. .more-item {
  543. height: 60rpx;
  544. .title {
  545. font-size: 26rpx;
  546. }
  547. }
  548. }
  549. .more-btn {
  550. color: $dark-9;
  551. font-size: 24rpx;
  552. }
  553. .content {
  554. width: 154rpx;
  555. color: #333333;
  556. font-size: 26rpx;
  557. font-weight: 500;
  558. }
  559. }
  560. }
  561. :deep(.uni-tooltip-popup) {
  562. background: var(--ui-BG);
  563. }
  564. .warning-color {
  565. color: #faad14;
  566. }
  567. .danger-color {
  568. color: #ff3000;
  569. }
  570. .success-color {
  571. color: #52c41a;
  572. }
  573. .info-color {
  574. color: #999999;
  575. }
  576. </style>