my-order.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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. <!-- 取消订单弹窗 -->
  24. <cancel-order-popup ref="cancelDialog" @success="loadOrders(true, params)"></cancel-order-popup>
  25. </view>
  26. </template>
  27. <script>
  28. import BuyOrderItem from '../components/buy-order-item.vue';
  29. import pageScroll from '@/components/pageScroll/index.vue';
  30. import FastRefundDialog from '../components/fast-refund-dialog.vue';
  31. import UrgeDeliveryDialog from '../components/urge-delivery-dialog.vue';
  32. import CancelOrderPopup from '../components/cancel-order-popup.vue';
  33. export default {
  34. components: {
  35. BuyOrderItem,
  36. pageScroll,
  37. FastRefundDialog,
  38. UrgeDeliveryDialog,
  39. CancelOrderPopup
  40. },
  41. data() {
  42. return {
  43. // value用于前端标识,params用于后端查询
  44. tabList: [
  45. { name: '全部', value: '0', params: {} },
  46. { name: '待付款', value: '1', params: { status: '1' } },
  47. { name: '待发货', value: '2', params: { status: '2' } },
  48. { name: '待收货', value: '3', params: { status: '3' } },
  49. { name: '已完成', value: '4', params: { status: '4' } },
  50. { name: '退款/售后', value: '5', params: { status: '5' } },
  51. ],
  52. currentTab: 0,
  53. orderList: [],
  54. params: {},
  55. showActionSheet: false,
  56. actionSheetList: [],
  57. currentOrder: null,
  58. modifyingOrderId: null
  59. };
  60. },
  61. onLoad(options) {
  62. if (options.status) {
  63. const index = this.tabList.findIndex(item => item.value == options.status);
  64. if (index !== -1) {
  65. this.currentTab = index;
  66. this.params = this.tabList[index].params;
  67. }
  68. }
  69. this.loadOrders(true, this.params);
  70. // 监听地址选择
  71. uni.$on('selectAddr', this.onAddressSelected);
  72. },
  73. onUnload() {
  74. uni.$off('selectAddr', this.onAddressSelected);
  75. },
  76. methods: {
  77. onAddressSelected(addr) {
  78. if (this.modifyingOrderId && addr && addr.id) {
  79. uni.showLoading({ title: '修改中' });
  80. this.$u.api.modifyOrderAddressAjax({
  81. orderId: this.modifyingOrderId,
  82. addressId: addr.id
  83. }).then(res => {
  84. uni.hideLoading();
  85. if (res.code == 200) {
  86. uni.showToast({ title: '修改成功', icon: 'success' });
  87. }
  88. }).finally(() => {
  89. this.modifyingOrderId = null;
  90. });
  91. }
  92. },
  93. loadOrders(refresh = false, params = {}) {
  94. this.$nextTick(() => {
  95. this.$refs.pageRef?.loadData(refresh, params);
  96. });
  97. },
  98. handleTabChange(index) {
  99. this.currentTab = index;
  100. this.params = this.tabList[index].params;
  101. this.loadOrders(true, this.params);
  102. },
  103. handleUpdateList(list) {
  104. this.orderList = list;
  105. },
  106. handleAction({ type, order, data }) {
  107. console.log('Action:', type, order);
  108. this.currentOrder = order;
  109. if (type === 'more') {
  110. // data contains the list of actions to show in sheet
  111. // Map internal keys to display text
  112. const actionMap = {
  113. 'applyAfterSales': { text: '申请售后', type: 'refund' },
  114. 'logistics': { text: '查看物流', type: 'logistics' },
  115. 'invoice': { text: '申请开票', type: 'invoice' }
  116. };
  117. this.actionSheetList = data.map(key => actionMap[key]).filter(Boolean);
  118. this.showActionSheet = true;
  119. return;
  120. }
  121. this.processAction(type, order);
  122. },
  123. handleActionSheetClick(index) {
  124. const action = this.actionSheetList[index];
  125. if (action && action.type) {
  126. this.processAction(action.type, this.currentOrder);
  127. }
  128. },
  129. processAction(type, order) {
  130. if (type === 'rebuy' || type === 'addToCart') {
  131. uni.showToast({ title: '已加入购物车', icon: 'none' });
  132. } else if (type === 'remind') {
  133. this.$refs.urgeDialog.open(order);
  134. } else if (type === 'refund') {
  135. if (order.status == '2') {
  136. this.$refs.refundDialog.open(order);
  137. } else {
  138. // 跳转到申请售后页面
  139. uni.navigateTo({
  140. url: `/pages-car/pages/apply-refund?orderId=${order.orderId}`
  141. });
  142. }
  143. } else if (type === 'confirm') {
  144. uni.showModal({
  145. title: '提示',
  146. content: '确认已收到商品?',
  147. success: (res) => {
  148. if (res.confirm) {
  149. uni.showToast({ title: '确认收货成功', icon: 'none' });
  150. this.loadOrders(true, this.params);
  151. }
  152. }
  153. });
  154. } else if (type === 'logistics') {
  155. uni.showToast({ title: '查看物流信息', icon: 'none' });
  156. } else if (type === 'address') {
  157. this.modifyingOrderId = order.orderId;
  158. // 兼容列表和详情可能的字段差异
  159. const addressId = order.addressId || order.receiverAddressId || '';
  160. uni.navigateTo({
  161. url: `/pages-mine/pages/address/list?id=${addressId}&isSelect=1&editAddress=1`
  162. });
  163. } else if (type === 'pay') {
  164. // 跳转到收银台
  165. uni.navigateTo({
  166. url: `/pages-car/pages/cashier-desk?id=${order.orderId}`
  167. });
  168. } else if (type === 'cancel') {
  169. this.$refs.cancelDialog.open(order.orderId);
  170. } else {
  171. uni.showToast({ title: '功能开发中', icon: 'none' });
  172. }
  173. }
  174. }
  175. }
  176. </script>
  177. <style lang="scss" scoped>
  178. .my-order-page {
  179. min-height: 100vh;
  180. background-color: #F5F5F5;
  181. .tabs-wrapper {
  182. position: sticky;
  183. top: 0;
  184. z-index: 99;
  185. background: #FFFFFF;
  186. border-bottom: 1rpx solid #eee;
  187. }
  188. .order-list-container {
  189. padding: 20rpx;
  190. }
  191. }
  192. </style>