唐耀东
2022-05-10 3a02d6a0f7c5d2dfb2df2e1635315304b85695eb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<template>
  <div class="tree-list-main">
    <div class="tree-search">
      <div class="main-search" style="margin-bottom: 0;">
        <input class="search-input" v-model="queryParams.name" @keyup.enter.prevent="getList" placeholder="请输入名称"/>
      </div>
    </div>
 
    <div class="main-tree">
      <div class="question-list" v-for="item in list" :key="item.id">
        <div class="question-item text-ellipsis" :class="item.id === id ? 'question-current' : ''">
          <div class="question-item-text text-ellipsis" @click="handleClick(item.id)">{{item.name}}</div>
        </div>
      </div>
    </div>
  </div>
</template>
 
<script>
import {listSchool} from "@/api/common/common";
 
export default {
  name: "QuestionType",
  watch: {
    'queryParams.name': function (val) {
      this.getList()
    }
  },
  data() {
    return {
      id: undefined,
      // 查询参数
      queryParams: {
        name: undefined
      },
      list: []
    };
  },
  created() {
    this.getList();
  },
  methods: {
    getList() {
      this.loading = true;
      listSchool(this.queryParams).then(r => {
        this.list = r.data;
        if (this.list.length > 0) {
          this.id = this.list[0].id;
          this.$emit('schoolChange', this.id)
        }
      })
    },
    // 选中
    handleClick(id) {
      if (this.id === id) return
      this.$emit('schoolChange', id)
      this.id = id
    }
  }
};
</script>
<style scoped lang="scss">
.tree-search {
  display: flex;
  flex-direction: row;
  align-items: center;
  height: 32px;
  margin-bottom: 10px;
  .search-add {
    width: 60px;
    text-align: center;
    cursor: pointer;
    line-height: 32px;
    font-size: 14px;
    height: 100%;
    background-color: #3CA2E0;
    color: #ffffff;
  }
}
 
.question-list {
  display: flex;
  flex-direction: column;
 
  .question-item {
    height: 30px;
    line-height: 30px;
    width: 100%;
    color: #333333;
    font-size: 14px;
    padding: 0 5px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
 
    .question-item-text {
      flex: 1;
    }
  }
 
  .question-current {
    background: #53A3FF;
    color: #ffffff !important;
  }
 
  .operation-region {
    display: none;
    cursor: pointer;
  }
 
  .question-item:hover .operation-region {
    display: block;
  }
  .question-item:hover {
    background: #F5F7FA;
    color: #333333!important;
  }
}
</style>