index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541
  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. 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.clubName)" />
  42. <div class="info">
  43. <div class="name" v-text="item.clubName"></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="item.distance + 'km'"
  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 { loactionSelf } 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. clubName: '',
  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. // 初始化页面数据
  134. async initData() {
  135. this.listQuery.authUserId = this.authUserId
  136. // 自定义加载图标
  137. this.$toast.loading({
  138. message: '正在获取您附近的机构...',
  139. duration: 0,
  140. })
  141. // 获取定位信息 百度坐标转高德坐标
  142. try {
  143. const location = await loactionSelf()
  144. const result = await this.$http.api.assistant({
  145. key: '1bcc97330f6cf517e8dd9d5278957e67',
  146. locations: `${location.point.lng},${location.point.lat}`,
  147. coordsys: 'baidu',
  148. output: 'JSON',
  149. })
  150. const res = await result.json()
  151. this.listQuery.lngAndLat = res.locations
  152. } catch (error) {
  153. this.$toast.clear()
  154. this.$toast('获取定位信息失败,请确保您开启的定位权限并保存网络畅通')
  155. this.isRequest = false
  156. }
  157. // 获取机构列表
  158. this.fetchList()
  159. },
  160. // 获取机构列表
  161. fetchList: debounce(async function () {
  162. try {
  163. this.isLoadingMore = true
  164. const res = await this.$http.api.getAuthClubList(this.listQuery)
  165. this.total = res.data.total
  166. this.list = [...this.list, ...res.data.list]
  167. this.finished = !res.data.hasNextPage
  168. this.isLoadingMore = false
  169. this.listQuery.pageNum += 1
  170. } catch (error) {
  171. console.log(error)
  172. } finally {
  173. this.$toast.clear()
  174. this.isRequest = false
  175. }
  176. }, 400),
  177. // 获取地址列表
  178. fetchCityList() {
  179. this.$http.api.fetchAllCityList().then((res) => {
  180. this.cityList = res.data
  181. })
  182. },
  183. // 城市变化
  184. onCityChange(selectValue) {
  185. this.listQuery.provinceId = ''
  186. this.listQuery.cityId = ''
  187. this.listQuery.townId = ''
  188. this.selectValue = selectValue
  189. selectValue.map((item, index) => {
  190. if (index === 0) {
  191. this.listQuery.provinceId = item.id
  192. } else if (index === 1) {
  193. this.listQuery.cityId = item.id
  194. } else {
  195. this.listQuery.townId = item.id
  196. }
  197. })
  198. this.listQuery.pageNum = 1
  199. this.list = []
  200. this.fetchList()
  201. },
  202. // 搜索
  203. onSearch() {
  204. this.listQuery.pageNum = 1
  205. this.list = []
  206. this.fetchList()
  207. },
  208. // 格式化地址
  209. formatAddress(a1, a2) {
  210. let resutl = ''
  211. if (typeof a1 === 'string') {
  212. resutl += a1
  213. }
  214. if (typeof a2 === 'string') {
  215. resutl += a2
  216. }
  217. return resutl || '未知'
  218. },
  219. // 加载更多
  220. onLoadMore() {
  221. this.fetchList()
  222. },
  223. },
  224. }
  225. </script>
  226. <style scoped lang="scss">
  227. @media screen and (min-width: 768px) {
  228. .page-top {
  229. height: 596px;
  230. background: url(https://static.caimei365.com/www/authentic/pc/ldm-bg-club.png)
  231. no-repeat center;
  232. background-size: auto 596px;
  233. }
  234. .page-content {
  235. width: 836px;
  236. margin: 0 auto;
  237. overflow: hidden;
  238. .city {
  239. position: relative;
  240. z-index: 99;
  241. }
  242. .search {
  243. width: 836px;
  244. position: relative;
  245. margin: 69px auto 40px;
  246. input {
  247. display: block;
  248. width: 100%;
  249. height: 56px;
  250. border: 0.1vw solid #000000;
  251. box-sizing: border-box;
  252. padding-left: 80px;
  253. font-size: 24px;
  254. }
  255. &::after {
  256. position: absolute;
  257. left: 33px;
  258. top: 50%;
  259. transform: translateY(-50%);
  260. content: '';
  261. display: block;
  262. width: 37px;
  263. height: 37px;
  264. background: url(https://static.caimei365.com/www/authentic/pc/ldm-icon-search.png)
  265. no-repeat center;
  266. background-size: 37px;
  267. }
  268. }
  269. .title {
  270. text-align: right;
  271. font-size: 22px;
  272. color: #000;
  273. }
  274. .list {
  275. padding-top: 24px;
  276. display: flex;
  277. align-items: center;
  278. justify-content: space-between;
  279. flex-wrap: wrap;
  280. .section {
  281. width: 409px;
  282. background: #f1f1f1;
  283. border-radius: 20px;
  284. padding: 16px;
  285. box-sizing: border-box;
  286. margin-bottom: 20px;
  287. cursor: pointer;
  288. .cover {
  289. width: 92px;
  290. height: 92px;
  291. border-radius: 17px;
  292. }
  293. .info {
  294. position: relative;
  295. width: 263px;
  296. margin-left: 23px;
  297. .name {
  298. width: 200px;
  299. position: relative;
  300. font-size: 15px;
  301. color: #000;
  302. font-weight: bold;
  303. text-overflow: ellipsis;
  304. white-space: nowrap;
  305. overflow: hidden;
  306. padding-left: 20px;
  307. line-height: 20px;
  308. &::after {
  309. content: '';
  310. display: block;
  311. width: 20px;
  312. height: 20px;
  313. position: absolute;
  314. left: 0;
  315. top: 50%;
  316. transform: translateY(-50%);
  317. background-size: 20px 20px;
  318. background-repeat: no-repeat;
  319. background-position: left center;
  320. }
  321. }
  322. .name {
  323. &::after {
  324. background-image: url(https://static.caimei365.com/www/authentic/pc/ldm-icon-store.png);
  325. }
  326. }
  327. .line {
  328. height: 1px;
  329. margin: 14px 0;
  330. background: rgba(0, 0, 0, 0.169);
  331. }
  332. .mobile,
  333. .address {
  334. position: relative;
  335. font-size: 12px;
  336. color: #000000;
  337. padding-left: 20px;
  338. line-height: 20px;
  339. text-overflow: ellipsis;
  340. white-space: nowrap;
  341. overflow: hidden;
  342. &::after {
  343. content: '';
  344. display: block;
  345. width: 24px;
  346. height: 24px;
  347. position: absolute;
  348. left: 0;
  349. top: 50%;
  350. transform: translateY(-50%);
  351. background-size: 24px 24px;
  352. background-repeat: no-repeat;
  353. background-position: left center;
  354. }
  355. }
  356. .mobile {
  357. &::after {
  358. background-image: url(https://static.caimei365.com/www/authentic/pc/ldm-icon-contact.png);
  359. }
  360. }
  361. .address {
  362. &::after {
  363. background-image: url(https://static.caimei365.com/www/authentic/pc/ldm-icon-address.png);
  364. }
  365. }
  366. .distance {
  367. position: absolute;
  368. font-size: 12px;
  369. color: #404040;
  370. top: 0.2vw;
  371. right: 0;
  372. }
  373. }
  374. }
  375. }
  376. }
  377. }
  378. @media screen and (max-width: 768px) {
  379. .page-top {
  380. height: 59.6vw;
  381. background: url(https://static.caimei365.com/www/authentic/h5/ldm-bg-club.png);
  382. background-size: auto 59.6vw;
  383. }
  384. .page-content {
  385. overflow: hidden;
  386. .search {
  387. width: 86vw;
  388. position: relative;
  389. margin: 7.6vw auto 5.6vw;
  390. input {
  391. display: block;
  392. width: 100%;
  393. height: 8vw;
  394. border: 0.1vw solid #000000;
  395. box-sizing: border-box;
  396. padding-left: 10.5vw;
  397. }
  398. &::after {
  399. position: absolute;
  400. left: 2.9vw;
  401. top: 50%;
  402. transform: translateY(-50%);
  403. content: '';
  404. display: block;
  405. width: 5.4vw;
  406. height: 5.4vw;
  407. background: url(https://static.caimei365.com/www/authentic/h5/ldm-icon-search.png)
  408. no-repeat center;
  409. background-size: 5.4vw;
  410. }
  411. }
  412. .title {
  413. text-align: right;
  414. padding-right: 6.6vw;
  415. font-size: 3.5vw;
  416. color: #000;
  417. }
  418. .list {
  419. display: flex;
  420. flex-direction: column;
  421. align-items: center;
  422. .section {
  423. width: 95.1vw;
  424. background: #f1f1f1;
  425. border-radius: 2vw;
  426. padding: 3.2vw;
  427. box-sizing: border-box;
  428. margin-top: 5.7vw;
  429. .cover {
  430. width: 21.5vw;
  431. height: 21.5vw;
  432. border-radius: 1.7vw;
  433. }
  434. .info {
  435. position: relative;
  436. width: 61.3vw;
  437. margin-left: 5.8vw;
  438. .name {
  439. width: 46vw;
  440. position: relative;
  441. font-size: 3.5vw;
  442. color: #000;
  443. font-weight: bold;
  444. text-overflow: ellipsis;
  445. white-space: nowrap;
  446. overflow: hidden;
  447. padding-left: 5vw;
  448. line-height: 5vw;
  449. &::after {
  450. content: '';
  451. display: block;
  452. width: 4vw;
  453. height: 4vw;
  454. position: absolute;
  455. left: 0;
  456. top: 50%;
  457. transform: translateY(-50%);
  458. background-size: 4vw;
  459. background-repeat: no-repeat;
  460. }
  461. }
  462. .name {
  463. &::after {
  464. background-image: url(https://static.caimei365.com/www/authentic/h5/ldm-icon-store.png);
  465. }
  466. }
  467. .line {
  468. height: 0.1vw;
  469. margin: 2.8vw 0;
  470. background: rgba(0, 0, 0, 0.169);
  471. }
  472. .mobile,
  473. .address {
  474. position: relative;
  475. font-size: 3vw;
  476. color: #000000;
  477. padding-left: 5vw;
  478. line-height: 5vw;
  479. text-overflow: ellipsis;
  480. white-space: nowrap;
  481. overflow: hidden;
  482. &::after {
  483. content: '';
  484. display: block;
  485. width: 4vw;
  486. height: 4vw;
  487. position: absolute;
  488. left: 0;
  489. top: 50%;
  490. transform: translateY(-50%);
  491. background-size: 4vw 4vw;
  492. background-repeat: no-repeat;
  493. }
  494. }
  495. .mobile {
  496. &::after {
  497. background-image: url(https://static.caimei365.com/www/authentic/h5/ldm-icon-contact.png);
  498. }
  499. }
  500. .address {
  501. &::after {
  502. background-image: url(https://static.caimei365.com/www/authentic/h5/ldm-icon-address.png);
  503. }
  504. }
  505. .distance {
  506. position: absolute;
  507. font-size: 3vw;
  508. color: #404040;
  509. top: 0.2vw;
  510. right: 0;
  511. }
  512. }
  513. }
  514. }
  515. }
  516. }
  517. </style>