my-order.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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. this.$u.api.orderAddToCartAjax({
  132. orderId: order.orderId
  133. }).then(res => {
  134. if (res.code == 200) {
  135. uni.showToast({
  136. title: '已加入购物车',
  137. icon: 'success'
  138. });
  139. this.$updateCartBadge();
  140. }
  141. });
  142. } else if (type === 'remind') {
  143. this.$refs.urgeDialog.open(order);
  144. } else if (type === 'overtime') {
  145. // 超时发货补偿
  146. uni.showModal({
  147. title: '提示',
  148. content: '确认申请超时发货补偿?',
  149. success: (res) => {
  150. if (res.confirm) {
  151. this.$u.api.sendTimeoutCompensationAjax(order.orderId).then(res => {
  152. if (res.code == 200) {
  153. uni.showToast({
  154. title: '申请成功',
  155. icon: 'success'
  156. });
  157. this.loadOrders(true, this.params);
  158. }
  159. });
  160. }
  161. }
  162. });
  163. } else if (type === 'priceMatch') {
  164. // 降价补差
  165. uni.showModal({
  166. title: '提示',
  167. content: '确认申请降价补差?',
  168. success: (res) => {
  169. if (res.confirm) {
  170. this.$u.api.priceReductionCompensationAjax(order.orderId).then(res => {
  171. if (res.code == 200) {
  172. uni.showToast({
  173. title: '申请成功',
  174. icon: 'success'
  175. });
  176. this.loadOrders(true, this.params);
  177. }
  178. });
  179. }
  180. }
  181. });
  182. } else if (type === 'refund') {
  183. if (order.status == '2') {
  184. this.$refs.refundDialog.open(order);
  185. } else {
  186. // 跳转到申请售后页面
  187. uni.navigateTo({
  188. url: `/pages-car/pages/apply-refund?orderId=${order.orderId}`
  189. });
  190. }
  191. } else if (type === 'confirm') {
  192. uni.showModal({
  193. title: '提示',
  194. content: '确认已收到商品?',
  195. success: (res) => {
  196. if (res.confirm) {
  197. uni.showToast({ title: '确认收货成功', icon: 'none' });
  198. this.loadOrders(true, this.params);
  199. }
  200. }
  201. });
  202. } else if (type === 'logistics') {
  203. uni.navigateTo({
  204. url: `/pages-car/pages/logistics-detail?orderId=${order.orderId}`
  205. });
  206. } else if (type === 'address') {
  207. this.modifyingOrderId = order.orderId;
  208. // 兼容列表和详情可能的字段差异
  209. const addressId = order.addressId || order.receiverAddressId || '';
  210. uni.navigateTo({
  211. url: `/pages-mine/pages/address/list?id=${addressId}&isSelect=1&editAddress=1`
  212. });
  213. } else if (type === 'pay') {
  214. // 跳转到收银台
  215. uni.navigateTo({
  216. url: `/pages-car/pages/cashier-desk?id=${order.orderId}`
  217. });
  218. } else if (type === 'cancel') {
  219. this.$refs.cancelDialog.open(order.orderId);
  220. } else if (type === 'extend') {
  221. uni.showModal({
  222. title: '提示',
  223. content: '每笔订单只能延长一次收货时间,确认延长收货?',
  224. success: (res) => {
  225. if (res.confirm) {
  226. this.$u.api.orderAddDeadlineAjax(order.orderId).then(res => {
  227. if (res.code == 200) {
  228. uni.showToast({
  229. title: '延长收货成功',
  230. icon: 'success'
  231. });
  232. this.loadOrders(true, this.params);
  233. }
  234. });
  235. }
  236. }
  237. });
  238. } else {
  239. uni.showToast({ title: '功能开发中', icon: 'none' });
  240. }
  241. }
  242. }
  243. }
  244. </script>
  245. <style lang="scss" scoped>
  246. .my-order-page {
  247. min-height: 100vh;
  248. background-color: #F5F5F5;
  249. .tabs-wrapper {
  250. position: sticky;
  251. top: 0;
  252. z-index: 99;
  253. background: #FFFFFF;
  254. border-bottom: 1rpx solid #eee;
  255. }
  256. .order-list-container {
  257. padding: 20rpx;
  258. }
  259. }
  260. </style>