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.

72 lines
1.7 KiB

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