index.vue 12 KB

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