list.vue 12 KB

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