my-order.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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. //NULL-全部 1待付款 2待发货 3待收货 4已完成 5已取消 6退款中 7已退款
  31. tabList: [
  32. { name: '全部', status: '' },
  33. { name: '待付款', status: 1 },
  34. { name: '待发货', status: 2 },
  35. { name: '待收货', status: 3 },
  36. { name: '已完成', status: 4 },
  37. { name: '已取消', status: 5 },
  38. { name: '退款中', status: 6 },
  39. { name: '已退款', status: 7 }
  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.status == options.status);
  52. if (index !== -1) {
  53. this.currentTab = index;
  54. this.params.status = options.status;
  55. }
  56. }
  57. // Load mock data for now since API might not be ready
  58. // But pageScroll calls API. We can mock in updateList if API fails or returns empty.
  59. // For now let's rely on pageScroll but maybe we need to mock response in pageScroll or here.
  60. // Actually, let's trigger load.
  61. this.loadOrders(true, this.params);
  62. },
  63. methods: {
  64. loadOrders(refresh = false, params = {}) {
  65. this.$nextTick(() => {
  66. // If API is not real, pageScroll might fail.
  67. // We can mock data here if needed by directly setting list if API fails.
  68. // Let's try to use pageScroll mechanism.
  69. this.$refs.pageRef?.loadData(refresh, params);
  70. });
  71. },
  72. handleTabChange(index) {
  73. this.currentTab = index;
  74. this.params.status = this.tabList[index].status;
  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.orderNo !== order.orderNo);
  115. uni.showToast({ title: '删除成功', icon: 'none' });
  116. }
  117. }
  118. });
  119. } else if (type === 'remind') {
  120. uni.showToast({ title: '已提醒商家发货', icon: 'none' });
  121. } else if (type === 'refund') {
  122. uni.showToast({ title: '进入极速退款/售后流程', icon: 'none' });
  123. } else if (type === 'confirm') {
  124. uni.showModal({
  125. title: '提示',
  126. content: '确认已收到商品?',
  127. success: (res) => {
  128. if (res.confirm) {
  129. uni.showToast({ title: '确认收货成功', icon: 'none' });
  130. // Update status locally or reload
  131. this.loadOrders(true, this.params);
  132. }
  133. }
  134. });
  135. } else if (type === 'logistics') {
  136. uni.showToast({ title: '查看物流信息', icon: 'none' });
  137. } else if (type === 'address') {
  138. uni.showToast({ title: '修改地址', icon: 'none' });
  139. } else if (type === 'pay') {
  140. uni.showToast({ title: '去支付', icon: 'none' });
  141. } else if (type === 'cancel') {
  142. uni.showModal({
  143. title: '提示',
  144. content: '确定要取消订单吗?',
  145. success: (res) => {
  146. if (res.confirm) {
  147. uni.showToast({ title: '订单已取消', icon: 'none' });
  148. this.loadOrders(true, this.params);
  149. }
  150. }
  151. });
  152. } else {
  153. uni.showToast({ title: '功能开发中', icon: 'none' });
  154. }
  155. },
  156. getMockOrders(status) {
  157. // Generate some mock data based on status
  158. const allOrders = [
  159. {
  160. orderNo: 'SN1893294923003',
  161. status: 2, // 待付款
  162. totalPrice: 17.2,
  163. realPayPrice: 17.2,
  164. goodsList: [
  165. {
  166. title: '马克思主义基本原理',
  167. cover: 'https://k.sinaimg.cn/n/sinakd20116/234/w1000h1634/20251003/b66b-587c9ff400fcf01be52c6693594b6a6d.jpg/w700d1q75cms.jpg',
  168. price: 8.60,
  169. num: 2,
  170. quality: '中等'
  171. }
  172. ]
  173. },
  174. {
  175. orderNo: 'SN1893294923004',
  176. status: 3, // 待发货
  177. totalPrice: 17.2,
  178. realPayPrice: 17.2,
  179. goodsList: [
  180. { cover: 'https://k.sinaimg.cn/n/sinakd20116/234/w1000h1634/20251003/b66b-587c9ff400fcf01be52c6693594b6a6d.jpg/w700d1q75cms.jpg' }, { cover: 'https://k.sinaimg.cn/n/sinakd20116/234/w1000h1634/20251003/b66b-587c9ff400fcf01be52c6693594b6a6d.jpg/w700d1q75cms.jpg' }, { cover: 'https://k.sinaimg.cn/n/sinakd20116/234/w1000h1634/20251003/b66b-587c9ff400fcf01be52c6693594b6a6d.jpg/w700d1q75cms.jpg' }
  181. ]
  182. },
  183. {
  184. orderNo: 'SN1893294923005',
  185. status: -1, // 已取消
  186. totalPrice: 17.2,
  187. realPayPrice: 17.2,
  188. goodsList: [
  189. {
  190. title: '马克思主义基本原理',
  191. cover: 'https://k.sinaimg.cn/n/sinakd20116/234/w1000h1634/20251003/b66b-587c9ff400fcf01be52c6693594b6a6d.jpg/w700d1q75cms.jpg',
  192. price: 8.60,
  193. num: 2,
  194. quality: '中等'
  195. }
  196. ]
  197. }
  198. ];
  199. if (!status) return allOrders;
  200. return allOrders.filter(o => o.status == status);
  201. }
  202. }
  203. }
  204. </script>
  205. <style lang="scss" scoped>
  206. .my-order-page {
  207. min-height: 100vh;
  208. background-color: #F5F5F5;
  209. .tabs-wrapper {
  210. position: sticky;
  211. top: 0;
  212. z-index: 99;
  213. background: #FFFFFF;
  214. border-bottom: 1rpx solid #eee;
  215. }
  216. .order-list-container {
  217. padding: 20rpx;
  218. }
  219. }
  220. </style>