|
|
|
@ -25,6 +25,7 @@ class MessagChat extends Component{
|
|
|
|
|
mypagey:20,
|
|
|
|
|
messages:[],
|
|
|
|
|
objc:[],
|
|
|
|
|
datanull:1,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
componentDidMount(){
|
|
|
|
@ -50,7 +51,7 @@ class MessagChat extends Component{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
componentDidUpdate() {
|
|
|
|
|
this.scrollToBottom();
|
|
|
|
|
// this.scrollToBottom();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
scrollToBottom() {
|
|
|
|
@ -64,11 +65,19 @@ class MessagChat extends Component{
|
|
|
|
|
|
|
|
|
|
contentViewScrolltop=(e)=>{
|
|
|
|
|
if(e.currentTarget.scrollTop===0){
|
|
|
|
|
console.log("调用了方法1111111")
|
|
|
|
|
|
|
|
|
|
if(this.state.datanull===0){
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
console.log("调用了方法1111111");
|
|
|
|
|
let {pages}=this.state;
|
|
|
|
|
let newpage=pages+1
|
|
|
|
|
let target_ids=this.props.match.params.private;
|
|
|
|
|
this.getChatList(newpage,this.state.limits,target_ids);
|
|
|
|
|
const query = this.props.location.search;
|
|
|
|
|
let target_ids = query.split('?target_ids=');
|
|
|
|
|
this.shuaxingetChatList(newpage,this.state.limits,target_ids[1],true);
|
|
|
|
|
this.messageList.scrollTop=50;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 滑动刷新
|
|
|
|
@ -100,7 +109,77 @@ class MessagChat extends Component{
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
shuaxingetChatList=(page,listl,target_ids,bool)=>{
|
|
|
|
|
this.setState({
|
|
|
|
|
isSpin:true,
|
|
|
|
|
});
|
|
|
|
|
let url = `/users/${this.props.match.params.userid}/private_message_details.json`;
|
|
|
|
|
axios.get((url),{params:{
|
|
|
|
|
target_id:target_ids,
|
|
|
|
|
page: page,
|
|
|
|
|
per_page:listl,
|
|
|
|
|
}}).then((result) => {
|
|
|
|
|
this.setState({
|
|
|
|
|
isSpin: false,
|
|
|
|
|
});
|
|
|
|
|
if (result) {
|
|
|
|
|
// if (result.data.status === 0) {
|
|
|
|
|
if (result.data !== null) {
|
|
|
|
|
if(result.data.messages.length===0){
|
|
|
|
|
console.log("没有数据了");
|
|
|
|
|
this.setState({
|
|
|
|
|
datanull:0,
|
|
|
|
|
})
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
var laoshuju=this.state.messages;
|
|
|
|
|
var datas = [];
|
|
|
|
|
var datay = result.data.messages;
|
|
|
|
|
datay = datay.reverse();
|
|
|
|
|
datay=datay.concat(laoshuju);
|
|
|
|
|
var obj = {};
|
|
|
|
|
for (var i = 0; i < datay.length; i++) {
|
|
|
|
|
if (i === 0) {
|
|
|
|
|
var timetwoy=datay[i].send_time.slice(0,10);
|
|
|
|
|
datay[i].send_day = timetwoy;
|
|
|
|
|
obj = datay[i];
|
|
|
|
|
datas.push(datay[i]);
|
|
|
|
|
} else {
|
|
|
|
|
try {
|
|
|
|
|
var timeone=obj.send_time.slice(0,10);
|
|
|
|
|
var timetwo=datay[i].send_time.slice(0,10);
|
|
|
|
|
if (moment(timeone).isSame(timetwo)) {
|
|
|
|
|
datay[i].send_day = "";
|
|
|
|
|
} else {
|
|
|
|
|
datay[i].send_day = timetwo;
|
|
|
|
|
obj = datay[i];
|
|
|
|
|
}
|
|
|
|
|
}catch (e) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
datas.push(datay[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
console.log("新数组+++++++++++++++++++++++++++++++++++++");
|
|
|
|
|
console.log(datas)
|
|
|
|
|
//颠倒数组
|
|
|
|
|
this.setState({
|
|
|
|
|
messages: datas,
|
|
|
|
|
myuserl: result.data.target,
|
|
|
|
|
pages:page,
|
|
|
|
|
})
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}).catch((error) => {
|
|
|
|
|
console.log(error);
|
|
|
|
|
this.setState({
|
|
|
|
|
isSpin:false,
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
};
|
|
|
|
|
getChatList=(page,listl,target_ids)=>{
|
|
|
|
|
this.setState({
|
|
|
|
|
isSpin:true,
|
|
|
|
@ -120,6 +199,8 @@ class MessagChat extends Component{
|
|
|
|
|
var obj = {};
|
|
|
|
|
for (var i = 0; i < datay.length; i++) {
|
|
|
|
|
if (i === 0) {
|
|
|
|
|
var timetwoy=datay[i].send_time.slice(0,10);
|
|
|
|
|
datay[i].send_day = timetwoy;
|
|
|
|
|
obj = datay[i];
|
|
|
|
|
datas.push(datay[i]);
|
|
|
|
|
} else {
|
|
|
|
@ -142,6 +223,7 @@ class MessagChat extends Component{
|
|
|
|
|
this.setState({
|
|
|
|
|
messages: datas,
|
|
|
|
|
myuserl: result.data.target,
|
|
|
|
|
pages:page,
|
|
|
|
|
})
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
@ -167,15 +249,19 @@ class MessagChat extends Component{
|
|
|
|
|
page: pages,
|
|
|
|
|
per_page:listls,
|
|
|
|
|
}}).then((result) => {
|
|
|
|
|
if (result) {
|
|
|
|
|
// if (result.data.status === 0) {
|
|
|
|
|
if (result) {
|
|
|
|
|
// if (result.data.status === 0) {
|
|
|
|
|
if (result.data !== null) {
|
|
|
|
|
var datas = []
|
|
|
|
|
var datas = [];
|
|
|
|
|
var datay = result.data.messages;
|
|
|
|
|
datay = datay.reverse();
|
|
|
|
|
var obj = {};
|
|
|
|
|
for (var i = 0; i < datay.length; i++) {
|
|
|
|
|
if (i === 0) {
|
|
|
|
|
var timetwoy=datay[i].send_time.slice(0,10);
|
|
|
|
|
datay[i].send_day = timetwoy;
|
|
|
|
|
obj = datay[i];
|
|
|
|
|
datas.push(datay[i]);
|
|
|
|
|
} else {
|
|
|
|
@ -189,22 +275,24 @@ class MessagChat extends Component{
|
|
|
|
|
obj = datay[i];
|
|
|
|
|
}
|
|
|
|
|
}catch (e) {
|
|
|
|
|
|
|
|
|
|
console.log("271271271271");
|
|
|
|
|
console.log(e);
|
|
|
|
|
}
|
|
|
|
|
datas.push(datay[i]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//颠倒数组
|
|
|
|
|
this.setState({
|
|
|
|
|
messages: datas,
|
|
|
|
|
myuserl: result.data.target,
|
|
|
|
|
});
|
|
|
|
|
// this.getdatatwo(this.state.page);
|
|
|
|
|
pages:pages,
|
|
|
|
|
datanull:1
|
|
|
|
|
})
|
|
|
|
|
this.scrollToBottom();
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
this.setState({
|
|
|
|
@ -305,10 +393,13 @@ class MessagChat extends Component{
|
|
|
|
|
// myyslusers:user,
|
|
|
|
|
// mess:true,
|
|
|
|
|
// })
|
|
|
|
|
this.setState({
|
|
|
|
|
myuserl:user,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
this.props.history.replace(`/message/${this.props.current_user.user_id}/message_detail?target_ids=${user.id}`);
|
|
|
|
|
// this.getdatatwo(this.state.page);
|
|
|
|
|
this.getChatListtwo(this.state.pages,this.state.mypagey,user.id);
|
|
|
|
|
this.getChatListtwo(1,this.state.mypagey,user.id);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
//回复
|
|
|
|
@ -334,9 +425,9 @@ class MessagChat extends Component{
|
|
|
|
|
if(response.data.status===0){
|
|
|
|
|
// console.log("回复成功");
|
|
|
|
|
// console.log(response);
|
|
|
|
|
var datas=[];
|
|
|
|
|
var dataso=this.state.messages;
|
|
|
|
|
var datays=response.data.private_message;
|
|
|
|
|
// var datas=[];
|
|
|
|
|
// var dataso=this.state.messages;
|
|
|
|
|
// var datays=response.data.private_message;
|
|
|
|
|
// var obj={};
|
|
|
|
|
// for (var i=0;i<dataso.length;i++){
|
|
|
|
|
// if(i===0){
|
|
|
|
@ -351,28 +442,30 @@ class MessagChat extends Component{
|
|
|
|
|
// datas.push(dataso[i]);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
try {
|
|
|
|
|
var time =dataso[dataso.length-1].send_time.slice(0,10);
|
|
|
|
|
console.log(time);
|
|
|
|
|
var timetwo=datays.send_time.slice(0,10);
|
|
|
|
|
console.log(timetwo);
|
|
|
|
|
if( moment(time).isSame(timetwo)){
|
|
|
|
|
datays.send_day="";
|
|
|
|
|
dataso.push(datays);
|
|
|
|
|
}else {
|
|
|
|
|
datays.send_day=timetwo;
|
|
|
|
|
dataso.push(datays);
|
|
|
|
|
}
|
|
|
|
|
}catch (e) {
|
|
|
|
|
console.log("回去出现错误");
|
|
|
|
|
console.log(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//颠倒数组
|
|
|
|
|
this.setState({
|
|
|
|
|
messages: dataso,
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
this.getChatListtwo(1,this.state.mypagey,target_ids[1]);
|
|
|
|
|
// try {
|
|
|
|
|
// var time =dataso[dataso.length-1].send_time.slice(0,10);
|
|
|
|
|
// console.log(time);
|
|
|
|
|
// var timetwo=datays.send_time.slice(0,10);
|
|
|
|
|
// console.log(timetwo);
|
|
|
|
|
// if( moment(time).isSame(timetwo)){
|
|
|
|
|
// datays.send_day="";
|
|
|
|
|
// dataso.push(datays);
|
|
|
|
|
// }else {
|
|
|
|
|
// datays.send_day=timetwo;
|
|
|
|
|
// dataso.push(datays);
|
|
|
|
|
// }
|
|
|
|
|
// }catch (e) {
|
|
|
|
|
// console.log("回去出现错误");
|
|
|
|
|
// console.log(e);
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// //颠倒数组
|
|
|
|
|
// this.setState({
|
|
|
|
|
// messages: dataso,
|
|
|
|
|
//
|
|
|
|
|
// });
|
|
|
|
|
this.scrollToBottom();
|
|
|
|
|
this.messageRef.current.setValue('')
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
@ -407,9 +500,10 @@ class MessagChat extends Component{
|
|
|
|
|
this.setState({
|
|
|
|
|
messages:this.state.messages,
|
|
|
|
|
isSpin:false,
|
|
|
|
|
// datanull:1
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
this.scrollToBottom()
|
|
|
|
|
// this.scrollToBottom()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -431,7 +525,7 @@ class MessagChat extends Component{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
render() {
|
|
|
|
|
let{isSpins,datay,myyslusers,mess,limits,myuserl,messages,isSpin}=this.state;
|
|
|
|
|
let{isSpins,datay,myyslusers,mess,limits,myuserl,messages,isSpin,datanull}=this.state;
|
|
|
|
|
// console.log(mess);
|
|
|
|
|
// console.log(myyslusers);
|
|
|
|
|
// console.log("MessagChat");
|
|
|
|
@ -459,6 +553,11 @@ class MessagChat extends Component{
|
|
|
|
|
}}>
|
|
|
|
|
<div >
|
|
|
|
|
<Spin size="large" className="myw100baifenbi" spinning={isSpin}>
|
|
|
|
|
{
|
|
|
|
|
datanull===0?
|
|
|
|
|
<p className="mt30 edu-txt-center"><span className="letter-time">没有信息了~~</span></p>
|
|
|
|
|
:""
|
|
|
|
|
}
|
|
|
|
|
<div id="yslysl" >
|
|
|
|
|
{
|
|
|
|
|
messages===undefined?
|
|
|
|
|