index.vue 12 KB

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