index.vue 14 KB

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