index.vue 7.4 KB

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