index.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655
  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. 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 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 = (item) => {
  355. uni.makePhoneCall({
  356. phoneNumber: item.shop || '110',
  357. success: function () {
  358. console.log('拨打电话成功');
  359. },
  360. fail: function () {
  361. console.log('拨打电话失败');
  362. }
  363. });
  364. };
  365. // 查看详情
  366. const toView = (item) => {
  367. uni.navigateTo({
  368. url: `/pagesHome/car/index?id=${item.id || item._id}`
  369. })
  370. };
  371. // 预览营业执照
  372. const toImage = () => {
  373. if (shop.value?.file.length > 0) {
  374. // 预览图片
  375. uni.previewImage({
  376. urls: [shop.value.file[0].url],
  377. longPressActions: {
  378. itemList: ['发送给朋友', '保存图片', '收藏'],
  379. success: function (data) {
  380. console.log('选中了第' + (data.tapIndex + 1) + '个按钮,第' + (data.index + 1) + '张图片');
  381. },
  382. fail: function (err) {
  383. console.log(err.errMsg);
  384. }
  385. }
  386. });
  387. }
  388. };
  389. // 分页
  390. const toPage = () => {
  391. if (total.value > list.value.length) {
  392. uni.showLoading({
  393. title: '加载中',
  394. mask: true
  395. })
  396. page.value = page.value + 1;
  397. skip.value = page.value * limit.value;
  398. search();
  399. uni.hideLoading();
  400. } else is_bottom.value = true
  401. };
  402. // 清空列表
  403. const clearPage = () => {
  404. list.value = []
  405. skip.value = 0
  406. limit.value = 6
  407. page.value = 0
  408. };
  409. </script>
  410. <style lang="scss" scoped>
  411. .content {
  412. display: flex;
  413. flex-direction: column;
  414. width: 100vw;
  415. height: 100vh;
  416. .info {
  417. position: relative;
  418. flex-grow: 1;
  419. background-color: var(--f1Color);
  420. .top {
  421. .image {
  422. width: 100%;
  423. height: 55vw;
  424. }
  425. }
  426. .bottom {
  427. margin: -8vw 2vw 0 2vw;
  428. .one {
  429. border-radius: 5px;
  430. padding: 2vw;
  431. background-color: var(--mainColor);
  432. .name {
  433. font-size: var(--font16Size);
  434. }
  435. .other {
  436. display: flex;
  437. justify-content: space-between;
  438. font-size: var(--font12Size);
  439. padding: 2vw 0;
  440. .left {
  441. width: 45%;
  442. .left_2 {
  443. margin: 1vw 0;
  444. }
  445. .left_3 {
  446. display: flex;
  447. align-items: center;
  448. text {
  449. margin: 0 0 1vw 0;
  450. color: #606266;
  451. }
  452. }
  453. }
  454. .right {
  455. width: 45%;
  456. }
  457. }
  458. }
  459. .two {
  460. .search {
  461. display: flex;
  462. justify-content: space-between;
  463. align-items: center;
  464. padding: 2vw 2vw 0 2vw;
  465. .searchlist {
  466. display: flex;
  467. align-items: center;
  468. padding: 1vw 0;
  469. .title_1 {
  470. margin: 0 1vw 0 0;
  471. font-size: var(--font14Size);
  472. }
  473. .title_2 {
  474. margin: 0 1vw 0 0;
  475. font-size: var(--font14Size);
  476. color: var(--fFFColor);
  477. }
  478. }
  479. }
  480. .popup-layer {
  481. position: absolute;
  482. z-index: 999999;
  483. background: rgba(0, 0, 0, .3);
  484. height: calc(100% - 50px);
  485. width: 100%;
  486. left: 0px;
  487. overflow: hidden;
  488. height: 87.5vh;
  489. }
  490. .popup-content {
  491. position: absolute;
  492. width: 100%;
  493. z-index: 1000000;
  494. background: #FFFFFF;
  495. transition: all .3s ease;
  496. .search_1 {
  497. display: flex;
  498. flex-wrap: wrap;
  499. padding: 2vw;
  500. .list {
  501. font-size: var(--font14Size);
  502. width: 24vw;
  503. text-align: center;
  504. .title_1 {
  505. padding: 2vw;
  506. margin: 1vw;
  507. background-color: var(--f5Color);
  508. }
  509. .title_2 {
  510. padding: 2vw;
  511. margin: 1vw;
  512. background: rgba(255, 222, 173, 0.35);
  513. border: 1px solid var(--fFFColor);
  514. }
  515. }
  516. }
  517. }
  518. .search_2 {
  519. padding: 2vw;
  520. background-color: var(--f5Color);
  521. display: flex;
  522. justify-content: space-between;
  523. align-items: center;
  524. .left {
  525. width: 80vw;
  526. .scroll {
  527. display: flex;
  528. white-space: nowrap;
  529. .title {
  530. font-size: var(--font14Size);
  531. display: flex;
  532. padding: 2vw;
  533. margin: 1vw;
  534. background-color: var(--mainColor);
  535. }
  536. }
  537. }
  538. }
  539. .pubuBox {
  540. padding: 2vw 0;
  541. }
  542. .pubuItem {
  543. column-count: 2;
  544. column-gap: 2vw;
  545. }
  546. .list {
  547. box-sizing: border-box;
  548. border-radius: 2vw;
  549. overflow: hidden;
  550. background-color: var(--mainColor);
  551. break-inside: avoid;
  552. /*避免在元素内部插入分页符*/
  553. box-sizing: border-box;
  554. margin-bottom: 2vw;
  555. .list_1 {
  556. .left {
  557. .image {
  558. width: 100%;
  559. height: 120px;
  560. border-radius: 5px 5px 0 0;
  561. }
  562. }
  563. .right {
  564. display: flex;
  565. flex-direction: column;
  566. justify-content: space-between;
  567. padding: 0 2vw;
  568. .name {
  569. font-size: var(--font14Size);
  570. }
  571. .other {
  572. color: var(--f85Color);
  573. font-size: var(--font12Size);
  574. }
  575. .money {
  576. color: var(--fF0Color);
  577. font-size: var(--font12Size);
  578. margin: 0 0 1vw 0;
  579. text:first-child {
  580. font-size: var(--font18Size);
  581. }
  582. }
  583. }
  584. }
  585. }
  586. }
  587. }
  588. }
  589. .foot {
  590. padding: 2vw 1vw;
  591. }
  592. }
  593. .scroll-view {
  594. position: absolute;
  595. top: 0;
  596. left: 0;
  597. right: 0;
  598. bottom: 0;
  599. .list-scroll-view {
  600. display: flex;
  601. flex-direction: column;
  602. }
  603. }
  604. .is_bottom {
  605. width: 100%;
  606. text-align: center;
  607. text {
  608. padding: 2vw 0;
  609. display: inline-block;
  610. color: var(--f85Color);
  611. font-size: var(--font12Size);
  612. }
  613. }
  614. </style>