index.vue 7.2 KB

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