list.vue 12 KB

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