indexes.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <template>
  2. <view>
  3. <cu-custom bgImage="https://image.weilanwl.com/color2.0/plugin/sylb2244.jpg" :isBack="true"><block slot="backText">返回</block>
  4. <block slot="content">索引</block>
  5. </cu-custom>
  6. <view class="cu-bar bg-white search fixed" :style="[{top:CustomBar + 'px'}]">
  7. <view class="search-form round">
  8. <text class="cuIcon-search"></text>
  9. <input type="text" placeholder="输入搜索的关键词" confirm-type="search"></input>
  10. </view>
  11. <view class="action">
  12. <button class="cu-btn bg-gradual-green shadow-blur round">搜索</button>
  13. </view>
  14. </view>
  15. <scroll-view scroll-y class="indexes" :scroll-into-view="'indexes-'+ listCurID" :style="[{height:'calc(100vh - '+ CustomBar + 'px - 50px)'}]"
  16. :scroll-with-animation="true" :enable-back-to-top="true">
  17. <block v-for="(item,index) in list" :key="index">
  18. <view :class="'indexItem-' + item.name" :id="'indexes-' + item.name" :data-index="item.name">
  19. <view class="padding">{{item.name}}</view>
  20. <view class="cu-list menu-avatar no-padding">
  21. <view class="cu-item" v-for="(items,sub) in 2" :key="sub">
  22. <view class="cu-avatar round lg">{{item.name}}</view>
  23. <view class="content">
  24. <view class="text-grey">{{item.name}}<text class="text-abc">{{list[sub].name}}</text>君</view>
  25. <view class="text-gray text-sm">
  26. 有{{sub+2}}个主子需要伺候
  27. </view>
  28. </view>
  29. </view>
  30. </view>
  31. </view>
  32. </block>
  33. </scroll-view>
  34. <view class="indexBar" :style="[{height:'calc(100vh - ' + CustomBar + 'px - 50px)'}]">
  35. <view class="indexBar-box" @touchstart="tStart" @touchend="tEnd" @touchmove.stop="tMove">
  36. <view class="indexBar-item" v-for="(item,index) in list" :key="index" :id="index" @touchstart="getCur" @touchend="setCur"> {{item.name}}</view>
  37. </view>
  38. </view>
  39. <!--选择显示-->
  40. <view v-show="!hidden" class="indexToast">
  41. {{listCur}}
  42. </view>
  43. </view>
  44. </template>
  45. <script>
  46. export default {
  47. data() {
  48. return {
  49. StatusBar: this.StatusBar,
  50. CustomBar: this.CustomBar,
  51. hidden: true,
  52. listCurID: '',
  53. list: [],
  54. listCur: '',
  55. };
  56. },
  57. onLoad() {
  58. let list = [{}];
  59. for (let i = 0; i < 26; i++) {
  60. list[i] = {};
  61. list[i].name = String.fromCharCode(65 + i);
  62. }
  63. this.list = list;
  64. this.listCur = list[0];
  65. },
  66. onReady() {
  67. let that = this;
  68. uni.createSelectorQuery().select('.indexBar-box').boundingClientRect(function(res) {
  69. that.boxTop = res.top
  70. }).exec();
  71. uni.createSelectorQuery().select('.indexes').boundingClientRect(function(res) {
  72. that.barTop = res.top
  73. }).exec()
  74. },
  75. methods: {
  76. //获取文字信息
  77. getCur(e) {
  78. this.hidden = false;
  79. this.listCur = this.list[e.target.id].name;
  80. },
  81. setCur(e) {
  82. this.hidden = true;
  83. this.listCur = this.listCur
  84. },
  85. //滑动选择Item
  86. tMove(e) {
  87. let y = e.touches[0].clientY,
  88. offsettop = this.boxTop,
  89. that = this;
  90. //判断选择区域,只有在选择区才会生效
  91. if (y > offsettop) {
  92. let num = parseInt((y - offsettop) / 20);
  93. this.listCur = that.list[num].name
  94. };
  95. },
  96. //触发全部开始选择
  97. tStart() {
  98. this.hidden = false
  99. },
  100. //触发结束选择
  101. tEnd() {
  102. this.hidden = true;
  103. this.listCurID = this.listCur
  104. },
  105. indexSelect(e) {
  106. let that = this;
  107. let barHeight = this.barHeight;
  108. let list = this.list;
  109. let scrollY = Math.ceil(list.length * e.detail.y / barHeight);
  110. for (let i = 0; i < list.length; i++) {
  111. if (scrollY < i + 1) {
  112. that.listCur = list[i].name;
  113. that.movableY = i * 20
  114. return false
  115. }
  116. }
  117. }
  118. }
  119. }
  120. </script>
  121. <style>
  122. page {
  123. padding-top: 100upx;
  124. }
  125. .indexes {
  126. position: relative;
  127. }
  128. .indexBar {
  129. position: fixed;
  130. right: 0px;
  131. bottom: 0px;
  132. padding: 20upx 20upx 20upx 60upx;
  133. display: flex;
  134. align-items: center;
  135. }
  136. .indexBar .indexBar-box {
  137. width: 40upx;
  138. height: auto;
  139. background: #fff;
  140. display: flex;
  141. flex-direction: column;
  142. box-shadow: 0 0 20upx rgba(0, 0, 0, 0.1);
  143. border-radius: 10upx;
  144. }
  145. .indexBar-item {
  146. flex: 1;
  147. width: 40upx;
  148. height: 40upx;
  149. display: flex;
  150. align-items: center;
  151. justify-content: center;
  152. font-size: 24upx;
  153. color: #888;
  154. }
  155. movable-view.indexBar-item {
  156. width: 40upx;
  157. height: 40upx;
  158. z-index: 9;
  159. position: relative;
  160. }
  161. movable-view.indexBar-item::before {
  162. content: "";
  163. display: block;
  164. position: absolute;
  165. left: 0;
  166. top: 10upx;
  167. height: 20upx;
  168. width: 4upx;
  169. background-color: #f37b1d;
  170. }
  171. .indexToast {
  172. position: fixed;
  173. top: 0;
  174. right: 80upx;
  175. bottom: 0;
  176. background: rgba(0, 0, 0, 0.5);
  177. width: 100upx;
  178. height: 100upx;
  179. border-radius: 10upx;
  180. margin: auto;
  181. color: #fff;
  182. line-height: 100upx;
  183. text-align: center;
  184. font-size: 48upx;
  185. }
  186. </style>