index.vue 12 KB

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