my-order.vue 7.8 KB

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