index.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <template>
  2. <view class="content">
  3. <view class="top">
  4. <u-search shape="square" :show-action="false" placeholder="品牌/车系"></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 searchInfo = ref({});
  45. // 列表
  46. const list = ref([]);
  47. const total = ref(0);
  48. const skip = ref(0);
  49. const limit = ref(6);
  50. const page = ref(0);
  51. // 数据是否触底
  52. const is_bottom = ref(false);
  53. const scrollTop = ref(0);
  54. onShow(async () => {
  55. await searchConfig();
  56. await clearPage();
  57. await search();
  58. })
  59. onPullDownRefresh(async () => {
  60. await clearPage();
  61. await search();
  62. uni.stopPullDownRefresh();
  63. })
  64. // config信息
  65. const searchConfig = async () => {
  66. config.value = uni.getStorageSync('config');
  67. };
  68. // 查询
  69. const search = async () => {
  70. const info = {
  71. skip: skip.value,
  72. limit: limit.value,
  73. status: '0'
  74. }
  75. const res = await $api('car', 'GET', {
  76. ...info,
  77. ...searchInfo.value
  78. });
  79. if (res.errcode === 0) {
  80. list.value = list.value.concat(res.data)
  81. total.value = res.total
  82. } else {
  83. uni.showToast({
  84. title: res.errmsg || '',
  85. icon: 'error',
  86. });
  87. }
  88. };
  89. const toCommon = (item) => {
  90. console.log(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>