list.vue 10 KB

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