zengh
2022-05-09 52c39f5e2711e5535b689b66dfa5e100c7882b7f
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
<template>
    <div class="subnvue" @click.stop="">
        <div class="mask" @click="hide()"></div>
        <div class="bottom" >
            <div v-if="!flag"></div>
            <input class="input" ref="input" @keyboardheightchange="heightChange" :cursor-spacing="space" v-model="message" :placeholder="placeholder" v-if="flag"/>
            <div class="bottomBtn-box">
                <div class="bottomBtn" @click="clickSubmit" :style="{backgroundColor:message!=''?'#00CAFC':'#B1EFFE'}">
                    <text class="bottom-text">发送</text>
                </div>
            </div>
            
        </div>
    </div>
</template>
 
<script>
    export default {
        data() {
            return {
                flag:false,
                message:'',
                space:0  //兼容ios
            }
        },
        beforeCreate() {
            
        },
        created(){
            //ios首页输入兼容
            uni.getSystemInfo({
                success: (e) => {
                    if(e.platform=='ios') this.space = -50
                }
            })
            uni.$on('showInput', (e) => {
                this.flag = true
                console.log(e)
                this.$nextTick(()=>{
                    this.$refs.input.focus()
                })
            })  
        },
        destroyed() {
            uni.$off('showInput')
        },
        methods: {
            hide() {
                uni.hideKeyboard()
                setTimeout(()=>{
                    this.quit()
                },200)
            },
            heightChange(e){
                console.log(e.detail.height)
                if(e.detail.height<=0) this.quit()
                
            },
            clickSubmit(){
                if(this.message=='') return
                uni.$emit('sendComment',this.message)
                this.quit()
            },
            quit(){
                uni.hideKeyboard()
                this.message = ''
                uni.$emit('showComment')
                uni.getSubNVueById('input-box').hide();
                this.flag = false
            }
        },
    }
</script>
 
<style lang="scss" scoped>
    .subnvue {
        flex-direction: column;
        flex: 1;
        background-color: transparent;
    }
    .mask{
        flex: 1;
        opacity: 0.1;
        //background-color: #fff;
    }
    .bottom{
        box-shadow: 0 -1px 4px 1px rgba(0,0,0,0.1);
        background-color: #fff;
        padding: 30rpx 30rpx 0 30rpx;
        align-items: center;
        flex-direction: row;
        justify-content: space-between;
    }
    .input{
        flex: 1;
        font-size: 16px;
        height: 90rpx;
        padding: 0 0 50rpx 0;
    }
    .bottomBtn-box{
        height: 140rpx;
        padding: 10rpx 0 0 0;
    }
    .bottomBtn{
        padding: 5rpx 15rpx;
        border-radius:10rpx;
        margin-left: 30rpx;
        
    }
    .bottom-text{
        color: #fff;
    }
</style>