index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  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. if (options && options.type != '3') {
  121. searchInfo.value.brand = options && options.brand || ''
  122. searchInfo.value.money = options && options.money || ''
  123. }
  124. await searchConfig();
  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. if (data.type != '0') searchInfo.value.money = data.title
  215. else searchInfo.value.money = ''
  216. }
  217. await clearPage();
  218. await search();
  219. };
  220. // 删除筛选
  221. const toDelete = async (item, type) => {
  222. if (type == '0') searchInfo.value.brand = ''
  223. else if (type == '1') {
  224. moneyList.value = moneyList.value.map((item, index) => {
  225. if (item.type == '0') item.is_open = true
  226. else item.is_open = false
  227. return item
  228. })
  229. searchInfo.value.money = ''
  230. }
  231. else moreList.value = moreList.value.filter((i, index) => i.type != item.type)
  232. await clearPage();
  233. await search();
  234. };
  235. // 重置
  236. const toReset = async () => {
  237. searchInfo.value.brand = ''
  238. searchInfo.value.money = ''
  239. moreList.value = []
  240. toClear();
  241. await clearPage();
  242. await search();
  243. };
  244. // 清除
  245. const toClear = () => {
  246. searchList.value = searchList.value.map((i, index) => {
  247. if (i.type == '0') i.title = '默认排序'
  248. return i
  249. })
  250. moneyList.value = moneyList.value.map((item, index) => {
  251. if (item.type == '0') item.is_open = true
  252. else item.is_open = false
  253. return item
  254. })
  255. sortList.value = sortList.value.map((item, index) => {
  256. if (item.type == '0') item.is_open = true
  257. else item.is_open = false
  258. return item
  259. })
  260. };
  261. // 联系卖家
  262. const toChat = (item) => {
  263. uni.makePhoneCall({
  264. phoneNumber: item.shop?.tel,
  265. success: function () {
  266. console.log('拨打电话成功');
  267. },
  268. fail: function () {
  269. uni.showToast({
  270. title: '拨打电话失败',
  271. icon: 'error',
  272. });
  273. }
  274. });
  275. };
  276. // 查看详情
  277. const toView = (item) => {
  278. uni.navigateTo({
  279. url: `/pagesHome/car/index?id=${item.id || item._id}`
  280. })
  281. };
  282. // 分页
  283. const toPage = () => {
  284. if (total.value > list.value.length) {
  285. uni.showLoading({
  286. title: '加载中',
  287. mask: true
  288. })
  289. page.value = page.value + 1;
  290. skip.value = page.value * limit.value;
  291. search();
  292. uni.hideLoading();
  293. } else is_bottom.value = true
  294. };
  295. // 清空列表
  296. const clearPage = () => {
  297. list.value = []
  298. skip.value = 0
  299. limit.value = 6
  300. page.value = 0
  301. };
  302. </script>
  303. <style lang="scss" scoped>
  304. .content {
  305. display: flex;
  306. flex-direction: column;
  307. width: 100vw;
  308. height: 100vh;
  309. .top {
  310. margin: 2vw;
  311. .search {
  312. display: flex;
  313. justify-content: space-between;
  314. align-items: center;
  315. padding: 2vw 2vw 0 2vw;
  316. .list {
  317. display: flex;
  318. align-items: center;
  319. padding: 1vw 0;
  320. .title_1 {
  321. margin: 0 1vw 0 0;
  322. font-size: var(--font14Size);
  323. }
  324. .title_2 {
  325. margin: 0 1vw 0 0;
  326. font-size: var(--font14Size);
  327. color: var(--fFFColor);
  328. }
  329. }
  330. }
  331. .popup-layer {
  332. position: absolute;
  333. z-index: 999999;
  334. background: rgba(0, 0, 0, .3);
  335. height: calc(100% - 50px);
  336. width: 100%;
  337. left: 0px;
  338. overflow: hidden;
  339. height: 87.5vh;
  340. }
  341. .popup-content {
  342. position: absolute;
  343. width: 100%;
  344. z-index: 1000000;
  345. background: #FFFFFF;
  346. transition: all .3s ease;
  347. .search_1 {
  348. display: flex;
  349. flex-wrap: wrap;
  350. padding: 2vw;
  351. .list {
  352. font-size: var(--font14Size);
  353. width: 24vw;
  354. text-align: center;
  355. .title_1 {
  356. padding: 2vw;
  357. margin: 1vw;
  358. background-color: var(--f5Color);
  359. }
  360. .title_2 {
  361. padding: 2vw;
  362. margin: 1vw;
  363. background: rgba(255, 222, 173, 0.35);
  364. border: 1px solid var(--fFFColor);
  365. }
  366. }
  367. }
  368. }
  369. .search_2 {
  370. padding: 2vw;
  371. background-color: var(--f5Color);
  372. display: flex;
  373. justify-content: space-between;
  374. align-items: center;
  375. .left {
  376. width: 80vw;
  377. .scroll {
  378. display: flex;
  379. white-space: nowrap;
  380. .title {
  381. font-size: var(--font14Size);
  382. display: flex;
  383. padding: 2vw;
  384. margin: 1vw;
  385. background-color: var(--mainColor);
  386. }
  387. }
  388. }
  389. }
  390. }
  391. .bottom {
  392. position: relative;
  393. flex-grow: 1;
  394. .one {
  395. margin: 0 2vw 2vw 2vw;
  396. .list {
  397. display: flex;
  398. margin: 1vw 0 0 0;
  399. padding: 1vw;
  400. .left {
  401. .image {
  402. width: 130px;
  403. height: 100px;
  404. border-radius: 2px;
  405. }
  406. }
  407. .right {
  408. display: flex;
  409. flex-direction: column;
  410. justify-content: space-between;
  411. margin: 0 0 0 2vw;
  412. width: 100%;
  413. .name {
  414. font-size: var(--font14Size);
  415. }
  416. .other {
  417. color: var(--f85Color);
  418. font-size: var(--font12Size);
  419. }
  420. .right_1 {
  421. display: flex;
  422. justify-content: space-between;
  423. align-items: center;
  424. .money {
  425. color: var(--fF0Color);
  426. font-size: var(--font12Size);
  427. text:first-child {
  428. font-size: var(--font18Size);
  429. }
  430. }
  431. .button {
  432. background-color: var(--fFFColor);
  433. }
  434. }
  435. }
  436. }
  437. }
  438. }
  439. }
  440. .scroll-view {
  441. position: absolute;
  442. top: 0;
  443. left: 0;
  444. right: 0;
  445. bottom: 0;
  446. .list-scroll-view {
  447. display: flex;
  448. flex-direction: column;
  449. }
  450. }
  451. .is_bottom {
  452. width: 100%;
  453. text-align: center;
  454. text {
  455. padding: 2vw 0;
  456. display: inline-block;
  457. color: var(--f85Color);
  458. font-size: var(--font12Size);
  459. }
  460. }
  461. </style>