addressPicker.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <template>
  2. <div class="form-group" :id="thisId">
  3. <el-select v-model="selectedProvince" placeholder="请选择省" style="width:186px;marginRight:20px;" :disabled="disabled" @change="getCityList" clearable>
  4. <el-option>-- 省 --</el-option>
  5. <el-option
  6. v-for="item in ['河南省','河北省','山东省']"
  7. :key="item"
  8. :label="item"
  9. :value="item">
  10. </el-option>
  11. </el-select>
  12. <!-- <label>市</label> -->
  13. <el-select v-model="selectedCity" placeholder="请选择市" style="width:186px;" :disabled="disabled" @change="getDistrictList" clearable>
  14. <el-option>-- 市 --</el-option>
  15. <el-option
  16. v-for="item in ['郑州市','天津市','青岛市']"
  17. :key="item"
  18. :label="item"
  19. :value="item">
  20. </el-option>
  21. </el-select>
  22. <!-- <label>区</label>
  23. <el-select v-model="selectedCity" placeholder="请选择市" style="width:186px;" :disabled="disabled" @change="getDistrictList">
  24. <el-option>-- 市 --</el-option>
  25. <el-option
  26. v-for="item in ['郑州市','天津市','青岛市']"
  27. :key="item"
  28. :label="item"
  29. :value="item">
  30. </el-option>
  31. </el-select>-->
  32. </div>
  33. </template>
  34. <script>
  35. export default {
  36. mounted () {
  37. // this.getProvinceList();
  38. if (this.init_province) {
  39. this.selectedProvince = this.init_province;
  40. this.getCityList(function(){
  41. if (this.init_city) {
  42. this.selectedCity = this.init_city;
  43. this.getDistrictList(function(){
  44. if (this.init_district) {
  45. this.selectedDistrict = this.init_district;
  46. }
  47. });
  48. }
  49. });
  50. }
  51. },
  52. props : ['id','init_province','init_city','init_district','disabled'],
  53. data () {
  54. return {
  55. provinceList : [],
  56. cityList : [],
  57. districtList : [],
  58. selectedProvince : '',
  59. selectedCity : '',
  60. selectedDistrict : ''
  61. }
  62. },
  63. computed: {
  64. thisId () {
  65. return this.id || 'select-region-wrap';
  66. }
  67. },
  68. watch : {
  69. selectedProvince : function (newVal) {
  70. this.$emit('update:init_province',newVal);
  71. },
  72. init_province : function (newVal) {
  73. this.selectedProvince = newVal;
  74. },
  75. selectedCity : function (newVal) {
  76. this.$emit('update:init_city',newVal);
  77. },
  78. init_city : function (newVal) {
  79. this.selectedCity = newVal;
  80. },
  81. selectedDistrict : function (newVal) {
  82. this.$emit('update:init_district',newVal);
  83. },
  84. init_district : function (newVal) {
  85. this.selectedDistrict = newVal;
  86. }
  87. },
  88. methods : {
  89. getProvinceList () {
  90. // const this = this;
  91. // $.ajax({
  92. // url: host.api + 'region/list',
  93. // type: 'get',
  94. // dataType : 'json',
  95. // xhrFields: {
  96. // withCredentials: true
  97. // },
  98. // data: {
  99. // parent_id:1,
  100. // region_type : 1
  101. // },
  102. // success (res) {
  103. // if (res.code == 0) {
  104. // this.provinceList = res.data;
  105. // }
  106. // }
  107. // });
  108. },
  109. getCityList (callback) {
  110. // const this = this;
  111. // $.ajax({
  112. // url: host.api + 'region/list',
  113. // type: 'get',
  114. // dataType : 'json',
  115. // xhrFields: {
  116. // withCredentials: true
  117. // },
  118. // data: {
  119. // parent_id:this.selectedProvince,
  120. // region_type : 2
  121. // },
  122. // success (res) {
  123. // if (res.code == 0) {
  124. // this.cityList = res.data;
  125. // this.selectedCity = '';
  126. // this.selectedDistrict = '';
  127. // if (callback && typeof callback == 'function') {
  128. // callback();
  129. // }
  130. // }
  131. // }
  132. // });
  133. },
  134. getDistrictList (callback) {
  135. // $.ajax({
  136. // url: host.api + 'region/list',
  137. // type: 'get',
  138. // dataType : 'json',
  139. // data: {
  140. // parent_id:this.selectedCity,
  141. // region_type : 3
  142. // },
  143. // success (res) {
  144. // if (res.code == 0) {
  145. // this.districtList = res.data;
  146. // this.selectedDistrict = '';
  147. // if (callback && typeof callback == 'function') {
  148. // callback();
  149. // }
  150. // }
  151. // }
  152. // });
  153. }
  154. }
  155. }
  156. </script>
  157. <style scoped>
  158. label {
  159. width: 6em;
  160. text-align: right;
  161. margin-right: .5em;
  162. color: #606266;
  163. margin-left: -2em;
  164. }
  165. .form-control {
  166. width: 110px;
  167. }
  168. </style>