index.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <template>
  2. <view class="main-Location">
  3. <!-- 字母区域 -->
  4. <view class="Location-Letter">
  5. <view hover-class="Click-Latter" @tap="getLetter('ScrollTop')">*</view>
  6. <view v-for="(l,i) in LatterName" :key="i" hover-class="Click-Latter" @tap="getLetter(l)"
  7. :style="{'color': LetterId === l ? '#2979ff' : '#000' }">{{l}}</view>
  8. </view>
  9. <scroll-view scroll-y="true" class="ynq-ScrollView" :scroll-into-view="LetterId">
  10. <!-- 城市列表 -->
  11. <view class="ynq-CityList">
  12. <block v-for="(item,index) in CityList" :key="index">
  13. <view class="ynq-CityLetter" :id="item.initial">{{item.initial}}</view>
  14. <view class="ynq-CityLine">
  15. <text @tap="getStorage(item_city)" v-for="(item_city,name_index) in item.list"
  16. :key="name_index">{{item_city.name}}</text>
  17. </view>
  18. </block>
  19. </view>
  20. </scroll-view>
  21. </view>
  22. </template>
  23. <script setup lang="ts">
  24. import { getCurrentInstance, ref } from 'vue';
  25. //该依赖已内置不需要单独安装
  26. import { onLoad } from "@dcloudio/uni-app";
  27. // 请求接口
  28. const $api = getCurrentInstance()?.appContext.config.globalProperties.$api;
  29. const $config = getCurrentInstance()?.appContext.config.globalProperties.$config;
  30. // 字段
  31. const field = ref('');
  32. const CityName = ref('');
  33. const LatterName = ref(['全', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']);
  34. const CityList = ref($config.china);
  35. const LetterId = ref('');
  36. onLoad(async (options) => {
  37. field.value = options && options.field || ''
  38. })
  39. // 获取定位点
  40. const getLetter = (name) => {
  41. LetterId.value = name
  42. // 跳转城市首字母定位
  43. uni.pageScrollTo({
  44. selector: '#' + name,
  45. duration: 300
  46. })
  47. };
  48. // 存储城市缓存(点击城市)
  49. const getStorage = (item) => {
  50. item.field = field.value
  51. uni.$emit('toCity', item)
  52. // 4. 返回上一页面
  53. uni.navigateBack({
  54. delta: 1 // 返回的页面数
  55. })
  56. };
  57. </script>
  58. <style lang="scss" scoped>
  59. .main-Location {
  60. height: 100vh;
  61. }
  62. // 侧边字母选择栏
  63. .Location-Letter {
  64. position: fixed;
  65. right: 5px;
  66. top: 80px;
  67. width: 15px;
  68. z-index: 100;
  69. color: #c8c9cc;
  70. view {
  71. display: block;
  72. width: 15px;
  73. text-align: center;
  74. padding: 1px 0 0 0;
  75. font-size: var(--font12Size);
  76. transition: ease .3s;
  77. -webkit-transition: ease .3s;
  78. }
  79. }
  80. // 城市列表
  81. .ynq-CityList {
  82. padding: 10px 0;
  83. .ynq-CityLetter {
  84. font-size: var(--font16Size);
  85. border-bottom: 1px solid #f7f7f7;
  86. padding: 5px;
  87. background-color: #f4f4f5;
  88. border-bottom: 0.5px solid #dadbde;
  89. }
  90. .ynq-CityLine {
  91. background-color: #fff;
  92. margin: 10px 0;
  93. text {
  94. display: block;
  95. line-height: 30px;
  96. padding: 10px 15px;
  97. font-size: var(--font14Size);
  98. border-bottom: 1px solid var(--f4Color);
  99. }
  100. }
  101. }
  102. </style>