phone-area.vue 3.7 KB

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