list.vue 11 KB

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