list.vue 14 KB

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