HHSLinkSLink/HSLink-app/pages/tabbar/message/chat-page.vue

200 lines
4.6 KiB
Vue
Raw Normal View History

2020-09-17 20:03:25 +08:00
<template>
<view class="pages">
2020-09-27 15:39:35 +08:00
<view class="cu-chat" id="chart-page" :style="[{'margin-bottom': 50+InputBottom+'px'}]">
2020-12-19 12:13:27 +08:00
<view class="cu-item" :class="[isMy(item,'self')]" v-for="(item,index) in letterList" :key="index">
2020-09-27 15:39:35 +08:00
<view class="cu-avatar radius" v-if="item.send_id !== userInfo.user_id" @tap="goToOther(item)">
<avatar :userName="otherInfo.real_name" size="45"></avatar>
2020-09-17 20:03:25 +08:00
</view>
<view class="main">
2020-12-19 12:13:27 +08:00
<view class="content shadow" :class="[isMy(item,'bg-green')]">
2020-09-17 20:03:25 +08:00
<text>{{item.content}}</text>
</view>
</view>
2020-09-27 15:39:35 +08:00
<view class="cu-avatar radius" v-if="item.send_id === userInfo.user_id" @tap="goToMy">
<avatar :userName="userInfo.real_name" size="45"></avatar>
2020-09-17 20:03:25 +08:00
</view>
<view class="date">{{item.letter_create_time}}</view>
</view>
</view>
<view class="cu-bar foot input" :style="[{bottom:InputBottom+'px'}]">
<view class="action">
<text class="cuIcon-sound text-grey"></text>
</view>
<input class="solid-bottom" :adjust-position="false" :focus="false" maxlength="300" cursor-spacing="10"
@focus="InputFocus" @blur="InputBlur" v-model="messageContent"></input>
<view class="action">
<text class="cuIcon-emojifill text-grey"></text>
</view>
<button class="cu-btn bg-green shadow" @tap="sendMessage">发送</button>
</view>
</view>
</template>
<script>
import request from '@/util/request.js';
import $ from '@/static/js/jquery-1.12.2.js';
2020-09-27 15:39:35 +08:00
import avatar from "@/pages/components/avatar/avatar.vue";
2020-09-17 20:03:25 +08:00
export default {
2020-09-27 15:39:35 +08:00
components: {
avatar
},
2020-09-17 20:03:25 +08:00
data() {
return {
2020-09-23 18:53:25 +08:00
otherInfo: uni.getStorageSync("otherInfo"),
2020-09-17 20:03:25 +08:00
userInfo: uni.getStorageSync('userInfo'),
InputBottom: 0,
//消息内容
messageContent: '',
//私信列表
2020-09-18 14:33:24 +08:00
letterList: [],
//定时任务
interval: {}
2020-09-17 20:03:25 +08:00
}
},
onShow() {
this.updateRead();
this.getTwoLetterApp();
2020-09-21 18:02:14 +08:00
let timesRun = 0;
let interval = setInterval(() => {
2020-09-18 14:33:24 +08:00
this.getTwoLetterApp();
2020-10-10 10:44:32 +08:00
timesRun += 1;
if(timesRun === 5){
clearInterval(interval);
}
2020-09-21 18:02:14 +08:00
}, 2000);
2020-09-18 14:33:24 +08:00
},
onBackPress() {
2020-09-17 20:03:25 +08:00
},
2020-10-10 10:44:32 +08:00
onPullDownRefresh () {
this.getTwoLetterApp();
uni.startPullDownRefresh();
},
2020-09-17 20:03:25 +08:00
onLoad() {
uni.setNavigationBarTitle({
2020-09-23 18:53:25 +08:00
title: this.otherInfo.real_name
2020-09-17 20:03:25 +08:00
});
},
watch: {
letterList() {
this.$nextTick(() => {
uni.pageScrollTo({scrollTop: 99999, duration: 0});
})
}
},
methods: {
2020-09-27 15:39:35 +08:00
/**
* 调整弹框高度
*/
InputFocus(e) {
this.InputBottom = e.detail.height;
},
InputBlur(e) {
2020-10-10 10:44:32 +08:00
this.InputBottom = 0
2020-09-27 15:39:35 +08:00
},
2020-09-21 18:02:14 +08:00
/**
* 跳转到其他人的主页
* @param {Object} item
*/
goToOther(item) {
uni.navigateTo({
url: `/pages/person-info-page/person-info-page?userId=${item.send_id}`
})
},
/**
* 跳转到我的主页
* @param {Object} item
*/
goToMy() {
uni.switchTab({
url: '/pages/tabbar/my/my'
});
},
2020-09-17 20:03:25 +08:00
/**
* 获取两个人的私信
*/
getTwoLetterApp() {
request.post('/hs/getTwoLetterApp',{
userId: uni.getStorageSync("userInfo").user_id,
2020-09-23 18:53:25 +08:00
otherId: this.otherInfo.user_id,
2020-09-17 20:03:25 +08:00
}).then(res => {
console.log("获取两个人的私信",res);
if (res.data !== null) {
this.letterList = res.data;
} else {
}
},err=>{
console.log("err",err);
})
},
/**
* 发送消息
*/
sendMessage() {
2020-09-18 21:13:55 +08:00
if (this.messageContent === '') {
uni.showToast({
icon: 'none',
title: '请输入消息,亲'
})
} else {
request.post('/hs/sendLetter',{
sendId: uni.getStorageSync("userInfo").user_id,
2020-09-23 18:53:25 +08:00
receiveId: this.otherInfo.user_id,
2020-09-18 21:13:55 +08:00
content: this.messageContent
}).then(res => {
2020-09-17 20:03:25 +08:00
this.messageContent = '';
2020-09-18 21:13:55 +08:00
console.log("发送消息",res);
if (res.data === 1) {
this.getTwoLetterApp();
this.messageContent = '';
}
},err=>{
console.log("err",err);
})
}
2020-09-17 20:03:25 +08:00
},
/**
* 改为已读
*/
updateRead() {
request.post('/hs/updateReadApp',{
userId: uni.getStorageSync("userInfo").user_id,
2020-09-23 18:53:25 +08:00
otherId: this.otherInfo.user_id
2020-09-17 20:03:25 +08:00
}).then(res => {
console.log("改为已读",res);
},err=>{
console.log("err",err);
})
},
/**
* 判断是否是发送人
* @param {Object} item
*/
isMy(item,classText) {
return item.send_id === uni.getStorageSync("userInfo").user_id ? classText : ''
},
}
}
</script>
<style scoped>
2020-09-27 15:39:35 +08:00
/* .cu-item .date{
2020-09-17 20:03:25 +08:00
color: #FFFFFF;
2020-09-27 15:39:35 +08:00
}
.pages{
background-image: url("@/static/img/chat-bg.jpg");
background-size: 100% 100%;
height: calc(100vh - 100rpx);
overflow: scroll;
} */
.cu-avatar{
background-color: rgba(0,0,0,0);
2020-09-17 20:03:25 +08:00
}
.cu-chat{
margin-bottom: 100rpx;
}
</style>