my-order.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <template>
  2. <view class="my-order-page">
  3. <!-- 标签页 -->
  4. <view class="tabs-wrapper">
  5. <u-tabs :list="tabList" :current="currentTab" @change="handleTabChange" active-color="#38C148" bar-width="60"></u-tabs>
  6. </view>
  7. <!-- 订单列表 -->
  8. <page-scroll :page-size="10" @updateList="handleUpdateList" ref="pageRef" slotEmpty
  9. url="/token/shop/order/getShopOrderList" :params="params" :immediate="false">
  10. <view v-if="orderList.length > 0" class="order-list-container">
  11. <buy-order-item v-for="(order, index) in orderList" :key="index" :order="order"
  12. @action="handleAction"></buy-order-item>
  13. </view>
  14. </page-scroll>
  15. <!-- 更多操作菜单 -->
  16. <u-action-sheet :list="actionSheetList" v-model="showActionSheet"
  17. @click="handleActionSheetClick"></u-action-sheet>
  18. </view>
  19. </template>
  20. <script>
  21. import BuyOrderItem from '../components/buy-order-item.vue';
  22. import pageScroll from '@/components/pageScroll/index.vue';
  23. export default {
  24. components: {
  25. BuyOrderItem,
  26. pageScroll
  27. },
  28. data() {
  29. return {
  30. // value用于前端标识,params用于后端查询
  31. tabList: [
  32. { name: '全部', value: '0', params: {} },
  33. { name: '待付款', value: '1', params: { status: '1' } },
  34. { name: '待发货', value: '2', params: { status: '2' } },
  35. { name: '待收货', value: '3', params: { status: '3' } },
  36. { name: '已完成', value: '4', params: { status: '4' } },
  37. { name: '已取消', value: '5', params: { cancelStatus: '1' } },
  38. { name: '退款中', value: '6', params: { refundStatus: '2' } },
  39. { name: '已退款', value: '7', params: { refundStatus: '3' } }
  40. ],
  41. currentTab: 0,
  42. orderList: [],
  43. params: {},
  44. showActionSheet: false,
  45. actionSheetList: [],
  46. currentOrder: null
  47. };
  48. },
  49. onLoad(options) {
  50. if (options.status) {
  51. const index = this.tabList.findIndex(item => item.value == options.status);
  52. if (index !== -1) {
  53. this.currentTab = index;
  54. this.params = this.tabList[index].params;
  55. }
  56. }
  57. this.loadOrders(true, this.params);
  58. },
  59. methods: {
  60. loadOrders(refresh = false, params = {}) {
  61. this.$nextTick(() => {
  62. this.$refs.pageRef?.loadData(refresh, params);
  63. });
  64. },
  65. handleTabChange(index) {
  66. this.currentTab = index;
  67. this.params = this.tabList[index].params;
  68. this.loadOrders(true, this.params);
  69. },
  70. handleUpdateList(list) {
  71. this.orderList = list;
  72. },
  73. handleAction({ type, order, data }) {
  74. console.log('Action:', type, order);
  75. this.currentOrder = order;
  76. if (type === 'more') {
  77. // data contains the list of actions to show in sheet
  78. // Map internal keys to display text
  79. const actionMap = {
  80. 'applyAfterSales': { text: '申请售后', type: 'refund' },
  81. 'logistics': { text: '查看物流', type: 'logistics' },
  82. 'invoice': { text: '申请开票', type: 'invoice' }
  83. };
  84. this.actionSheetList = data.map(key => actionMap[key]).filter(Boolean);
  85. this.showActionSheet = true;
  86. return;
  87. }
  88. this.processAction(type, order);
  89. },
  90. handleActionSheetClick(index) {
  91. const action = this.actionSheetList[index];
  92. if (action && action.type) {
  93. this.processAction(action.type, this.currentOrder);
  94. }
  95. },
  96. processAction(type, order) {
  97. if (type === 'rebuy' || type === 'addToCart') {
  98. // Logic to add to cart
  99. uni.showToast({ title: '已加入购物车', icon: 'none' });
  100. } else if (type === 'delete') {
  101. uni.showModal({
  102. title: '提示',
  103. content: '确定要删除该订单吗?',
  104. success: (res) => {
  105. if (res.confirm) {
  106. // Remove from list
  107. this.orderList = this.orderList.filter(item => item.orderId !== order.orderId);
  108. uni.showToast({ title: '删除成功', icon: 'none' });
  109. // Call API to delete if needed
  110. }
  111. }
  112. });
  113. } else if (type === 'remind') {
  114. uni.showToast({ title: '已提醒商家发货', icon: 'none' });
  115. } else if (type === 'refund') {
  116. uni.showToast({ title: '进入极速退款/售后流程', icon: 'none' });
  117. } else if (type === 'confirm') {
  118. uni.showModal({
  119. title: '提示',
  120. content: '确认已收到商品?',
  121. success: (res) => {
  122. if (res.confirm) {
  123. uni.showToast({ title: '确认收货成功', icon: 'none' });
  124. // Update status locally or reload
  125. this.loadOrders(true, this.params);
  126. }
  127. }
  128. });
  129. } else if (type === 'logistics') {
  130. uni.showToast({ title: '查看物流信息', icon: 'none' });
  131. } else if (type === 'address') {
  132. uni.showToast({ title: '修改地址', icon: 'none' });
  133. } else if (type === 'pay') {
  134. // 跳转到收银台
  135. uni.navigateTo({
  136. url: `/pages-car/pages/cashier-desk?id=${order.orderId}`
  137. });
  138. } else if (type === 'cancel') {
  139. uni.showModal({
  140. title: '提示',
  141. content: '确定要取消订单吗?',
  142. success: (res) => {
  143. if (res.confirm) {
  144. uni.showToast({ title: '订单已取消', icon: 'none' });
  145. this.loadOrders(true, this.params);
  146. }
  147. }
  148. });
  149. } else {
  150. uni.showToast({ title: '功能开发中', icon: 'none' });
  151. }
  152. }
  153. }
  154. }
  155. </script>
  156. <style lang="scss" scoped>
  157. .my-order-page {
  158. min-height: 100vh;
  159. background-color: #F5F5F5;
  160. .tabs-wrapper {
  161. position: sticky;
  162. top: 0;
  163. z-index: 99;
  164. background: #FFFFFF;
  165. border-bottom: 1rpx solid #eee;
  166. }
  167. .order-list-container {
  168. padding: 20rpx;
  169. }
  170. }
  171. </style>