index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509
  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-approve.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',
  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. background: url(https://static.caimei365.com/www/authentic/pc/bg-club.png);
  249. background-size: auto 420px;
  250. .logo {
  251. display: block;
  252. width: 120px;
  253. height: 120px;
  254. border-radius: 50%;
  255. background: #fff;
  256. }
  257. .name {
  258. font-size: 30px;
  259. color: #fff;
  260. }
  261. .logo,
  262. .name {
  263. transform: translateY(-60px);
  264. }
  265. }
  266. .page-content {
  267. width: 1200px;
  268. margin: 0 auto;
  269. .search {
  270. position: absolute;
  271. left: 50%;
  272. top: 260px;
  273. transform: translateX(-50%);
  274. }
  275. .city {
  276. position: absolute;
  277. left: 50%;
  278. top: 320px;
  279. transform: translateX(-50%);
  280. z-index: 9;
  281. }
  282. .title {
  283. font-size: 16px;
  284. color: #404040;
  285. span {
  286. color: #bc1724;
  287. }
  288. }
  289. .list {
  290. display: flex;
  291. align-items: center;
  292. justify-content: space-between;
  293. flex-wrap: wrap;
  294. .empty {
  295. width: 390px;
  296. }
  297. .section {
  298. width: 390px;
  299. height: 108px;
  300. background-color: #f3f5f6;
  301. border-radius: 4px;
  302. box-sizing: border-box;
  303. padding: 12px;
  304. cursor: pointer;
  305. transition: all 0.4s;
  306. &:hover {
  307. box-shadow: 0 0 24px rgba(0, 0, 0, 0.2);
  308. }
  309. .cover {
  310. display: block;
  311. width: 84px;
  312. height: 84px;
  313. }
  314. .info {
  315. position: relative;
  316. margin-left: 12px;
  317. .name {
  318. width: 228px;
  319. font-size: 16px;
  320. color: #101010;
  321. font-weight: bold;
  322. margin-bottom: 16px;
  323. text-overflow: ellipsis;
  324. white-space: nowrap;
  325. overflow: hidden;
  326. }
  327. .mobile,
  328. .address {
  329. width: 268px;
  330. position: relative;
  331. font-size: 14px;
  332. color: #404040;
  333. padding-left: 24px;
  334. line-height: 24px;
  335. text-overflow: ellipsis;
  336. white-space: nowrap;
  337. overflow: hidden;
  338. &::after {
  339. content: '';
  340. display: block;
  341. width: 16px;
  342. height: 16px;
  343. position: absolute;
  344. left: 0;
  345. top: 50%;
  346. transform: translateY(-50%);
  347. background-size: 16px;
  348. background-repeat: no-repeat;
  349. }
  350. }
  351. .mobile {
  352. &::after {
  353. background-image: url(https://static.caimei365.com/www/authentic/pc/icon-phone.png);
  354. }
  355. }
  356. .address {
  357. &::after {
  358. background-image: url(https://static.caimei365.com/www/authentic/pc/icon-address.png);
  359. }
  360. }
  361. .distance {
  362. position: absolute;
  363. font-size: 12px;
  364. color: #404040;
  365. top: 2px;
  366. right: 0;
  367. }
  368. }
  369. }
  370. }
  371. }
  372. }
  373. // 移动 端
  374. @media screen and (max-width: 768px) {
  375. .page-top {
  376. height: 46vw;
  377. background: url(https://static.caimei365.com/www/authentic/h5/bg-club.png);
  378. background-size: auto 46vw;
  379. .logo {
  380. display: block;
  381. width: 14.8vw;
  382. height: 14.8vw;
  383. border-radius: 50%;
  384. background: #fff;
  385. }
  386. .name {
  387. font-size: 4vw;
  388. color: #fff;
  389. }
  390. }
  391. .page-content {
  392. position: relative;
  393. .search {
  394. position: absolute;
  395. left: 50%;
  396. top: 0;
  397. transform: translate(-50%, -50%);
  398. }
  399. .city {
  400. position: relative;
  401. z-index: 9;
  402. padding-top: 12vw;
  403. }
  404. .title {
  405. font-size: 3.4vw;
  406. color: #404040;
  407. span {
  408. color: #bc1724;
  409. }
  410. }
  411. .list {
  412. display: flex;
  413. align-items: center;
  414. flex-direction: column;
  415. .section {
  416. width: 93.6vw;
  417. height: 26vw;
  418. background-color: #f3f5f6;
  419. border-radius: 4px;
  420. box-sizing: border-box;
  421. padding: 3.2vw;
  422. .cover {
  423. display: block;
  424. width: 19.6vw;
  425. height: 19.6vw;
  426. }
  427. .info {
  428. position: relative;
  429. margin-left: 3.2vw;
  430. .name {
  431. width: 48vw;
  432. font-size: 4vw;
  433. color: #101010;
  434. font-weight: bold;
  435. margin-bottom: 4vw;
  436. text-overflow: ellipsis;
  437. white-space: nowrap;
  438. overflow: hidden;
  439. }
  440. .mobile,
  441. .address {
  442. width: 66vw;
  443. position: relative;
  444. font-size: 3vw;
  445. color: #404040;
  446. padding-left: 5vw;
  447. line-height: 5vw;
  448. text-overflow: ellipsis;
  449. white-space: nowrap;
  450. overflow: hidden;
  451. &::after {
  452. content: '';
  453. display: block;
  454. width: 4vw;
  455. height: 4vw;
  456. position: absolute;
  457. left: 0;
  458. top: 50%;
  459. transform: translateY(-50%);
  460. background-size: 4vw 4vw;
  461. background-repeat: no-repeat;
  462. }
  463. }
  464. .mobile {
  465. &::after {
  466. background-image: url(https://static.caimei365.com/www/authentic/h5/icon-phone.png);
  467. }
  468. }
  469. .address {
  470. &::after {
  471. background-image: url(https://static.caimei365.com/www/authentic/h5/icon-address.png);
  472. }
  473. }
  474. .distance {
  475. position: absolute;
  476. font-size: 3vw;
  477. color: #404040;
  478. top: 0.8vw;
  479. right: 0;
  480. }
  481. }
  482. }
  483. }
  484. }
  485. }
  486. </style>