order.vue 6.8 KB

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