my-order.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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: { status: '5' } },
  38. ],
  39. currentTab: 0,
  40. orderList: [],
  41. params: {},
  42. showActionSheet: false,
  43. actionSheetList: [],
  44. currentOrder: null
  45. };
  46. },
  47. onLoad(options) {
  48. if (options.status) {
  49. const index = this.tabList.findIndex(item => item.value == options.status);
  50. if (index !== -1) {
  51. this.currentTab = index;
  52. this.params = this.tabList[index].params;
  53. }
  54. }
  55. this.loadOrders(true, this.params);
  56. },
  57. methods: {
  58. loadOrders(refresh = false, params = {}) {
  59. this.$nextTick(() => {
  60. this.$refs.pageRef?.loadData(refresh, params);
  61. });
  62. },
  63. handleTabChange(index) {
  64. this.currentTab = index;
  65. this.params = this.tabList[index].params;
  66. this.loadOrders(true, this.params);
  67. },
  68. handleUpdateList(list) {
  69. this.orderList = list;
  70. },
  71. handleAction({ type, order, data }) {
  72. console.log('Action:', type, order);
  73. this.currentOrder = order;
  74. if (type === 'more') {
  75. // data contains the list of actions to show in sheet
  76. // Map internal keys to display text
  77. const actionMap = {
  78. 'applyAfterSales': { text: '申请售后', type: 'refund' },
  79. 'logistics': { text: '查看物流', type: 'logistics' },
  80. 'invoice': { text: '申请开票', type: 'invoice' }
  81. };
  82. this.actionSheetList = data.map(key => actionMap[key]).filter(Boolean);
  83. this.showActionSheet = true;
  84. return;
  85. }
  86. this.processAction(type, order);
  87. },
  88. handleActionSheetClick(index) {
  89. const action = this.actionSheetList[index];
  90. if (action && action.type) {
  91. this.processAction(action.type, this.currentOrder);
  92. }
  93. },
  94. processAction(type, order) {
  95. if (type === 'rebuy' || type === 'addToCart') {
  96. // Logic to add to cart
  97. uni.showToast({ title: '已加入购物车', icon: 'none' });
  98. } else if (type === 'delete') {
  99. uni.showModal({
  100. title: '提示',
  101. content: '确定要删除该订单吗?',
  102. success: (res) => {
  103. if (res.confirm) {
  104. // Remove from list
  105. this.orderList = this.orderList.filter(item => item.orderId !== order.orderId);
  106. uni.showToast({ title: '删除成功', icon: 'none' });
  107. // Call API to delete if needed
  108. }
  109. }
  110. });
  111. } else if (type === 'remind') {
  112. uni.showToast({ title: '已提醒商家发货', icon: 'none' });
  113. } else if (type === 'refund') {
  114. uni.showToast({ title: '进入极速退款/售后流程', icon: 'none' });
  115. } else if (type === 'confirm') {
  116. uni.showModal({
  117. title: '提示',
  118. content: '确认已收到商品?',
  119. success: (res) => {
  120. if (res.confirm) {
  121. uni.showToast({ title: '确认收货成功', icon: 'none' });
  122. // Update status locally or reload
  123. this.loadOrders(true, this.params);
  124. }
  125. }
  126. });
  127. } else if (type === 'logistics') {
  128. uni.showToast({ title: '查看物流信息', icon: 'none' });
  129. } else if (type === 'address') {
  130. uni.showToast({ title: '修改地址', icon: 'none' });
  131. } else if (type === 'pay') {
  132. // 跳转到收银台
  133. uni.navigateTo({
  134. url: `/pages-car/pages/cashier-desk?id=${order.orderId}`
  135. });
  136. } else if (type === 'cancel') {
  137. uni.showModal({
  138. title: '提示',
  139. content: '确定要取消订单吗?',
  140. success: (res) => {
  141. if (res.confirm) {
  142. uni.showToast({ title: '订单已取消', icon: 'none' });
  143. this.loadOrders(true, this.params);
  144. }
  145. }
  146. });
  147. } else {
  148. uni.showToast({ title: '功能开发中', icon: 'none' });
  149. }
  150. }
  151. }
  152. }
  153. </script>
  154. <style lang="scss" scoped>
  155. .my-order-page {
  156. min-height: 100vh;
  157. background-color: #F5F5F5;
  158. .tabs-wrapper {
  159. position: sticky;
  160. top: 0;
  161. z-index: 99;
  162. background: #FFFFFF;
  163. border-bottom: 1rpx solid #eee;
  164. }
  165. .order-list-container {
  166. padding: 20rpx;
  167. }
  168. }
  169. </style>