index.vue 18 KB

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