order.vue 6.9 KB

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