index.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <template>
  2. <!-- 订单 -->
  3. <view class="card_order">
  4. <view class="top_cardOrder">
  5. <u-tabs :list="list1" lineColor="#333333" lineWidth="60" :scrollable="false" :current="current"
  6. @change="tabClick"></u-tabs>
  7. </view>
  8. <view class="cardOrder_tab"></view>
  9. <view class="card_order_manag">
  10. <orderManagement :key="Math.random()" :datalist="datalist" @toDeliver="toDeliver"
  11. @delDelivery="delDelivery"></orderManagement>
  12. </view>
  13. <view class="card_empty" v-if="datalist.length === 0">
  14. <u-empty mode="order"></u-empty>
  15. </view>
  16. </view>
  17. </template>
  18. <script>
  19. // 订单
  20. import orderManagement from '@/components/orderManagement.vue'
  21. export default {
  22. components: {
  23. orderManagement,
  24. },
  25. data() {
  26. return {
  27. current: 0,
  28. list1: [{
  29. name: '全部',
  30. }, {
  31. name: '待配送',
  32. }, {
  33. name: '配送中'
  34. }, {
  35. name: '已送达'
  36. }, {
  37. name: '已取消'
  38. }],
  39. datalist: [],
  40. Pagination: {
  41. PageIndex: 1,
  42. PageSize: 20,
  43. Total: 0,
  44. },
  45. loadingMore: true,
  46. }
  47. },
  48. onTabItemTap() {
  49. this.getOrderList()
  50. },
  51. mounted() {
  52. uni.$on('refresh', () => {
  53. this.datalist = []
  54. this.getOrderList()
  55. })
  56. var token = this.$cache.getToken()
  57. if (token) {
  58. this.getOrderList()
  59. }
  60. },
  61. methods: {
  62. // 触底事件
  63. bottomingEvent() {
  64. if (!this.loadingMore) {
  65. this.getOrderList()
  66. }
  67. },
  68. // 获取订单列表
  69. getOrderList() {
  70. this.$api.get('/api/order/delivery', {
  71. page: this.Pagination.PageIndex,
  72. pageSize: this.Pagination.PageSize,
  73. state: this.orderID,
  74. }).then(res => {
  75. if (res.code == 200) {
  76. const data = res.data.list
  77. if (this.loadingMore == true && data) {
  78. this.datalist = this.datalist.concat(data);
  79. }
  80. if (data.length < this.Pagination.PageSize) {
  81. this.loadingMore = true
  82. } else {
  83. this.loadingMore = false
  84. this.Pagination.PageIndex++
  85. }
  86. }
  87. })
  88. },
  89. // 去配送
  90. toDeliver(row) {
  91. this.$api.put('/api/order/state', {
  92. id: row.id,
  93. state: 5,
  94. }).then(res => {
  95. if (res.code == 200) {
  96. this.current = 2
  97. this.orderID = 5
  98. this.datalist = []
  99. this.getOrderList()
  100. } else {
  101. uni.$u.toast(res.data.msg)
  102. }
  103. })
  104. },
  105. // 删除已取消订单
  106. delDelivery(row) {
  107. this.$api.delete('/api/order', {
  108. id: row.id,
  109. }).then(res => {
  110. if (res.code == 200) {
  111. this.Pagination.PageIndex = 1
  112. this.datalist = []
  113. this.getOrderList()
  114. uni.$u.toast(res.msg)
  115. } else {
  116. uni.$u.toast(res.data.msg)
  117. }
  118. })
  119. },
  120. tabClick(row) {
  121. // console.log(row, 26)
  122. if (row.index == 1) {
  123. // 待配送
  124. this.orderID = 2
  125. } else if (row.index == 2) {
  126. // 配送中
  127. this.orderID = 5
  128. } else if (row.index == 3) {
  129. // 已送达
  130. this.orderID = 3
  131. } else if (row.index == 4) {
  132. // 已取消
  133. this.orderID = 4
  134. } else {
  135. this.orderID = null
  136. }
  137. this.datalist = []
  138. this.current = row.index;
  139. this.getOrderList()
  140. }
  141. }
  142. }
  143. </script>
  144. <style lang="scss" scoped>
  145. .top_cardOrder {
  146. position: fixed;
  147. top: 0;
  148. left: 0;
  149. right: 0;
  150. background-color: #fff;
  151. z-index: 1;
  152. padding: 10rpx;
  153. padding-top: var(--status-bar-height);
  154. }
  155. .cardOrder_tab {
  156. width: 100%;
  157. height: 88rpx;
  158. padding-top: var(--status-bar-height);
  159. }
  160. .card_empty {
  161. padding-top: 30%;
  162. }
  163. .card_order_manag {
  164. margin-bottom: 50rpx;
  165. }
  166. </style>