list.vue 10 KB

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