area.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <template>
  2. <div class="clearfix">
  3. <div class="pull-left name"><span v-if="IslookOrUpdate !== 'look'">*</span>所在地区</div>
  4. <div class="pull-left select" v-if="IslookOrUpdate !== 'look'">
  5. <el-select v-model="pro" placeholder="省级行政区" @change="ProselectChange">
  6. <el-option v-for="proItem in cityData.province" :label="proItem" :value="proItem" v-bind:key="proItem"></el-option>
  7. </el-select>
  8. </div>
  9. <div class="pull-left select" v-else>
  10. <el-input v-model="pro" :disabled="true">
  11. </el-input>
  12. </div>
  13. <div class="pull-left select" v-if="IslookOrUpdate !== 'look'">
  14. <el-select v-model="city" placeholder="市" @change="CityselectChange">
  15. <el-option v-for="proItem in cityData.city" :label="proItem" :value="proItem" v-bind:key="proItem"></el-option>
  16. </el-select>
  17. </div>
  18. <div class="pull-left select" v-else>
  19. <el-input v-model="city" :disabled="true">
  20. </el-input>
  21. </div>
  22. <div class="pull-left select" v-if="IslookOrUpdate !== 'look'">
  23. <el-select v-model="area" placeholder="区" @change="setup">
  24. <el-option v-for="proItem in cityData.district" :label="proItem" :value="proItem" v-bind:key="proItem"></el-option>
  25. </el-select>
  26. </div>
  27. <div class="pull-left select" v-else>
  28. <el-input v-model="area" :disabled="true">
  29. </el-input>
  30. </div>
  31. </div>
  32. </template>
  33. <script>
  34. export default {
  35. name: 'Cityarea',
  36. props: {
  37. data: {
  38. type: String,
  39. default: ''
  40. },
  41. IslookOrUpdate: {
  42. type: String,
  43. default: 'update'
  44. }
  45. },
  46. data() {
  47. return {
  48. area: '',
  49. pro: '',
  50. city: '',
  51. cityData: {
  52. province: [],
  53. city: [],
  54. district: []
  55. }
  56. }
  57. },
  58. created() {
  59. },
  60. mounted() {
  61. this.$nextTick(()=>{
  62. this.$http.get('/data/city.json').then(response => {
  63. this.temCityData = response.data
  64. for (let province in response.data) {
  65. this.cityData.province.push(province)
  66. }
  67. this.setValshow()
  68. })
  69. })
  70. },
  71. methods: {
  72. ProselectChange(am) {
  73. this.proText = am
  74. this.city = ''
  75. this.area = ''
  76. this.cityData.city = []
  77. for (let item in this.temCityData[am]) {
  78. this.cityData.city.push(item)
  79. }
  80. },
  81. CityselectChange(am) {
  82. this.area = ''
  83. this.cityData.district = this.temCityData[this.proText][am]
  84. },
  85. setValshow() {
  86. this.pro = this.data ? this.data.split(',')[0] : ''
  87. if (this.data && this.pro) {
  88. this.ProselectChange(this.pro)
  89. this.city = this.data.split(',')[1]
  90. } else {
  91. this.city = ''
  92. }
  93. if (this.data && this.city) {
  94. this.CityselectChange(this.city)
  95. this.area = this.data.split(',')[2]
  96. } else {
  97. this.area = ''
  98. }
  99. },
  100. setup() {
  101. let info = this.pro + ',' + this.city + ',' + this.area
  102. this.$emit('setup', info)
  103. }
  104. }
  105. }
  106. </script>
  107. <style>
  108. </style>