phone-area.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <template>
  2. <view class="phone-area">
  3. <custom-nav noback="noback" transparent="transparent" ref="ltm" title=" " />
  4. <view class="content">
  5. <!-- <scroll-view scroll-y :style="{ height: scrollviewHeight + 'px' }" :scroll-into-view="'item'+ itemName" -->
  6. <scroll-view scroll-y :scroll-into-view="'item'+ itemName" :scroll-with-animation="true"
  7. :enable-back-to-top="true">
  8. <view class="list-item" v-for="(item, index) in list" v-if="item.list.length" :key="index"
  9. :id="'item' + item.name">
  10. <!-- <view class="name">{{ item.name }}</view> -->
  11. <view class="item" v-for="(codeItem, codeIndex) in item.list" :key="codeIndex"
  12. @click="chooseCode(codeItem.name, codeItem.code,codeItem.reg,codeItem.phoneReg)">
  13. <text>{{ codeItem.name }}</text>
  14. <text class="code">{{ codeItem.code }}</text>
  15. </view>
  16. </view>
  17. </scroll-view>
  18. <!-- <view class="chooseIndex" @touchstart="tMove" @touchmove.stop="tMove" @touchend="tEnd">
  19. <view class="chooseIndex-item" v-for="(item, index) in list" :key="index" :id="'indexes-' + item.name">
  20. {{ item.name }}
  21. </view>
  22. </view> -->
  23. <view v-if="isShowChar" class="showChar">{{ showChar }}</view>
  24. </view>
  25. </view>
  26. </template>
  27. <script>
  28. import areaList from '@/common/util/phone-area.js'
  29. export default {
  30. data() {
  31. return {
  32. title: '选择国家/地区',
  33. scrollviewHeight: 0,
  34. list: areaList,
  35. itemName: '',
  36. chooseBar: {},
  37. isShowChar: false,
  38. showChar: ''
  39. }
  40. },
  41. mounted() { // 设置scrollview 高
  42. this.$offset('.content').then(res => this.scrollviewHeight = res.height) // 设置scrollview 高
  43. this.$offset('.chooseIndex').then(res => this.chooseBar = res) // 获取chooseBar高度
  44. },
  45. methods: {
  46. tMove(e) { // chooseBar touch 事件开始
  47. this.isShowChar = true
  48. if (e.touches[0].clientY >= this.chooseBar.top && e.touches[0].clientY <= this.chooseBar.bottom) {
  49. this.itemName = this.showChar = this.list[Math.floor(((e.touches[0].clientY - this.chooseBar.top) /
  50. this.chooseBar.height) * 26)].name
  51. }
  52. },
  53. tEnd() { // chooseBar touch 事件结束
  54. this.isShowChar = false;
  55. },
  56. chooseCode(name, code, reg, phoneReg) { // 选择代码
  57. uni.$emit('CHOOSEPHONECODE', name, '+' + code, reg, phoneReg)
  58. uni.navigateBack()
  59. }
  60. }
  61. }
  62. </script>
  63. <style lang="scss">
  64. .phone-area {
  65. // @include page();
  66. width: 100%;
  67. height: 100vh;
  68. background: #F2F2F2;
  69. .content {
  70. scroll-view {
  71. background: #FFFFFF;
  72. height: 100vh;
  73. .list-item {
  74. .name {
  75. display: flex;
  76. height: 48rpx;
  77. font-size: 32rpx;
  78. padding: 0 30rpx;
  79. position: sticky;
  80. box-sizing: border-box;
  81. background: #F2F2F2;
  82. justify-content: flex-start;
  83. }
  84. .item {
  85. display: flex;
  86. align-items: center;
  87. height: 88rpx;
  88. box-sizing: border-box;
  89. padding: 0 100rpx 0 30rpx;
  90. justify-content: space-between;
  91. border-bottom: 1rpx solid #F2F2F2;
  92. text {
  93. color: #000;
  94. }
  95. .code {
  96. color: #42b983;
  97. padding: 10rpx 20rpx;
  98. border-radius: 8rpx;
  99. border: 1rpx solid #1AAD19;
  100. }
  101. }
  102. }
  103. }
  104. .chooseIndex {
  105. display: flex;
  106. flex-direction: column;
  107. top: 50%;
  108. right: 30rpx;
  109. width: 30rpx;
  110. height: 780rpx;
  111. position: fixed;
  112. background: #FFFFFF;
  113. border-radius: 8rpx;
  114. transform: translateY(-50%);
  115. box-shadow: 0rpx 0rpx 1rpx 1rpx #666666;
  116. .chooseIndex-item {
  117. // @include flex();
  118. width: 30rpx;
  119. height: 30rpx;
  120. border-radius: 50%;
  121. }
  122. }
  123. .showChar {
  124. // @include flex();
  125. top: 50%;
  126. left: 50%;
  127. z-index: 1;
  128. width: 123rpx;
  129. height: 123rpx;
  130. color: #FFFFFF;
  131. position: fixed;
  132. font-size: 88rpx;
  133. border-radius: 50%;
  134. background: rgba(0, 0, 0, .3);
  135. transform: translate(-50%, -50%);
  136. }
  137. }
  138. }
  139. </style>