MobileAreaCodeDict.vue 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <template>
  2. <view>
  3. <uni-nav-bar
  4. status-bar = true
  5. fixed = true
  6. background-color="#03b6b3"
  7. color="#ffffff">
  8. <text slot="default" style="text-align: center; flex: 1; font-size: 18px; font-weight: bold;">Mobile Area Code</text>
  9. </uni-nav-bar>
  10. <view>
  11. <uni-indexed-list :options="list" :showSelect="false" @click="bindClick"></uni-indexed-list>
  12. </view>
  13. </view>
  14. </template>
  15. <script>
  16. import uniNavBar from "@/components/uni-nav-bar/uni-nav-bar.vue";
  17. import uniIndexedList from "@/components/uni-indexed-list/uni-indexed-list.vue";
  18. import country from "@/static/js/counytryCode.js";
  19. export default {
  20. comments: {uniNavBar, uniIndexedList},
  21. data() {
  22. return {
  23. list: []
  24. }
  25. },
  26. mounted(){
  27. this.initCode();
  28. },
  29. methods: {
  30. bindClick(e){
  31. let finallyCode = e.item.name.slice(-5, -1);
  32. const eventChannel = this.getOpenerEventChannel()
  33. eventChannel.emit('watchMobileAreaCode', {code: finallyCode});
  34. uni.navigateBack();
  35. },
  36. initCode(){
  37. country.forEach(code => {
  38. let letter = code.enValue[0].toUpperCase();
  39. let itemValue = `${code.enValue} (${code.id})`;
  40. if(this.list.length){
  41. let hasSameLetter = false;
  42. let listItemIndex;
  43. for(let l = 0; l < this.list.length; l++){
  44. if(this.list[l].letter == letter){
  45. hasSameLetter = true;
  46. listItemIndex = l;
  47. break;
  48. }
  49. }
  50. if(hasSameLetter){
  51. this.list[listItemIndex].data.push(itemValue);
  52. }else{
  53. this.list.push({
  54. letter: letter,
  55. data: [itemValue]
  56. });
  57. }
  58. }else{
  59. this.list.push({
  60. letter: letter,
  61. data: [itemValue]
  62. });
  63. }
  64. this.list.sort(function(a, b){
  65. return a.letter.charCodeAt()-b.letter.charCodeAt();
  66. })
  67. })
  68. }
  69. }
  70. }
  71. </script>
  72. <style scoped>
  73. /deep/ .uni-indexed-list__menu{
  74. width: 30px;
  75. }
  76. </style>