list.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  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 _ from 'lodash-es';
  130. import { isEmpty } from 'lodash-es';
  131. import OrderApi from '@/sheep/api/trade/order';
  132. import { resetPagination } from '@/sheep/util';
  133. // 数据
  134. const state = reactive({
  135. currentTab: 0, // 选中的 tabMaps 下标
  136. pagination: {
  137. list: [],
  138. total: 0,
  139. pageNo: 1,
  140. pageSize: 5,
  141. },
  142. loadStatus: '',
  143. });
  144. const tabMaps = [
  145. {
  146. name: '全部',
  147. },
  148. {
  149. name: '待付款',
  150. value: 0,
  151. },
  152. {
  153. name: '待发货',
  154. value: 10,
  155. },
  156. {
  157. name: '待收货',
  158. value: 20,
  159. },
  160. {
  161. name: '待评价',
  162. value: 30,
  163. },
  164. ];
  165. // 切换选项卡
  166. function onTabsChange(e) {
  167. if (state.currentTab === e.index) {
  168. return;
  169. }
  170. // 重头加载代码
  171. resetPagination(state.pagination);
  172. state.currentTab = e.index;
  173. getOrderList();
  174. }
  175. // 订单详情
  176. function onOrderDetail(id) {
  177. sheep.$router.go('/pages/order/detail', {
  178. id,
  179. });
  180. }
  181. // 跳转拼团记录的详情
  182. function onOrderGroupon(order) {
  183. sheep.$router.go('/pages/activity/groupon/detail', {
  184. id: order.combinationRecordId,
  185. });
  186. }
  187. // 继续支付
  188. function onPay(payOrderId) {
  189. sheep.$router.go('/pages/pay/index', {
  190. id: payOrderId,
  191. });
  192. }
  193. // 评价
  194. function onComment(id) {
  195. sheep.$router.go('/pages/goods/comment/add', {
  196. id,
  197. });
  198. }
  199. // 确认收货 TODO 芋艿:待测试
  200. async function onConfirm(order, ignore = false) {
  201. // 需开启确认收货组件
  202. // todo: 芋艿:需要后续接入微信收货组件
  203. // 1.怎么检测是否开启了发货组件功能?如果没有开启的话就不能在这里return出去
  204. // 2.如果开启了走mpConfirm方法,需要在App.vue的show方法中拿到确认收货结果
  205. let isOpenBusinessView = true;
  206. if (
  207. sheep.$platform.name === 'WechatMiniProgram' &&
  208. !isEmpty(order.wechat_extra_data) &&
  209. isOpenBusinessView &&
  210. !ignore
  211. ) {
  212. mpConfirm(order);
  213. return;
  214. }
  215. // 正常的确认收货流程
  216. const { code } = await OrderApi.receiveOrder(order.id);
  217. if (code === 0) {
  218. resetPagination(state.pagination);
  219. await getOrderList();
  220. }
  221. }
  222. // #ifdef MP-WEIXIN
  223. // 小程序确认收货组件 TODO 芋艿:后续再接入
  224. function mpConfirm(order) {
  225. if (!wx.openBusinessView) {
  226. sheep.$helper.toast(`请升级微信版本`);
  227. return;
  228. }
  229. wx.openBusinessView({
  230. businessType: 'weappOrderConfirm',
  231. extraData: {
  232. merchant_id: '1481069012',
  233. merchant_trade_no: order.wechat_extra_data.merchant_trade_no,
  234. transaction_id: order.wechat_extra_data.transaction_id,
  235. },
  236. success(response) {
  237. console.log('success:', response);
  238. if (response.errMsg === 'openBusinessView:ok') {
  239. if (response.extraData.status === 'success') {
  240. onConfirm(order, true);
  241. }
  242. }
  243. },
  244. fail(error) {
  245. console.log('error:', error);
  246. },
  247. complete(result) {
  248. console.log('result:', result);
  249. },
  250. });
  251. }
  252. // #endif
  253. // 查看物流
  254. async function onExpress(id) {
  255. sheep.$router.go('/pages/order/express/log', {
  256. id,
  257. });
  258. }
  259. // 取消订单
  260. async function onCancel(orderId) {
  261. uni.showModal({
  262. title: '提示',
  263. content: '确定要取消订单吗?',
  264. success: async function (res) {
  265. if (!res.confirm) {
  266. return;
  267. }
  268. const { code } = await OrderApi.cancelOrder(orderId);
  269. if (code === 0) {
  270. // 修改数据的状态
  271. let index = state.pagination.list.findIndex((order) => order.id === orderId);
  272. const orderInfo = state.pagination.list[index];
  273. orderInfo.status = 40;
  274. handleOrderButtons(orderInfo);
  275. }
  276. },
  277. });
  278. }
  279. // 删除订单
  280. function onDelete(orderId) {
  281. uni.showModal({
  282. title: '提示',
  283. content: '确定要删除订单吗?',
  284. success: async function (res) {
  285. if (res.confirm) {
  286. const { code } = await OrderApi.deleteOrder(orderId);
  287. if (code === 0) {
  288. // 删除数据
  289. let index = state.pagination.list.findIndex((order) => order.id === orderId);
  290. state.pagination.list.splice(index, 1);
  291. }
  292. }
  293. },
  294. });
  295. }
  296. // 获取订单列表
  297. async function getOrderList() {
  298. state.loadStatus = 'loading';
  299. let { code, data } = await OrderApi.getOrderPage({
  300. pageNo: state.pagination.pageNo,
  301. pageSize: state.pagination.pageSize,
  302. status: tabMaps[state.currentTab].value,
  303. commentStatus: tabMaps[state.currentTab].value === 30 ? false : null,
  304. });
  305. if (code !== 0) {
  306. return;
  307. }
  308. data.list.forEach((order) => handleOrderButtons(order));
  309. state.pagination.list = _.concat(state.pagination.list, data.list);
  310. state.pagination.total = data.total;
  311. state.loadStatus = state.pagination.list.length < state.pagination.total ? 'more' : 'noMore';
  312. }
  313. onLoad(async (options) => {
  314. if (options.type) {
  315. state.currentTab = options.type;
  316. }
  317. await getOrderList();
  318. });
  319. // 加载更多
  320. function loadMore() {
  321. if (state.loadStatus === 'noMore') {
  322. return;
  323. }
  324. state.pagination.pageNo++;
  325. getOrderList();
  326. }
  327. // 上拉加载更多
  328. onReachBottom(() => {
  329. loadMore();
  330. });
  331. // 下拉刷新
  332. onPullDownRefresh(() => {
  333. resetPagination(state.pagination);
  334. getOrderList();
  335. setTimeout(function () {
  336. uni.stopPullDownRefresh();
  337. }, 800);
  338. });
  339. </script>
  340. <style lang="scss" scoped>
  341. .score-img {
  342. width: 36rpx;
  343. height: 36rpx;
  344. margin: 0 4rpx;
  345. }
  346. .tool-btn {
  347. width: 160rpx;
  348. height: 60rpx;
  349. background: #f6f6f6;
  350. font-size: 26rpx;
  351. border-radius: 30rpx;
  352. margin-right: 10rpx;
  353. &:last-of-type {
  354. margin-right: 0;
  355. }
  356. }
  357. .delete-btn {
  358. width: 160rpx;
  359. height: 56rpx;
  360. color: #ff3000;
  361. background: #fee;
  362. border-radius: 28rpx;
  363. font-size: 26rpx;
  364. margin-right: 10rpx;
  365. line-height: normal;
  366. &:last-of-type {
  367. margin-right: 0;
  368. }
  369. }
  370. .apply-btn {
  371. width: 140rpx;
  372. height: 50rpx;
  373. border-radius: 25rpx;
  374. font-size: 24rpx;
  375. border: 2rpx solid #dcdcdc;
  376. line-height: normal;
  377. margin-left: 16rpx;
  378. }
  379. .swiper-box {
  380. flex: 1;
  381. .swiper-item {
  382. height: 100%;
  383. width: 100%;
  384. }
  385. }
  386. .order-list-card-box {
  387. .order-card-header {
  388. height: 80rpx;
  389. .order-no {
  390. font-size: 26rpx;
  391. font-weight: 500;
  392. }
  393. .order-state {
  394. }
  395. }
  396. .pay-box {
  397. .discounts-title {
  398. font-size: 24rpx;
  399. line-height: normal;
  400. color: #999999;
  401. }
  402. .discounts-money {
  403. font-size: 24rpx;
  404. line-height: normal;
  405. color: #999;
  406. font-family: OPPOSANS;
  407. }
  408. .pay-color {
  409. color: #333;
  410. }
  411. }
  412. .order-card-footer {
  413. height: 100rpx;
  414. .more-item-box {
  415. padding: 20rpx;
  416. .more-item {
  417. height: 60rpx;
  418. .title {
  419. font-size: 26rpx;
  420. }
  421. }
  422. }
  423. .more-btn {
  424. color: $dark-9;
  425. font-size: 24rpx;
  426. }
  427. .content {
  428. width: 154rpx;
  429. color: #333333;
  430. font-size: 26rpx;
  431. font-weight: 500;
  432. }
  433. }
  434. }
  435. :deep(.uni-tooltip-popup) {
  436. background: var(--ui-BG);
  437. }
  438. .warning-color {
  439. color: #faad14;
  440. }
  441. .danger-color {
  442. color: #ff3000;
  443. }
  444. .success-color {
  445. color: #52c41a;
  446. }
  447. .info-color {
  448. color: #999999;
  449. }
  450. </style>