智慧农业大数据平台
xiebin
2022-11-16 3dc278f10a4c3e3db7ce3a445bed710bdc88916e
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
<template>
    <div>
        <div class="current-select" @click="listFlag = !listFlag">
            <div class="title">{{ currentTitle }}</div>
            <i class="el-icon-caret-bottom"></i>
        </div>
 
        <div class="list-box" v-show="listFlag">
            <ul>
                <li v-for="(item, index) in selectList"
                    :key="index"
                    @click="currentClick(item, index)"
                >{{item.name}}</li>
            </ul>
        </div>
    </div>
</template>
 
<script>
export default {
    name: 'selectName',
    props: ['selectList', 'value'],
    data () {
        return {
            listFlag: false,
            currentTitle: null,
            currentIndex: null
        }
    },
    created () {
        this.currentTitle = this.value
    },
    watch:{
      value: {
        handler (newName, oldName) {
          this.currentTitle = newName
        }
      }
    },
    methods: {
 
        currentClick (item, index) {
            this.$emit('selectItem', item, index)
            if (this.currentIndex == index) {
                this.listFlag = false
                return
            }
            this.currentTitle = item.name
            this.currentIndex = index
 
            this.listFlag = false
        }
    }
}
</script>
 
<style  lang="scss" scoped>
.current-select {
    padding: 0 15px;
    width: 166px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #ffffff;
    border-radius: 4px 4px 4px 4px;
    box-sizing: border-box;
    font-size: 12px;
    color: #717171;
    cursor: pointer;
}
 
.list-box {
    position: absolute;
    top: 32px;
    width: 166px;
    height: 240px;
    overflow-y: auto;
    background: #ffffff;
    border-radius: 4px 4px 4px 4px;
    box-sizing: border-box;
    font-size: 12px;
    color: #717171;
 
    li {
        line-height: 30px;
        text-align: center;
        cursor: pointer;
    }
}
</style>