index.vue 13 KB

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