pickerAddr.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. <!--
  2. * @LastEditors: wangcc
  3. -->
  4. <template>
  5. <div class="pickerAddr u-flex">
  6. <div class="select-wrap select-province" @click="provinceClick">
  7. 省:
  8. <el-select v-model="selectProvince" placeholder="请选择" disabled>
  9. <!-- <el-option
  10. v-for="item in vuexCityList"
  11. :key="item.areaCode"
  12. :label="item.areaName"
  13. :value="{value:item.areaCode,label:item.areaName,areaId:item.areaId}"
  14. ></el-option>-->
  15. </el-select>
  16. </div>
  17. <div class="select-wrap">
  18. 市:
  19. <el-select v-model="selectCity" placeholder="请选择" @change="cityChange($event,'city')">
  20. <el-option
  21. v-for="item in vuexCityList"
  22. :key="item.areaCode"
  23. :label="item.areaName"
  24. :value="{value:item.areaCode,label:item.areaName,areaId:item.areaId}"
  25. ></el-option>
  26. </el-select>
  27. </div>
  28. <div class="select-wrap">
  29. 县:
  30. <el-select v-model="selectDistrict" placeholder="请选择" @change="cityChange($event,'district')">
  31. <el-option
  32. v-for="item in vuexDistrictList"
  33. :key="item.areaCode"
  34. :label="item.areaName"
  35. :value="{value:item.areaCode,label:item.areaName,areaId:item.areaId}"
  36. ></el-option>
  37. </el-select>
  38. </div>
  39. <div class="select-wrap">
  40. 乡:
  41. <el-select v-model="selectStreet" placeholder="请选择" @change="cityChange($event,'street')">
  42. <el-option
  43. v-for="item in vuexStreetList"
  44. :key="item.areaCode"
  45. :label="item.areaName"
  46. :value="{value:item.areaCode,label:item.areaName,areaId:item.areaId}"
  47. ></el-option>
  48. </el-select>
  49. </div>
  50. </div>
  51. </template>
  52. <script>
  53. import { mapMutations, mapState, mapGetters } from 'vuex';
  54. export default {
  55. // props:{
  56. // selectCity:{},
  57. // selectDistrict:{},
  58. // selectStreet: {}
  59. // },
  60. name: '',
  61. components: {},
  62. data() {
  63. return {
  64. selectProvince: '贵州省',
  65. selectCity: {},
  66. selectDistrict: {},
  67. selectStreet: {},
  68. value: '',
  69. parentId: '520000',
  70. name: '',
  71. areaId: ''
  72. };
  73. },
  74. watch: {
  75. '$store.state.addr.selectCity'(val) {
  76. this.selectCity = val;
  77. },
  78. '$store.state.addr.selectDistrict'(val) {
  79. this.selectDistrict = val;
  80. },
  81. '$store.state.addr.selectStreet'(val) {
  82. this.selectStreet = val;
  83. }
  84. // '$store.state.addr.smallClassSearch': {
  85. // handler(val) {
  86. // console.log(val);
  87. // this.areaData = val;
  88. // this.getCityChange();
  89. // this.getDistrictChange();
  90. // // this.vuexStreetList.forEach((item) => {
  91. // // if (val.townId == item.areaId) {
  92. // // valCode = item.areaCode;
  93. // // }
  94. // // });
  95. // // this.selectStreet = {
  96. // // areaId: val.townId,
  97. // // label: val.townName,
  98. // // value: valCode
  99. // // };
  100. // // if (val.countyId && val.countyName) {
  101. // // console.log(this.selectDistrict);
  102. // // this.setcity();
  103. // // }
  104. // }
  105. // }
  106. },
  107. computed: {
  108. // 引入getters中的计算属性,需要在 computed 中引入
  109. ...mapGetters(['vuexCityList', 'vuexDistrictList', 'vuexStreetList'])
  110. },
  111. created() {
  112. this.$store.dispatch('searchArea', {
  113. parentId: this.parentId,
  114. name: this.name,
  115. mapLevel: 'province'
  116. });
  117. },
  118. mounted() {},
  119. methods: {
  120. ...mapMutations([
  121. 'changeSelectCity',
  122. 'changeSelectDistrict',
  123. 'changeSelectStreet'
  124. ]),
  125. // getCityChange() {
  126. // if (this.areaData.cityId && this.areaData.cityName) {
  127. // let valCode = '';
  128. // this.vuexCityList.forEach((item) => {
  129. // if (this.areaData.cityId == item.areaId) {
  130. // valCode = item.areaCode.substring(0, 6);
  131. // }
  132. // });
  133. // this.selectCity = {
  134. // areaId: this.areaData.cityId,
  135. // label: this.areaData.cityName,
  136. // value: valCode
  137. // };
  138. // this.$store.dispatch('searchArea', {
  139. // parentId: valCode,
  140. // name: this.areaData.cityName,
  141. // mapLevel: 'city'
  142. // });
  143. // }
  144. // },
  145. // getDistrictChange() {
  146. // let valCode = '';
  147. // this.vuexDistrictList.forEach((item) => {
  148. // if (this.areaData.countyId == item.areaId) {
  149. // valCode = item.areaCode.substring(0, 6);
  150. // }
  151. // });
  152. // this.selectDistrict = {
  153. // areaId: this.areaData.countyId,
  154. // label: this.areaData.countyName,
  155. // value: valCode
  156. // };
  157. // this.$store.dispatch('searchArea', {
  158. // parentId: valCode,
  159. // name: this.areaData.countyName,
  160. // mapLevel: 'district'
  161. // });
  162. // },
  163. cityChange(val, level) {
  164. if (level == 'city') {
  165. this.changeSelectCity({
  166. value: val.value,
  167. label: val.label,
  168. areaId: val.areaId
  169. });
  170. } else if (level == 'district') {
  171. this.changeSelectDistrict({
  172. value: val.value,
  173. label: val.label,
  174. areaId: val.areaId
  175. });
  176. } else if (level == 'street') {
  177. this.changeSelectStreet({
  178. value: val.value,
  179. label: val.label,
  180. areaId: val.areaId
  181. });
  182. }
  183. this.parentId = val.value.substring(0, 6);
  184. this.name = level;
  185. this.$store.dispatch('searchArea', {
  186. parentId: this.parentId,
  187. name: val.label,
  188. mapLevel: level
  189. });
  190. },
  191. provinceClick() {
  192. // console.log('provinceClick','provinceClick');
  193. this.$store.dispatch('searchArea', {
  194. parentId: '520000',
  195. name: '贵州省',
  196. mapLevel: 'province'
  197. });
  198. },
  199. getSelectModel() {}
  200. }
  201. };
  202. </script>
  203. <style lang='scss' scoped>
  204. .pickerAddr {
  205. font-size: 18px;
  206. color: var(--main-color);
  207. text-align: right;
  208. margin-bottom: 1vh;
  209. .select-wrap:not(:last-of-type) {
  210. margin-right: 10px;
  211. }
  212. .select-province {
  213. position: relative;
  214. &::after {
  215. content: '';
  216. width: 100%;
  217. height: 100%;
  218. position: absolute;
  219. left: 0;
  220. top: 0;
  221. background: transparent;
  222. cursor: pointer;
  223. }
  224. }
  225. .select-province.select-wrap {
  226. /deep/ .el-input__inner {
  227. cursor: pointer;
  228. }
  229. }
  230. .el-select {
  231. width: 8vw;
  232. /deep/ .el-input__inner {
  233. font-size: 18px;
  234. // height: 50px;
  235. // line-height: 50px;
  236. color: var(--main-color);
  237. background: url(../assets/img/select-bg.png) no-repeat;
  238. background-size: 100% 100%;
  239. border: none;
  240. &::-webkit-input-placeholder {
  241. color: var(--main-color);
  242. }
  243. &:hover {
  244. border-color: var(--main-color);
  245. }
  246. }
  247. /deep/ .el-input__icon {
  248. color: var(--main-color);
  249. }
  250. }
  251. }
  252. @media only screen and (max-width: 1200px) {
  253. .pickerAddr {
  254. font-size: 16px;
  255. .el-select {
  256. /deep/ .el-input__inner {
  257. font-size: 16px;
  258. }
  259. }
  260. }
  261. }
  262. </style>