index.vue 13 KB

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