list.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  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 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
  19. :img="item.picUrl"
  20. :title="item.spuName"
  21. :skuText="item.properties.map((property) => property.valueName).join(' ')"
  22. :price="item.price"
  23. :num="item.count"
  24. />
  25. </view>
  26. <view class="pay-box ss-m-t-30 ss-flex ss-row-right ss-p-r-20">
  27. <view class="ss-flex ss-col-center">
  28. <view class="discounts-title pay-color">共 {{ order.productCount }} 件商品,总金额:</view>
  29. <view class="discounts-money pay-color">
  30. ¥{{ fen2yuan(order.payPrice) }}
  31. </view>
  32. </view>
  33. </view>
  34. <view class="order-card-footer ss-flex ss-col-center ss-p-x-20"
  35. :class="order.buttons.length > 3 ? 'ss-row-between' : 'ss-row-right'">
  36. <view class="ss-flex ss-col-center">
  37. <!-- TODO 芋艿:再次购买 -->
  38. <button v-if="order.buttons.includes('combination')" class="tool-btn ss-reset-button"
  39. @tap.stop="onOrderGroupon(order)">
  40. 拼团详情
  41. </button>
  42. <button v-if="order.buttons.length === 0" class="tool-btn ss-reset-button"
  43. @tap.stop="onOrderDetail(order.id)">
  44. 查看详情
  45. </button>
  46. <button v-if="order.buttons.includes('confirm')" class="tool-btn ss-reset-button"
  47. @tap.stop="onConfirm(order)">
  48. 确认收货
  49. </button>
  50. <button v-if="order.buttons.includes('express')" class="tool-btn ss-reset-button"
  51. @tap.stop="onExpress(order.id)">
  52. 查看物流
  53. </button>
  54. <button v-if="order.buttons.includes('cancel')" class="tool-btn ss-reset-button"
  55. @tap.stop="onCancel(order.id)">
  56. 取消订单
  57. </button>
  58. <button v-if="order.buttons.includes('comment')" class="tool-btn ss-reset-button"
  59. @tap.stop="onComment(order.order_sn)">
  60. 评价
  61. </button>
  62. <button v-if="order.buttons.includes('delete')" class="delete-btn ss-reset-button"
  63. @tap.stop="onDelete(order.id)">
  64. 删除订单
  65. </button>
  66. <button v-if="order.buttons.includes('pay')" class="tool-btn ss-reset-button ui-BG-Main-Gradient"
  67. @tap.stop="onPay(order.payOrderId)">
  68. 继续支付
  69. </button>
  70. </view>
  71. </view>
  72. </view>
  73. </view>
  74. <!-- 加载更多 -->
  75. <uni-load-more v-if="state.pagination.total > 0" :status="state.loadStatus" :content-text="{
  76. contentdown: '上拉加载更多',
  77. }" @tap="loadMore" />
  78. </s-layout>
  79. </template>
  80. <script setup>
  81. import {
  82. computed,
  83. reactive
  84. } from 'vue';
  85. import {
  86. onLoad,
  87. onReachBottom,
  88. onPullDownRefresh
  89. } from '@dcloudio/uni-app';
  90. import {
  91. fen2yuan,
  92. formatOrderColor, formatOrderStatus, handleOrderButtons,
  93. } from '@/sheep/hooks/useGoods';
  94. import sheep from '@/sheep';
  95. import _ from 'lodash';
  96. import {
  97. isEmpty
  98. } from 'lodash';
  99. import OrderApi from '@/sheep/api/trade/order';
  100. const paginationNull = {
  101. list: [],
  102. total: 0,
  103. pageNo: 1,
  104. pageSize: 5,
  105. };
  106. // 数据
  107. const state = reactive({
  108. currentTab: 0, // 选中的 tabMaps 下标
  109. pagination: {
  110. list: [],
  111. total: 0,
  112. pageNo: 1,
  113. pageSize: 5,
  114. },
  115. loadStatus: ''
  116. });
  117. const tabMaps = [{
  118. name: '全部'
  119. },
  120. {
  121. name: '待付款',
  122. value: 0,
  123. },
  124. {
  125. name: '待发货',
  126. value: 10,
  127. },
  128. {
  129. name: '待收货',
  130. value: 20,
  131. },
  132. {
  133. name: '待评价',
  134. value: 30,
  135. },
  136. ];
  137. // 切换选项卡
  138. function onTabsChange(e) {
  139. if (state.currentTab === e.index) {
  140. return;
  141. }
  142. // 重头加载代码
  143. state.pagination = paginationNull;
  144. state.currentTab = e.index;
  145. getOrderList();
  146. }
  147. // 订单详情
  148. function onOrderDetail(id) {
  149. sheep.$router.go('/pages/order/detail', {
  150. id,
  151. });
  152. }
  153. // 分享拼团 TODO 芋艿:待测试
  154. function onOrderGroupon(order) {
  155. sheep.$router.go('/pages/activity/groupon/detail', {
  156. id: order.ext.groupon_id,
  157. });
  158. }
  159. // 继续支付
  160. function onPay(payOrderId) {
  161. sheep.$router.go('/pages/pay/index', {
  162. id: payOrderId,
  163. });
  164. }
  165. // 评价 TODO 芋艿:待测试
  166. function onComment(orderSN) {
  167. sheep.$router.go('/pages/goods/comment/add', {
  168. orderSN,
  169. });
  170. }
  171. // 确认收货 TODO 芋艿:待测试
  172. async function onConfirm(order, ignore = false) {
  173. // 需开启确认收货组件
  174. // todo: 芋艿:需要后续接入微信收货组件
  175. // 1.怎么检测是否开启了发货组件功能?如果没有开启的话就不能在这里return出去
  176. // 2.如果开启了走mpConfirm方法,需要在App.vue的show方法中拿到确认收货结果
  177. let isOpenBusinessView = true;
  178. if (
  179. sheep.$platform.name === 'WechatMiniProgram' &&
  180. !isEmpty(order.wechat_extra_data) &&
  181. isOpenBusinessView &&
  182. !ignore
  183. ) {
  184. mpConfirm(order);
  185. return;
  186. }
  187. // 正常的确认收货流程
  188. const { code } = await OrderApi.receiveOrder(order.id);
  189. if (code === 0) {
  190. state.pagination = paginationNull;
  191. await getOrderList();
  192. }
  193. }
  194. // #ifdef MP-WEIXIN
  195. // 小程序确认收货组件 TODO 芋艿:后续再接入
  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. // 查看物流 TODO 芋艿:待测试
  226. async function onExpress(orderId) {
  227. sheep.$router.go('/pages/order/express/list', {
  228. orderId,
  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 { code } = await OrderApi.cancelOrder(orderId);
  241. if (code === 0) {
  242. // 修改数据的状态
  243. let index = state.pagination.list.findIndex((order) => order.id === orderId);
  244. const orderInfo = state.pagination.list[index];
  245. orderInfo.status = 40;
  246. handleOrderButtons(orderInfo);
  247. }
  248. },
  249. });
  250. }
  251. // 删除订单
  252. function onDelete(orderId) {
  253. uni.showModal({
  254. title: '提示',
  255. content: '确定要删除订单吗?',
  256. success: async function(res) {
  257. if (res.confirm) {
  258. const { code } = await OrderApi.deleteOrder(orderId);
  259. if (code === 0) {
  260. // 删除数据
  261. let index = state.pagination.list.findIndex((order) => order.id === orderId);
  262. state.pagination.list.splice(index, 1);
  263. }
  264. }
  265. },
  266. });
  267. }
  268. // 获取订单列表
  269. async function getOrderList() {
  270. state.loadStatus = 'loading';
  271. let { code, data } = await OrderApi.getOrderPage({
  272. pageNo: state.pagination.pageNo,
  273. pageSize: state.pagination.pageSize,
  274. status: tabMaps[state.currentTab].value,
  275. commentStatus: tabMaps[state.currentTab].value === 30 ? false : null
  276. });
  277. if (code !== 0) {
  278. return;
  279. }
  280. data.list.forEach(order => handleOrderButtons(order));
  281. state.pagination.list = _.concat(state.pagination.list, data.list)
  282. state.pagination.total = data.total;
  283. state.loadStatus = state.pagination.list.length < state.pagination.total ? 'more' : 'noMore';
  284. }
  285. onLoad(async (options) => {
  286. if (options.type) {
  287. state.currentTab = options.type;
  288. }
  289. await getOrderList();
  290. });
  291. // 加载更多
  292. function loadMore() {
  293. if (state.loadStatus === 'noMore') {
  294. return
  295. }
  296. state.pagination.pageNo++;
  297. getOrderList();
  298. }
  299. // 上拉加载更多
  300. onReachBottom(() => {
  301. loadMore();
  302. });
  303. // 下拉刷新
  304. onPullDownRefresh(() => {
  305. state.pagination = paginationNull;
  306. getOrderList();
  307. setTimeout(function() {
  308. uni.stopPullDownRefresh();
  309. }, 800);
  310. });
  311. </script>
  312. <style lang="scss" scoped>
  313. .score-img {
  314. width: 36rpx;
  315. height: 36rpx;
  316. margin: 0 4rpx;
  317. }
  318. .tool-btn {
  319. width: 160rpx;
  320. height: 60rpx;
  321. background: #f6f6f6;
  322. font-size: 26rpx;
  323. border-radius: 30rpx;
  324. margin-right: 10rpx;
  325. &:last-of-type {
  326. margin-right: 0;
  327. }
  328. }
  329. .delete-btn {
  330. width: 160rpx;
  331. height: 56rpx;
  332. color: #ff3000;
  333. background: #fee;
  334. border-radius: 28rpx;
  335. font-size: 26rpx;
  336. margin-right: 10rpx;
  337. line-height: normal;
  338. &:last-of-type {
  339. margin-right: 0;
  340. }
  341. }
  342. .apply-btn {
  343. width: 140rpx;
  344. height: 50rpx;
  345. border-radius: 25rpx;
  346. font-size: 24rpx;
  347. border: 2rpx solid #dcdcdc;
  348. line-height: normal;
  349. margin-left: 16rpx;
  350. }
  351. .swiper-box {
  352. flex: 1;
  353. .swiper-item {
  354. height: 100%;
  355. width: 100%;
  356. }
  357. }
  358. .order-list-card-box {
  359. .order-card-header {
  360. height: 80rpx;
  361. .order-no {
  362. font-size: 26rpx;
  363. font-weight: 500;
  364. }
  365. .order-state {}
  366. }
  367. .pay-box {
  368. .discounts-title {
  369. font-size: 24rpx;
  370. line-height: normal;
  371. color: #999999;
  372. }
  373. .discounts-money {
  374. font-size: 24rpx;
  375. line-height: normal;
  376. color: #999;
  377. font-family: OPPOSANS;
  378. }
  379. .pay-color {
  380. color: #333;
  381. }
  382. }
  383. .order-card-footer {
  384. height: 100rpx;
  385. .more-item-box {
  386. padding: 20rpx;
  387. .more-item {
  388. height: 60rpx;
  389. .title {
  390. font-size: 26rpx;
  391. }
  392. }
  393. }
  394. .more-btn {
  395. color: $dark-9;
  396. font-size: 24rpx;
  397. }
  398. .content {
  399. width: 154rpx;
  400. color: #333333;
  401. font-size: 26rpx;
  402. font-weight: 500;
  403. }
  404. }
  405. }
  406. :deep(.uni-tooltip-popup) {
  407. background: var(--ui-BG);
  408. }
  409. .warning-color {
  410. color: #faad14;
  411. }
  412. .danger-color {
  413. color: #ff3000;
  414. }
  415. .success-color {
  416. color: #52c41a;
  417. }
  418. .info-color {
  419. color: #999999;
  420. }
  421. </style>