addressList.blade.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <script>
  2. Vue.component('addressList', {
  3. props: {
  4. province_id:{
  5. type:Number|String,
  6. default:'',
  7. },
  8. city_id:{
  9. type:Number|String,
  10. default:'',
  11. },
  12. district_id:{
  13. type:Number|String,
  14. default:'',
  15. },
  16. street_id:{
  17. type:Number|String,
  18. default:'',
  19. },
  20. //是否开启街道
  21. street:{
  22. type:Number|String,
  23. default:2,
  24. },
  25. // 宽度
  26. widthStyle:{
  27. type:String,
  28. default:'',
  29. },
  30. },
  31. delimiters: ['[[', ']]'],
  32. data(){
  33. return{
  34. form:{
  35. province_id:this.province_id,
  36. city_id:this.city_id,
  37. district_id:this.district_id,
  38. street_id:this.street_id,
  39. },
  40. province_list:[],
  41. city_list:[],
  42. district_list:[],
  43. street_list:[],
  44. }
  45. },
  46. watch:{
  47. 'form.province_id':{
  48. handler(val) {
  49. this.$emit('change-province','province_id',val);
  50. },
  51. },
  52. 'form.city_id':{
  53. handler(val) {
  54. this.$emit('change-province','city_id',val);
  55. },
  56. },
  57. 'form.district_id':{
  58. handler(val) {
  59. this.$emit('change-province','district_id',val);
  60. },
  61. },
  62. 'form.street_id':{
  63. handler(val) {
  64. this.$emit('change-province','street_id',val);
  65. },
  66. },
  67. province_id(val) {
  68. if(val&&this.province_id!=this.form.province_id) {
  69. this.form.province_id = this.province_id
  70. this.changeProvince(val,1)
  71. }
  72. },
  73. city_id(val) {
  74. if(val&&this.city_id!=this.form.city_id) {
  75. this.form.city_id = this.city_id
  76. this.changeCity(val,1)
  77. }
  78. },
  79. district_id(val) {
  80. if(val&&this.district_id!=this.form.district_id) {
  81. this.form.district_id = this.district_id
  82. this.changeDistrict(val,1)
  83. }
  84. },
  85. street_id(val) {
  86. if(val&&this.street_id!=this.form.street_id) {
  87. this.form.street_id = this.street_id
  88. }
  89. },
  90. },
  91. mounted: function(){
  92. this.initProvince();
  93. this.getStreet();
  94. if(this.form.province_id) {
  95. this.changeProvince(this.form.province_id,1)
  96. }
  97. if(this.form.city_id) {
  98. this.changeCity(this.form.city_id,1)
  99. }
  100. if(this.form.district_id) {
  101. this.changeDistrict(this.form.district_id,1)
  102. }
  103. },
  104. methods:{
  105. initProvince(val) {
  106. this.$http.get("{!! yzWebUrl('area.list.init', ['area_ids'=>'']) !!}"+val).then(response => {
  107. this.province_list = response.data.data;
  108. }, response => {
  109. });
  110. },
  111. // 区改变
  112. getStreet() {
  113. let url = "<?php echo yzWebUrl('area.list.open-street', []); ?>";
  114. this.$http.get(url).then(response => {
  115. if (response.data.result) {
  116. if(this.street==2) {
  117. this.street = response.data.data.is_street
  118. }
  119. } else {
  120. this.street_list = null;
  121. }
  122. }, response => {
  123. });
  124. },
  125. changeProvince(val,type) {
  126. if(!type) {
  127. this.city_list = [];
  128. this.district_list = [];
  129. this.street_list = [];
  130. // this.form.province_id = "";
  131. this.form.city_id = "";
  132. this.form.district_id = "";
  133. this.form.street_id = "";
  134. }
  135. let url = "<?php echo yzWebUrl('area.list', ['parent_id'=> '']); ?>" + val;
  136. this.$http.get(url).then(response => {
  137. if (response.data.data.length) {
  138. this.city_list = response.data.data;
  139. } else {
  140. this.city_list = null;
  141. }
  142. }, response => {
  143. });
  144. },
  145. // 市改变
  146. changeCity(val,type) {
  147. if(!type) {
  148. this.district_list = [];
  149. this.street_list = [];
  150. this.form.district_id = "";
  151. this.form.street_id = "";
  152. }
  153. let url = "<?php echo yzWebUrl('area.list', ['parent_id'=> '']); ?>" + val;
  154. this.$http.get(url).then(response => {
  155. if (response.data.data.length) {
  156. this.district_list = response.data.data;
  157. } else {
  158. this.district_list = null;
  159. }
  160. }, response => {
  161. });
  162. },
  163. // 区改变
  164. changeDistrict(val,type) {
  165. if(!type) {
  166. this.street_list = [];
  167. this.form.street_id = "";
  168. }
  169. let url = "<?php echo yzWebUrl('area.list', ['parent_id'=> '']); ?>" + val;
  170. this.$http.get(url).then(response => {
  171. if (response.data.data.length) {
  172. this.street_list = response.data.data;
  173. } else {
  174. this.street_list = null;
  175. }
  176. }, response => {
  177. });
  178. },
  179. },
  180. template: `
  181. <div>
  182. <el-select v-model="form.province_id" clearable placeholder="省" @change="changeProvince(form.province_id)" :style="{width:widthStyle=='search'?'150px':street==1?'17.5%':'23.33%'}">
  183. <el-option v-for="(item,index) in province_list" :key="index" :label="item.areaname" :value="item.id"></el-option>
  184. </el-select>
  185. <el-select v-model="form.city_id" clearable placeholder="市" @change="changeCity(form.city_id)" :style="{width:widthStyle=='search'?'150px':street==1?'17.5%':'23.33%'}">
  186. <el-option v-for="(item,index) in city_list" :key="index" :label="item.areaname" :value="item.id"></el-option>
  187. </el-select>
  188. <el-select v-model="form.district_id" clearable placeholder="区/县" @change="changeDistrict(form.district_id)" :style="{width:widthStyle=='search'?'150px':street==1?'17.5%':'23.33%'}">
  189. <el-option v-for="(item,index) in district_list" :key="index" :label="item.areaname" :value="item.id"></el-option>
  190. </el-select>
  191. <el-select v-if="street==1" v-model="form.street_id" clearable placeholder="街道/乡镇" :style="{width:widthStyle=='search'?'150px':street==1?'17.5%':'23.33%'}">
  192. <el-option v-for="(item,index) in street_list" :key="index" :label="item.areaname" :value="item.id"></el-option>
  193. </el-select>
  194. </div>
  195. `
  196. });
  197. </script>