list.vue 13 KB

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