index.vue 13 KB

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