list.vue 10 KB

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