<scroll-view @scroll="scrollPosition" :style="{height:scrollViewHeight+'rpx'}" :scroll-y="true" :scroll-top="scrollTop" :scroll-with-animation="true" >
<uni-load-more :status="discussionStatus" v-show="isMore"></uni-load-more>
<view id="scroll-view" v-show="weChatList.length">
<view v-for="item in weChatList" :key="item.uid">
<view class="send-message-content" v-if="userId==item.uid">
<view class="receive-message-item">
<view class="receive-message-item flex align-items justify-end">
<view class="receive-content mineRecive">
<view class="send-user-name">{{item.user_nickname}}</view>
<view class="send-content">{{item.content}}</view>
</view>
<view class="receive-photo"><image :src="item.avatar"
alt="用户头像"></image></view>
</view>
</view>
</view>
<view class="receive-message-content" v-else>
<view class="receive-message-item flex align-items">
<view class="receive-photo"><image :src="item.avatar"
alt="用户头像"></image></view>
<view class="receive-content" style="display: flex;flex-direction: column;align-items: flex-start;">
<view class="user-name">{{item.user_nickname}}</view>
<view class="user-content">{{item.content}}</view>
</view>
</view>
</view>
</view>
</view>
<uni-load-more status="暂无聊天" v-show="!weChatList.length"></uni-load-more>
</scroll-view>
#scroll-view-content{
height: 300rpx!important;
overflow: scroll;
max-height: 300rpx!important;
}
data(){
scrollTop:0,
scrollViewHeight:300,
},
methods:{
scrollPosition(e){
if(e.detail.scrollTop<10){
this.isMore = true
if(this.discussionPage<this.discussionTotall){
this.discussionPage += 1;
this.discussionFn();
this.discussionStatus = 'loading';
}else{
this.discussionStatus = '暂无更多';
}
}
},
discussionFn(){
let params = {
courseid:this.courseid,
page:this.discussionPage
}
discussList(params).then((res)=>{
let {code, numpage, list} = res
if(code==0){
this.isMore = false
this.discussionStatus = ''
}
})
},
initContentHeight() {
uni.createSelectorQuery()
.in(this)
.select('#scroll-view')
.boundingClientRect(data => {
if (data) {
let top = Number(data.height)
if (top > 0) {
this.scrollTop = top;
}
}
})
.exec();
},
websocketsend(){
this.$nextTick(()=>{
tihs.initContentHeight()
})
}
}