area-code.vue 4.3 KB

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