index.vue 14 KB

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