areaSelect.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  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==current}"
  10. >{{ item.text }}</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(index)"
  19. :class="current2[index]"
  20. >{{ item.text }}</li>
  21. </ul>
  22. <!-- end:选择省份 -->
  23. <button>确定</button>
  24. </div>
  25. </template>
  26. <script>
  27. export default {
  28. data() {
  29. return {
  30. current: '0',
  31. current2: [],
  32. areaone: [
  33. {
  34. text: '全国',
  35. province: [
  36. { text: '全部' },
  37. { text: '北京' },
  38. { text: 'assa' },
  39. { text: '上海' },
  40. { text: '湖北' },
  41. { text: '河南' },
  42. { text: '山西' },
  43. { text: '新疆' },
  44. { text: '各小区' }
  45. ]
  46. },
  47. {
  48. text: '西北',
  49. province: [
  50. { text: '全部' },
  51. { text: '北京' },
  52. { text: '2' },
  53. { text: '上海' },
  54. { text: '湖北' },
  55. { text: '河南' },
  56. { text: '山西' },
  57. { text: '新疆' },
  58. { text: '各小区' }
  59. ]
  60. },
  61. {
  62. text: '西南',
  63. province: [
  64. { text: '全部' },
  65. { text: '北京' },
  66. { text: '3' },
  67. { text: '上海' },
  68. { text: '湖北' },
  69. { text: '河南' },
  70. { text: '山西' },
  71. { text: '新疆' },
  72. { text: '各小区' }
  73. ]
  74. },
  75. {
  76. text: '东北',
  77. province: [
  78. { text: '全部' },
  79. { text: '北京' },
  80. { text: '4' },
  81. { text: '上海' },
  82. { text: '湖北' },
  83. { text: '河南' },
  84. { text: '山西' },
  85. { text: '新疆' },
  86. { text: '各小区' }
  87. ]
  88. },
  89. {
  90. text: '东南',
  91. province: [
  92. { text: '全部' },
  93. { text: '北京' },
  94. { text: '5' },
  95. { text: '上海' },
  96. { text: '湖北' },
  97. { text: '河南' },
  98. { text: '山西' },
  99. { text: '新疆' },
  100. { text: '各小区' }
  101. ]
  102. },
  103. {
  104. text: '华中',
  105. province: [
  106. { text: '全部' },
  107. { text: '北京' },
  108. { text: '6' },
  109. { text: '上海' },
  110. { text: '湖北' },
  111. { text: '河南' },
  112. { text: '山西' },
  113. { text: '新疆' },
  114. { text: '各小区' }
  115. ]
  116. },
  117. {
  118. text: '华北',
  119. province: [
  120. { text: '全部' },
  121. { text: '北京' },
  122. { text: '天津' },
  123. { text: '7' },
  124. { text: '湖北' },
  125. { text: '河南' },
  126. { text: '山西' },
  127. { text: '新疆' },
  128. { text: '各小区' }
  129. ]
  130. },
  131. {
  132. text: '华南',
  133. province: [
  134. { text: '全部' },
  135. { text: '北京' },
  136. { text: '天津' },
  137. { text: '8' },
  138. { text: '湖北' },
  139. { text: '河南' },
  140. { text: '山西' },
  141. { text: '新疆' },
  142. { text: '各小区' }
  143. ]
  144. }
  145. ],
  146. areatwo: [],
  147. a: true //true为为全部选中
  148. }
  149. },
  150. created() {
  151. this.areatwo = this.areaone[0].province
  152. },
  153. methods: {
  154. addClass: function(index) {
  155. this.areatwo = this.areaone[index].province
  156. this.current = index
  157. },
  158. choose: function(index) {
  159. var current = this.current2
  160. //判断点击的是否为全选
  161. if (index == 0) {
  162. //判断是否以及全选
  163. console.log(this.a)
  164. if (this.a) {
  165. //如果未全部选中则全部选中
  166. for (var i = 0; i < this.areatwo.length; i++) {
  167. current[i] = ['active']
  168. }
  169. this.a = false
  170. } else {
  171. //如果已经全部选中则初始化
  172. current = []
  173. this.a = true
  174. }
  175. } else {
  176. if (current[index] == 'active') {
  177. //如果当前数组的这个值为已选中
  178. current[index] = ['']
  179. } else {
  180. //如果未选中
  181. current[index] = ['active']
  182. }
  183. var k = 1;//设置初始值
  184. for (var i = 0; i < current.length; i++) {
  185. //循环整个数组看看有多少已选中
  186. if (current[i] == 'active') {
  187. //赋值k的值为已选中的数量
  188. k++
  189. }
  190. }
  191. if (k == current.length) {
  192. //如果k(已选中的数量)等于数组全部的数量
  193. this.a = false
  194. //设置当前已经全部选中
  195. }
  196. }
  197. if(current.length>0){
  198. this.$set(this.current2, current)
  199. }else{
  200. this.current2=current
  201. }
  202. }
  203. }
  204. }
  205. </script>
  206. <style>
  207. .me_search {
  208. width: 100%;
  209. height: 100%;
  210. position: relative;
  211. padding-bottom: 50px;
  212. }
  213. .me_search button {
  214. width: 100%;
  215. height: 50px;
  216. line-height: 50px;
  217. position: fixed;
  218. background-color: #ff5c5c;
  219. text-align: center;
  220. bottom: 0;
  221. left: 0;
  222. right: 0;
  223. color: #fff;
  224. font-size: 18px;
  225. border: 0;
  226. outline: none;
  227. }
  228. .big_area {
  229. width: 30%;
  230. background-color: #efefef;
  231. text-align: center;
  232. height: 100%;
  233. position: absolute;
  234. top: 0;
  235. bottom: 0;
  236. }
  237. .big_area li {
  238. color: #7a7a7a;
  239. }
  240. .area_province {
  241. width: 100%;
  242. background-color: #fff;
  243. text-align: left;
  244. padding-left: 30%;
  245. height: 100%;
  246. padding-right: 1.5rem;
  247. }
  248. .area_province li {
  249. padding-left: 30px;
  250. background-image: url('../static/img/icon_select.png');
  251. background-position: right center;
  252. background-size: 20px;
  253. background-repeat: no-repeat;
  254. }
  255. .area_sel li {
  256. line-height: 60px;
  257. transition: 0.2s;
  258. }
  259. .big_area li.active {
  260. background-color: #fff;
  261. color: #ff5c5c;
  262. transition: 0.2s;
  263. }
  264. .area_province li.active {
  265. color: #ff5c5c;
  266. background-image: url('../static/img/icon_selected.png');
  267. transition: 0.2s;
  268. }
  269. </style>