index.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <template>
  2. <view style="padding: 20rpx;">
  3. <view style="margin-bottom: 20rpx;">
  4. <swiper circular autoplay :interval="3000" :duration="500" indicator-dots style="height: 320rpx;"
  5. indicator-color="rgba(255, 255, 255, 0.6)" indicator-active-color="#006eff">
  6. <swiper-item v-for="item in imgs" :key="item" >
  7. <image :src="item" alt="" style="width: 100%; height: 350rpx;" />
  8. </swiper-item>
  9. </swiper>
  10. </view>
  11. <view style="margin-bottom: 20rpx;">
  12. <uni-notice-bar v-if="content" show-icon single :text="content" />
  13. </view>
  14. <view style="display: flex; margin-bottom: 20rpx;" class="box">
  15. <view class="cartegory-item" @click="goPreOrder('代拿快递')">
  16. <image src="../../static/imgs/快递.png" style="width: 50%;" mode="widthFix"></image>
  17. <view style="flex: 1;">代拿快递</view>
  18. </view>
  19. <view class="cartegory-item" @click="goPreOrder('代取餐品')">
  20. <image src="../../static/imgs/取餐.png" style="width: 50%;" mode="widthFix"></image>
  21. <view style="flex: 1;">代取餐品</view>
  22. </view>
  23. <view class="cartegory-item" @click="goPreOrder('代买零食')">
  24. <image src="../../static/imgs/零食.png" style="width: 50%;" mode="widthFix"></image>
  25. <view style="flex: 1;">代买零食</view>
  26. </view>
  27. <view class="cartegory-item" @click="goPreOrder('代送鲜花')">
  28. <image src="../../static/imgs/花.png" style="width: 50%;" mode="widthFix"></image>
  29. <view style="flex: 1;">代送鲜花</view>
  30. </view>
  31. </view>
  32. <view class="box" style="color: #006eff; font-weight: bold; margin-bottom: 10rpx;">跑腿订单</view>
  33. <view>
  34. <view v-for="item in orderList" :key="item.id" class="box" style="margin-bottom: 10rpx;" @click="goDetail(item.id)">
  35. <view style="display: flex; align-items: center; margin-bottom: 20rpx;">
  36. <view style="flex: 1;">
  37. <uni-tag text="餐品" size="small" type="success" v-if="item.type === '代取餐品'"></uni-tag>
  38. <uni-tag text="快递" size="small" type="primary" v-if="item.type === '代拿快递'"></uni-tag>
  39. <uni-tag text="零食" size="small" type="warning" v-if="item.type === '代买零食'"></uni-tag>
  40. <uni-tag text="鲜花" size="small" type="error" v-if="item.type === '代送鲜花'"></uni-tag>
  41. <text style="margin-left: 10rpx;">{{ item.name }}</text>
  42. </view>
  43. <view style="flex: 1; text-align: right;">
  44. <text style="color: #888;">跑腿费</text>
  45. <text style="color: red; font-size: 34rpx;">¥{{ item.price }}</text>
  46. </view>
  47. </view>
  48. <view style="display: flex; align-items: center;">
  49. <view style="flex: 1;">
  50. <text style="margin-right: 10rpx;">已下单{{ item.range }}分钟</text>
  51. <text style="color: orange;">待接单</text>
  52. </view>
  53. <view style="flex: 1; text-align: right;">
  54. <uni-tag text="接单" type="primary" size="small" @click.native.stop="accept(item)"></uni-tag>
  55. </view>
  56. </view>
  57. </view>
  58. </view>
  59. </view>
  60. </template>
  61. <script>
  62. export default {
  63. data() {
  64. return {
  65. imgs: [
  66. require('../../static/imgs/banner1.png'),
  67. require('../../static/imgs/banner2.png'),
  68. ],
  69. content: '',
  70. noticeList: [],
  71. inter: null,
  72. orderList: [],
  73. user: uni.getStorageSync('xm-user')
  74. }
  75. },
  76. onShow() {
  77. this.load()
  78. this.loadNotice()
  79. },
  80. onHide() {
  81. clearInterval(this.inter)
  82. this.inter = null
  83. },
  84. methods: {
  85. accept(orders) {
  86. if (!this.user.isRider) { // 判断是否是骑手
  87. uni.showToast({
  88. icon: 'none',
  89. title: '只有认证骑手才可以接单'
  90. })
  91. return
  92. }
  93. this.$request.put('/orders/accept', orders).then(res => {
  94. if (res.code === '200') {
  95. uni.showToast({
  96. icon: 'success',
  97. title: '操作成功'
  98. })
  99. this.load()
  100. } else {
  101. uni.showToast({
  102. icon: 'none',
  103. title: res.msg
  104. })
  105. }
  106. })
  107. },
  108. goDetail(orderId) {
  109. uni.navigateTo({
  110. url: '/pages/detail/detail?orderId=' + orderId
  111. })
  112. },
  113. goPreOrder(type) {
  114. let orderStore = uni.getStorageSync('orderStore') || {} // 先获取缓存的数据
  115. orderStore.type = type // 设置订单的类型
  116. uni.setStorageSync('orderStore', orderStore)
  117. uni.navigateTo({
  118. url: '/pages/preOrder/preOrder'
  119. })
  120. },
  121. load() {
  122. this.$request.get('/orders/selectAll', {
  123. status: '待接单'
  124. }).then(res => {
  125. this.orderList = res.data || []
  126. })
  127. },
  128. loadNotice() {
  129. this.$request.get('/notice/selectAll').then(res => {
  130. this.noticeList = res.data || []
  131. let i = 0
  132. this.content = this.noticeList.length ? this.noticeList[i].content : ''
  133. // 切换展示公告内容,使用setInterval定时切换器
  134. if (this.noticeList.length > 1) {
  135. this.inter = setInterval(() => {
  136. i++
  137. if (i === this.noticeList.length) {
  138. i = 0
  139. }
  140. this.content = this.noticeList[i].content
  141. }, 5000)
  142. }
  143. })
  144. }
  145. }
  146. }
  147. </script>
  148. <style>
  149. .cartegory-item {
  150. flex: 1;
  151. display: flex;
  152. justify-content: space-between;
  153. align-items: center;
  154. flex-direction: column;
  155. grid-gap: 20rpx;
  156. }
  157. </style>