phone-list.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <template>
  2. <view>
  3. <scroll-view class="scroll-list"
  4. :scroll-top="1"
  5. scroll-y="true"
  6. :scroll-with-animation="scrollAnimationOFF"
  7. :scroll-into-view="scrollViewId"
  8. :style="{height:winHeight + 'px'}"
  9. @scroll="handleScroll">
  10. <view class="phone-list">
  11. <view class="list-item"
  12. v-for="(item, key) of phones"
  13. :key="key"
  14. :id="key">
  15. <view class="list-item-title">{{key}}</view>
  16. <view class="list-item-phone"
  17. @click="handleClick"
  18. hover-class="commonly-hover"
  19. :hover-start-time="20"
  20. :hover-stay-time="70"
  21. v-for="innerItem in item"
  22. :key="innerItem.id"
  23. :data-name="innerItem.name"
  24. :data-id="innerItem.id"
  25. :data-phoneNumber="innerItem.phoneNumber"
  26. >
  27. {{innerItem.name}}
  28. </view>
  29. </view>
  30. </view>
  31. </scroll-view>
  32. </view>
  33. </template>
  34. <script>
  35. export default {
  36. name:"phone-list",
  37. props:{
  38. phones:Object,
  39. letter:String,
  40. scrollAnimationOFF:Boolean
  41. },
  42. data () {
  43. return {
  44. winHeight:0,
  45. scrollTop:0,
  46. letterDetails:[],
  47. timer:null
  48. }
  49. },
  50. computed:{
  51. scrollViewId () {
  52. return this.letter
  53. }
  54. },
  55. mounted(){
  56. // #ifndef APP-PLUS
  57. this.winHeight = uni.getSystemInfoSync().windowHeight - 49.50
  58. //#endif
  59. //#ifdef APP-PLUS
  60. this.winHeight = uni.getSystemInfoSync().windowHeight - 100
  61. //#endif
  62. },
  63. methods:{
  64. handleClick (e) {
  65. this.$emit('handleClick',e.target.dataset)
  66. },
  67. handleScroll (e){
  68. if(this.letterDetails.length === 0){
  69. let view = uni.createSelectorQuery().selectAll('.list-item')
  70. view.boundingClientRect(data=>{
  71. let top = data[0].top
  72. data.forEach((item,index)=>{
  73. item.top = item.top - top
  74. item.bottom = item.bottom - top
  75. this.letterDetails.push({
  76. id:item.id,
  77. top:item.top,
  78. bottom:item.bottom
  79. })
  80. })
  81. }).exec()
  82. }
  83. const scrollTop = e.detail.scrollTop
  84. this.letterDetails.some((item,index)=>{
  85. if(scrollTop>=item.top && scrollTop <= item.bottom - 5){
  86. this.$emit('change',item.id)
  87. this.$emit('reset',true)
  88. return true
  89. }
  90. })
  91. }
  92. }
  93. }
  94. </script>
  95. <style>
  96. .commonly-hover{
  97. background-color: #eee;
  98. }
  99. .scroll-list{
  100. flex: 1;
  101. height: 100vh;
  102. overflow-y: hidden;
  103. }
  104. .phone-list{
  105. display: flex;
  106. background-color: #fff;
  107. flex-direction:column;
  108. position:relative;
  109. width: 100%;
  110. }
  111. .list-item {
  112. width: 100%;
  113. display: flex;
  114. align-items: center;
  115. flex-wrap:wrap;
  116. height: 92upx;
  117. background-color: #fff;
  118. height: 100%;
  119. }
  120. .list-item >.list-item-phone{
  121. font-weight: normal;
  122. }
  123. .list-item-title{
  124. background-color: #eee;
  125. }
  126. .list-item-title,.list-item-phone{
  127. width: 100%;
  128. height: 92upx;
  129. line-height: 92upx;
  130. font-size: 32upx;
  131. font-weight: bold;
  132. padding: 0 20upx;
  133. border-bottom: 1px solid #e5e5e5;
  134. }
  135. </style>