AreaSelector.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <template>
  2. <selector-card
  3. class="area-selector"
  4. :cardType="selectorType"
  5. @onConfirm="onConfirm"
  6. @onCancel="onCancel">
  7. <div slot="header" :class="{ 's-header': selectorType === 'line' }">
  8. <slot name="header">选择区域</slot>
  9. </div>
  10. <AreaSelectorContent
  11. ref="content"
  12. :selectorType="selectorType"
  13. :showSearchInput="showSearchInput"
  14. :showSelectResult="showSelectResult"
  15. :onlyProvince="onlyProvince"
  16. :singleChoice="singleChoice"
  17. :initCityMap="initCityMap"
  18. :beforeTabClick="beforeTabClick"
  19. :comtype="comtype"
  20. @onChange="onChange"
  21. />
  22. </selector-card>
  23. </template>
  24. <script>
  25. import SelectorCard from '@/components/selector/SelectorCard.vue'
  26. import AreaSelectorContent from '@/components/selector/AreaSelectorContent.vue'
  27. export default {
  28. name: 'area-selector',
  29. components: {
  30. SelectorCard,
  31. AreaSelectorContent
  32. },
  33. props: {
  34. selectorType: {
  35. type: String,
  36. default: 'card' // card/line
  37. },
  38. // 仅选中省份
  39. onlyProvince: {
  40. type: Boolean,
  41. default: false
  42. },
  43. singleChoice: { // 是否单选? 只有在selectorType=line下才会生效
  44. // type: Boolean,
  45. default: false
  46. },
  47. showSearchInput: { // 是否显示搜索 只有在selectorType=card下才会生效
  48. type: Boolean,
  49. default: true
  50. },
  51. showSelectResult: { // 是否显示选择结果 只有在selectorType=card下才会生效
  52. type: Boolean,
  53. default: false
  54. },
  55. beforeTabClick: Function,
  56. comtype: {
  57. type: String,
  58. default: ''
  59. },
  60. // 初始化城市数据
  61. // 刚进入页面需要被选中的城市数据
  62. initCityMap: {
  63. type: Object,
  64. default () {
  65. return {}
  66. }
  67. }
  68. },
  69. computed: {
  70. content () {
  71. return this.$refs.content
  72. }
  73. },
  74. created () {},
  75. methods: {
  76. initList (map = {}) {
  77. return this.$refs.content.initIndexBarAndAreaMap(map)
  78. },
  79. setCitySelected (data) {
  80. return this.$refs.content.setCitySelected(data)
  81. },
  82. getSelectedCity () {
  83. return this.$refs.content.getSelectedCity()
  84. },
  85. onCancel () {
  86. this.$emit('onCancel')
  87. },
  88. onConfirm () {
  89. const selectedCity = this.getSelectedCity()
  90. this.$emit('onConfirm', selectedCity)
  91. },
  92. onChange (selected) {
  93. this.$emit('onChange', selected)
  94. }
  95. }
  96. }
  97. </script>
  98. <style lang="scss" scoped>
  99. </style>