t-index-address.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <template>
  2. <view class="t-index-address">
  3. <scroll-view class="t-index-address__scroll-view" :scroll-into-view="scrollview" :scroll-y="true"
  4. :enable-flex="true">
  5. <view :id="group.initial" v-for="group in cityList" :key="group.initial">
  6. <view class="t-index-address__anchor">
  7. <text>{{ group.initial }}</text>
  8. </view>
  9. <view class="t-index-address__list">
  10. <view class="t-index-address__cell" v-for="(city, index) in group.list" :key="index"
  11. @click="$emit('select', city)">
  12. <text>{{ city.name }}</text>
  13. </view>
  14. </view>
  15. </view>
  16. </scroll-view>
  17. <view class="t-index-address__sidebar">
  18. <view class="t-index-address__index" v-for="group in cityList" :key="group.initial"
  19. @touchstart.stop.prevent="onTouchMove(group.initial)" @touchend.stop.prevent="onTouchStop"
  20. @touchcancel.stop.prevent="onTouchStop">
  21. <span>{{ group.initial }}</span>
  22. </view>
  23. </view>
  24. <view class="t-index-address__alert" v-if="touchmove">
  25. <text>{{ activeIndex }}</text>
  26. </view>
  27. </view>
  28. </template>
  29. <script>
  30. import cityList from "./cities.json";
  31. export default {
  32. data() {
  33. return {
  34. scrollview: "A",
  35. cityList: [],
  36. activeIndex: "A",
  37. touchmove: false,
  38. };
  39. },
  40. watch: {
  41. activeIndex(value) {
  42. this.scrollview = value;
  43. },
  44. },
  45. methods: {
  46. initCityList() {
  47. this.cityList = cityList;
  48. },
  49. onTouchMove(index) {
  50. this.activeIndex = index;
  51. this.touchmove = true;
  52. },
  53. onTouchStop() {
  54. this.touchmove = false;
  55. },
  56. },
  57. mounted() {
  58. this.initCityList();
  59. },
  60. };
  61. </script>
  62. <style lang="scss" scoped>
  63. .t-index-address {
  64. height: 100%;
  65. &__scroll-view {
  66. width: 100%;
  67. height: 100%;
  68. max-height: 100vh;
  69. }
  70. &__anchor {
  71. padding: 15rpx 30rpx;
  72. width: 100%;
  73. font-size: 28rpx;
  74. font-weight: 500;
  75. color: #606266;
  76. background-color: rgb(245, 245, 245);
  77. }
  78. &__list {
  79. padding: 0 70rpx 0 30rpx;
  80. }
  81. &__cell {
  82. height: 100rpx;
  83. line-height: 100rpx;
  84. border-bottom: 1rpx solid #f2f2f2;
  85. &:last-child {
  86. border: none;
  87. }
  88. }
  89. &__sidebar {
  90. position: fixed;
  91. top: 50%;
  92. right: 0;
  93. transform: translateY(-50%);
  94. z-index: 99;
  95. }
  96. &__index {
  97. padding: 10rpx 20rpx;
  98. font-size: 22rpx;
  99. font-weight: 500;
  100. line-height: 1;
  101. }
  102. &__alert {
  103. position: fixed;
  104. top: 50%;
  105. right: 90rpx;
  106. z-index: 99;
  107. margin-top: -60rpx;
  108. width: 120rpx;
  109. height: 120rpx;
  110. font-size: 50rpx;
  111. color: #fff;
  112. border-radius: 24rpx;
  113. background-color: rgba(0, 0, 0, 0.5);
  114. display: flex;
  115. justify-content: center;
  116. align-items: center;
  117. }
  118. }
  119. </style>