list.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504
  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. />
  11. </su-sticky>
  12. <s-empty v-if="state.pagination.total === 0" icon="/static/order-empty.png" text="暂无订单" />
  13. <view v-if="state.pagination.total > 0">
  14. <view
  15. class="bg-white order-list-card-box ss-r-10 ss-m-t-14 ss-m-20"
  16. v-for="order in state.pagination.list"
  17. :key="order.id"
  18. @tap="onOrderDetail(order.id)"
  19. >
  20. <view class="order-card-header ss-flex ss-col-center ss-row-between ss-p-x-20">
  21. <view class="order-no">订单号:{{ order.no }}</view>
  22. <view class="order-state ss-font-26" :class="formatOrderColor(order)">
  23. {{ formatOrderStatus(order) }}
  24. </view>
  25. </view>
  26. <view class="border-bottom" v-for="item in order.items" :key="item.id">
  27. <s-goods-item
  28. :img="item.picUrl"
  29. :title="item.spuName"
  30. :skuText="item.properties.map((property) => property.valueName).join(' ')"
  31. :price="item.price"
  32. :num="item.count"
  33. />
  34. </view>
  35. <view class="pay-box ss-m-t-30 ss-flex ss-row-right ss-p-r-20">
  36. <view class="ss-flex ss-col-center">
  37. <view class="discounts-title pay-color"
  38. >共 {{ order.productCount }} 件商品,总金额:</view
  39. >
  40. <view class="discounts-money pay-color"> ¥{{ fen2yuan(order.payPrice) }} </view>
  41. </view>
  42. </view>
  43. <view
  44. class="order-card-footer ss-flex ss-col-center ss-p-x-20"
  45. :class="order.buttons.length > 3 ? 'ss-row-between' : 'ss-row-right'"
  46. >
  47. <view class="ss-flex ss-col-center">
  48. <button
  49. v-if="order.buttons.includes('combination')"
  50. class="tool-btn ss-reset-button"
  51. @tap.stop="onOrderGroupon(order)"
  52. >
  53. 拼团详情
  54. </button>
  55. <button
  56. v-if="order.buttons.length === 0"
  57. class="tool-btn ss-reset-button"
  58. @tap.stop="onOrderDetail(order.id)"
  59. >
  60. 查看详情
  61. </button>
  62. <button
  63. v-if="order.buttons.includes('confirm')"
  64. class="tool-btn ss-reset-button"
  65. @tap.stop="onConfirm(order)"
  66. >
  67. 确认收货
  68. </button>
  69. <button
  70. v-if="order.buttons.includes('express')"
  71. class="tool-btn ss-reset-button"
  72. @tap.stop="onExpress(order.id)"
  73. >
  74. 查看物流
  75. </button>
  76. <button
  77. v-if="order.buttons.includes('cancel')"
  78. class="tool-btn ss-reset-button"
  79. @tap.stop="onCancel(order.id)"
  80. >
  81. 取消订单
  82. </button>
  83. <button
  84. v-if="order.buttons.includes('comment')"
  85. class="tool-btn ss-reset-button"
  86. @tap.stop="onComment(order.id)"
  87. >
  88. 评价
  89. </button>
  90. <button
  91. v-if="order.buttons.includes('delete')"
  92. class="delete-btn ss-reset-button"
  93. @tap.stop="onDelete(order.id)"
  94. >
  95. 删除订单
  96. </button>
  97. <button
  98. v-if="order.buttons.includes('pay')"
  99. class="tool-btn ss-reset-button ui-BG-Main-Gradient"
  100. @tap.stop="onPay(order.payOrderId)"
  101. >
  102. 继续支付
  103. </button>
  104. </view>
  105. </view>
  106. </view>
  107. </view>
  108. <!-- 加载更多 -->
  109. <uni-load-more
  110. v-if="state.pagination.total > 0"
  111. :status="state.loadStatus"
  112. :content-text="{
  113. contentdown: '上拉加载更多',
  114. }"
  115. @tap="loadMore"
  116. />
  117. </s-layout>
  118. </template>
  119. <script setup>
  120. import { reactive } from 'vue';
  121. import { onLoad, onReachBottom, onPullDownRefresh } from '@dcloudio/uni-app';
  122. import {
  123. fen2yuan,
  124. formatOrderColor,
  125. formatOrderStatus,
  126. handleOrderButtons,
  127. } from '@/sheep/hooks/useGoods';
  128. import sheep from '@/sheep';
  129. import { concat, isEmpty } from 'lodash-es';
  130. import OrderApi from '@/sheep/api/trade/order';
  131. import { resetPagination } from '@/sheep/helper/utils';
  132. // 数据
  133. const state = reactive({
  134. currentTab: 0, // 选中的 tabMaps 下标
  135. pagination: {
  136. list: [],
  137. total: 0,
  138. pageNo: 1,
  139. pageSize: 5,
  140. },
  141. loadStatus: '',
  142. });
  143. const tabMaps = [
  144. {
  145. name: '全部',
  146. },
  147. {
  148. name: '待付款',
  149. value: 0,
  150. },
  151. {
  152. name: '待发货',
  153. value: 10,
  154. },
  155. {
  156. name: '待收货',
  157. value: 20,
  158. },
  159. {
  160. name: '待评价',
  161. value: 30,
  162. },
  163. ];
  164. // 切换选项卡
  165. function onTabsChange(e) {
  166. if (state.currentTab === e.index) {
  167. return;
  168. }
  169. // 重头加载代码
  170. resetPagination(state.pagination);
  171. state.currentTab = e.index;
  172. getOrderList();
  173. }
  174. // 订单详情
  175. function onOrderDetail(id) {
  176. sheep.$router.go('/pages/order/detail', {
  177. id,
  178. });
  179. }
  180. // 跳转拼团记录的详情
  181. function onOrderGroupon(order) {
  182. sheep.$router.go('/pages/activity/groupon/detail', {
  183. id: order.combinationRecordId,
  184. });
  185. }
  186. // 继续支付
  187. function onPay(payOrderId) {
  188. sheep.$router.go('/pages/pay/index', {
  189. id: payOrderId,
  190. });
  191. }
  192. // 评价
  193. function onComment(id) {
  194. sheep.$router.go('/pages/goods/comment/add', {
  195. id,
  196. });
  197. }
  198. // 确认收货
  199. async function onConfirm(order, ignore = false) {
  200. // 需开启确认收货组件
  201. // todo: 芋艿:【微信物流】需要后续接入微信收货组件 https://gitee.com/sheepjs/shopro-uniapp/commit/a6bbba49b84dd418b84c5fefc8b7463df8f4901f
  202. // 1.怎么检测是否开启了发货组件功能?如果没有开启的话就不能在这里return出去
  203. // 2.如果开启了走mpConfirm方法,需要在App.vue的show方法中拿到确认收货结果
  204. let isOpenBusinessView = true;
  205. if (
  206. sheep.$platform.name === 'WechatMiniProgram' &&
  207. !isEmpty(order.wechat_extra_data) &&
  208. isOpenBusinessView &&
  209. !ignore
  210. ) {
  211. mpConfirm(order);
  212. return;
  213. }
  214. uni.showModal({
  215. title: '提示',
  216. content: '确认收货吗?',
  217. success: async function (res) {
  218. if (!res.confirm) {
  219. return;
  220. }
  221. // 正常的确认收货流程
  222. const { code } = await OrderApi.receiveOrder(order.id);
  223. if (code === 0) {
  224. resetPagination(state.pagination);
  225. await getOrderList();
  226. }
  227. },
  228. });
  229. }
  230. // #ifdef MP-WEIXIN
  231. // 小程序确认收货组件 TODO 芋艿:【微信物流】后续再接入
  232. function mpConfirm(order) {
  233. if (!wx.openBusinessView) {
  234. sheep.$helper.toast(`请升级微信版本`);
  235. return;
  236. }
  237. wx.openBusinessView({
  238. businessType: 'weappOrderConfirm',
  239. extraData: {
  240. merchant_id: '1481069012',
  241. merchant_trade_no: order.wechat_extra_data.merchant_trade_no,
  242. transaction_id: order.wechat_extra_data.transaction_id,
  243. },
  244. success(response) {
  245. console.log('success:', response);
  246. if (response.errMsg === 'openBusinessView:ok') {
  247. if (response.extraData.status === 'success') {
  248. onConfirm(order, true);
  249. }
  250. }
  251. },
  252. fail(error) {
  253. console.log('error:', error);
  254. },
  255. complete(result) {
  256. console.log('result:', result);
  257. },
  258. });
  259. }
  260. // #endif
  261. // 查看物流
  262. async function onExpress(id) {
  263. sheep.$router.go('/pages/order/express/log', {
  264. id,
  265. });
  266. }
  267. // 取消订单
  268. async function onCancel(orderId) {
  269. uni.showModal({
  270. title: '提示',
  271. content: '确定要取消订单吗?',
  272. success: async function (res) {
  273. if (!res.confirm) {
  274. return;
  275. }
  276. const { code } = await OrderApi.cancelOrder(orderId);
  277. if (code === 0) {
  278. // 修改数据的状态
  279. let index = state.pagination.list.findIndex((order) => order.id === orderId);
  280. const orderInfo = state.pagination.list[index];
  281. orderInfo.status = 40;
  282. handleOrderButtons(orderInfo);
  283. }
  284. },
  285. });
  286. }
  287. // 删除订单
  288. function onDelete(orderId) {
  289. uni.showModal({
  290. title: '提示',
  291. content: '确定要删除订单吗?',
  292. success: async function (res) {
  293. if (res.confirm) {
  294. const { code } = await OrderApi.deleteOrder(orderId);
  295. if (code === 0) {
  296. // 删除数据
  297. let index = state.pagination.list.findIndex((order) => order.id === orderId);
  298. state.pagination.list.splice(index, 1);
  299. }
  300. }
  301. },
  302. });
  303. }
  304. // 获取订单列表
  305. async function getOrderList() {
  306. state.loadStatus = 'loading';
  307. let { code, data } = await OrderApi.getOrderPage({
  308. pageNo: state.pagination.pageNo,
  309. pageSize: state.pagination.pageSize,
  310. status: tabMaps[state.currentTab].value,
  311. commentStatus: tabMaps[state.currentTab].value === 30 ? false : null,
  312. });
  313. if (code !== 0) {
  314. return;
  315. }
  316. data.list.forEach((order) => handleOrderButtons(order));
  317. state.pagination.list = concat(state.pagination.list, data.list);
  318. state.pagination.total = data.total;
  319. state.loadStatus = state.pagination.list.length < state.pagination.total ? 'more' : 'noMore';
  320. }
  321. onLoad(async (options) => {
  322. if (options.type) {
  323. state.currentTab = options.type;
  324. }
  325. await getOrderList();
  326. });
  327. // 加载更多
  328. function loadMore() {
  329. if (state.loadStatus === 'noMore') {
  330. return;
  331. }
  332. state.pagination.pageNo++;
  333. getOrderList();
  334. }
  335. // 上拉加载更多
  336. onReachBottom(() => {
  337. loadMore();
  338. });
  339. // 下拉刷新
  340. onPullDownRefresh(() => {
  341. resetPagination(state.pagination);
  342. getOrderList();
  343. setTimeout(function () {
  344. uni.stopPullDownRefresh();
  345. }, 800);
  346. });
  347. </script>
  348. <style lang="scss" scoped>
  349. .score-img {
  350. width: 36rpx;
  351. height: 36rpx;
  352. margin: 0 4rpx;
  353. }
  354. .tool-btn {
  355. width: 160rpx;
  356. height: 60rpx;
  357. background: #f6f6f6;
  358. font-size: 26rpx;
  359. border-radius: 30rpx;
  360. margin-right: 10rpx;
  361. &:last-of-type {
  362. margin-right: 0;
  363. }
  364. }
  365. .delete-btn {
  366. width: 160rpx;
  367. height: 56rpx;
  368. color: #ff3000;
  369. background: #fee;
  370. border-radius: 28rpx;
  371. font-size: 26rpx;
  372. margin-right: 10rpx;
  373. line-height: normal;
  374. &:last-of-type {
  375. margin-right: 0;
  376. }
  377. }
  378. .apply-btn {
  379. width: 140rpx;
  380. height: 50rpx;
  381. border-radius: 25rpx;
  382. font-size: 24rpx;
  383. border: 2rpx solid #dcdcdc;
  384. line-height: normal;
  385. margin-left: 16rpx;
  386. }
  387. .swiper-box {
  388. flex: 1;
  389. .swiper-item {
  390. height: 100%;
  391. width: 100%;
  392. }
  393. }
  394. .order-list-card-box {
  395. .order-card-header {
  396. height: 80rpx;
  397. .order-no {
  398. font-size: 26rpx;
  399. font-weight: 500;
  400. }
  401. .order-state {
  402. }
  403. }
  404. .pay-box {
  405. .discounts-title {
  406. font-size: 24rpx;
  407. line-height: normal;
  408. color: #999999;
  409. }
  410. .discounts-money {
  411. font-size: 24rpx;
  412. line-height: normal;
  413. color: #999;
  414. font-family: OPPOSANS;
  415. }
  416. .pay-color {
  417. color: #333;
  418. }
  419. }
  420. .order-card-footer {
  421. height: 100rpx;
  422. .more-item-box {
  423. padding: 20rpx;
  424. .more-item {
  425. height: 60rpx;
  426. .title {
  427. font-size: 26rpx;
  428. }
  429. }
  430. }
  431. .more-btn {
  432. color: $dark-9;
  433. font-size: 24rpx;
  434. }
  435. .content {
  436. width: 154rpx;
  437. color: #333333;
  438. font-size: 26rpx;
  439. font-weight: 500;
  440. }
  441. }
  442. }
  443. :deep(.uni-tooltip-popup) {
  444. background: var(--ui-BG);
  445. }
  446. .warning-color {
  447. color: #faad14;
  448. }
  449. .danger-color {
  450. color: #ff3000;
  451. }
  452. .success-color {
  453. color: #52c41a;
  454. }
  455. .info-color {
  456. color: #999999;
  457. }
  458. </style>