order.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. <!-- 页面 -->
  2. <template>
  3. <s-layout title="我的拼团">
  4. <su-sticky bgColor="#fff">
  5. <su-tabs
  6. :list="tabMaps"
  7. :scrollable="false"
  8. @change="onTabsChange"
  9. :current="state.currentTab"
  10. ></su-tabs>
  11. </su-sticky>
  12. <s-empty v-if="state.pagination.total === 0" icon="/static/goods-empty.png"> </s-empty>
  13. <view v-if="state.pagination.total > 0">
  14. <view
  15. class="order-list-card-box bg-white ss-r-10 ss-m-t-14 ss-m-20"
  16. v-for="order in state.pagination.data"
  17. :key="order.id"
  18. >
  19. <view class="border-bottom">
  20. <s-goods-item
  21. :img="order.goods.image"
  22. :title="order.goods.title"
  23. :price="order.goods.price[0]"
  24. priceColor="#E1212B"
  25. >
  26. <template #groupon>
  27. <view class="ss-flex">
  28. <view class="sales-title"> {{ order.num }}人团 </view>
  29. <!-- <view class="num-title ss-m-l-20"> 已拼{{ order.goods.sales }}件 </view> -->
  30. </view>
  31. </template>
  32. </s-goods-item>
  33. </view>
  34. <view class="order-card-footer ss-flex ss-row-right ss-p-x-20">
  35. <button
  36. class="detail-btn ss-reset-button"
  37. @tap="sheep.$router.go('/pages/order/detail', { id: order.my.order_id })"
  38. >
  39. 订单详情
  40. </button>
  41. <button
  42. class="detail-btn ss-reset-button"
  43. @tap="sheep.$router.go('/pages/activity/groupon/detail', { id: order.id })"
  44. >
  45. {{ order.status === 'ing' ? '邀请拼团' : '拼团详情' }}
  46. </button>
  47. </view>
  48. </view>
  49. </view>
  50. <uni-load-more
  51. v-if="state.pagination.total > 0"
  52. :status="state.loadStatus"
  53. :content-text="{
  54. contentdown: '上拉加载更多',
  55. }"
  56. @tap="loadmore"
  57. />
  58. </s-layout>
  59. </template>
  60. <script setup>
  61. import { computed, reactive } from 'vue';
  62. import { onLoad, onReachBottom, onPullDownRefresh } from '@dcloudio/uni-app';
  63. import sheep from '@/sheep';
  64. import _ from 'lodash';
  65. // 数据
  66. const state = reactive({
  67. currentTab: 0,
  68. pagination: {
  69. data: [],
  70. current_page: 1,
  71. total: 1,
  72. last_page: 1,
  73. },
  74. loadStatus: '',
  75. deleteOrderId: 0,
  76. });
  77. const tabMaps = [
  78. {
  79. name: '全部',
  80. value: 'all',
  81. },
  82. {
  83. name: '进行中',
  84. value: 'ing',
  85. },
  86. {
  87. name: '拼团成功',
  88. value: 'finish',
  89. },
  90. {
  91. name: '拼团失败',
  92. value: 'invalid',
  93. },
  94. ];
  95. // 切换选项卡
  96. function onTabsChange(e) {
  97. state.pagination = {
  98. data: [],
  99. current_page: 1,
  100. total: 1,
  101. last_page: 1,
  102. };
  103. state.currentTab = e.index;
  104. getGrouponList();
  105. }
  106. // 订单详情
  107. function onDetail(orderSN) {
  108. sheep.$router.go('/pages/order/detail', {
  109. orderSN,
  110. });
  111. }
  112. // 继续支付
  113. function onPay(orderSN) {
  114. sheep.$router.go('/pages/pay/index', {
  115. orderSN,
  116. });
  117. }
  118. // 评价
  119. function onComment(orderSN) {
  120. sheep.$router.go('/pages/order/comment/add', {
  121. orderSN,
  122. });
  123. }
  124. // 确认收货
  125. async function onConfirm(orderId) {
  126. const { error, data } = await sheep.$api.order.confirm(orderId);
  127. if (error === 0) {
  128. let index = state.pagination.data.findIndex((order) => order.id === orderId);
  129. state.pagination.data[index] = data;
  130. }
  131. }
  132. // 取消订单
  133. async function onCancel(orderId) {
  134. const { error, data } = await sheep.$api.order.cancel(orderId);
  135. if (error === 0) {
  136. let index = state.pagination.data.findIndex((order) => order.id === orderId);
  137. state.pagination.data[index] = data;
  138. }
  139. }
  140. // 获取订单列表
  141. async function getGrouponList(page = 1, list_rows = 5) {
  142. state.loadStatus = 'loading';
  143. let res = await sheep.$api.activity.myGroupon({
  144. type: tabMaps[state.currentTab].value,
  145. });
  146. if (res.error === 0) {
  147. if (page >= 2) {
  148. let orderList = _.concat(state.pagination.data, res.data.data);
  149. state.pagination = {
  150. ...res.data,
  151. data: orderList,
  152. };
  153. } else {
  154. state.pagination = res.data;
  155. }
  156. if (state.pagination.current_page < state.pagination.last_page) {
  157. state.loadStatus = 'more';
  158. } else {
  159. state.loadStatus = 'noMore';
  160. }
  161. }
  162. }
  163. onLoad((options) => {
  164. if (options.type) {
  165. state.currentTab = options.type;
  166. }
  167. getGrouponList();
  168. });
  169. // 加载更多
  170. function loadmore() {
  171. if (state.loadStatus !== 'noMore') {
  172. getGrouponList(state.pagination.current_page + 1);
  173. }
  174. }
  175. // 上拉加载更多
  176. onReachBottom(() => {
  177. loadmore();
  178. });
  179. //下拉刷新
  180. onPullDownRefresh(() => {
  181. getGrouponList();
  182. setTimeout(function () {
  183. uni.stopPullDownRefresh();
  184. }, 800);
  185. });
  186. </script>
  187. <style lang="scss" scoped>
  188. .tool-btn {
  189. width: 160rpx;
  190. height: 60rpx;
  191. background: #f6f6f6;
  192. font-size: 26rpx;
  193. border-radius: 30rpx;
  194. margin-right: 10rpx;
  195. &:last-of-type {
  196. margin-right: 0;
  197. }
  198. }
  199. .swiper-box {
  200. flex: 1;
  201. .swiper-item {
  202. height: 100%;
  203. width: 100%;
  204. }
  205. }
  206. .order-list-card-box {
  207. .order-card-header {
  208. height: 80rpx;
  209. .order-no {
  210. font-size: 26rpx;
  211. font-weight: 500;
  212. }
  213. .order-state {
  214. color: var(--ui-BG-Main);
  215. }
  216. }
  217. .order-card-footer {
  218. height: 100rpx;
  219. .detail-btn {
  220. width: 210rpx;
  221. height: 66rpx;
  222. border: 2rpx solid #dfdfdf;
  223. border-radius: 33rpx;
  224. font-size: 26rpx;
  225. font-weight: 400;
  226. color: #999999;
  227. margin-right: 20rpx;
  228. }
  229. .invite-btn {
  230. width: 210rpx;
  231. height: 66rpx;
  232. background: linear-gradient(90deg, #fe832a, #ff6600);
  233. box-shadow: 0px 8rpx 6rpx 0px rgba(255, 104, 4, 0.22);
  234. border-radius: 33rpx;
  235. color: #fff;
  236. font-size: 26rpx;
  237. font-weight: 500;
  238. }
  239. }
  240. }
  241. .sales-title {
  242. height: 32rpx;
  243. background: rgba(#ffe0e2, 0.29);
  244. border-radius: 16rpx;
  245. font-size: 24rpx;
  246. font-weight: 400;
  247. padding: 6rpx 20rpx;
  248. color: #f7979c;
  249. }
  250. .num-title {
  251. font-size: 24rpx;
  252. font-weight: 400;
  253. color: #999999;
  254. }
  255. </style>