index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518
  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 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.series||'暂无'}} {{item.year||'暂无'}}款
  63. {{item.style||'暂无'}}</view>
  64. <view class="other">
  65. <text v-if="item.year">{{item.year||'暂无'}}年 | </text>
  66. <text v-if="item.mileage">{{item.mileage||'暂无'}}公里 | </text>
  67. <text v-if="item.place">{{item.place||'暂无'}}</text>
  68. </view>
  69. <view class="right_1">
  70. <view class="money">
  71. <text>{{item.total_money||'0'}}</text>
  72. <text>万</text>
  73. </view>
  74. <view>
  75. <button @tap.stop="toChat(item)" class="button" size="mini"
  76. type="default">询底价</button>
  77. </view>
  78. </view>
  79. </view>
  80. </view>
  81. </view>
  82. <view class="is_bottom" v-if="is_bottom">
  83. <text>{{config.bottom_title||'没有更多了!'}}</text>
  84. </view>
  85. </view>
  86. </scroll-view>
  87. </view>
  88. </view>
  89. </template>
  90. <script setup lang="ts">
  91. import { getCurrentInstance, ref } from 'vue';
  92. //该依赖已内置不需要单独安装
  93. import { onLoad, onShow } from "@dcloudio/uni-app";
  94. // 请求接口
  95. const $api = getCurrentInstance()?.appContext.config.globalProperties.$api;
  96. const $config = getCurrentInstance()?.appContext.config.globalProperties.$config;
  97. // 基本信息
  98. const config = ref({ logoUrl: [] });
  99. const type = ref('0');
  100. const is_show = ref(false);
  101. //查询
  102. 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 }]);
  103. //排序
  104. 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 }]);
  105. //价格
  106. 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 }]);
  107. // 选择的查询条件
  108. const brandInfo = ref({});
  109. const moneyInfo = ref({});
  110. const moreList = ref([]);
  111. // 列表
  112. const list = ref([]);
  113. const total = ref(0);
  114. const skip = ref(0);
  115. const limit = ref(6);
  116. const page = ref(0);
  117. // 数据是否触底
  118. const is_bottom = ref(false);
  119. const scrollTop = ref(0);
  120. // 字典表
  121. const typeList = ref([
  122. {
  123. title: '5万以下',
  124. type: '0',
  125. },
  126. {
  127. title: '5-10万',
  128. type: '1',
  129. },
  130. {
  131. title: '10-15万',
  132. type: '2',
  133. },
  134. {
  135. title: '更多条件',
  136. type: '3',
  137. }
  138. ]);
  139. const carList = ref([
  140. {
  141. title: '大众',
  142. type: '0',
  143. },
  144. {
  145. title: '宝马',
  146. type: '1',
  147. },
  148. {
  149. title: '本田',
  150. type: '2',
  151. },
  152. {
  153. title: '丰田',
  154. type: '3',
  155. },
  156. {
  157. title: '更多品牌',
  158. type: '4',
  159. }
  160. ]);
  161. onLoad(async () => {
  162. await searchConfig();
  163. await search();
  164. })
  165. onShow(() => {
  166. uni.$on('toRoute', function (data) {
  167. brandInfo.value = data
  168. })
  169. })
  170. // config信息
  171. const searchConfig = async () => {
  172. config.value = uni.getStorageSync('config');
  173. };
  174. // 查询
  175. const search = async () => {
  176. const info = {
  177. skip: skip.value,
  178. limit: limit.value,
  179. status: '0'
  180. }
  181. const res = await $api('car', 'GET',info);
  182. if (res.errcode === 0) {
  183. list.value = list.value.concat(res.data)
  184. total.value = res.total
  185. } else {
  186. uni.showToast({
  187. title: res.errmsg || '',
  188. icon: 'error',
  189. });
  190. }
  191. };
  192. // 查询
  193. const toSearch = (value) => {
  194. // 判断点击的是那个筛选
  195. searchList.value = searchList.value.map((item, index) => {
  196. if (item.type == value.type && !item.is_open) item.is_open = true
  197. else item.is_open = false
  198. return item
  199. })
  200. type.value = value.type
  201. if (value.type == '1') {
  202. toClose()
  203. uni.navigateTo({
  204. url: `/pagesHome/brand/index`,
  205. })
  206. }
  207. else if (value.type == '3') {
  208. toClose()
  209. uni.navigateTo({
  210. url: `/pagesHome/condition/index`,
  211. })
  212. } else is_show.value = searchList.value.some(item => item.is_open == true)
  213. };
  214. // 搜索
  215. const toChange = () => {
  216. uni.navigateTo({
  217. url: `/pagesHome/type/index`
  218. })
  219. };
  220. // 关闭筛选
  221. const toClose = () => {
  222. is_show.value = false
  223. searchList.value = searchList.value.map((item, index) => {
  224. item.is_open = false
  225. return item
  226. })
  227. };
  228. // 选择
  229. const toSelect = (data, type) => {
  230. // 判断点击的是那个筛选
  231. if (type == '0') {
  232. sortList.value = sortList.value.map((item, index) => {
  233. if (item.type == data.type) item.is_open = true
  234. else item.is_open = false
  235. return item
  236. })
  237. searchList.value = searchList.value.map((i, index) => {
  238. if (i.type == '0') i.title = data.title
  239. return i
  240. })
  241. } else {
  242. moneyList.value = moneyList.value.map((item, index) => {
  243. if (item.type == data.type) item.is_open = true
  244. else item.is_open = false
  245. return item
  246. })
  247. moneyInfo.value = data
  248. }
  249. };
  250. // 删除筛选
  251. const toDelete = (item, type) => {
  252. if (type == '0') brandInfo.value = {}
  253. else if (type == '1') {
  254. moneyList.value = moneyList.value.map((item, index) => {
  255. if (item.type == '0') item.is_open = true
  256. else item.is_open = false
  257. return item
  258. })
  259. moneyInfo.value = {}
  260. }
  261. else moreList.value = moreList.value.filter((i, index) => i.type != item.type)
  262. };
  263. // 重置
  264. const toReset = () => {
  265. brandInfo.value = {}
  266. moneyInfo.value = {}
  267. moreList.value = []
  268. toClear();
  269. };
  270. // 清除
  271. const toClear = () => {
  272. searchList.value = searchList.value.map((i, index) => {
  273. if (i.type == '0') i.title = '默认排序'
  274. return i
  275. })
  276. moneyList.value = moneyList.value.map((item, index) => {
  277. if (item.type == '0') item.is_open = true
  278. else item.is_open = false
  279. return item
  280. })
  281. sortList.value = sortList.value.map((item, index) => {
  282. if (item.type == '0') item.is_open = true
  283. else item.is_open = false
  284. return item
  285. })
  286. };
  287. // 联系卖家
  288. const toChat = (item) => {
  289. uni.makePhoneCall({
  290. phoneNumber: item.shop?.tel,
  291. success: function () {
  292. console.log('拨打电话成功');
  293. },
  294. fail: function () {
  295. uni.showToast({
  296. title: '拨打电话失败',
  297. icon: 'error',
  298. });
  299. }
  300. });
  301. };
  302. // 查看详情
  303. const toView = (item) => {
  304. uni.navigateTo({
  305. url: `/pagesHome/car/index?id=${item.id || item._id}`
  306. })
  307. };
  308. // 分页
  309. const toPage = () => {
  310. if (total.value > list.value.length) {
  311. uni.showLoading({
  312. title: '加载中',
  313. mask: true
  314. })
  315. page.value = page.value + 1;
  316. skip.value = page.value * limit.value;
  317. search();
  318. uni.hideLoading();
  319. } else is_bottom.value = true
  320. };
  321. // 清空列表
  322. const clearPage = () => {
  323. list.value = []
  324. skip.value = 0
  325. limit.value = 6
  326. page.value = 0
  327. };
  328. </script>
  329. <style lang="scss" scoped>
  330. .content {
  331. display: flex;
  332. flex-direction: column;
  333. width: 100vw;
  334. height: 100vh;
  335. .top {
  336. margin: 2vw;
  337. .search {
  338. display: flex;
  339. justify-content: space-between;
  340. align-items: center;
  341. padding: 2vw 2vw 0 2vw;
  342. .list {
  343. display: flex;
  344. align-items: center;
  345. padding: 1vw 0;
  346. .title_1 {
  347. margin: 0 1vw 0 0;
  348. font-size: var(--font14Size);
  349. }
  350. .title_2 {
  351. margin: 0 1vw 0 0;
  352. font-size: var(--font14Size);
  353. color: var(--fFFColor);
  354. }
  355. }
  356. }
  357. .popup-layer {
  358. position: absolute;
  359. z-index: 999999;
  360. background: rgba(0, 0, 0, .3);
  361. height: calc(100% - 50px);
  362. width: 100%;
  363. left: 0px;
  364. overflow: hidden;
  365. height: 87.5vh;
  366. }
  367. .popup-content {
  368. position: absolute;
  369. width: 100%;
  370. z-index: 1000000;
  371. background: #FFFFFF;
  372. transition: all .3s ease;
  373. .search_1 {
  374. display: flex;
  375. flex-wrap: wrap;
  376. padding: 2vw;
  377. .list {
  378. font-size: var(--font14Size);
  379. width: 24vw;
  380. text-align: center;
  381. .title_1 {
  382. padding: 2vw;
  383. margin: 1vw;
  384. background-color: var(--f5Color);
  385. }
  386. .title_2 {
  387. padding: 2vw;
  388. margin: 1vw;
  389. background: rgba(255, 222, 173, 0.35);
  390. border: 1px solid var(--fFFColor);
  391. }
  392. }
  393. }
  394. }
  395. .search_2 {
  396. padding: 2vw;
  397. background-color: var(--f5Color);
  398. display: flex;
  399. justify-content: space-between;
  400. align-items: center;
  401. .left {
  402. width: 80vw;
  403. .scroll {
  404. display: flex;
  405. white-space: nowrap;
  406. .title {
  407. font-size: var(--font14Size);
  408. display: flex;
  409. padding: 2vw;
  410. margin: 1vw;
  411. background-color: var(--mainColor);
  412. }
  413. }
  414. }
  415. }
  416. }
  417. .bottom {
  418. position: relative;
  419. flex-grow: 1;
  420. .one {
  421. margin: 0 2vw 2vw 2vw;
  422. .list {
  423. display: flex;
  424. margin: 1vw 0 0 0;
  425. padding: 1vw;
  426. .left {
  427. .image {
  428. width: 130px;
  429. height: 100px;
  430. border-radius: 2px;
  431. }
  432. }
  433. .right {
  434. display: flex;
  435. flex-direction: column;
  436. justify-content: space-between;
  437. margin: 0 0 0 2vw;
  438. width: 100%;
  439. .name {
  440. font-size: var(--font14Size);
  441. }
  442. .other {
  443. color: var(--f85Color);
  444. font-size: var(--font12Size);
  445. }
  446. .right_1 {
  447. display: flex;
  448. justify-content: space-between;
  449. align-items: center;
  450. .money {
  451. color: var(--fF0Color);
  452. font-size: var(--font12Size);
  453. text:first-child {
  454. font-size: var(--font18Size);
  455. }
  456. }
  457. .button {
  458. background-color: var(--fFFColor);
  459. }
  460. }
  461. }
  462. }
  463. }
  464. }
  465. }
  466. .scroll-view {
  467. position: absolute;
  468. top: 0;
  469. left: 0;
  470. right: 0;
  471. bottom: 0;
  472. .list-scroll-view {
  473. display: flex;
  474. flex-direction: column;
  475. }
  476. }
  477. .is_bottom {
  478. width: 100%;
  479. text-align: center;
  480. text {
  481. padding: 2vw 0;
  482. display: inline-block;
  483. color: var(--f85Color);
  484. font-size: var(--font12Size);
  485. }
  486. }
  487. </style>