areaSelect.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <template>
  2. <div class="me_search">
  3. <!-- 选择大区 -->
  4. <ul class="area_sel big_area">
  5. <li
  6. v-for="(item,index) in areaone"
  7. :key="index"
  8. @click="addClass(index)"
  9. :class="{active:index+1==current}"
  10. >{{ item.name }}</li>
  11. </ul>
  12. <!-- end:选择大区 -->
  13. <!-- 选择省份 -->
  14. <ul class="area_sel area_province">
  15. <li
  16. v-for="(item,index) in areatwo"
  17. :key="index"
  18. @click="choose(item.id)"
  19. :class="current2[item.id]"
  20. >{{ item.name }}</li>
  21. </ul>
  22. <!-- end:选择省份 -->
  23. <button @click="coolse">确定</button>
  24. </div>
  25. </template>
  26. <script>
  27. export default {
  28. data() {
  29. return {
  30. current: '1',
  31. current2: [],
  32. areaone: [{ id: '1', name: '全国' }],
  33. areatwo: [{ id: '1', name: '全国' }]
  34. }
  35. },
  36. props: ['regiont'],
  37. created() {
  38. this.areaone = this.areaone.concat(this.regiont)
  39. },
  40. methods: {
  41. addClass: function(index) {
  42. if (index > 0) {
  43. this.areatwo = [{ id: this.areaone[index].id, name: '全部' }]
  44. this.areatwo = this.areatwo.concat(this.areaone[index].province)
  45. } else {
  46. this.areatwo = [{ id: '1', name: '全国' }]
  47. }
  48. this.current = this.areaone[index].id
  49. },
  50. choose: function(index) {
  51. if (index == '1') {
  52. this.current2 = []
  53. this.current2[index] = 'active'
  54. } else {
  55. if (index == this.current) {
  56. for (var i = 0; i < this.areaone[index - 1].province.length; i++) {
  57. this.current2[this.areaone[index - 1].province[i].id] = ''
  58. }
  59. } else {
  60. this.current2[this.current] = ''
  61. }
  62. if (this.current2[index] == 'active') {
  63. this.current2[index] = ''
  64. } else {
  65. this.current2[index] = 'active'
  66. }
  67. this.current2[1] = ''
  68. }
  69. this.current2 = [].concat(this.current2)
  70. },
  71. coolse:function(){
  72. this.$emit('province','4545454456456');
  73. }
  74. }
  75. }
  76. </script>
  77. <style>
  78. .me_search {
  79. width: 100%;
  80. height: 100%;
  81. position: relative;
  82. padding-bottom: 50px;
  83. }
  84. .me_search button {
  85. width: 100%;
  86. height: 50px;
  87. line-height: 50px;
  88. position: fixed;
  89. background-color: #ff5c5c;
  90. text-align: center;
  91. bottom: 0;
  92. max-width: 500px;
  93. color: #fff;
  94. font-size: 18px;
  95. border: 0;
  96. outline: none;
  97. }
  98. .big_area {
  99. width: 30%;
  100. background-color: #efefef;
  101. text-align: center;
  102. height: 100%;
  103. position: absolute;
  104. top: 0;
  105. bottom: 0;
  106. }
  107. .big_area li {
  108. color: #7a7a7a;
  109. }
  110. .area_province {
  111. width: 100%;
  112. background-color: #fff;
  113. text-align: left;
  114. padding-left: 30%;
  115. height: 100%;
  116. padding-right: 1.5rem;
  117. overflow-y: scroll;
  118. }
  119. .area_province li {
  120. padding-left: 30px;
  121. background-image: url('../static/img/icon_select.png');
  122. background-position: right center;
  123. background-size: 20px;
  124. background-repeat: no-repeat;
  125. }
  126. .area_sel li {
  127. line-height: 60px;
  128. transition: 0.2s;
  129. }
  130. .big_area li.active {
  131. background-color: #fff;
  132. color: #ff5c5c;
  133. transition: 0.2s;
  134. }
  135. .area_province li.active {
  136. color: #ff5c5c;
  137. background-image: url('../static/img/icon_selected.png');
  138. transition: 0.2s;
  139. }
  140. </style>