index.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <template>
  2. <view class="content">
  3. <view class="top">
  4. <u-search shape="square" :show-action="false" placeholder="品牌/车系" @focus="toChange"></u-search>
  5. </view>
  6. <view class="bottom">
  7. <scroll-view scroll-y="true" class="scroll-view" @scrolltolower="toPage">
  8. <view class="list-scroll-view">
  9. <view class="list" v-for="(item, index) in list" :key="index" @tap="toView(item)">
  10. <view class="list_1">
  11. <view class="left">
  12. <image class="image" :src="item.file&&item.file.length>0?item.file[0].url:''">
  13. </image>
  14. </view>
  15. <view class="right">
  16. <view class="name textOver">{{item.series||'暂无'}} {{item.year||'暂无'}}款
  17. {{item.style||'暂无'}}
  18. </view>
  19. <view class="money">
  20. <text>{{item.total_money||'0'}}</text>
  21. <text>万</text>
  22. </view>
  23. </view>
  24. </view>
  25. </view>
  26. <view class="is_bottom" v-if="is_bottom">
  27. <text>{{config.bottom_title||'没有更多了!'}}</text>
  28. </view>
  29. </view>
  30. </scroll-view>
  31. </view>
  32. </view>
  33. </template>
  34. <script setup lang="ts">
  35. import { getCurrentInstance, ref } from 'vue';
  36. //该依赖已内置不需要单独安装
  37. import { onShow, onPullDownRefresh } from "@dcloudio/uni-app";
  38. // 请求接口
  39. const $api = getCurrentInstance()?.appContext.config.globalProperties.$api;
  40. const $config = getCurrentInstance()?.appContext.config.globalProperties.$config;
  41. // 基本信息
  42. const config = ref({ logoUrl: [] });
  43. // 列表
  44. const list = ref([]);
  45. const total = ref(0);
  46. const skip = ref(0);
  47. const limit = ref(6);
  48. const page = ref(0);
  49. // 数据是否触底
  50. const is_bottom = ref(false);
  51. const scrollTop = ref(0);
  52. onShow(async () => {
  53. await searchConfig();
  54. await clearPage();
  55. await search();
  56. })
  57. onPullDownRefresh(async () => {
  58. await clearPage();
  59. await search();
  60. uni.stopPullDownRefresh();
  61. })
  62. // config信息
  63. const searchConfig = async () => {
  64. config.value = uni.getStorageSync('config');
  65. };
  66. // 查询
  67. const search = async () => {
  68. const info = {
  69. skip: skip.value,
  70. limit: limit.value,
  71. status: '0'
  72. }
  73. const res = await $api('car', 'GET', info);
  74. if (res.errcode === 0) {
  75. list.value = list.value.concat(res.data)
  76. total.value = res.total
  77. } else {
  78. uni.showToast({
  79. title: res.errmsg || '',
  80. icon: 'error',
  81. });
  82. }
  83. };
  84. // 搜索
  85. const toChange = () => {
  86. uni.navigateTo({
  87. url: `/pagesHome/type/index`
  88. })
  89. };
  90. const toCommon = (item) => {
  91. uni.navigateTo({
  92. url: `/pagesHome/search/index?type=${item.type || ''}`
  93. })
  94. };
  95. // 查看详情
  96. const toView = (item) => {
  97. uni.navigateTo({
  98. url: `/pagesHome/car/index?id=${item.id || item._id}`
  99. })
  100. };
  101. // 分页
  102. const toPage = () => {
  103. if (total.value > list.value.length) {
  104. uni.showLoading({
  105. title: '加载中',
  106. mask: true
  107. })
  108. page.value = page.value + 1;
  109. skip.value = page.value * limit.value;
  110. search();
  111. uni.hideLoading();
  112. } else is_bottom.value = true
  113. };
  114. // 清空列表
  115. const clearPage = () => {
  116. list.value = []
  117. skip.value = 0
  118. limit.value = 6
  119. page.value = 0
  120. };
  121. </script>
  122. <style lang="scss" scoped>
  123. .content {
  124. display: flex;
  125. flex-direction: column;
  126. width: 100vw;
  127. height: 100vh;
  128. .top {
  129. margin: 2vw;
  130. }
  131. .bottom {
  132. position: relative;
  133. flex-grow: 1;
  134. .list {
  135. width: 47vw;
  136. margin: 2vw 0 0 0;
  137. border-radius: 5px;
  138. border: 1px solid var(--f5Color);
  139. .list_1 {
  140. .left {
  141. .image {
  142. width: 100%;
  143. height: 120px;
  144. border-radius: 5px 5px 0 0;
  145. }
  146. }
  147. .right {
  148. display: flex;
  149. flex-direction: column;
  150. justify-content: space-between;
  151. padding: 0 2vw;
  152. .name {
  153. font-size: var(--font14Size);
  154. }
  155. .money {
  156. color: var(--fF0Color);
  157. font-size: var(--font12Size);
  158. margin: 0 0 1vw 0;
  159. text:first-child {
  160. font-size: var(--font18Size);
  161. }
  162. }
  163. }
  164. }
  165. }
  166. }
  167. }
  168. .scroll-view {
  169. position: absolute;
  170. top: 0;
  171. left: 0;
  172. right: 0;
  173. bottom: 0;
  174. .list-scroll-view {
  175. display: flex;
  176. justify-content: space-between;
  177. flex-wrap: wrap;
  178. padding: 0 2vw;
  179. }
  180. }
  181. .is_bottom {
  182. width: 100%;
  183. text-align: center;
  184. text {
  185. padding: 2vw 0;
  186. display: inline-block;
  187. color: var(--f85Color);
  188. font-size: var(--font12Size);
  189. }
  190. }
  191. </style>