region.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. <template>
  2. <view>
  3. <!--标题栏-->
  4. <bar-title bgColor="bg-white" isBack>
  5. <block slot="content">地区</block>
  6. </bar-title>
  7. <view class="padding">当前位置</view>
  8. <view class="cu-list menu">
  9. <view class="cu-item">
  10. <view class="content">
  11. <text class="cuIcon-location text-red"/>
  12. <text class="text-black">重庆</text>
  13. </view>
  14. </view>
  15. </view>
  16. <!--列表-->
  17. <scroll-view scroll-y class="indexes" :scroll-into-view="'indexes-'+ listCurID" :style="[{height:'calc(100vh - '+ CustomBar + 'px - 50px)'}]"
  18. :scroll-with-animation="true" :enable-back-to-top="true">
  19. <block v-for="(item,index) in list" :key="index">
  20. <view :class="'indexItem-' + item.name" :id="'indexes-' + item.name" :data-index="item.name">
  21. <view class="padding">{{item.name}}</view>
  22. <!--列表内容-->
  23. <view class="cu-list menu">
  24. <view class="cu-item" v-for="(items,sub) in 2" :key="sub">
  25. <view class="content">
  26. <text class="text-black">{{item.name}} {{list[sub].name}}</text>
  27. </view>
  28. </view>
  29. </view>
  30. </view>
  31. </block>
  32. </scroll-view>
  33. <!--快捷字母-->
  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. import barTitle from '@/components/zaiui-common/basics/bar-title';
  47. import _tool from '@/static/zaiui/util/tools.js'; //工具函数
  48. export default {
  49. components: {
  50. barTitle
  51. },
  52. data() {
  53. return {
  54. StatusBar: this.StatusBar,
  55. CustomBar: this.CustomBar,
  56. hidden: true,
  57. listCurID: '',
  58. list: [],
  59. listCur: '',
  60. }
  61. },
  62. onLoad() {
  63. let list = [{}];
  64. for (let i = 0; i < 26; i++) {
  65. list[i] = {};
  66. list[i].name = String.fromCharCode(65 + i);
  67. }
  68. this.list = list;
  69. this.listCur = list[0];
  70. },
  71. onReady() {
  72. _tool.setBarColor(true);
  73. uni.pageScrollTo({
  74. scrollTop: 0,
  75. duration: 0
  76. });
  77. uni.createSelectorQuery().select('.indexBar-box').boundingClientRect(res => {
  78. this.boxTop = res.top
  79. }).exec();
  80. uni.createSelectorQuery().select('.indexes').boundingClientRect(res => {
  81. this.barTop = res.top
  82. }).exec()
  83. },
  84. methods: {
  85. //获取文字信息
  86. getCur(e) {
  87. this.hidden = false;
  88. this.listCur = this.list[e.target.id].name;
  89. },
  90. setCur(e) {
  91. this.hidden = true;
  92. this.listCur = this.listCur
  93. },
  94. //滑动选择Item
  95. tMove(e) {
  96. let y = e.touches[0].clientY,
  97. offsettop = this.boxTop,
  98. that = this;
  99. //判断选择区域,只有在选择区才会生效
  100. if (y > offsettop) {
  101. let num = parseInt((y - offsettop) / 20);
  102. this.listCur = that.list[num].name
  103. };
  104. },
  105. //触发全部开始选择
  106. tStart() {
  107. this.hidden = false
  108. },
  109. //触发结束选择
  110. tEnd() {
  111. this.hidden = true;
  112. this.listCurID = this.listCur
  113. },
  114. indexSelect(e) {
  115. let barHeight = this.barHeight;
  116. let list = this.list;
  117. let scrollY = Math.ceil(list.length * e.detail.y / barHeight);
  118. for (let i = 0; i < list.length; i++) {
  119. if (scrollY < i + 1) {
  120. this.listCur = list[i].name;
  121. this.movableY = i * 20
  122. return false
  123. }
  124. }
  125. }
  126. }
  127. }
  128. </script>
  129. <style lang="scss">
  130. /* #ifdef APP-PLUS */
  131. @import "../../static/colorui/main.css";
  132. @import "../../static/colorui/icon.css";
  133. @import "../../static/zaiui/style/app.scss";
  134. /* #endif */
  135. .indexes {
  136. position: relative;
  137. }
  138. .indexBar {
  139. position: fixed;
  140. right: 0px;
  141. bottom: 16%;
  142. padding: 20upx 20upx 20upx 60upx;
  143. display: flex;
  144. align-items: center;
  145. }
  146. .indexBar .indexBar-box {
  147. width: 40upx;
  148. height: auto;
  149. background: #fff;
  150. display: flex;
  151. flex-direction: column;
  152. box-shadow: 0 0 20upx rgba(0, 0, 0, 0.1);
  153. border-radius: 10upx;
  154. }
  155. .indexBar-item {
  156. flex: 1;
  157. width: 40upx;
  158. height: 40upx;
  159. display: flex;
  160. align-items: center;
  161. justify-content: center;
  162. font-size: 24upx;
  163. color: #888;
  164. }
  165. movable-view.indexBar-item {
  166. width: 40upx;
  167. height: 40upx;
  168. z-index: 9;
  169. position: relative;
  170. }
  171. movable-view.indexBar-item::before {
  172. content: "";
  173. display: block;
  174. position: absolute;
  175. left: 0;
  176. top: 10upx;
  177. height: 20upx;
  178. width: 4upx;
  179. background-color: #f37b1d;
  180. }
  181. .indexToast {
  182. position: fixed;
  183. top: 0;
  184. right: 80upx;
  185. bottom: 0;
  186. background: rgba(0, 0, 0, 0.5);
  187. width: 100upx;
  188. height: 100upx;
  189. border-radius: 10upx;
  190. margin: auto;
  191. color: #fff;
  192. line-height: 100upx;
  193. text-align: center;
  194. font-size: 48upx;
  195. }
  196. </style>