my-order.vue 12 KB

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