index.vue 13 KB

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