list.vue 10 KB

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