index.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <template>
  2. <view class="container">
  3. <u-navbar title="接单中心" :autoBack="true" :placeholder="true" v-hideNav></u-navbar>
  4. <scroll-view class="scroll_wrap" scroll-y @scrolltolower="scrolltolower">
  5. <order-card v-for="order, index in ordersList" :key="order.receiptId" :order="order"
  6. @handleCardClick="handleCardClick" @handleBuzyBtnClick="handleBuzyBtnClick"></order-card>
  7. <view class="hasMore">
  8. {{ ordersList.length >= page.total ? '没有更多了~' : '向下滑动加载更多~' }}
  9. </view>
  10. </scroll-view>
  11. <view class="createOrder" @click="handleAddClick">
  12. <u-icon name="plus" size="30" color="#ffffff"></u-icon>
  13. </view>
  14. </view>
  15. </template>
  16. <script>
  17. import orderCard from "./compounts/orderCard.vue";
  18. export default {
  19. components: {
  20. orderCard
  21. },
  22. data() {
  23. return {
  24. ordersList: [],
  25. page: {
  26. pageSize: 10,
  27. pageNum: 1,
  28. total: 0
  29. }
  30. };
  31. },
  32. methods: {
  33. async getOrderList() {
  34. try {
  35. const result = await uni.$u.api.selectClueOrderFormList({
  36. pageSize: this.page.pageSize,
  37. pageNum: this.page.pageNum,
  38. });
  39. // 检查result是否有值,以及是否包含rows和total
  40. if (result && Array.isArray(result.rows)) {
  41. console.log('接单列表', result.rows);
  42. this.ordersList.push(...result.rows);
  43. // 只有当total存在且为数字时才更新
  44. if (typeof result.total === 'number') {
  45. this.page.total = result.total;
  46. }
  47. }
  48. } catch (error) {
  49. console.error('接单列表接口调用失败:', error);
  50. // 添加用户友好的错误提示
  51. uni.$u.toast('获取订单列表失败,请稍后重试');
  52. }
  53. },
  54. scrolltolower() {
  55. if (this.ordersList.length >= this.page.total) {
  56. return uni.$u.toast('没有更多了');
  57. }
  58. this.page.pageNum++;
  59. this.getOrderList();
  60. },
  61. reset() {
  62. this.ordersList = [];
  63. this.page.pageNum = 1;
  64. },
  65. // 跳转按钮接单
  66. handleCardClick(order) {
  67. console.log('点击了订单', order);
  68. //跳转
  69. // uni.navigateTo({
  70. // url: `/pages/orderDetail/index?orderId=${order.id}&item=${order.item}&type=${this.type}&clueId=${order.clueId}`,
  71. // })
  72. //跳转新的页面
  73. uni.navigateTo({
  74. url: `/pages/orderDetailNew/index?orderId=${order.id}&item=${order.item}&type=${this.type}&clueId=${order.clueId}`,
  75. })
  76. },
  77. // 在忙按钮先延迟把当前项目移动到队列末尾
  78. // 点击或者在忙的时候倒计时300s结束之后触发
  79. // 目前的问题是移动到当前10个item
  80. // 队列的最后,而不是全部队列的最后
  81. handleBuzyBtnClick(order) {
  82. console.log('在忙', order);
  83. // 先把当前项目移动到队列末尾
  84. const index = this.ordersList.findIndex(item => item.id == order.id);
  85. if (index != -1) {
  86. const item = this.ordersList.splice(index, 1)[0];
  87. this.ordersList.push(item);
  88. }
  89. },
  90. },
  91. onLoad() {
  92. this.getOrderList();
  93. }
  94. }
  95. </script>
  96. <style scoped>
  97. .scroll_wrap {
  98. height: calc(100vh - 44px);
  99. }
  100. .hasMore {
  101. text-align: center;
  102. padding: 20rpx 0;
  103. font-size: 24rpx;
  104. color: #999;
  105. }
  106. .createOrder {
  107. position: fixed;
  108. bottom: 20rpx;
  109. right: 20rpx;
  110. z-index: 999;
  111. background-color: #007AFF;
  112. border-radius: 50%;
  113. padding: 10rpx;
  114. box-shadow: 0 2px 12px rgba(0, 0, 0, 0.04);
  115. width: 80rpx;
  116. height: 80rpx;
  117. display: flex;
  118. justify-content: center;
  119. align-items: center;
  120. }
  121. </style>