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 _ 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. uni.showModal({
  216. title: '提示',
  217. content: '确认收货吗?',
  218. success: async function (res) {
  219. if (!res.confirm) {
  220. return;
  221. }
  222. // 正常的确认收货流程
  223. const { code } = await OrderApi.receiveOrder(order.id);
  224. if (code === 0) {
  225. resetPagination(state.pagination);
  226. await getOrderList();
  227. }
  228. },
  229. });
  230. }
  231. // #ifdef MP-WEIXIN
  232. // 小程序确认收货组件 TODO 芋艿:后续再接入
  233. function mpConfirm(order) {
  234. if (!wx.openBusinessView) {
  235. sheep.$helper.toast(`请升级微信版本`);
  236. return;
  237. }
  238. wx.openBusinessView({
  239. businessType: 'weappOrderConfirm',
  240. extraData: {
  241. merchant_id: '1481069012',
  242. merchant_trade_no: order.wechat_extra_data.merchant_trade_no,
  243. transaction_id: order.wechat_extra_data.transaction_id,
  244. },
  245. success(response) {
  246. console.log('success:', response);
  247. if (response.errMsg === 'openBusinessView:ok') {
  248. if (response.extraData.status === 'success') {
  249. onConfirm(order, true);
  250. }
  251. }
  252. },
  253. fail(error) {
  254. console.log('error:', error);
  255. },
  256. complete(result) {
  257. console.log('result:', result);
  258. },
  259. });
  260. }
  261. // #endif
  262. // 查看物流
  263. async function onExpress(id) {
  264. sheep.$router.go('/pages/order/express/log', {
  265. id,
  266. });
  267. }
  268. // 取消订单
  269. async function onCancel(orderId) {
  270. uni.showModal({
  271. title: '提示',
  272. content: '确定要取消订单吗?',
  273. success: async function (res) {
  274. if (!res.confirm) {
  275. return;
  276. }
  277. const { code } = await OrderApi.cancelOrder(orderId);
  278. if (code === 0) {
  279. // 修改数据的状态
  280. let index = state.pagination.list.findIndex((order) => order.id === orderId);
  281. const orderInfo = state.pagination.list[index];
  282. orderInfo.status = 40;
  283. handleOrderButtons(orderInfo);
  284. }
  285. },
  286. });
  287. }
  288. // 删除订单
  289. function onDelete(orderId) {
  290. uni.showModal({
  291. title: '提示',
  292. content: '确定要删除订单吗?',
  293. success: async function (res) {
  294. if (res.confirm) {
  295. const { code } = await OrderApi.deleteOrder(orderId);
  296. if (code === 0) {
  297. // 删除数据
  298. let index = state.pagination.list.findIndex((order) => order.id === orderId);
  299. state.pagination.list.splice(index, 1);
  300. }
  301. }
  302. },
  303. });
  304. }
  305. // 获取订单列表
  306. async function getOrderList() {
  307. state.loadStatus = 'loading';
  308. let { code, data } = await OrderApi.getOrderPage({
  309. pageNo: state.pagination.pageNo,
  310. pageSize: state.pagination.pageSize,
  311. status: tabMaps[state.currentTab].value,
  312. commentStatus: tabMaps[state.currentTab].value === 30 ? false : null,
  313. });
  314. if (code !== 0) {
  315. return;
  316. }
  317. data.list.forEach((order) => handleOrderButtons(order));
  318. state.pagination.list = _.concat(state.pagination.list, data.list);
  319. state.pagination.total = data.total;
  320. state.loadStatus = state.pagination.list.length < state.pagination.total ? 'more' : 'noMore';
  321. }
  322. onLoad(async (options) => {
  323. if (options.type) {
  324. state.currentTab = options.type;
  325. }
  326. await getOrderList();
  327. });
  328. // 加载更多
  329. function loadMore() {
  330. if (state.loadStatus === 'noMore') {
  331. return;
  332. }
  333. state.pagination.pageNo++;
  334. getOrderList();
  335. }
  336. // 上拉加载更多
  337. onReachBottom(() => {
  338. loadMore();
  339. });
  340. // 下拉刷新
  341. onPullDownRefresh(() => {
  342. resetPagination(state.pagination);
  343. getOrderList();
  344. setTimeout(function () {
  345. uni.stopPullDownRefresh();
  346. }, 800);
  347. });
  348. </script>
  349. <style lang="scss" scoped>
  350. .score-img {
  351. width: 36rpx;
  352. height: 36rpx;
  353. margin: 0 4rpx;
  354. }
  355. .tool-btn {
  356. width: 160rpx;
  357. height: 60rpx;
  358. background: #f6f6f6;
  359. font-size: 26rpx;
  360. border-radius: 30rpx;
  361. margin-right: 10rpx;
  362. &:last-of-type {
  363. margin-right: 0;
  364. }
  365. }
  366. .delete-btn {
  367. width: 160rpx;
  368. height: 56rpx;
  369. color: #ff3000;
  370. background: #fee;
  371. border-radius: 28rpx;
  372. font-size: 26rpx;
  373. margin-right: 10rpx;
  374. line-height: normal;
  375. &:last-of-type {
  376. margin-right: 0;
  377. }
  378. }
  379. .apply-btn {
  380. width: 140rpx;
  381. height: 50rpx;
  382. border-radius: 25rpx;
  383. font-size: 24rpx;
  384. border: 2rpx solid #dcdcdc;
  385. line-height: normal;
  386. margin-left: 16rpx;
  387. }
  388. .swiper-box {
  389. flex: 1;
  390. .swiper-item {
  391. height: 100%;
  392. width: 100%;
  393. }
  394. }
  395. .order-list-card-box {
  396. .order-card-header {
  397. height: 80rpx;
  398. .order-no {
  399. font-size: 26rpx;
  400. font-weight: 500;
  401. }
  402. .order-state {
  403. }
  404. }
  405. .pay-box {
  406. .discounts-title {
  407. font-size: 24rpx;
  408. line-height: normal;
  409. color: #999999;
  410. }
  411. .discounts-money {
  412. font-size: 24rpx;
  413. line-height: normal;
  414. color: #999;
  415. font-family: OPPOSANS;
  416. }
  417. .pay-color {
  418. color: #333;
  419. }
  420. }
  421. .order-card-footer {
  422. height: 100rpx;
  423. .more-item-box {
  424. padding: 20rpx;
  425. .more-item {
  426. height: 60rpx;
  427. .title {
  428. font-size: 26rpx;
  429. }
  430. }
  431. }
  432. .more-btn {
  433. color: $dark-9;
  434. font-size: 24rpx;
  435. }
  436. .content {
  437. width: 154rpx;
  438. color: #333333;
  439. font-size: 26rpx;
  440. font-weight: 500;
  441. }
  442. }
  443. }
  444. :deep(.uni-tooltip-popup) {
  445. background: var(--ui-BG);
  446. }
  447. .warning-color {
  448. color: #faad14;
  449. }
  450. .danger-color {
  451. color: #ff3000;
  452. }
  453. .success-color {
  454. color: #52c41a;
  455. }
  456. .info-color {
  457. color: #999999;
  458. }
  459. </style>