index.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  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="shop.logo&&shop.logo?.length>0?shop.logo[0].url:'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" @tap="toImage">
  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. // 店铺
  165. const shop = ref({});
  166. const type = ref('0');
  167. const is_show = ref(false);
  168. //查询
  169. 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 }]);
  170. //排序
  171. 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 }]);
  172. //价格
  173. 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 }]);
  174. //车龄
  175. 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 }]);
  176. // 选择的查询条件
  177. const brandInfo = ref({});
  178. const moneyInfo = ref({});
  179. const yearInfo = ref({});
  180. const moreList = ref([]);
  181. // 列表
  182. const list = ref([]);
  183. const total = ref(0);
  184. const skip = ref(0);
  185. const limit = ref(6);
  186. const page = ref(0);
  187. // 数据是否触底
  188. const is_bottom = ref(false);
  189. const scrollTop = ref(0);
  190. onLoad(async (options) => {
  191. id.value = options && options.id
  192. uni.setNavigationBarTitle({
  193. title: options && options.name || '车行详情'
  194. });
  195. await searchConfig();
  196. await search();
  197. await searchOther();
  198. })
  199. onShow(() => {
  200. uni.$on('toRoute', function (data) {
  201. brandInfo.value = data
  202. })
  203. })
  204. // config信息
  205. const searchConfig = async () => {
  206. config.value = uni.getStorageSync('config');
  207. };
  208. // 查询
  209. const search = async () => {
  210. if (id.value) {
  211. const res = await $api(`shop/${id.value}`, 'GET', {});
  212. if (res.errcode === 0) {
  213. shop.value = res.data
  214. } else {
  215. uni.showToast({
  216. title: res.errmsg || '',
  217. icon: 'error',
  218. });
  219. }
  220. }
  221. };
  222. // 查询其他信息
  223. const searchOther = async () => {
  224. let res;
  225. const info = {
  226. skip: skip.value,
  227. limit: limit.value,
  228. status: '0',
  229. shop: id.value
  230. }
  231. res = await $api('car', 'GET', {
  232. ...info,
  233. });
  234. if (res.errcode === 0) {
  235. list.value = list.value.concat(res.data)
  236. total.value = res.total
  237. shop.value.sale = res.total
  238. } else {
  239. uni.showToast({
  240. title: res.errmsg || '',
  241. icon: 'error',
  242. });
  243. }
  244. res = await $api('car', 'GET', {
  245. skip: 0,
  246. limit: 1,
  247. status: '1',
  248. shop: id.value
  249. });
  250. if (res.errcode === 0) shop.value.sold = res.total
  251. };
  252. // 查询
  253. const toSearch = (value) => {
  254. // 判断点击的是那个筛选
  255. searchList.value = searchList.value.map((item, index) => {
  256. if (item.type == value.type && !item.is_open) item.is_open = true
  257. else item.is_open = false
  258. return item
  259. })
  260. type.value = value.type
  261. if (value.type == '1') {
  262. toClose()
  263. uni.navigateTo({
  264. url: `/pagesHome/brand/index`,
  265. })
  266. }
  267. else if (value.type == '4') {
  268. toClose()
  269. uni.navigateTo({
  270. url: `/pagesHome/condition/index`,
  271. })
  272. } else is_show.value = searchList.value.some(item => item.is_open == true)
  273. };
  274. // 关闭筛选
  275. const toClose = () => {
  276. is_show.value = false
  277. searchList.value = searchList.value.map((item, index) => {
  278. item.is_open = false
  279. return item
  280. })
  281. };
  282. // 选择
  283. const toSelect = (data, type) => {
  284. // 判断点击的是那个筛选
  285. if (type == '0') {
  286. sortList.value = sortList.value.map((item, index) => {
  287. if (item.type == data.type) item.is_open = true
  288. else item.is_open = false
  289. return item
  290. })
  291. searchList.value = searchList.value.map((i, index) => {
  292. if (i.type == '0') i.title = data.title
  293. return i
  294. })
  295. } else if (type == '2') {
  296. moneyList.value = moneyList.value.map((item, index) => {
  297. if (item.type == data.type) item.is_open = true
  298. else item.is_open = false
  299. return item
  300. })
  301. moneyInfo.value = data
  302. } else {
  303. yearList.value = yearList.value.map((item, index) => {
  304. if (item.type == data.type) item.is_open = true
  305. else item.is_open = false
  306. return item
  307. })
  308. yearInfo.value = data
  309. }
  310. };
  311. // 删除筛选
  312. const toDelete = (item, type) => {
  313. if (type == '0') brandInfo.value = {}
  314. else if (type == '1') {
  315. moneyList.value = moneyList.value.map((item, index) => {
  316. if (item.type == '0') item.is_open = true
  317. else item.is_open = false
  318. return item
  319. })
  320. moneyInfo.value = {}
  321. }
  322. else if (type == '2') {
  323. yearList.value = yearList.value.map((item, index) => {
  324. if (item.type == '0') item.is_open = true
  325. else item.is_open = false
  326. return item
  327. })
  328. yearInfo.value = {}
  329. }
  330. else moreList.value = moreList.value.filter((i, index) => i.type != item.type)
  331. };
  332. // 重置
  333. const toReset = () => {
  334. toDelete({}, '0')
  335. toDelete({}, '1')
  336. toDelete({}, '2')
  337. moreList.value = []
  338. toClear();
  339. };
  340. // 清除
  341. const toClear = () => {
  342. searchList.value = searchList.value.map((i, index) => {
  343. if (i.type == '0') i.title = '默认排序'
  344. return i
  345. })
  346. sortList.value = sortList.value.map((item, index) => {
  347. if (item.type == '0') item.is_open = true;
  348. else item.is_open = false
  349. return item
  350. })
  351. };
  352. // 联系卖家
  353. const toChat = (item) => {
  354. uni.makePhoneCall({
  355. phoneNumber: item.shop || '110',
  356. success: function () {
  357. console.log('拨打电话成功');
  358. },
  359. fail: function () {
  360. console.log('拨打电话失败');
  361. }
  362. });
  363. };
  364. // 查看详情
  365. const toView = (item) => {
  366. uni.navigateTo({
  367. url: `/pagesHome/car/index?id=${item.id || item._id}`
  368. })
  369. };
  370. // 预览营业执照
  371. const toImage = () => {
  372. if (shop.value?.file.length > 0) {
  373. // 预览图片
  374. uni.previewImage({
  375. urls: [shop.value.file[0].url],
  376. longPressActions: {
  377. itemList: ['发送给朋友', '保存图片', '收藏'],
  378. success: function (data) {
  379. console.log('选中了第' + (data.tapIndex + 1) + '个按钮,第' + (data.index + 1) + '张图片');
  380. },
  381. fail: function (err) {
  382. console.log(err.errMsg);
  383. }
  384. }
  385. });
  386. }
  387. };
  388. // 分页
  389. const toPage = () => {
  390. if (total.value > list.value.length) {
  391. uni.showLoading({
  392. title: '加载中',
  393. mask: true
  394. })
  395. page.value = page.value + 1;
  396. skip.value = page.value * limit.value;
  397. search();
  398. uni.hideLoading();
  399. } else is_bottom.value = true
  400. };
  401. // 清空列表
  402. const clearPage = () => {
  403. list.value = []
  404. skip.value = 0
  405. limit.value = 6
  406. page.value = 0
  407. };
  408. </script>
  409. <style lang="scss" scoped>
  410. .content {
  411. display: flex;
  412. flex-direction: column;
  413. width: 100vw;
  414. height: 100vh;
  415. .info {
  416. position: relative;
  417. flex-grow: 1;
  418. background-color: var(--f1Color);
  419. .top {
  420. .image {
  421. width: 100%;
  422. height: 55vw;
  423. }
  424. }
  425. .bottom {
  426. margin: -8vw 2vw 0 2vw;
  427. .one {
  428. border-radius: 5px;
  429. padding: 2vw;
  430. background-color: var(--mainColor);
  431. .name {
  432. font-size: var(--font16Size);
  433. }
  434. .other {
  435. display: flex;
  436. justify-content: space-between;
  437. font-size: var(--font12Size);
  438. padding: 2vw 0;
  439. .left {
  440. width: 45%;
  441. .left_2 {
  442. margin: 1vw 0;
  443. }
  444. .left_3 {
  445. display: flex;
  446. align-items: center;
  447. text {
  448. margin: 0 0 1vw 0;
  449. color: #606266;
  450. }
  451. }
  452. }
  453. .right {
  454. width: 45%;
  455. }
  456. }
  457. }
  458. .two {
  459. .search {
  460. display: flex;
  461. justify-content: space-between;
  462. align-items: center;
  463. padding: 2vw 2vw 0 2vw;
  464. .searchlist {
  465. display: flex;
  466. align-items: center;
  467. padding: 1vw 0;
  468. .title_1 {
  469. margin: 0 1vw 0 0;
  470. font-size: var(--font14Size);
  471. }
  472. .title_2 {
  473. margin: 0 1vw 0 0;
  474. font-size: var(--font14Size);
  475. color: var(--fFFColor);
  476. }
  477. }
  478. }
  479. .popup-layer {
  480. position: absolute;
  481. z-index: 999999;
  482. background: rgba(0, 0, 0, .3);
  483. height: calc(100% - 50px);
  484. width: 100%;
  485. left: 0px;
  486. overflow: hidden;
  487. height: 87.5vh;
  488. }
  489. .popup-content {
  490. position: absolute;
  491. width: 100%;
  492. z-index: 1000000;
  493. background: #FFFFFF;
  494. transition: all .3s ease;
  495. .search_1 {
  496. display: flex;
  497. flex-wrap: wrap;
  498. padding: 2vw;
  499. .list {
  500. font-size: var(--font14Size);
  501. width: 24vw;
  502. text-align: center;
  503. .title_1 {
  504. padding: 2vw;
  505. margin: 1vw;
  506. background-color: var(--f5Color);
  507. }
  508. .title_2 {
  509. padding: 2vw;
  510. margin: 1vw;
  511. background: rgba(255, 222, 173, 0.35);
  512. border: 1px solid var(--fFFColor);
  513. }
  514. }
  515. }
  516. }
  517. .search_2 {
  518. padding: 2vw;
  519. background-color: var(--f5Color);
  520. display: flex;
  521. justify-content: space-between;
  522. align-items: center;
  523. .left {
  524. width: 80vw;
  525. .scroll {
  526. display: flex;
  527. white-space: nowrap;
  528. .title {
  529. font-size: var(--font14Size);
  530. display: flex;
  531. padding: 2vw;
  532. margin: 1vw;
  533. background-color: var(--mainColor);
  534. }
  535. }
  536. }
  537. }
  538. .pubuBox {
  539. padding: 2vw 0;
  540. }
  541. .pubuItem {
  542. column-count: 2;
  543. column-gap: 2vw;
  544. }
  545. .list {
  546. box-sizing: border-box;
  547. border-radius: 2vw;
  548. overflow: hidden;
  549. background-color: var(--mainColor);
  550. break-inside: avoid;
  551. /*避免在元素内部插入分页符*/
  552. box-sizing: border-box;
  553. margin-bottom: 2vw;
  554. .list_1 {
  555. .left {
  556. .image {
  557. width: 100%;
  558. height: 120px;
  559. border-radius: 5px 5px 0 0;
  560. }
  561. }
  562. .right {
  563. display: flex;
  564. flex-direction: column;
  565. justify-content: space-between;
  566. padding: 0 2vw;
  567. .name {
  568. font-size: var(--font14Size);
  569. }
  570. .other {
  571. color: var(--f85Color);
  572. font-size: var(--font12Size);
  573. }
  574. .money {
  575. color: var(--fF0Color);
  576. font-size: var(--font12Size);
  577. margin: 0 0 1vw 0;
  578. text:first-child {
  579. font-size: var(--font18Size);
  580. }
  581. }
  582. }
  583. }
  584. }
  585. }
  586. }
  587. }
  588. .foot {
  589. padding: 2vw 1vw;
  590. }
  591. }
  592. .scroll-view {
  593. position: absolute;
  594. top: 0;
  595. left: 0;
  596. right: 0;
  597. bottom: 0;
  598. .list-scroll-view {
  599. display: flex;
  600. flex-direction: column;
  601. }
  602. }
  603. .is_bottom {
  604. width: 100%;
  605. text-align: center;
  606. text {
  607. padding: 2vw 0;
  608. display: inline-block;
  609. color: var(--f85Color);
  610. font-size: var(--font12Size);
  611. }
  612. }
  613. </style>