GlobalRoaming.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. <template>
  2. <el-input
  3. :placeholder="$i18n.locale=='en'?'Please enter cellphone number.': '请输入手机号码'"
  4. class="input-with-select login2_item dcp_input"
  5. style="width:100%"
  6. maxlength="11"
  7. show-word-limit
  8. @input="inputTel"
  9. v-model="tel"
  10. oninput="value=value.replace(/[^0-9.]/g,'')"
  11. >
  12. <el-select v-model="select" slot="prepend" placeholder="" @change="countryChange">
  13. <div :style="{width: size.width, padding: '0 20px', 'box-sizing': 'border-box'}">
  14. <el-input
  15. :placeholder="$i18n.locale=='en'?'Search your country and area': '搜索您的国家和地区'"
  16. suffix-icon="el-icon-search"
  17. v-model="searchVal"
  18. maxlength="20"
  19. show-word-limit
  20. @input="inputSearch"
  21. ></el-input>
  22. <div style="padding-top: 10px; font-size: 14px; overflow: hidden">
  23. <span
  24. style="float: left; margin-right: 10px;"
  25. :class="getSearchs=='常用国家/地区'?'getSearchs2 cursor':'getSearchs1 cursor' "
  26. @click="commonAreas"
  27. v-show="!isInputSearch"
  28. >{{$i18n.locale=='en'?'The Commonly Used': '常用国家/地区'}}</span>
  29. <span
  30. style="float: left;margin-right: 10px;"
  31. v-for="item in countrySearchs"
  32. :key="item"
  33. :class="item==getSearchs?'getSearchs2 cursor':'getSearchs1 cursor' "
  34. @click="getCountrySearchs(item)"
  35. >{{item}}</span>
  36. </div>
  37. <div class="scroll-view">
  38. <el-option value="空选项" disabled style="height: 0px"></el-option>
  39. <el-option
  40. :label="$i18n.locale == 'en'? computedLabel(item.enValue, item.id, 9): computedLabel(item.cnValue, item.id, 5)"
  41. :value="item.id"
  42. v-for="item in countrys"
  43. :key="item.pinyin"
  44. >
  45. <span style="float: left; margin-right: 10px">
  46. <img
  47. v-if="showFlag"
  48. style="margin-top: 11px"
  49. :src="require('@/assets/img/nationalflag/'+item.pinyin+'_'+item.id+'.png')"
  50. width="19"
  51. height="12"
  52. alt
  53. />
  54. </span>
  55. <span style="float: left;">{{ $i18n.locale == 'en'? item.enValue: item.cnValue }}</span>
  56. <span style="float: right;">{{ item.id }}</span>
  57. </el-option>
  58. <div
  59. v-show="countryEmpty"
  60. style="color: #606266; font-size: 14px; line-height: 24px"
  61. >{{$i18n.locale=='en'?'No matching country or region was found': '未找到匹配的国家或地区'}}</div>
  62. </div>
  63. </div>
  64. </el-select>
  65. </el-input>
  66. </template>
  67. <script>
  68. import country from "@/assets/js/counytryCode.js";
  69. export default {
  70. props: {
  71. size: {
  72. type: Object
  73. },
  74. language: {
  75. type: String,
  76. default: 'zh'
  77. },
  78. showFlag: {
  79. type: Boolean,
  80. default: true,
  81. },
  82. code: {
  83. type: String,
  84. default: '',
  85. },
  86. mobile: {
  87. type: String,
  88. default: ''
  89. }
  90. },
  91. data() {
  92. return {
  93. tel: '',
  94. searchVal: '',
  95. select: "0086",
  96. isInputSearch: false, //是否是输入搜索
  97. getSearchs: "",
  98. countrys: [],
  99. countrySearchs: [],
  100. countryEmpty: false, // 是否没有匹配项
  101. };
  102. },
  103. watch: {
  104. code(val){
  105. this.select = val;
  106. },
  107. mobile(val){
  108. this.tel = val
  109. }
  110. },
  111. mounted() {
  112. this.commonAreas();
  113. this.countrySearchs = this.getLetters(country);
  114. this.$emit('getAreaCode', this.select)
  115. },
  116. methods: {
  117. computedLabel(value, id, n){
  118. return value.length>n? value.slice(0, n-1)+'... '+id: value+' '+id
  119. },
  120. inputTel(value){
  121. this.$emit('input', value)
  122. },
  123. // 输入框搜索国家地区
  124. inputSearch(value) {
  125. if (value.length) {
  126. this.isInputSearch = true;
  127. let reg = new RegExp(value, "i");
  128. if (this.$i18n.locale == "zh") {
  129. this.searchScope = country.filter((item, i) => {
  130. return reg.test(item.pinyin) || reg.test(item.cnValue);
  131. });
  132. } else {
  133. this.searchScope = country.filter((item, i) => {
  134. return reg.test(item.enValue);
  135. });
  136. }
  137. this.countrySearchs = this.getLetters(this.searchScope);
  138. if (this.searchScope.length) {
  139. this.countryEmpty = false;
  140. } else {
  141. this.countryEmpty = true;
  142. }
  143. this.countrys = this.searchScope;
  144. this.getCountrySearchs(this.countrySearchs[0]);
  145. } else {
  146. this.isInputSearch = false;
  147. this.commonAreas();
  148. this.countrySearchs = this.getLetters(country);
  149. }
  150. },
  151. // 点击字母搜索国家地区
  152. getCountrySearchs(letter) {
  153. this.getSearchs = letter;
  154. let searchScope = this.isInputSearch ? this.searchScope : country;
  155. let reg = new RegExp("^" + letter, "i");
  156. if (this.$i18n.locale == "zh") {
  157. this.countrys = searchScope.filter((item, i) => {
  158. return reg.test(item.pinyin);
  159. });
  160. } else {
  161. this.countrys = searchScope.filter((item, i) => {
  162. return reg.test(item.enValue);
  163. });
  164. }
  165. },
  166. // 点击常用国家/地区
  167. commonAreas() {
  168. this.getSearchs = "常用国家/地区";
  169. this.countrys = country.slice(0, 10);
  170. },
  171. // 获取索引字母
  172. getLetters(region) {
  173. let arr = [];
  174. if (this.$i18n.locale == "zh") {
  175. region.forEach((item, i) => {
  176. let initial = item.pinyin.slice(0, 1).toUpperCase();
  177. if (!arr.includes(initial)) {
  178. arr.push(initial);
  179. }
  180. });
  181. } else {
  182. region.forEach((item, i) => {
  183. let initial = item.enValue.slice(0, 1);
  184. if (!arr.includes(initial)) {
  185. arr.push(initial);
  186. }
  187. });
  188. }
  189. return arr.sort();
  190. },
  191. // 搜索地区发生变化
  192. countryChange(item) {
  193. console.log(item);
  194. this.$emit('getAreaCode', item)
  195. },
  196. },
  197. };
  198. </script>
  199. <style scoped>
  200. .scroll-view{
  201. width: 100%;
  202. height: 150px;
  203. overflow-x: hidden;
  204. }
  205. .scroll-view::-webkit-scrollbar{
  206. display: none;
  207. }
  208. .getSearchs1 {
  209. color: #0c27ff;
  210. }
  211. .getSearchs2 {
  212. color: #d12910;
  213. }
  214. .dcp_input /deep/ .el-select-dropdown__item{
  215. padding: 0;
  216. }
  217. </style>