index.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  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="one">
  10. <view class="one_1">
  11. <view class="list" v-for="(item, index) in $config.searchList" :key="index"
  12. @tap="toRoute(item)">
  13. <view class="icon">
  14. <text class="t-icon" :class="item.icon"></text>
  15. </view>
  16. <view class="title">{{item.title||'暂无'}}</view>
  17. </view>
  18. </view>
  19. <view class="one_1 one_2">
  20. <view class="list" v-for="(item, index) in carList" :key="index" @tap="toCommon(item,'0')">
  21. <view class="icon">
  22. <image class="image"
  23. :src="item.url&&item.url.length>0?item.url[0].url:'/static/logo.png'">
  24. </image>
  25. </view>
  26. <view class="title">{{item.title}}</view>
  27. </view>
  28. </view>
  29. <view class="one_1 one_3">
  30. <view class="list" v-for="(item, index) in typeList" :key="index" @tap="toCommon(item,'1')">
  31. <view class="name">{{item.title||'暂无'}}</view>
  32. </view>
  33. </view>
  34. </view>
  35. <view class="two">
  36. <view class="list" v-for="(item, index) in list" :key="index" @tap="toView(item)">
  37. <view class="left">
  38. <image class="image" :src="item.file&&item.file.length>0?item.file[0].url:''">
  39. </image>
  40. </view>
  41. <view class="right">
  42. <view class="name textOver">{{item.series||'暂无'}} {{item.year||'暂无'}}款
  43. {{item.style||'暂无'}}</view>
  44. <view class="other">
  45. <text v-if="item.year">{{item.year||'暂无'}}年 | </text>
  46. <text v-if="item.mileage">{{item.mileage||'暂无'}}公里 | </text>
  47. <text v-if="item.place">{{item.place||'暂无'}}</text>
  48. </view>
  49. <view class="money">
  50. <text>{{item.total_money||'0'}}</text>
  51. <text>万</text>
  52. </view>
  53. </view>
  54. </view>
  55. </view>
  56. <view class="is_bottom" v-if="is_bottom">
  57. <text>{{config.bottom_title||'没有更多了!'}}</text>
  58. </view>
  59. </view>
  60. </scroll-view>
  61. </view>
  62. </view>
  63. </template>
  64. <script setup lang="ts">
  65. import { getCurrentInstance, ref } from 'vue';
  66. //该依赖已内置不需要单独安装
  67. import { onShow, onPullDownRefresh } from "@dcloudio/uni-app";
  68. // 请求接口
  69. const $api = getCurrentInstance()?.appContext.config.globalProperties.$api;
  70. const $config = getCurrentInstance()?.appContext.config.globalProperties.$config;
  71. // 基本信息
  72. const config = ref({ logoUrl: [] });
  73. // 查询
  74. const searchInfo = ref({});
  75. // 列表
  76. const list = ref([]);
  77. const total = ref(0);
  78. const skip = ref(0);
  79. const limit = ref(6);
  80. const page = ref(0);
  81. // 数据是否触底
  82. const is_bottom = ref(false);
  83. const scrollTop = ref(0);
  84. // 字典表
  85. const typeList = ref([
  86. {
  87. title: '5万以下',
  88. type: '0',
  89. },
  90. {
  91. title: '5-10万',
  92. type: '1',
  93. },
  94. {
  95. title: '10-15万',
  96. type: '2',
  97. },
  98. {
  99. title: '更多条件',
  100. type: '3',
  101. }
  102. ])
  103. const carList = ref([
  104. {
  105. title: '大众',
  106. type: '0',
  107. },
  108. {
  109. title: '宝马',
  110. type: '1',
  111. },
  112. {
  113. title: '本田',
  114. type: '2',
  115. },
  116. {
  117. title: '丰田',
  118. type: '3',
  119. },
  120. {
  121. title: '更多品牌',
  122. type: '4',
  123. }
  124. ])
  125. onShow(async () => {
  126. await searchConfig();
  127. await clearPage();
  128. await search();
  129. })
  130. onPullDownRefresh(async () => {
  131. await clearPage();
  132. await search();
  133. uni.stopPullDownRefresh();
  134. })
  135. // config信息
  136. const searchConfig = async () => {
  137. config.value = uni.getStorageSync('config');
  138. };
  139. // 查询
  140. const search = async () => {
  141. const info = {
  142. skip: skip.value,
  143. limit: limit.value,
  144. status: '0'
  145. }
  146. const res = await $api('car', 'GET', {
  147. ...info,
  148. ...searchInfo.value
  149. });
  150. if (res.errcode === 0) {
  151. list.value = list.value.concat(res.data)
  152. total.value = res.total
  153. } else {
  154. uni.showToast({
  155. title: res.errmsg || '',
  156. icon: 'error',
  157. });
  158. }
  159. };
  160. const toRoute = (item) => {
  161. uni.navigateTo({
  162. url: `/${item.route}`,
  163. })
  164. };
  165. const toCommon = (item, type) => {
  166. console.log(item);
  167. if (type == '0' && item.type == '4') {
  168. uni.navigateTo({
  169. url: `/pagesHome/brand/index?type=${item.type || ''}`,
  170. })
  171. } else {
  172. uni.navigateTo({
  173. url: `/pagesHome/search/index?type=${item.type || ''}`,
  174. })
  175. }
  176. };
  177. // 查看详情
  178. const toView = (item) => {
  179. uni.navigateTo({
  180. url: `/pagesHome/car/index?id=${item.id || item._id}`
  181. })
  182. };
  183. // 分页
  184. const toPage = () => {
  185. if (total.value > list.value.length) {
  186. uni.showLoading({
  187. title: '加载中',
  188. mask: true
  189. })
  190. page.value = page.value + 1;
  191. skip.value = page.value * limit.value;
  192. search();
  193. uni.hideLoading();
  194. } else is_bottom.value = true
  195. };
  196. // 清空列表
  197. const clearPage = () => {
  198. list.value = []
  199. skip.value = 0
  200. limit.value = 6
  201. page.value = 0
  202. };
  203. </script>
  204. <style lang="scss" scoped>
  205. .content {
  206. display: flex;
  207. flex-direction: column;
  208. width: 100vw;
  209. height: 100vh;
  210. .top {
  211. margin: 2vw;
  212. }
  213. .bottom {
  214. position: relative;
  215. flex-grow: 1;
  216. .one {
  217. .one_1 {
  218. display: flex;
  219. justify-content: space-between;
  220. align-items: center;
  221. padding: 2vw 4vw;
  222. .list {
  223. display: flex;
  224. flex-direction: column;
  225. align-items: center;
  226. .title {
  227. margin: 1vw 0 0 0;
  228. font-size: var(--font14Size);
  229. }
  230. }
  231. }
  232. .one_2 {
  233. .image {
  234. width: 35px;
  235. height: 35px;
  236. border-radius: 35px;
  237. }
  238. }
  239. .one_3 {
  240. padding: 2vw;
  241. .list {
  242. background-color: var(--f9Color);
  243. .name {
  244. padding: 2vw 4vw;
  245. font-size: var(--font14Size);
  246. }
  247. }
  248. }
  249. }
  250. .two {
  251. margin: 2vw;
  252. .list {
  253. display: flex;
  254. margin: 1vw 0 0 0;
  255. padding: 1vw;
  256. height: 100px;
  257. .left {
  258. .image {
  259. width: 130px;
  260. height: 100px;
  261. border-radius: 2px;
  262. }
  263. }
  264. .right {
  265. display: flex;
  266. flex-direction: column;
  267. justify-content: space-between;
  268. margin: 0 0 0 2vw;
  269. width: 100%;
  270. .name {
  271. font-size: var(--font14Size);
  272. }
  273. .other {
  274. color: var(--f85Color);
  275. font-size: var(--font12Size);
  276. }
  277. .money {
  278. color: var(--fF0Color);
  279. font-size: var(--font12Size);
  280. text:first-child {
  281. font-size: var(--font18Size);
  282. }
  283. }
  284. }
  285. }
  286. }
  287. }
  288. }
  289. .scroll-view {
  290. position: absolute;
  291. top: 0;
  292. left: 0;
  293. right: 0;
  294. bottom: 0;
  295. .list-scroll-view {
  296. display: flex;
  297. flex-direction: column;
  298. }
  299. }
  300. .is_bottom {
  301. width: 100%;
  302. text-align: center;
  303. text {
  304. padding: 2vw 0;
  305. display: inline-block;
  306. color: var(--f85Color);
  307. font-size: var(--font12Size);
  308. }
  309. }
  310. </style>