area-code.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <template>
  2. <view>
  3. <headContent>
  4. <template #left>
  5. <view class="head-revers-back iconfont" @click.stop="reversBackBtn()">&#xe604;</view>
  6. </template>
  7. <template #content>
  8. <view class="haed-title">
  9. 国家/地区
  10. </view>
  11. </template>
  12. </headContent>
  13. <!-- :style="{'top': searchHeight + 'px'}" -->
  14. <view class="search-box">
  15. </view>
  16. <view class="scroll-box" :style="{'height':scrollViewHeight + 'px'}">
  17. <scroll-view scroll-y="true" class="scroll-Y" scroll-with-animation :scroll-into-view="scrollIntoView">
  18. <block v-for="(val , key , index) in AreaList">
  19. <view :id="key" v-if="val && val.length > 0">
  20. <text class="search-letter">{{ key }}</text>
  21. <view class="area-list">
  22. <view class="area-item" v-for="item in val">
  23. <text>{{item.name}}</text>
  24. <text>+{{item.area_code}}</text>
  25. </view>
  26. </view>
  27. </view>
  28. </block>
  29. </scroll-view>
  30. <view class="letter-tag">
  31. <block v-for="(val , key , index) in AreaList">
  32. <text @click.stop="scrollIntoView = key" :class="['tag-item' , scrollIntoView === key ? 'area-key' : '']"
  33. v-if="val && val.length > 0">{{ key }}</text>
  34. </block>
  35. </view>
  36. </view>
  37. </view>
  38. </template>
  39. <script>
  40. import {
  41. reverseBack
  42. } from "@/utils/common.js"
  43. import {
  44. mapGetters
  45. } from 'vuex'
  46. import {
  47. Api_getAreaCode
  48. } from "@/api/index.js"
  49. export default {
  50. data() {
  51. return {
  52. scrollIntoView: 'A',
  53. scrollViewHeight: 0,
  54. AreaList: []
  55. };
  56. },
  57. computed: {
  58. ...mapGetters([
  59. 'statusBarHeight',
  60. 'headHeight'
  61. ])
  62. },
  63. created() {
  64. const app = uni.getWindowInfo()
  65. let pageHeight = app.windowHeight || app.screenHeight
  66. this.scrollViewHeight = pageHeight - uni.upx2px(this.headHeight.split('rpx')[0]) - this.statusBarHeight - uni
  67. .upx2px(100)
  68. console.log('app = ', this.scrollViewHeight)
  69. this.getAreaCode()
  70. },
  71. methods: {
  72. reversBackBtn() {
  73. reverseBack()
  74. },
  75. getAreaCode() {
  76. Api_getAreaCode().then(res => {
  77. this.areaRank(res)
  78. }).catch(err => {
  79. })
  80. },
  81. areaRank(areaList = []) {
  82. const letters = {
  83. 'A': [],
  84. 'B': [],
  85. 'C': [],
  86. 'D': [],
  87. 'E': [],
  88. 'F': [],
  89. 'G': [],
  90. 'H': [],
  91. 'I': [],
  92. 'J': [],
  93. 'K': [],
  94. 'L': [],
  95. 'M': [],
  96. 'N': [],
  97. 'O': [],
  98. 'P': [],
  99. 'Q': [],
  100. 'R': [],
  101. 'S': [],
  102. 'T': [],
  103. 'U': [],
  104. 'V': [],
  105. 'W': [],
  106. 'X': [],
  107. 'Y': [],
  108. 'Z': [],
  109. '#': []
  110. }
  111. if (areaList && areaList.length > 0) {
  112. areaList.forEach(el => {
  113. if (el.name) {
  114. let initialLetter = el.name.slice(0, 1)
  115. letters[initialLetter].push(el)
  116. } else {
  117. letters['#'].push(el)
  118. }
  119. })
  120. };
  121. this.AreaList = letters
  122. }
  123. }
  124. }
  125. </script>
  126. <style lang="scss" scoped>
  127. @import "~./common.scss";
  128. .search-box {
  129. width: 100%;
  130. height: 100rpx;
  131. }
  132. .search-shadow {
  133. width: 100%;
  134. height: 100rpx;
  135. }
  136. .search-letter {
  137. display: inline-block;
  138. width: 100%;
  139. height: 80rpx;
  140. background-color: $page-bg;
  141. padding: 0 $pages-padding;
  142. line-height: 80rpx;
  143. font-size: 28rpx;
  144. color: #c1c1c1;
  145. }
  146. .area-list {
  147. width: 100%;
  148. padding: 0 $pages-padding;
  149. .area-item {
  150. width: 100%;
  151. height: 100rpx;
  152. display: flex;
  153. justify-content: space-between;
  154. align-items: center;
  155. border-bottom: 1rpx solid $border-color;
  156. font-size: 28rpx;
  157. padding-right: 30rpx;
  158. &:last-child {
  159. border-bottom: none;
  160. }
  161. }
  162. }
  163. .scroll-box {
  164. width: 100%;
  165. position: relative;
  166. .letter-tag {
  167. position: absolute;
  168. right: 0;
  169. top: 50%;
  170. padding: 0 10rpx 0 20rpx;
  171. transform: translateY(-50%);
  172. display: flex;
  173. flex-direction: column;
  174. align-items: center;
  175. justify-content: center;
  176. .tag-item {
  177. padding: 10rpx;
  178. font-size: 22rpx;
  179. // width: 20rpx;
  180. }
  181. .area-key{
  182. background-color: #c1c1c1;
  183. border-radius: 50%;
  184. }
  185. }
  186. }
  187. .scroll-Y {
  188. width: 100%;
  189. height: 100%;
  190. }
  191. </style>