chatrecord.vue
5.6 KB
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
<template>
<div class="body">
<nav-bar class="chatnav">
<div slot="left" class="back" @click="goBack">
<img src="../../assets/img/back.png" alt="">
</div>
<div slot="center" class="userinfotitle">
</div>
<div slot="right" class="result"></div>
</nav-bar>
<van-pull-refresh class="noticecont" v-model="isLoading" @refresh="onRefresh">
<div style="overflow: scroll;padding-bottom: 2rem;" ref="wrapper">
<div v-for="(item,index) in detail" :key="index">
<div class="time" v-if="item.is_show_time==1">{{item.create_time}}</div>
<div>
<div class="noticeone display-flex" v-if="item.from_id_type=='1'">
<img :src="item.avatar" alt="" class="noticeimg">
<div class="noticetexts">{{item.content}}</div>
</div>
<div class="noticeone2 display-flex" v-if="item.from_id_type=='2'">
<div class="noticetexts">{{item.content}}</div>
<img :src="item.avatar" alt="" class="noticeimg">
</div>
</div>
</div>
</div>
<!-- <p>刷新次数: {{ count }}</p> -->
</van-pull-refresh>
<div class="sendnotice display-flex-between">
<input type="text" v-model="searchvalue" placeholder="输入新消息">
<div class="send" @click="send">发送</div>
</div>
</div>
</template>
<script>
export default {
data () {
return {
id: '',
detail: [],
searchvalue: '',
time: '',
isLoading: false,
page: 1,
pagenum: 10,
ifmore: ''
}
},
created () {
this.id = this.$route.query.id
this.getchatdetail()
this.scrollToBottom()
this.time = new Date().getTime() - 5 * 60 * 1000
},
methods: {
scrollToBottom () {
var heightCss = window.getComputedStyle(this.$refs.wrapper).height
console.log(heightCss)
},
goBack () {
this.$router.go(-1)
},
strfun (str) {
const newstr = str.replaceAll('-', '/')
return newstr
},
onRefresh () {
if (this.ifmore) {
this.isLoading = true
this.page++
this.getchatdetail()
} else {
this.$toast('没有更多了')
}
},
async getchatdetail () {
const params = {
teacher_id: this.id,
page: this.page,
page_num: this.pagenum
}
const res = await this.api.chatdetail(params)
if (res.code = 1) {
const list = res.data.detail.data
if (list.length > 0) {
this.ifmore = true
this.detail = this.page == 1 ? list.reverse() : (this.detail.reverse().concat(list)).reverse()
this.isLoading = false
} else {
this.ifmore = false
setTimeout(() => {
this.isLoading = false
}, 1000)
this.detail = this.page == 1 ? list.reverse() : (this.detail.reverse().concat(list)).reverse()
}
console.log(list, this.detail)
}
},
async send () {
const params = {
teacher_id: this.id,
content: this.searchvalue
}
const res = await this.api.chatsend(params)
if (res.code = 1) {
this.searchvalue = ''
this.page = 1
this.getchatdetail()
}
}
}
}
</script>
<style lang="scss">
.body{
height: 100vh;
background-color: #f7f8fa;
}
.chatnav{
background-color: #fff;
}
.noticecont{
width: 100%;
height: 100%;
background: #f7f8fa;
padding: 0.32rem 0.32rem 2rem;
box-sizing: border-box;
overflow: scroll;
}
.noticeimg{
width:0.72rem;
height: 0.72rem;
border-radius: 50%;
margin-right: 0.16rem;
}
.noticeone{
align-items: flex-start;
margin-bottom: 0.32rem;
}
.noticeone .noticetexts{
text-align: left;
}
.noticeone2 .noticetexts{
text-align:right;
}
.noticeone2{
align-items: flex-start;
margin-bottom: 0.32rem;
justify-content: flex-end;
}
.noticeone2 img{
margin-left: 0.32rem;
}
.noticetexts{
border-radius: 0.08rem;
opacity: 1;
background: rgba(255,255,255,1);
font-size: 0.3rem;
font-weight: 400;
font-family: "PingFang SC";
line-height: 0.44rem;
padding: 0.24rem;
box-sizing: border-box;
}
.time{
margin: 0.3rem auto;
}
.sendnotice{
width: 100%;
height: auto;
background-color: #ffffff;
position: fixed;
bottom: 0;
left: 0;
padding: 0.08rem 0.32rem 0.5rem;
box-sizing: border-box;
}
.sendnotice input{
width: 5.3rem;
height: 0.72rem;
border-radius: 0.08rem;
opacity: 1;
border: 0.01rem solid #eee;
padding:0 0.32rem ;
box-sizing: border-box;
line-height: 0.72rem;
text-align: left;
font-size: 0.28rem;
}
.send{
width: 1.2rem;
height: 0.72rem;
border-radius: 0.08rem;
opacity: 1;
background: rgba(37.19,124.31,255,1);
color: rgba(255,255,255,1);
font-size: 0.28rem;
font-weight: 400;
line-height: 0.72rem;
text-align: center;
margin-left: 0.32rem;
}
.van-pull-refresh {
overflow: scroll !important;
padding-bottom: 1.8rem;
}
</style>