list.vue 10 KB

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