areaSelect.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. var g=""
  73. for(var i=0;i<this.current2.length;i++){
  74. if(this.current2[i]=='active'){
  75. if(i>10){
  76. }
  77. }
  78. }
  79. console.log(this.current2)
  80. this.$emit('province','4545454456456');
  81. }
  82. }
  83. }
  84. </script>
  85. <style>
  86. .me_search {
  87. width: 100%;
  88. height: 100%;
  89. position: relative;
  90. padding-bottom: 50px;
  91. }
  92. .me_search button {
  93. width: 100%;
  94. height: 50px;
  95. line-height: 50px;
  96. position: fixed;
  97. background-color: #ff5c5c;
  98. text-align: center;
  99. bottom: 0;
  100. max-width: 500px;
  101. color: #fff;
  102. font-size: 18px;
  103. border: 0;
  104. outline: none;
  105. }
  106. .big_area {
  107. width: 30%;
  108. background-color: #efefef;
  109. text-align: center;
  110. height: 100%;
  111. position: absolute;
  112. top: 0;
  113. bottom: 0;
  114. }
  115. .big_area li {
  116. color: #7a7a7a;
  117. }
  118. .area_province {
  119. width: 100%;
  120. background-color: #fff;
  121. text-align: left;
  122. padding-left: 30%;
  123. height: 100%;
  124. padding-right: 1.5rem;
  125. overflow-y: scroll;
  126. }
  127. .area_province li {
  128. padding-left: 30px;
  129. background-image: url('../static/img/icon_select.png');
  130. background-position: right center;
  131. background-size: 20px;
  132. background-repeat: no-repeat;
  133. }
  134. .area_sel li {
  135. line-height: 60px;
  136. transition: 0.2s;
  137. }
  138. .big_area li.active {
  139. background-color: #fff;
  140. color: #ff5c5c;
  141. transition: 0.2s;
  142. }
  143. .area_province li.active {
  144. color: #ff5c5c;
  145. background-image: url('../static/img/icon_selected.png');
  146. transition: 0.2s;
  147. }
  148. </style>