spaceSelect.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <template>
  2. <div id="spaceSelect">
  3. <span class="buildFloor" style="padding-right:12px">空间类型</span>
  4. <el-cascader
  5. v-model="value"
  6. placeholder="请选择空间类型"
  7. clearable
  8. :style="isWidth ? '' : 'width:160px;'" size="small"
  9. :props="{value:'Code',label:'Name',children:'ZoneType'}"
  10. :options="options"
  11. @change="changeVal">
  12. </el-cascader>
  13. </div>
  14. </template>
  15. <script>
  16. import { queryAllZoneType } from '@/api/scan/request';
  17. import { mapGetters } from 'vuex'
  18. export default {
  19. computed: {
  20. ...mapGetters("layout", ["projectId"])
  21. },
  22. props: {
  23. isWidth: {
  24. type: Boolean,
  25. default: true
  26. }
  27. },
  28. data() {
  29. return {
  30. value:[null],
  31. spaceVal: null,//值
  32. options: [],
  33. props: {
  34. isWidth:false
  35. }
  36. }
  37. },
  38. methods: {
  39. setValue(val) {
  40. this.value = val;
  41. this.changeVal(val);
  42. },
  43. //获取下拉框数据
  44. getOptionData() {
  45. let params1 = {cascade: [{ name: 'zoneType', filters: `projectId='${this.projectId}'` }]}
  46. queryAllZoneType(params1, res => {
  47. this.options = res.content;
  48. this.changeVal(this.value);
  49. })
  50. },
  51. //改变空间
  52. changeVal(value) {
  53. let val = value[value.length - 1];
  54. let space = {};
  55. this.options.forEach(item => {
  56. if (item.ZoneType) {
  57. item.ZoneType.forEach(other => {
  58. if (other.Code == val) {
  59. space = other
  60. }
  61. })
  62. } else {
  63. if (item.Code == val) {
  64. space = item
  65. }
  66. }
  67. })
  68. this.$emit('change', val, space, value)
  69. }
  70. },
  71. created() {
  72. this.getOptionData();
  73. }
  74. }
  75. </script>
  76. <style lang="less" scoped>
  77. #spaceSelect {
  78. float: left;
  79. margin-left: 10px;
  80. .buildFloor {
  81. color: #999999;
  82. font-size: 14px;
  83. }
  84. }
  85. </style>