index.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. <template>
  2. <view class="content">
  3. <view class="info">
  4. <scroll-view scroll-y="true" class="scroll-view" @scrolltolower="toPage">
  5. <view class="list-scroll-view">
  6. <view class="top">
  7. <image class="image" src="https://cdn.uviewui.com/uview/album/1.jpg" />
  8. </view>
  9. <view class="bottom">
  10. <view class="one">
  11. <view class="name">
  12. {{shop.name||'暂无'}}
  13. </view>
  14. <view class="other">
  15. <view class="left">
  16. <view class="left_1">
  17. <span>在售 {{shop.sale||'0'}} 辆</span>
  18. |
  19. <span>已售 {{shop.sold||'0'}} 辆</span>
  20. </view>
  21. <view class="left_2">
  22. <span>{{shop.status=='0'?'营业中':'休息中'}}</span>&nbsp;
  23. <span>{{shop.start_time||'8:00'}}-{{shop.end_time||'17:00'}}</span>
  24. </view>
  25. <view class="left_3">
  26. <u-icon name="file-text" size="16"></u-icon>
  27. <text>营业执照</text>
  28. </view>
  29. </view>
  30. <view class="center">
  31. <u-line direction="col"></u-line>
  32. </view>
  33. <view class="right">{{shop.address||'暂无'}}</view>
  34. </view>
  35. </view>
  36. <view class="two">
  37. <view class="search">
  38. <view class="searchlist" v-for="(item, index) in searchList" :key="index"
  39. @tap="toSearch(item)">
  40. <view :class="[item.is_open==false?'title_1':'title_2']">{{item.title}}</view>
  41. <u-icon color="#000" size="10px" v-if="item.is_open==false"
  42. name="arrow-down-fill"></u-icon>
  43. <u-icon color="#ffbc00" size="10px" v-else name="arrow-up-fill"></u-icon>
  44. </view>
  45. </view>
  46. <view v-show="is_show" @tap="toClose" class="popup-layer">
  47. <view class="popup-content">
  48. <view class="search_1" v-if="type=='0'">
  49. <view class="list" v-for="(item, index) in sortList" :key="index"
  50. @tap="toSelect(item,type)">
  51. <view :class="[item.is_open==false?'title_1':'title_2']">{{item.title}}
  52. </view>
  53. </view>
  54. </view>
  55. <view class="search_1" v-else-if="type=='2'">
  56. <view class="list" v-for="(item, index) in moneyList" :key="index"
  57. @tap="toSelect(item,type)">
  58. <view :class="[item.is_open==false?'title_1':'title_2']">{{item.title}}
  59. </view>
  60. </view>
  61. </view>
  62. <view class="search_1" v-else-if="type=='3'">
  63. <view class="list" v-for="(item, index) in yearList" :key="index"
  64. @tap="toSelect(item,type)">
  65. <view :class="[item.is_open==false?'title_1':'title_2']">{{item.title}}
  66. </view>
  67. </view>
  68. </view>
  69. <view class="search_1" v-else>
  70. <view class="list" v-for="(item, index) in yearList" :key="index"
  71. @tap="toSelect(item,type)">
  72. <view :class="[item.is_open==false?'title_1':'title_2']">{{item.title}}
  73. </view>
  74. </view>
  75. </view>
  76. </view>
  77. </view>
  78. <view class="search_2"
  79. v-if="Object.keys(brandInfo).length > 0||Object.keys(moneyInfo).length > 0||Object.keys(yearInfo).length > 0||moreList.length>0">
  80. <view class="left">
  81. <scroll-view scroll-x="true">
  82. <view class="scroll">
  83. <view v-if="brandInfo&&brandInfo.type" class="title"
  84. @tap="toDelete({},'0')">
  85. <span>{{brandInfo.title}}</span>&nbsp;
  86. <u-icon color="#000" size="14px" name="close"></u-icon>
  87. </view>
  88. <view v-if="moneyInfo&&moneyInfo.type" class="title"
  89. @tap="toDelete({},'1')">
  90. <span>{{moneyInfo.title}}</span>&nbsp;
  91. <u-icon color="#000" size="14px" name="close"></u-icon>
  92. </view>
  93. <view v-if="yearInfo&&yearInfo.type" class="title" @tap="toDelete({},'2')">
  94. <span>{{yearInfo.title}}</span>&nbsp;
  95. <u-icon color="#000" size="14px" name="close"></u-icon>
  96. </view>
  97. <view v-if="moreList.length>0" class="title"
  98. v-for="(item, index) in moreList" :key="index"
  99. @tap="toDelete(item,'3')">
  100. <span>{{item.title}}</span>&nbsp;
  101. <u-icon color="#000" size="14px" name="close"></u-icon>
  102. </view>
  103. </view>
  104. </scroll-view>
  105. </view>
  106. <view class="right">
  107. <view class="right_1" @tap="toReset">重置</view>
  108. </view>
  109. </view>
  110. <!-- 瀑布流布局列表 -->
  111. <view class="pubuBox">
  112. <view class="pubuItem">
  113. <view class="list" v-for="(item, index) in list" :key="index" @tap="toView(item)">
  114. <view class="list_1">
  115. <view class="left">
  116. <image class="image"
  117. :src="item.file&&item.file.length>0?item.file[0].url:''">
  118. </image>
  119. </view>
  120. <view class="right">
  121. <view class="name textOver">{{item.series||'暂无'}} {{item.year||'暂无'}}款
  122. {{item.style||'暂无'}}
  123. </view>
  124. <view class="other">
  125. <text v-if="item.year">{{item.year||'暂无'}}年 | </text>
  126. <text v-if="item.mileage">{{item.mileage||'暂无'}}公里 | </text>
  127. <text v-if="item.place">{{item.place||'暂无'}}</text>
  128. </view>
  129. <view class="money">
  130. <text>{{item.total_money||'0'}}</text>
  131. <text>万</text>
  132. </view>
  133. </view>
  134. </view>
  135. </view>
  136. </view>
  137. </view>
  138. <view class="is_bottom" v-if="is_bottom">
  139. <text>{{config.bottom_title||'没有更多了!'}}</text>
  140. </view>
  141. </view>
  142. </view>
  143. </view>
  144. </scroll-view>
  145. </view>
  146. <view class="foot">
  147. <u-button icon="phone" text="电话联系" size="normal" type="info" @click="toChat"></u-button>
  148. </view>
  149. </view>
  150. </template>
  151. <script setup lang="ts">
  152. import { getCurrentInstance, computed, ref } from 'vue';
  153. //该依赖已内置不需要单独安装
  154. import { onLoad, onShow } from "@dcloudio/uni-app";
  155. // 请求接口
  156. const $api = getCurrentInstance()?.appContext.config.globalProperties.$api;
  157. // openid
  158. const openid = computed(() => {
  159. return uni.getStorageSync('openid');
  160. })
  161. // 基本信息
  162. const config = ref({});
  163. const id = ref('');
  164. const imageURL = ref('https://cdn.uviewui.com/uview/album/1.jpg');
  165. // 店铺
  166. const shop = ref({});
  167. const type = ref('0');
  168. const is_show = ref(false);
  169. //查询
  170. 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 }, { title: '更多筛选', type: '4', is_open: false }]);
  171. //排序
  172. 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 }]);
  173. //价格
  174. 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 }]);
  175. //车龄
  176. const yearList = ref([{ title: '不限车龄', type: '0', is_open: true }, { title: '2年以下', type: '1', is_open: false }, { title: '4年以下', type: '2', is_open: false }, { title: '6年以下', type: '3', is_open: false }]);
  177. // 选择的查询条件
  178. const brandInfo = ref({});
  179. const moneyInfo = ref({});
  180. const yearInfo = ref({});
  181. const moreList = ref([]);
  182. // 字典表
  183. const typeList = ref([
  184. {
  185. title: '5万以下',
  186. type: '0',
  187. },
  188. {
  189. title: '5-10万',
  190. type: '1',
  191. },
  192. {
  193. title: '10-15万',
  194. type: '2',
  195. },
  196. {
  197. title: '更多条件',
  198. type: '3',
  199. }
  200. ]);
  201. const carList = ref([
  202. {
  203. title: '大众',
  204. type: '0',
  205. },
  206. {
  207. title: '宝马',
  208. type: '1',
  209. },
  210. {
  211. title: '本田',
  212. type: '2',
  213. },
  214. {
  215. title: '丰田',
  216. type: '3',
  217. },
  218. {
  219. title: '更多品牌',
  220. type: '4',
  221. }
  222. ]);
  223. // 列表
  224. const list = ref([]);
  225. const total = ref(0);
  226. const skip = ref(0);
  227. const limit = ref(6);
  228. const page = ref(0);
  229. // 数据是否触底
  230. const is_bottom = ref(false);
  231. const scrollTop = ref(0);
  232. onLoad(async (options) => {
  233. id.value = options && options.id
  234. uni.setNavigationBarTitle({
  235. title: options && options.name || '车行详情'
  236. });
  237. await searchConfig();
  238. await search();
  239. await searchOther();
  240. })
  241. onShow(() => {
  242. uni.$on('toRoute', function (data) {
  243. brandInfo.value = data
  244. })
  245. })
  246. // config信息
  247. const searchConfig = async () => {
  248. config.value = uni.getStorageSync('config');
  249. };
  250. // 查询
  251. const search = async () => {
  252. if (id.value) {
  253. const res = await $api(`shop/${id.value}`, 'GET', {});
  254. if (res.errcode === 0) {
  255. shop.value = res.data
  256. } else {
  257. uni.showToast({
  258. title: res.errmsg || '',
  259. icon: 'error',
  260. });
  261. }
  262. }
  263. };
  264. // 查询其他信息
  265. const searchOther = async () => {
  266. let res;
  267. const info = {
  268. skip: skip.value,
  269. limit: limit.value,
  270. status: '0',
  271. shop: id.value
  272. }
  273. res = await $api('car', 'GET', {
  274. ...info,
  275. });
  276. if (res.errcode === 0) {
  277. list.value = list.value.concat(res.data)
  278. total.value = res.total
  279. shop.value.sale = res.total
  280. } else {
  281. uni.showToast({
  282. title: res.errmsg || '',
  283. icon: 'error',
  284. });
  285. }
  286. res = await $api('car', 'GET', {
  287. skip: 0,
  288. limit: 1,
  289. status: '1',
  290. shop: id.value
  291. });
  292. if (res.errcode === 0) shop.value.sold = res.total
  293. };
  294. // 查询
  295. const toSearch = (value) => {
  296. // 判断点击的是那个筛选
  297. searchList.value = searchList.value.map((item, index) => {
  298. if (item.type == value.type && !item.is_open) item.is_open = true
  299. else item.is_open = false
  300. return item
  301. })
  302. type.value = value.type
  303. if (value.type == '1') {
  304. toClose()
  305. uni.navigateTo({
  306. url: `/pagesHome/brand/index`,
  307. })
  308. }
  309. else if (value.type == '4') {
  310. toClose()
  311. uni.navigateTo({
  312. url: `/pagesHome/condition/index`,
  313. })
  314. } else is_show.value = searchList.value.some(item => item.is_open == true)
  315. };
  316. // 关闭筛选
  317. const toClose = () => {
  318. is_show.value = false
  319. searchList.value = searchList.value.map((item, index) => {
  320. item.is_open = false
  321. return item
  322. })
  323. };
  324. // 选择
  325. const toSelect = (data, type) => {
  326. // 判断点击的是那个筛选
  327. if (type == '0') {
  328. sortList.value = sortList.value.map((item, index) => {
  329. if (item.type == data.type) item.is_open = true
  330. else item.is_open = false
  331. return item
  332. })
  333. searchList.value = searchList.value.map((i, index) => {
  334. if (i.type == '0') i.title = data.title
  335. return i
  336. })
  337. } else if (type == '2') {
  338. moneyList.value = moneyList.value.map((item, index) => {
  339. if (item.type == data.type) item.is_open = true
  340. else item.is_open = false
  341. return item
  342. })
  343. moneyInfo.value = data
  344. } else {
  345. yearList.value = yearList.value.map((item, index) => {
  346. if (item.type == data.type) item.is_open = true
  347. else item.is_open = false
  348. return item
  349. })
  350. yearInfo.value = data
  351. }
  352. };
  353. // 删除筛选
  354. const toDelete = (item, type) => {
  355. if (type == '0') brandInfo.value = {}
  356. else if (type == '1') {
  357. moneyList.value = moneyList.value.map((item, index) => {
  358. if (item.type == '0') item.is_open = true
  359. else item.is_open = false
  360. return item
  361. })
  362. moneyInfo.value = {}
  363. }
  364. else if (type == '2') {
  365. yearList.value = yearList.value.map((item, index) => {
  366. if (item.type == '0') item.is_open = true
  367. else item.is_open = false
  368. return item
  369. })
  370. yearInfo.value = {}
  371. }
  372. else moreList.value = moreList.value.filter((i, index) => i.type != item.type)
  373. };
  374. // 重置
  375. const toReset = () => {
  376. toDelete({}, '0')
  377. toDelete({}, '1')
  378. toDelete({}, '2')
  379. moreList.value = []
  380. toClear();
  381. };
  382. // 清除
  383. const toClear = () => {
  384. searchList.value = searchList.value.map((i, index) => {
  385. if (i.type == '0') i.title = '默认排序'
  386. return i
  387. })
  388. sortList.value = sortList.value.map((item, index) => {
  389. if (item.type == '0') item.is_open = true;
  390. else item.is_open = false
  391. return item
  392. })
  393. };
  394. // 联系卖家
  395. const toChat = (item) => {
  396. uni.makePhoneCall({
  397. phoneNumber: item.shop || '110',
  398. success: function () {
  399. console.log('拨打电话成功');
  400. },
  401. fail: function () {
  402. console.log('拨打电话失败');
  403. }
  404. });
  405. };
  406. // 查看详情
  407. const toView = (item) => {
  408. uni.navigateTo({
  409. url: `/pagesHome/car/index?id=${item.id || item._id}`
  410. })
  411. };
  412. // 分页
  413. const toPage = () => {
  414. if (total.value > list.value.length) {
  415. uni.showLoading({
  416. title: '加载中',
  417. mask: true
  418. })
  419. page.value = page.value + 1;
  420. skip.value = page.value * limit.value;
  421. search();
  422. uni.hideLoading();
  423. } else is_bottom.value = true
  424. };
  425. // 清空列表
  426. const clearPage = () => {
  427. list.value = []
  428. skip.value = 0
  429. limit.value = 6
  430. page.value = 0
  431. };
  432. </script>
  433. <style lang="scss" scoped>
  434. .content {
  435. display: flex;
  436. flex-direction: column;
  437. width: 100vw;
  438. height: 100vh;
  439. .info {
  440. position: relative;
  441. flex-grow: 1;
  442. background-color: var(--f1Color);
  443. .top {
  444. .image {
  445. width: 100%;
  446. height: 55vw;
  447. }
  448. }
  449. .bottom {
  450. margin: -8vw 2vw 0 2vw;
  451. .one {
  452. border-radius: 5px;
  453. padding: 2vw;
  454. background-color: var(--mainColor);
  455. .name {
  456. font-size: var(--font16Size);
  457. }
  458. .other {
  459. display: flex;
  460. justify-content: space-between;
  461. font-size: var(--font12Size);
  462. padding: 2vw 0;
  463. .left {
  464. width: 45%;
  465. .left_2 {
  466. margin: 1vw 0;
  467. }
  468. .left_3 {
  469. display: flex;
  470. align-items: center;
  471. text {
  472. margin: 0 0 1vw 0;
  473. color: #606266;
  474. }
  475. }
  476. }
  477. .right {
  478. width: 45%;
  479. }
  480. }
  481. }
  482. .two {
  483. .search {
  484. display: flex;
  485. justify-content: space-between;
  486. align-items: center;
  487. padding: 2vw 2vw 0 2vw;
  488. .searchlist {
  489. display: flex;
  490. align-items: center;
  491. padding: 1vw 0;
  492. .title_1 {
  493. margin: 0 1vw 0 0;
  494. font-size: var(--font14Size);
  495. }
  496. .title_2 {
  497. margin: 0 1vw 0 0;
  498. font-size: var(--font14Size);
  499. color: var(--fFFColor);
  500. }
  501. }
  502. }
  503. .popup-layer {
  504. position: absolute;
  505. z-index: 999999;
  506. background: rgba(0, 0, 0, .3);
  507. height: calc(100% - 50px);
  508. width: 100%;
  509. left: 0px;
  510. overflow: hidden;
  511. height: 87.5vh;
  512. }
  513. .popup-content {
  514. position: absolute;
  515. width: 100%;
  516. z-index: 1000000;
  517. background: #FFFFFF;
  518. transition: all .3s ease;
  519. .search_1 {
  520. display: flex;
  521. flex-wrap: wrap;
  522. padding: 2vw;
  523. .list {
  524. font-size: var(--font14Size);
  525. width: 24vw;
  526. text-align: center;
  527. .title_1 {
  528. padding: 2vw;
  529. margin: 1vw;
  530. background-color: var(--f5Color);
  531. }
  532. .title_2 {
  533. padding: 2vw;
  534. margin: 1vw;
  535. background: rgba(255, 222, 173, 0.35);
  536. border: 1px solid var(--fFFColor);
  537. }
  538. }
  539. }
  540. }
  541. .search_2 {
  542. padding: 2vw;
  543. background-color: var(--f5Color);
  544. display: flex;
  545. justify-content: space-between;
  546. align-items: center;
  547. .left {
  548. width: 80vw;
  549. .scroll {
  550. display: flex;
  551. white-space: nowrap;
  552. .title {
  553. font-size: var(--font14Size);
  554. display: flex;
  555. padding: 2vw;
  556. margin: 1vw;
  557. background-color: var(--mainColor);
  558. }
  559. }
  560. }
  561. }
  562. .pubuBox {
  563. padding: 2vw 0;
  564. }
  565. .pubuItem {
  566. column-count: 2;
  567. column-gap: 2vw;
  568. }
  569. .list {
  570. box-sizing: border-box;
  571. border-radius: 2vw;
  572. overflow: hidden;
  573. background-color: var(--mainColor);
  574. break-inside: avoid;
  575. /*避免在元素内部插入分页符*/
  576. box-sizing: border-box;
  577. margin-bottom: 2vw;
  578. .list_1 {
  579. .left {
  580. .image {
  581. width: 100%;
  582. height: 120px;
  583. border-radius: 5px 5px 0 0;
  584. }
  585. }
  586. .right {
  587. display: flex;
  588. flex-direction: column;
  589. justify-content: space-between;
  590. padding: 0 2vw;
  591. .name {
  592. font-size: var(--font14Size);
  593. }
  594. .other {
  595. color: var(--f85Color);
  596. font-size: var(--font12Size);
  597. }
  598. .money {
  599. color: var(--fF0Color);
  600. font-size: var(--font12Size);
  601. margin: 0 0 1vw 0;
  602. text:first-child {
  603. font-size: var(--font18Size);
  604. }
  605. }
  606. }
  607. }
  608. }
  609. }
  610. }
  611. }
  612. .foot {
  613. padding: 2vw 1vw;
  614. }
  615. }
  616. .scroll-view {
  617. position: absolute;
  618. top: 0;
  619. left: 0;
  620. right: 0;
  621. bottom: 0;
  622. .list-scroll-view {
  623. display: flex;
  624. flex-direction: column;
  625. }
  626. }
  627. .is_bottom {
  628. width: 100%;
  629. text-align: center;
  630. text {
  631. padding: 2vw 0;
  632. display: inline-block;
  633. color: var(--f85Color);
  634. font-size: var(--font12Size);
  635. }
  636. }
  637. </style>