You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 lines
1.9 KiB

10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
  1. <template>
  2. <!-- 选择地区 -->
  3. <van-popup v-model:show="showArea" round position="bottom" @close="showArea = false">
  4. <!-- <van-picker
  5. title="地区选择" :columns="columns1" @confirm="onConfirm" @cancel="onCancel"
  6. /> -->
  7. <van-picker title="选择地区"
  8. :columns="columns"
  9. :columns-field-names="customFieldName"
  10. @cancel="onCancel"
  11. @confirm="onConfirm" />
  12. </van-popup>
  13. </template>
  14. <script>
  15. export default {
  16. props: ['show'],
  17. name: "selectArea",
  18. data() {
  19. return {
  20. showArea: false,
  21. columns: [],
  22. columns1: [{
  23. text: '星沙区',
  24. value: '星沙区'
  25. },
  26. {
  27. text: '雨花区',
  28. value: '雨花区'
  29. },
  30. {
  31. text: '岳麓区',
  32. value: '岳麓区'
  33. },
  34. {
  35. text: '天心区',
  36. value: '天心区'
  37. },
  38. {
  39. text: '开福区',
  40. value: '开福区'
  41. }
  42. ],
  43. customFieldName: {
  44. text: 'name',
  45. value: 'name',
  46. children: 'children'
  47. }
  48. }
  49. },
  50. watch: {
  51. show: {
  52. handler(newValue, oldValue) {
  53. this.showArea = newValue
  54. },
  55. immediate: true
  56. }
  57. },
  58. created() {
  59. this.getCurrentArea();
  60. },
  61. methods: {
  62. onConfirm(selectArea) {
  63. this.$store.commit('setArea', selectArea.selectedOptions[2])
  64. this.showArea = false
  65. this.$emit('select')
  66. // this.$emit('select', selectArea.selectedValues.pop())
  67. },
  68. onCancel() {
  69. this.$emit('close')
  70. },
  71. getCurrentArea() { //获取当前开放区域
  72. let self = this;
  73. this.$api('getCurrentArea', this.queryParams, res => {
  74. if (res.code == 200) {
  75. this.columns = this.handleTree(res.result, 'id', 'pid')
  76. // 使用pop移除并返回数组的最后一个元素
  77. // const lastElement = this.columns[0].children[0].children.pop();
  78. // this.columns[0].children[0].children.unshift(lastElement)
  79. }
  80. })
  81. }
  82. }
  83. }
  84. </script>
  85. <style lang="scss" scoped>
  86. </style>