index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584
  1. <template>
  2. <view class="content">
  3. <view class="top">
  4. <u-search shape="square" :show-action="false" placeholder="请输入车辆的名称或品牌"></u-search>
  5. <view class="search">
  6. <view class="list" v-for="(item, index) in searchList" :key="index" @tap="toSearch(item)">
  7. <view :class="[item.is_open==false?'title_1':'title_2']">{{item.title}}</view>
  8. <u-icon color="#000" size="10px" v-if="item.is_open==false" name="arrow-down-fill"></u-icon>
  9. <u-icon color="#ffbc00" size="10px" v-else name="arrow-up-fill"></u-icon>
  10. </view>
  11. </view>
  12. <view v-show="is_show" @tap="toClose" class="popup-layer">
  13. <view class="popup-content">
  14. <view class="search_1" v-if="type=='0'">
  15. <view class="list" v-for="(item, index) in sortList" :key="index" @tap="toSelect(item,type)">
  16. <view :class="[item.is_open==false?'title_1':'title_2']">{{item.title}}</view>
  17. </view>
  18. </view>
  19. <view class="search_1" v-else-if="type=='2'">
  20. <view class="list" v-for="(item, index) in moneyList" :key="index" @tap="toSelect(item,type)">
  21. <view :class="[item.is_open==false?'title_1':'title_2']">{{item.title}}</view>
  22. </view>
  23. </view>
  24. </view>
  25. </view>
  26. <view class="search_2"
  27. v-if="Object.keys(brandInfo).length > 0||Object.keys(moneyInfo).length > 0||moreList.length>0">
  28. <view class="left">
  29. <scroll-view scroll-x="true">
  30. <view class="scroll">
  31. <view v-if="brandInfo&&brandInfo.type" class="title" @tap="toDelete({},'0')">
  32. <span>{{brandInfo.title}}</span>&nbsp;
  33. <u-icon color="#000" size="14px" name="close"></u-icon>
  34. </view>
  35. <view v-if="moneyInfo&&moneyInfo.type" class="title" @tap="toDelete({},'1')">
  36. <span>{{moneyInfo.title}}</span>&nbsp;
  37. <u-icon color="#000" size="14px" name="close"></u-icon>
  38. </view>
  39. <view v-if="moreList.length>0" class="title" v-for="(item, index) in moreList" :key="index"
  40. @tap="toDelete(item,'2')">
  41. <span>{{item.title}}</span>&nbsp;
  42. <u-icon color="#000" size="14px" name="close"></u-icon>
  43. </view>
  44. </view>
  45. </scroll-view>
  46. </view>
  47. <view class="right">
  48. <view class="right_1" @tap="toReset">重置</view>
  49. </view>
  50. </view>
  51. </view>
  52. <view class="bottom">
  53. <scroll-view scroll-y="true" class="scroll-view" @scrolltolower="toPage">
  54. <view class="list-scroll-view">
  55. <view class="one">
  56. <view class="list" v-for="(item, index) in list" :key="index" @tap="toView(item)">
  57. <view class="left">
  58. <image class="image" :src="item.file&&item.file.length>0?item.file[0].url:''">
  59. </image>
  60. </view>
  61. <view class="right">
  62. <view class="name textOver">{{item.name||'暂无'}}</view>
  63. <view class="other">
  64. <text v-if="item.year">{{item.year||'暂无'}}| </text>
  65. <text v-if="item.kilometer">{{item.kilometer||'暂无'}} | </text>
  66. <text v-if="item.city">{{item.city||'暂无'}}</text>
  67. </view>
  68. <view class="right_1">
  69. <view class="money">
  70. <text>{{item.money||'0'}}</text>
  71. <text>万</text>
  72. </view>
  73. <view>
  74. <button @tap.stop="toChat(item)" class="button" size="mini"
  75. type="default">询底价</button>
  76. </view>
  77. </view>
  78. </view>
  79. </view>
  80. </view>
  81. <view class="is_bottom" v-if="is_bottom">
  82. <text>{{config.bottom_title||'没有更多了!'}}</text>
  83. </view>
  84. </view>
  85. </scroll-view>
  86. </view>
  87. </view>
  88. </template>
  89. <script setup lang="ts">
  90. import { getCurrentInstance, ref } from 'vue';
  91. //该依赖已内置不需要单独安装
  92. import { onLoad, onShow } from "@dcloudio/uni-app";
  93. // 请求接口
  94. const $api = getCurrentInstance()?.appContext.config.globalProperties.$api;
  95. const $config = getCurrentInstance()?.appContext.config.globalProperties.$config;
  96. // 基本信息
  97. const config = ref({ logoUrl: [] });
  98. const type = ref('0');
  99. const is_show = ref(false);
  100. //查询
  101. const searchList = ref([{ title: '默认排序', type: '0', is_open: false }, { title: '品牌', type: '1', is_open: false }, { title: '价格', type: '2', is_open: false }, { title: '更多筛选', type: '3', is_open: false }]);
  102. //排序
  103. const sortList = ref([{ title: '默认排序', type: '0', is_open: true }, { title: '最新上架', type: '1', is_open: false }, { title: '车龄最短', type: '2', is_open: false }, { title: '里程最少', type: '3', is_open: false }, { title: '价格最高', type: '4', is_open: false }, { title: '价格最低', type: '5', is_open: false }]);
  104. //价格
  105. const moneyList = ref([{ title: '不限价格', type: '0', is_open: true }, { title: '10万以下', type: '1', is_open: false }, { title: '10-15万', type: '2', is_open: false }, { title: '15-20万', type: '3', is_open: false }, { title: '20-25万', type: '4', is_open: false }, { title: '25-30万', type: '5', is_open: false }, { title: '30-50万', type: '6', is_open: false }, { title: '50万以上', type: '7', is_open: false }]);
  106. // 选择的查询条件
  107. const brandInfo = ref({});
  108. const moneyInfo = ref({});
  109. const moreList = ref([]);
  110. // 列表
  111. const list = ref([
  112. {
  113. id: '1',
  114. file: [{ url: 'https://cdn.uviewui.com/uview/album/1.jpg' }],
  115. name: '夏朗 2013款 1.8TSI 标配型 欧IV',
  116. year: '2014年 ',
  117. city: '丹东',
  118. kilometer: '8万公里',
  119. money: '7.80'
  120. },
  121. {
  122. id: '1',
  123. file: [{ url: 'https://cdn.uviewui.com/uview/album/2.jpg' }],
  124. name: '捷豹XEL 2020款 2.0T 200PS S进取优雅版',
  125. year: '2014年 ',
  126. city: '丹东',
  127. kilometer: '8万公里',
  128. money: '7.80'
  129. },
  130. {
  131. id: '1',
  132. file: [{ url: 'https://cdn.uviewui.com/uview/album/3.jpg' }],
  133. name: '夏朗 2013款 1.8TSI 标配型 欧IV',
  134. year: '2014年 ',
  135. city: '丹东',
  136. kilometer: '8万公里',
  137. money: '7.80'
  138. },
  139. {
  140. id: '1',
  141. file: [{ url: 'https://cdn.uviewui.com/uview/album/4.jpg' }],
  142. name: '夏朗 2013款 1.8TSI 标配型 欧IV',
  143. year: '2014年 ',
  144. city: '丹东',
  145. kilometer: '8万公里',
  146. money: '7.80'
  147. },
  148. {
  149. id: '1',
  150. file: [{ url: 'https://cdn.uviewui.com/uview/album/5.jpg' }],
  151. name: '夏朗 2013款 1.8TSI 标配型 欧IV',
  152. year: '2014年 ',
  153. city: '丹东',
  154. kilometer: '8万公里',
  155. money: '7.80'
  156. },
  157. {
  158. id: '1',
  159. file: [{ url: 'https://cdn.uviewui.com/uview/album/6.jpg' }],
  160. name: '夏朗 2013款 1.8TSI 标配型 欧IV',
  161. year: '2014年 ',
  162. city: '丹东',
  163. kilometer: '8万公里',
  164. money: '7.80'
  165. },
  166. {
  167. id: '1',
  168. file: [{ url: 'https://cdn.uviewui.com/uview/album/7.jpg' }],
  169. name: '夏朗 2013款 1.8TSI 标配型 欧IV',
  170. year: '2014年 ',
  171. city: '丹东',
  172. kilometer: '8万公里',
  173. money: '7.80'
  174. },
  175. {
  176. id: '1',
  177. file: [{ url: 'https://cdn.uviewui.com/uview/album/8.jpg' }],
  178. name: '夏朗 2013款 1.8TSI 标配型 欧IV',
  179. year: '2014年 ',
  180. city: '丹东',
  181. kilometer: '8万公里',
  182. money: '7.80'
  183. },
  184. {
  185. id: '1',
  186. file: [{ url: 'https://cdn.uviewui.com/uview/album/9.jpg' }],
  187. name: '夏朗 2013款 1.8TSI 标配型 欧IV',
  188. year: '2014年 ',
  189. city: '丹东',
  190. kilometer: '8万公里',
  191. money: '7.80'
  192. },
  193. {
  194. id: '1',
  195. file: [{ url: 'https://cdn.uviewui.com/uview/album/10.jpg' }],
  196. name: '夏朗 2013款 1.8TSI 标配型 欧IV',
  197. year: '2014年 ',
  198. city: '丹东',
  199. kilometer: '8万公里',
  200. money: '7.80'
  201. }]);
  202. const total = ref(0);
  203. const skip = ref(0);
  204. const limit = ref(6);
  205. const page = ref(0);
  206. // 数据是否触底
  207. const is_bottom = ref(false);
  208. const scrollTop = ref(0);
  209. // 字典表
  210. const typeList = ref([
  211. {
  212. title: '5万以下',
  213. type: '0',
  214. },
  215. {
  216. title: '5-10万',
  217. type: '1',
  218. },
  219. {
  220. title: '10-15万',
  221. type: '2',
  222. },
  223. {
  224. title: '更多条件',
  225. type: '3',
  226. }
  227. ]);
  228. const carList = ref([
  229. {
  230. title: '大众',
  231. type: '0',
  232. },
  233. {
  234. title: '宝马',
  235. type: '1',
  236. },
  237. {
  238. title: '本田',
  239. type: '2',
  240. },
  241. {
  242. title: '丰田',
  243. type: '3',
  244. },
  245. {
  246. title: '更多品牌',
  247. type: '4',
  248. }
  249. ]);
  250. onLoad(async () => {
  251. await searchConfig();
  252. await search();
  253. })
  254. onShow(() => {
  255. uni.$on('toRoute', function (data) {
  256. brandInfo.value = data
  257. })
  258. })
  259. // config信息
  260. const searchConfig = async () => {
  261. config.value = uni.getStorageSync('config');
  262. };
  263. // 查询
  264. const search = async () => {
  265. };
  266. // 查询
  267. const toSearch = (value) => {
  268. // 判断点击的是那个筛选
  269. searchList.value = searchList.value.map((item, index) => {
  270. if (item.type == value.type && !item.is_open) item.is_open = true
  271. else item.is_open = false
  272. return item
  273. })
  274. type.value = value.type
  275. if (value.type == '1') {
  276. toClose()
  277. uni.navigateTo({
  278. url: `/pagesHome/brand/index`,
  279. })
  280. }
  281. else if (value.type == '3') {
  282. toClose()
  283. uni.navigateTo({
  284. url: `/pagesHome/condition/index`,
  285. })
  286. } else is_show.value = searchList.value.some(item => item.is_open == true)
  287. };
  288. // 关闭筛选
  289. const toClose = () => {
  290. is_show.value = false
  291. searchList.value = searchList.value.map((item, index) => {
  292. item.is_open = false
  293. return item
  294. })
  295. };
  296. // 选择
  297. const toSelect = (data, type) => {
  298. // 判断点击的是那个筛选
  299. if (type == '0') {
  300. sortList.value = sortList.value.map((item, index) => {
  301. if (item.type == data.type) item.is_open = true
  302. else item.is_open = false
  303. return item
  304. })
  305. searchList.value = searchList.value.map((i, index) => {
  306. if (i.type == '0') i.title = data.title
  307. return i
  308. })
  309. } else {
  310. moneyList.value = moneyList.value.map((item, index) => {
  311. if (item.type == data.type) item.is_open = true
  312. else item.is_open = false
  313. return item
  314. })
  315. moneyInfo.value = data
  316. }
  317. };
  318. // 删除筛选
  319. const toDelete = (item, type) => {
  320. if (type == '0') brandInfo.value = {}
  321. else if (type == '1') {
  322. moneyList.value = moneyList.value.map((item, index) => {
  323. if (item.type == '0') item.is_open = true
  324. else item.is_open = false
  325. return item
  326. })
  327. moneyInfo.value = {}
  328. }
  329. else moreList.value = moreList.value.filter((i, index) => i.type != item.type)
  330. };
  331. // 重置
  332. const toReset = () => {
  333. brandInfo.value = {}
  334. moneyInfo.value = {}
  335. moreList.value = []
  336. toClear();
  337. };
  338. // 清除
  339. const toClear = () => {
  340. searchList.value = searchList.value.map((i, index) => {
  341. if (i.type == '0') i.title = '默认排序'
  342. return i
  343. })
  344. moneyList.value = moneyList.value.map((item, index) => {
  345. if (item.type == '0') item.is_open = true
  346. else item.is_open = false
  347. return item
  348. })
  349. sortList.value = sortList.value.map((item, index) => {
  350. if (item.type == '0') item.is_open = true
  351. else item.is_open = false
  352. return item
  353. })
  354. };
  355. // 联系卖家
  356. const toChat = (item) => {
  357. uni.makePhoneCall({
  358. phoneNumber: item.shop || '110',
  359. success: function () {
  360. console.log('拨打电话成功');
  361. },
  362. fail: function () {
  363. console.log('拨打电话失败');
  364. }
  365. });
  366. };
  367. // 查看详情
  368. const toView = (item) => {
  369. uni.navigateTo({
  370. url: `/pagesHome/car/index?id=${item.id || item._id}`
  371. })
  372. };
  373. // 分页
  374. const toPage = () => {
  375. if (total.value > list.value.length) {
  376. uni.showLoading({
  377. title: '加载中',
  378. mask: true
  379. })
  380. page.value = page.value + 1;
  381. skip.value = page.value * limit.value;
  382. search();
  383. uni.hideLoading();
  384. } else is_bottom.value = true
  385. };
  386. // 清空列表
  387. const clearPage = () => {
  388. list.value = []
  389. skip.value = 0
  390. limit.value = 6
  391. page.value = 0
  392. };
  393. </script>
  394. <style lang="scss" scoped>
  395. .content {
  396. display: flex;
  397. flex-direction: column;
  398. width: 100vw;
  399. height: 100vh;
  400. .top {
  401. margin: 2vw;
  402. .search {
  403. display: flex;
  404. justify-content: space-between;
  405. align-items: center;
  406. padding: 2vw 2vw 0 2vw;
  407. .list {
  408. display: flex;
  409. align-items: center;
  410. padding: 1vw 0;
  411. .title_1 {
  412. margin: 0 1vw 0 0;
  413. font-size: var(--font14Size);
  414. }
  415. .title_2 {
  416. margin: 0 1vw 0 0;
  417. font-size: var(--font14Size);
  418. color: var(--fFFColor);
  419. }
  420. }
  421. }
  422. .popup-layer {
  423. position: absolute;
  424. z-index: 999999;
  425. background: rgba(0, 0, 0, .3);
  426. height: calc(100% - 50px);
  427. width: 100%;
  428. left: 0px;
  429. overflow: hidden;
  430. height: 87.5vh;
  431. }
  432. .popup-content {
  433. position: absolute;
  434. width: 100%;
  435. z-index: 1000000;
  436. background: #FFFFFF;
  437. transition: all .3s ease;
  438. .search_1 {
  439. display: flex;
  440. flex-wrap: wrap;
  441. padding: 2vw;
  442. .list {
  443. font-size: var(--font14Size);
  444. width: 24vw;
  445. text-align: center;
  446. .title_1 {
  447. padding: 2vw;
  448. margin: 1vw;
  449. background-color: var(--f5Color);
  450. }
  451. .title_2 {
  452. padding: 2vw;
  453. margin: 1vw;
  454. background: rgba(255, 222, 173, 0.35);
  455. border: 1px solid var(--fFFColor);
  456. }
  457. }
  458. }
  459. }
  460. .search_2 {
  461. padding: 2vw;
  462. background-color: var(--f5Color);
  463. display: flex;
  464. justify-content: space-between;
  465. align-items: center;
  466. .left {
  467. width: 80vw;
  468. .scroll {
  469. display: flex;
  470. white-space: nowrap;
  471. .title {
  472. font-size: var(--font14Size);
  473. display: flex;
  474. padding: 2vw;
  475. margin: 1vw;
  476. background-color: var(--mainColor);
  477. }
  478. }
  479. }
  480. }
  481. }
  482. .bottom {
  483. position: relative;
  484. flex-grow: 1;
  485. .one {
  486. margin: 0 2vw 2vw 2vw;
  487. .list {
  488. display: flex;
  489. margin: 1vw 0 0 0;
  490. padding: 1vw;
  491. height: 100px;
  492. .left {
  493. .image {
  494. width: 130px;
  495. height: 100px;
  496. border-radius: 2px;
  497. }
  498. }
  499. .right {
  500. display: flex;
  501. flex-direction: column;
  502. justify-content: space-between;
  503. width: 100%;
  504. .name {
  505. font-size: var(--font14Size);
  506. }
  507. .other {
  508. color: var(--f85Color);
  509. font-size: var(--font12Size);
  510. }
  511. .right_1 {
  512. display: flex;
  513. justify-content: space-between;
  514. align-items: center;
  515. .money {
  516. color: var(--fF0Color);
  517. font-size: var(--font12Size);
  518. text:first-child {
  519. font-size: var(--font18Size);
  520. }
  521. }
  522. .button {
  523. background-color: var(--fFFColor);
  524. }
  525. }
  526. }
  527. }
  528. }
  529. }
  530. }
  531. .scroll-view {
  532. position: absolute;
  533. top: 0;
  534. left: 0;
  535. right: 0;
  536. bottom: 0;
  537. .list-scroll-view {
  538. display: flex;
  539. flex-direction: column;
  540. }
  541. }
  542. .is_bottom {
  543. width: 100%;
  544. text-align: center;
  545. text {
  546. padding: 2vw 0;
  547. display: inline-block;
  548. color: var(--f85Color);
  549. font-size: var(--font12Size);
  550. }
  551. }
  552. </style>