index.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <template>
  2. <div class="select-layout">
  3. <select class="prov" v-model="currentPID" @change="handleChange">
  4. <option :value="i" v-for="(item,i) in citylist" :key="i">{{item.p}}</option>
  5. </select>
  6. <select class="city" v-model="currentCID" @change="handleChange">
  7. <option :value="i" v-for="(item,i) in currentProv" :key="i">{{item.n}}</option>
  8. </select>
  9. <select class="dist" v-model="currentSID" @change="handleChange">
  10. <option :value="i" v-for="(item,i) in currentCity" :key="i">{{item.s}}</option>
  11. </select>
  12. </div>
  13. </template>
  14. <script>
  15. import {citylist} from './city'
  16. export default {
  17. props: ['areaPath'],
  18. data () {
  19. let idArr = ['', '', '']
  20. if (this.areaPath) {
  21. let tempArr = this.areaPath.split(',')
  22. let [p, c, d] = tempArr
  23. idArr = (() => {
  24. let tmp = []
  25. citylist.forEach((item, index) => {
  26. if (item.p === p) {
  27. tmp.push(index)
  28. item.c.forEach((t2, i2) => {
  29. if (t2.n === c) {
  30. tmp.push(i2)
  31. t2.a.forEach((t3, i3) => {
  32. if (t3.s === d) {
  33. tmp.push(i3)
  34. }
  35. })
  36. }
  37. })
  38. }
  39. })
  40. return tmp
  41. })()
  42. }
  43. return {
  44. citylist,
  45. currentPID: idArr[0] !== '' ? idArr[0] : 18,
  46. currentCID: idArr[1] !== '' ? idArr[1] : 3,
  47. currentSID: idArr[2] !== '' ? idArr[2] : 2
  48. }
  49. },
  50. computed: {
  51. currentProv: function () {
  52. let tmp = this.citylist[this.currentPID]
  53. return tmp.c
  54. },
  55. currentCity: function () {
  56. let cprov = this.citylist[this.currentPID]
  57. let tmp = cprov.c[this.currentCID]
  58. return tmp.a
  59. }
  60. },
  61. watch: {
  62. currentProv () {
  63. this.currentCID = 0
  64. this.currentSID = 0
  65. }
  66. },
  67. methods: {
  68. handleChange () {
  69. let prov = this.citylist[this.currentPID]
  70. let city = prov.c[this.currentCID]
  71. let dist = city.a[this.currentSID]
  72. this.$emit('currentVal', [
  73. prov.p, city.n, dist.s
  74. ])
  75. }
  76. },
  77. mounted () {
  78. this.handleChange()
  79. }
  80. }
  81. </script>
  82. <style lang="scss" scoped>
  83. .select-layout{
  84. .prov,.city,.dist{
  85. outline: none;
  86. appearance: none;
  87. border: solid 1px #e7e7e7;
  88. background: url('//4dscene.4dage.com/new4dkk/images/myAccount_selectOpen.png') no-repeat white;
  89. background-size: 6%;
  90. background-position: 95% 50%;
  91. width: 200px;
  92. line-height: 36px;
  93. padding-left: 10px;
  94. height: 36px;
  95. margin: 10px 25px 10px 0;
  96. }
  97. .dist{
  98. margin: 10px 0 10px 0;
  99. }
  100. }
  101. </style>