phone-area.vue 3.5 KB

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