Geen omschrijving

index.vue 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <template>
  2. <div class="linkage">
  3. <el-row :gutter="10">
  4. <el-col :span="8">
  5. <el-select
  6. v-model="sheng"
  7. @change="choseProvince"
  8. placeholder="省">
  9. <el-option
  10. v-for="item in province"
  11. :key="item.id"
  12. :label="item.value"
  13. :value="item.id">
  14. </el-option>
  15. </el-select>
  16. </el-col>
  17. <el-col :span="8">
  18. <el-select
  19. v-model="shi"
  20. @change="choseCity"
  21. placeholder="市">
  22. <el-option
  23. v-for="item in shi1"
  24. :key="item.id"
  25. :label="item.value"
  26. :value="item.id">
  27. </el-option>
  28. </el-select>
  29. </el-col>
  30. <el-col :span="8">
  31. <el-select
  32. v-model="qu"
  33. @change="choseBlock"
  34. placeholder="区(县)">
  35. <el-option
  36. v-for="item in qu1"
  37. :key="item.id"
  38. :label="item.value"
  39. :value="item.id">
  40. </el-option>
  41. </el-select>
  42. </el-col>
  43. </el-row>
  44. </div>
  45. </template>
  46. <script>
  47. import queryDict from '@/utils/queryDict'
  48. export default {
  49. props: ['addrCode'],
  50. data() {
  51. return {
  52. firstFlag: false,
  53. province: [],
  54. sheng: '',
  55. shi: '',
  56. shi1: [],
  57. qu: '',
  58. qu1: [],
  59. city: '',
  60. block: ''
  61. }
  62. },
  63. watch: {
  64. addrCode: function() {
  65. this.initpsq()
  66. }
  67. },
  68. methods: {
  69. getCityData: function() {
  70. var that = this
  71. queryDict.applyDict('XZQH', function(dictData) {
  72. if (dictData) {
  73. var data = dictData.sort((obj1, obj2) => {
  74. return obj1.code - obj2.code
  75. })
  76. that.province = {}
  77. data.map(item => {
  78. if (item.code.match(/0000$/)) {
  79. that.province[item.code] = { id: item.code, value: item.caption, children: {}}
  80. } else if (item.code.match(/00$/)) {
  81. var p = that.province[item.code.slice(0, 2) + '0000']
  82. p.children[item.code] = { id: item.code, value: item.caption, children: {}}
  83. if (!p.defaultChild) {
  84. p.defaultChild = p.children[item.code]
  85. }
  86. } else {
  87. var pp = that.province[item.code.slice(0, 2) + '0000'].children[item.code.slice(0, 4) + '00']
  88. pp.children[item.code] = { id: item.code, value: item.caption }
  89. if (!pp.defaultChild) {
  90. pp.defaultChild = pp.children[item.code]
  91. }
  92. }
  93. })
  94. } else {
  95. console.log(dictData.status)
  96. }
  97. })
  98. },
  99. choseProvince: function(e) {
  100. var p = this.province[e]
  101. this.shi1 = p.children
  102. this.shi = p.defaultChild.value
  103. this.qu1 = p.defaultChild.children
  104. this.qu = p.defaultChild.defaultChild.value
  105. this.E = p.defaultChild.defaultChild.id
  106. this.sheng = p.value
  107. this.$emit('paren', this.E)
  108. },
  109. choseCity: function(e) {
  110. var p = this.province[e.slice(0, 2) + '0000'].children[e]
  111. this.shi = p.value
  112. this.qu1 = p.children
  113. this.qu = p.defaultChild.value
  114. this.E = p.defaultChild.id
  115. this.$emit('paren', this.E)
  116. },
  117. choseBlock: function(e) {
  118. this.qu = this.province[e.slice(0, 2) + '0000'].children[e.slice(0, 4) + '00'].children[e].value
  119. this.E = e
  120. this.$emit('paren', this.E)
  121. },
  122. initpsq: function() {
  123. if (!this.addrCode) {
  124. this.sheng = ''
  125. this.shi = ''
  126. this.qu = ''
  127. return
  128. }
  129. const s = this.addrCode.substring(0, 2) + '0000'
  130. const si = this.addrCode.substring(0, 4) + '00'
  131. const x = this.addrCode
  132. var p = this.province[s]
  133. this.sheng = p.value
  134. this.shi = p.children[si].value
  135. this.qu = p.children[si].children[x].value
  136. }
  137. },
  138. created: function() {
  139. this.getCityData()
  140. }
  141. }
  142. </script>