index.vue 18 KB

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