area-code.vue 4.8 KB

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