index.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. <template>
  2. <view class="bg" :style="colorStyle">
  3. <headerSerch v-if="headerData" :dataConfig="headerData"></headerSerch>
  4. <view class="navTitle">
  5. <view class="left_tab" @click="navTabIndex==0">租车</view>
  6. <view class="right_tab">
  7. <tabNav v-if="tabNavData" :dataConfig="tabNavData" @bindSortId="bindSortId"></tabNav>
  8. </view>
  9. </view>
  10. <view v-if="navTabIndex==0">
  11. <swiperBg v-if="swiperBgData" :dataConfig="swiperBgData"></swiperBg>
  12. </view>
  13. <view v-if="navTabIndex==1">
  14. </view>
  15. <view class="acea-row item row-between row-middle">
  16. <view class="acea-row left">
  17. <image class="icon" src="../../static/images/homeLeftIcon.png" mode="scaleToFill"></image>
  18. <view>
  19. 火热租车
  20. </view>
  21. </view>
  22. <!-- <view class="right">
  23. 更多>
  24. </view> -->
  25. </view>
  26. <view class="list acea-row row-between ">
  27. <view class="ls" v-for="(item,ind) in carList" :key='ind' @click="navTo(item)">
  28. <image class="img" :src="item.image" mode="scaleToFill"></image>
  29. <view class="content">
  30. <view class="line1 title">
  31. {{item.title}}
  32. </view>
  33. <view class="info line1">
  34. {{item.info}}
  35. </view>
  36. <view class="acea-row row-middle">
  37. <text class="price">
  38. ¥{{+item.price}}
  39. </text>
  40. <text class="tip">
  41. /月
  42. </text>
  43. </view>
  44. </view>
  45. </view>
  46. </view>
  47. <pageFoot></pageFoot>
  48. </view>
  49. </template>
  50. <script>
  51. import pageFoot from '@/components/pageFooter/index.vue';
  52. import headerSerch from '../index/diy/components/headerSerch.vue';
  53. import swiperBg from '../index/diy/components/swiperBg';
  54. import tabNav from '../index/diy/components/tabNav';
  55. import colors from '@/mixins/color';
  56. import {
  57. getDiy
  58. } from '@/api/api.js';
  59. import {
  60. getCarList
  61. } from '@/api/rent.js';
  62. export default {
  63. data() {
  64. return {
  65. headerData: '', //搜索栏设置数据
  66. tabNavData: '', //分类设置数据
  67. swiperBgData: '', //轮播图设置数据
  68. navTabIndex: 0, //0租车1为商品
  69. carList: [],
  70. page: 1,
  71. limit: 10,
  72. loading: 'more', //加载状态more/loding/nomore
  73. }
  74. },
  75. components: {
  76. pageFoot,
  77. headerSerch,
  78. tabNav,
  79. swiperBg
  80. },
  81. mixins: [colors],
  82. onShow() {
  83. uni.hideTabBar()
  84. this.getSearch();
  85. this.getCarList();
  86. },
  87. onReachBottom() {
  88. this.getCarList();
  89. },
  90. methods: {
  91. navTo(item){
  92. uni.navigateTo({
  93. url: `/pages/rent/carDetail?id=${item.id}`
  94. });
  95. },
  96. bindSortId(data) {
  97. console.log(data)
  98. },
  99. // 获取车辆列表
  100. getCarList() {
  101. const that = this;
  102. if (that.loading == 'loding' || that.loading == 'nomore') {
  103. return
  104. }
  105. that.loading = 'loding'
  106. getCarList({
  107. page: that.page,
  108. limit: that.limit,
  109. }).then((res) => {
  110. that.carList = that.carList.concat(res.data.list);
  111. that.page++
  112. if (res.data.list.length == that.limit) {
  113. that.loading = 'more'
  114. } else {
  115. that.loading = 'nomore'
  116. }
  117. }).catch((res) => {
  118. console.log(res);
  119. that.loading = 'more'
  120. })
  121. },
  122. getSearch() {
  123. const that = this;
  124. getDiy(0).then(res => {
  125. let lastArr = that.objToArr(res.data.value);
  126. for (var i = 0; i < lastArr.length; i++) {
  127. if (lastArr[i].name == 'headerSerch') {
  128. that.headerData = lastArr[i]
  129. }
  130. if (lastArr[i].name == 'tabNav') {
  131. that.tabNavData = lastArr[i]
  132. }
  133. if (lastArr[i].name == 'swiperBg') {
  134. that.swiperBgData = lastArr[i]
  135. }
  136. }
  137. })
  138. },
  139. // 对象转数组
  140. objToArr(data) {
  141. let obj = Object.keys(data);
  142. let m = obj.map(key => data[key]);
  143. return m;
  144. },
  145. },
  146. }
  147. </script>
  148. <style lang="scss" scoped>
  149. .navTitle {
  150. display: flex;
  151. align-items: center;
  152. background-color: rgb(31, 33, 52);
  153. line-height: 0;
  154. padding-left: 30rpx;
  155. padding-bottom: 20rpx;
  156. .left_tab {
  157. background-image: url('../../static/images/hometext.png');
  158. background-size: 100%;
  159. width: 120rpx;
  160. text-align: center;
  161. color: #75EFFA;
  162. line-height: 1;
  163. font-size: 34rpx;
  164. font-weight: bold;
  165. padding: 10rpx 0;
  166. }
  167. .right_tab {
  168. width: 600rpx;
  169. }
  170. }
  171. .bg {
  172. background-color: rgb(31, 33, 52);
  173. }
  174. .item {
  175. line-height: 1;
  176. padding: 30rpx 20rpx;
  177. .left {
  178. font-size: $uni-font-size-lg;
  179. color: #FFFFFF;
  180. .icon {
  181. width: 36rpx;
  182. height: 36rpx;
  183. margin-right: 10rpx;
  184. }
  185. }
  186. .right {
  187. color: #999999;
  188. font-size: $uni-font-size-sm;
  189. }
  190. }
  191. .list {
  192. padding: 0rpx 20rpx;
  193. padding-bottom: 128rpx;
  194. .ls {
  195. width: 344rpx;
  196. border-radius: 10rpx;
  197. background-color: #161726;
  198. color: #989898;
  199. margin-bottom: 20rpx;
  200. .content {
  201. padding: 20rpx 10rpx;
  202. .title {
  203. font-size: $uni-font-size-base;
  204. color: #FFFFFF;
  205. font-weight: bold;
  206. }
  207. .info {
  208. padding: 10rpx 0;
  209. }
  210. .price {
  211. font-weight: bold;
  212. color: #75EFFA;
  213. font-size: 36rpx;
  214. }
  215. .tip {
  216. color: #FFFFFF;
  217. font-size: $uni-font-size-sm;
  218. }
  219. }
  220. .img {
  221. width: 344rpx;
  222. height: 344rpx;
  223. border-radius: 10rpx;
  224. background-color: #FFFFFF;
  225. }
  226. }
  227. }
  228. </style>