index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  1. <template>
  2. <div class="page">
  3. <van-list
  4. v-model="isLoadingMore"
  5. :finished="finished"
  6. :immediate-check="false"
  7. :finished-text="total ? '没有更多了' : ''"
  8. @load="onLoadMore"
  9. >
  10. <div class="page-top"></div>
  11. <div class="page-content">
  12. <!-- 搜索区域 -->
  13. <div class="search flex justify-center">
  14. <input
  15. type="text"
  16. placeholder="搜索店铺"
  17. v-model="listQuery.authParty"
  18. @keyup.enter="onSearch"
  19. />
  20. </div>
  21. <!-- 地区筛选 -->
  22. <div class="city">
  23. <LdmCity
  24. ref="citySelect"
  25. @change="onCityChange"
  26. :options="cityList"
  27. labelName="name"
  28. valueName="id"
  29. ></LdmCity>
  30. </div>
  31. <!-- 标题 -->
  32. <div class="title">距你最近...</div>
  33. <!-- 机构列表 -->
  34. <div class="list">
  35. <div
  36. class="section flex items-center"
  37. v-for="item in list"
  38. :key="item.authId"
  39. @click="toDetail(item)"
  40. >
  41. <img class="cover" :src="item.logo || drawLogo(item.authParty)" />
  42. <div class="info">
  43. <div class="name" v-text="item.authParty"></div>
  44. <div class="line"></div>
  45. <!--<div class="mobile">{{ item.mobile || '暂无' }}</div>-->
  46. <div class="address">
  47. {{ formatAddress(item.area, item.address) }}
  48. </div>
  49. <div
  50. class="distance"
  51. v-text="generateDistance(item.distance)"
  52. v-if="item.distance && item.distance !== 99999"
  53. ></div>
  54. </div>
  55. </div>
  56. </div>
  57. <!-- 列表为空 -->
  58. <LdmEmpty v-if="!total && !isRequest" name="ldm-empty.png"></LdmEmpty>
  59. </div>
  60. </van-list>
  61. </div>
  62. </template>
  63. <script>
  64. import { mapGetters } from 'vuex'
  65. import { geolocation } from '@/utils/map-utils'
  66. import { debounce, drawLogo } from '@/utils'
  67. export default {
  68. layout: 'app-ldm',
  69. data() {
  70. return {
  71. isLoadingMore: true,
  72. finished: false,
  73. isRequest: true,
  74. list: [],
  75. listQuery: {
  76. authUserId: '',
  77. lngAndLat: '',
  78. authParty: '',
  79. provinceId: '',
  80. cityId: '',
  81. townId: '',
  82. pageNum: 1,
  83. pageSize: 10,
  84. },
  85. total: 0,
  86. cityList: [],
  87. selectValue: [],
  88. }
  89. },
  90. computed: {
  91. ...mapGetters(['supplierInfo', 'authUserId', 'routePrefix']),
  92. emptyList() {
  93. return 3 - (this.list.length % 3)
  94. },
  95. },
  96. mounted() {
  97. const cacheData = this.$getStorage(this.routePrefix, 'club_list_data')
  98. if (cacheData) {
  99. this.initFromCache(cacheData)
  100. this.$removeStorage(this.routePrefix, 'club_list_data')
  101. } else {
  102. this.initData()
  103. this.fetchCityList()
  104. }
  105. },
  106. beforeDestroy() {
  107. this.$toast.clear()
  108. },
  109. methods: {
  110. // 绘制logo的方法
  111. drawLogo,
  112. // 查看详情
  113. toDetail(item) {
  114. this.$setStorage(this.routePrefix, 'club_list_data', this.$data, {
  115. expiredTime: 5 * 60 * 1000,
  116. })
  117. this.$setStorage(this.routePrefix, 'clubInfo', item)
  118. const url = `${this.routePrefix}/approve/club/detail?id=${item.authId}`
  119. this.$router.push(url)
  120. },
  121. // 从缓存中获取数据
  122. initFromCache(cacheData) {
  123. this.isLoadingMore = cacheData.isLoadingMore
  124. this.finished = cacheData.finished
  125. this.isRequest = cacheData.isRequest
  126. this.list = cacheData.list
  127. this.listQuery = cacheData.listQuery
  128. this.total = cacheData.total
  129. this.cityList = cacheData.cityList
  130. this.selectValue = cacheData.selectValue
  131. this.$refs.citySelect.setSelectValue(this.selectValue)
  132. },
  133. generateDistance(value) {
  134. return value > 1 ? value + 'km' : value * 1000 + 'm'
  135. },
  136. // 初始化页面数据
  137. async initData() {
  138. this.listQuery.authUserId = this.authUserId
  139. // 自定义加载图标
  140. this.$toast.loading({
  141. message: '正在获取您附近的机构...',
  142. duration: 0,
  143. })
  144. // 获取定位信息 这里使用的是高德地图获取用户具体位置信息
  145. try {
  146. const resLocation = await geolocation()
  147. this.listQuery.lngAndLat = `${resLocation.position.lng},${resLocation.position.lat}`
  148. } catch (error) {
  149. this.$toast('获取定位信息失败,请确保您开启的定位权限并保存网络畅通')
  150. this.isRequest = false
  151. }
  152. // 获取机构列表
  153. this.fetchList()
  154. },
  155. // 获取机构列表
  156. fetchList: debounce(async function () {
  157. try {
  158. this.isLoadingMore = true
  159. const res = await this.$http.api.getAuthClubList(this.listQuery)
  160. this.total = res.data.total
  161. this.list = [...this.list, ...res.data.list]
  162. this.finished = !res.data.hasNextPage
  163. this.isLoadingMore = false
  164. this.listQuery.pageNum += 1
  165. } catch (error) {
  166. console.log(error)
  167. } finally {
  168. this.$toast.clear()
  169. this.isRequest = false
  170. }
  171. }, 400),
  172. // 获取地址列表
  173. fetchCityList() {
  174. this.$http.api.fetchAllCityList().then((res) => {
  175. this.cityList = res.data
  176. })
  177. },
  178. // 城市变化
  179. onCityChange(selectValue) {
  180. this.listQuery.provinceId = ''
  181. this.listQuery.cityId = ''
  182. this.listQuery.townId = ''
  183. this.selectValue = selectValue
  184. selectValue.map((item, index) => {
  185. if (index === 0) {
  186. this.listQuery.provinceId = item.id
  187. } else if (index === 1) {
  188. this.listQuery.cityId = item.id
  189. } else {
  190. this.listQuery.townId = item.id
  191. }
  192. })
  193. this.listQuery.pageNum = 1
  194. this.list = []
  195. this.fetchList()
  196. },
  197. // 搜索
  198. onSearch() {
  199. this.listQuery.pageNum = 1
  200. this.list = []
  201. this.fetchList()
  202. },
  203. // 格式化地址
  204. formatAddress(a1, a2) {
  205. let resutl = ''
  206. if (typeof a1 === 'string') {
  207. resutl += a1
  208. }
  209. if (typeof a2 === 'string') {
  210. resutl += a2
  211. }
  212. return resutl || '暂无'
  213. },
  214. // 加载更多
  215. onLoadMore() {
  216. this.fetchList()
  217. },
  218. },
  219. }
  220. </script>
  221. <style scoped lang="scss">
  222. @media screen and (min-width: 768px) {
  223. .page-top {
  224. height: 596px;
  225. background: url(https://static.caimei365.com/www/authentic/pc/ldm-bg-club.png)
  226. no-repeat center;
  227. background-size: auto 596px;
  228. }
  229. .page-content {
  230. width: 836px;
  231. margin: 0 auto;
  232. overflow: hidden;
  233. .city {
  234. position: relative;
  235. z-index: 99;
  236. }
  237. .search {
  238. width: 836px;
  239. position: relative;
  240. margin: 69px auto 40px;
  241. input {
  242. display: block;
  243. width: 100%;
  244. height: 56px;
  245. border: 0.1vw solid #000000;
  246. box-sizing: border-box;
  247. padding-left: 80px;
  248. font-size: 24px;
  249. }
  250. &::after {
  251. position: absolute;
  252. left: 33px;
  253. top: 50%;
  254. transform: translateY(-50%);
  255. content: '';
  256. display: block;
  257. width: 37px;
  258. height: 37px;
  259. background: url(https://static.caimei365.com/www/authentic/pc/ldm-icon-search.png)
  260. no-repeat center;
  261. background-size: 37px;
  262. }
  263. }
  264. .title {
  265. text-align: right;
  266. font-size: 22px;
  267. color: #000;
  268. }
  269. .list {
  270. padding-top: 24px;
  271. display: flex;
  272. align-items: center;
  273. justify-content: space-between;
  274. flex-wrap: wrap;
  275. .section {
  276. width: 409px;
  277. background: #f1f1f1;
  278. border-radius: 20px;
  279. padding: 16px;
  280. box-sizing: border-box;
  281. margin-bottom: 20px;
  282. cursor: pointer;
  283. .cover {
  284. width: 92px;
  285. height: 92px;
  286. border-radius: 17px;
  287. }
  288. .info {
  289. position: relative;
  290. width: 263px;
  291. margin-left: 23px;
  292. .name {
  293. width: 200px;
  294. position: relative;
  295. font-size: 15px;
  296. color: #000;
  297. font-weight: bold;
  298. text-overflow: ellipsis;
  299. white-space: nowrap;
  300. overflow: hidden;
  301. padding-left: 20px;
  302. line-height: 20px;
  303. &::after {
  304. content: '';
  305. display: block;
  306. width: 20px;
  307. height: 20px;
  308. position: absolute;
  309. left: 0;
  310. top: 50%;
  311. transform: translateY(-50%);
  312. background-size: 20px 20px;
  313. background-repeat: no-repeat;
  314. background-position: left center;
  315. }
  316. }
  317. .name {
  318. &::after {
  319. background-image: url(https://static.caimei365.com/www/authentic/pc/ldm-icon-store.png);
  320. }
  321. }
  322. .line {
  323. height: 1px;
  324. margin: 14px 0;
  325. background: rgba(0, 0, 0, 0.169);
  326. }
  327. .mobile,
  328. .address {
  329. position: relative;
  330. font-size: 12px;
  331. color: #000000;
  332. padding-left: 20px;
  333. line-height: 20px;
  334. text-overflow: ellipsis;
  335. white-space: nowrap;
  336. overflow: hidden;
  337. &::after {
  338. content: '';
  339. display: block;
  340. width: 24px;
  341. height: 24px;
  342. position: absolute;
  343. left: 0;
  344. top: 50%;
  345. transform: translateY(-50%);
  346. background-size: 24px 24px;
  347. background-repeat: no-repeat;
  348. background-position: left center;
  349. }
  350. }
  351. .mobile {
  352. &::after {
  353. background-image: url(https://static.caimei365.com/www/authentic/pc/ldm-icon-contact.png);
  354. }
  355. }
  356. .address {
  357. &::after {
  358. background-image: url(https://static.caimei365.com/www/authentic/pc/ldm-icon-address.png);
  359. }
  360. }
  361. .distance {
  362. position: absolute;
  363. font-size: 12px;
  364. color: #404040;
  365. top: 0.2vw;
  366. right: 0;
  367. }
  368. }
  369. }
  370. }
  371. }
  372. }
  373. @media screen and (max-width: 768px) {
  374. .page-top {
  375. height: 59.6vw;
  376. background: url(https://static.caimei365.com/www/authentic/h5/ldm-bg-club.png);
  377. background-size: auto 59.6vw;
  378. }
  379. .page-content {
  380. overflow: hidden;
  381. .search {
  382. width: 86vw;
  383. position: relative;
  384. margin: 7.6vw auto 5.6vw;
  385. input {
  386. display: block;
  387. width: 100%;
  388. height: 8vw;
  389. border: 0.1vw solid #000000;
  390. box-sizing: border-box;
  391. padding-left: 10.5vw;
  392. }
  393. &::after {
  394. position: absolute;
  395. left: 2.9vw;
  396. top: 50%;
  397. transform: translateY(-50%);
  398. content: '';
  399. display: block;
  400. width: 5.4vw;
  401. height: 5.4vw;
  402. background: url(https://static.caimei365.com/www/authentic/h5/ldm-icon-search.png)
  403. no-repeat center;
  404. background-size: 5.4vw;
  405. }
  406. }
  407. .title {
  408. text-align: right;
  409. padding-right: 6.6vw;
  410. font-size: 3.5vw;
  411. color: #000;
  412. }
  413. .list {
  414. display: flex;
  415. flex-direction: column;
  416. align-items: center;
  417. .section {
  418. width: 95.1vw;
  419. background: #f1f1f1;
  420. border-radius: 2vw;
  421. padding: 3.2vw;
  422. box-sizing: border-box;
  423. margin-top: 5.7vw;
  424. .cover {
  425. width: 21.5vw;
  426. height: 21.5vw;
  427. border-radius: 1.7vw;
  428. }
  429. .info {
  430. position: relative;
  431. width: 61.3vw;
  432. margin-left: 5.8vw;
  433. .name {
  434. width: 46vw;
  435. position: relative;
  436. font-size: 3.5vw;
  437. color: #000;
  438. font-weight: bold;
  439. text-overflow: ellipsis;
  440. white-space: nowrap;
  441. overflow: hidden;
  442. padding-left: 5vw;
  443. line-height: 5vw;
  444. &::after {
  445. content: '';
  446. display: block;
  447. width: 4vw;
  448. height: 4vw;
  449. position: absolute;
  450. left: 0;
  451. top: 50%;
  452. transform: translateY(-50%);
  453. background-size: 4vw;
  454. background-repeat: no-repeat;
  455. }
  456. }
  457. .name {
  458. &::after {
  459. background-image: url(https://static.caimei365.com/www/authentic/h5/ldm-icon-store.png);
  460. }
  461. }
  462. .line {
  463. height: 0.1vw;
  464. margin: 2.8vw 0;
  465. background: rgba(0, 0, 0, 0.169);
  466. }
  467. .mobile,
  468. .address {
  469. position: relative;
  470. font-size: 3vw;
  471. color: #000000;
  472. padding-left: 5vw;
  473. line-height: 5vw;
  474. text-overflow: ellipsis;
  475. white-space: nowrap;
  476. overflow: hidden;
  477. &::after {
  478. content: '';
  479. display: block;
  480. width: 4vw;
  481. height: 4vw;
  482. position: absolute;
  483. left: 0;
  484. top: 50%;
  485. transform: translateY(-50%);
  486. background-size: 4vw 4vw;
  487. background-repeat: no-repeat;
  488. }
  489. }
  490. .mobile {
  491. &::after {
  492. background-image: url(https://static.caimei365.com/www/authentic/h5/ldm-icon-contact.png);
  493. }
  494. }
  495. .address {
  496. &::after {
  497. background-image: url(https://static.caimei365.com/www/authentic/h5/ldm-icon-address.png);
  498. }
  499. }
  500. .distance {
  501. position: absolute;
  502. font-size: 3vw;
  503. color: #404040;
  504. top: 0.2vw;
  505. right: 0;
  506. }
  507. }
  508. }
  509. }
  510. }
  511. }
  512. </style>