my-order.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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. this.loadOrders(true, this.params);
  89. }
  90. }).finally(() => {
  91. this.modifyingOrderId = null;
  92. });
  93. }
  94. },
  95. loadOrders(refresh = false, params = {}) {
  96. this.$nextTick(() => {
  97. this.$refs.pageRef?.loadData(refresh, params);
  98. });
  99. },
  100. handleTabChange(index) {
  101. this.currentTab = index;
  102. this.params = this.tabList[index].params;
  103. this.loadOrders(true, this.params);
  104. },
  105. handleUpdateList(list) {
  106. this.orderList = list;
  107. },
  108. handleAction({ type, order, data }) {
  109. console.log('Action:', type, order);
  110. this.currentOrder = order;
  111. if (type === 'more') {
  112. // data contains the list of actions to show in sheet
  113. // Map internal keys to display text
  114. const actionMap = {
  115. 'applyAfterSales': { text: '申请售后', type: 'refund' },
  116. 'logistics': { text: '查看物流', type: 'logistics' },
  117. 'invoice': { text: '申请开票', type: 'invoice' }
  118. };
  119. this.actionSheetList = data.map(key => actionMap[key]).filter(Boolean);
  120. this.showActionSheet = true;
  121. return;
  122. }
  123. this.processAction(type, order);
  124. },
  125. handleActionSheetClick(index) {
  126. const action = this.actionSheetList[index];
  127. if (action && action.type) {
  128. this.processAction(action.type, this.currentOrder);
  129. }
  130. },
  131. processAction(type, order) {
  132. if (type === 'rebuy' || type === 'addToCart') {
  133. this.$u.api.orderAddToCartAjax({
  134. orderId: order.orderId
  135. }).then(res => {
  136. if (res.code == 200) {
  137. uni.showToast({
  138. title: '已加入购物车',
  139. icon: 'success',
  140. duration: 3000
  141. });
  142. this.$updateCartBadge();
  143. }
  144. });
  145. } else if (type === 'remind') {
  146. this.$refs.urgeDialog.open(order);
  147. } else if (type === 'overtime') {
  148. // 超时发货补偿
  149. uni.showModal({
  150. title: '提示',
  151. content: '确认申请超时发货补偿?',
  152. success: (res) => {
  153. if (res.confirm) {
  154. this.$u.api.sendTimeoutCompensationAjax(order.orderId).then(res => {
  155. if (res.code == 200) {
  156. uni.showToast({
  157. title: '申请成功',
  158. icon: 'success'
  159. });
  160. this.loadOrders(true, this.params);
  161. }
  162. });
  163. }
  164. }
  165. });
  166. } else if (type === 'priceMatch') {
  167. // 降价补差
  168. uni.showModal({
  169. title: '提示',
  170. content: '确认申请降价补差?',
  171. success: (res) => {
  172. if (res.confirm) {
  173. this.$u.api.priceReductionCompensationAjax(order.orderId).then(res => {
  174. if (res.code == 200) {
  175. uni.showToast({
  176. title: '申请成功',
  177. icon: 'success'
  178. });
  179. this.loadOrders(true, this.params);
  180. }
  181. });
  182. }
  183. }
  184. });
  185. } else if (type === 'refund') {
  186. if (order.status == '2') {
  187. this.$refs.refundDialog.open(order);
  188. } else {
  189. // 跳转到申请售后页面
  190. uni.navigateTo({
  191. url: `/pages-car/pages/apply-refund?orderId=${order.orderId}`
  192. });
  193. }
  194. } else if (type === 'confirm') {
  195. uni.showModal({
  196. title: '提示',
  197. content: '确认已收到商品?',
  198. success: (res) => {
  199. if (res.confirm) {
  200. uni.showToast({ title: '确认收货成功', icon: 'none' });
  201. this.loadOrders(true, this.params);
  202. }
  203. }
  204. });
  205. } else if (type === 'logistics') {
  206. uni.navigateTo({
  207. url: `/pages-car/pages/logistics-detail?orderId=${order.orderId}`
  208. });
  209. } else if (type === 'address') {
  210. this.modifyingOrderId = order.orderId;
  211. // 兼容列表和详情可能的字段差异
  212. const addressId = order.addressId || order.receiverAddressId || '';
  213. uni.navigateTo({
  214. url: `/pages-mine/pages/address/list?id=${addressId}&isSelect=1`
  215. });
  216. } else if (type === 'pay') {
  217. // 跳转到收银台
  218. uni.navigateTo({
  219. url: `/pages-car/pages/cashier-desk?id=${order.orderId}`
  220. });
  221. } else if (type === 'cancel') {
  222. this.$refs.cancelDialog.open(order.orderId);
  223. } else if (type === 'extend') {
  224. uni.showModal({
  225. title: '提示',
  226. content: '每笔订单只能延长一次收货时间,确认延长收货?',
  227. success: (res) => {
  228. if (res.confirm) {
  229. this.$u.api.orderAddDeadlineAjax(order.orderId).then(res => {
  230. if (res.code == 200) {
  231. uni.showToast({
  232. title: '延长收货成功',
  233. icon: 'success'
  234. });
  235. this.loadOrders(true, this.params);
  236. }
  237. });
  238. }
  239. }
  240. });
  241. } else {
  242. uni.showToast({ title: '功能开发中', icon: 'none' });
  243. }
  244. }
  245. }
  246. }
  247. </script>
  248. <style lang="scss" scoped>
  249. .my-order-page {
  250. min-height: 100vh;
  251. background-color: #F5F5F5;
  252. .tabs-wrapper {
  253. position: sticky;
  254. top: 0;
  255. z-index: 99;
  256. background: #FFFFFF;
  257. border-bottom: 1rpx solid #eee;
  258. }
  259. .order-list-container {
  260. padding: 20rpx;
  261. }
  262. }
  263. </style>