list.vue 12 KB

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