phone-area.vue 3.1 KB

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