|
|
import React, { Component } from 'react';
|
|
|
import "../css/messagemy.css"
|
|
|
import {getImageUrl} from 'educoder';
|
|
|
import { Modal,Input,Icon,Tooltip,Spin} from 'antd';
|
|
|
import axios from 'axios';
|
|
|
import TPMMDEditor from '../../tpm/challengesnew/TPMMDEditor';
|
|
|
import moment from 'moment';
|
|
|
import Rightdialogue from './Rightdialogue'
|
|
|
import Leftdialogue from './Leftdialogue'
|
|
|
//私信聊天页面
|
|
|
class MessagChat extends Component{
|
|
|
constructor(props) {
|
|
|
super(props);
|
|
|
this.messageRef = React.createRef();
|
|
|
this.state={
|
|
|
isSpin:false,
|
|
|
isSpins:false,
|
|
|
limit:20,
|
|
|
page:1,
|
|
|
datay:[],
|
|
|
limits:20,
|
|
|
mess:false,
|
|
|
myuserl:[],
|
|
|
pages:1,
|
|
|
mypagey:20,
|
|
|
messages:[],
|
|
|
objc:[],
|
|
|
|
|
|
}
|
|
|
}
|
|
|
componentDidMount(){
|
|
|
this.getdata(1);
|
|
|
let target_ids=this.props.match.params.private;
|
|
|
this.getChatList(1,this.state.limit,target_ids);
|
|
|
// console.log("MessagChat111111");
|
|
|
console.log(this.props.myysluser);
|
|
|
this.setState({
|
|
|
myyslusers:this.props.myysluser
|
|
|
})
|
|
|
try {
|
|
|
this.props.Mtab(3);
|
|
|
}catch (e) {
|
|
|
|
|
|
}
|
|
|
console.log("MessagChat111111");
|
|
|
console.log(this.props);
|
|
|
console.log(this.props.match.params.userid);
|
|
|
|
|
|
}
|
|
|
// 滑动刷新
|
|
|
contentViewScrolledit=(e)=>{
|
|
|
|
|
|
//滑动到底判断
|
|
|
if(e.currentTarget.scrollHeight-e.currentTarget.scrollTop===e.currentTarget.clientHeight){
|
|
|
// console.log("滑动到底判断");
|
|
|
let {page}=this.state;
|
|
|
let newpage=page+1
|
|
|
this.getdata(newpage);
|
|
|
let ls=newpage*20
|
|
|
this.setState({
|
|
|
limits:ls,
|
|
|
})
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
getChatList=(page,listl,target_ids)=>{
|
|
|
this.setState({
|
|
|
isSpins: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) => {
|
|
|
if (result) {
|
|
|
|
|
|
if(result.data.message!==undefined){
|
|
|
return;
|
|
|
}
|
|
|
var datas=[]
|
|
|
var datay=result.data.messages;
|
|
|
var obj={};
|
|
|
for (var i=0;i<datay.length;i++){
|
|
|
if(i===0){
|
|
|
obj=datay[i];
|
|
|
datas.push(datay[i]);
|
|
|
}else{
|
|
|
obj=datay[i];
|
|
|
if(obj.send_day===datay[i].send_day){
|
|
|
datay[i].send_day="";
|
|
|
}
|
|
|
|
|
|
datas.push(datay[i]);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if(result.data!==null){
|
|
|
console.log(result)
|
|
|
this.setState({
|
|
|
messages:datas,
|
|
|
myuserl:result.data.target,
|
|
|
})
|
|
|
}
|
|
|
|
|
|
this.setState({
|
|
|
isSpins:false,
|
|
|
});
|
|
|
|
|
|
}
|
|
|
}).catch((error) => {
|
|
|
console.log(error);
|
|
|
this.setState({
|
|
|
isSpins:false,
|
|
|
})
|
|
|
})
|
|
|
};
|
|
|
getChatListtwo=(pages,listls,target_ids)=>{
|
|
|
this.setState({
|
|
|
isSpins:true,
|
|
|
});
|
|
|
let url = `/users/${this.props.match.params.userid}/private_message_details.json`;
|
|
|
axios.get((url),{params:{
|
|
|
target_id:target_ids,
|
|
|
page: pages,
|
|
|
per_page:listls,
|
|
|
}}).then((result) => {
|
|
|
if (result) {
|
|
|
|
|
|
if(result.data.message!==undefined){
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
if(result.data!==null){
|
|
|
console.log(result)
|
|
|
this.setState({
|
|
|
messages:result.data.messages,
|
|
|
myuserl:result.data.target,
|
|
|
});
|
|
|
this.getdatatwo(this.state.page);
|
|
|
}
|
|
|
|
|
|
this.setState({
|
|
|
isSpins:false,
|
|
|
});
|
|
|
|
|
|
}
|
|
|
}).catch((error) => {
|
|
|
console.log(error);
|
|
|
this.setState({
|
|
|
isSpins:false,
|
|
|
});
|
|
|
this.getdatatwo(this.state.page);
|
|
|
})
|
|
|
};
|
|
|
//获取数据地方
|
|
|
getdata=(page)=>{
|
|
|
|
|
|
let{limit}=this.state;
|
|
|
let url = `/users/${this.props.match&&this.props.match.params.userid}/private_messages.json`;
|
|
|
// let url = `/users/71519/private_messages.json`;
|
|
|
axios.get((url),{params:{
|
|
|
page:page,
|
|
|
per_page:limit,
|
|
|
}}).then((result) => {
|
|
|
if (result) {
|
|
|
// console.log(types);
|
|
|
// console.log(result);
|
|
|
if(result.data.message!==undefined){
|
|
|
// console.log("5151515151");
|
|
|
return;
|
|
|
}
|
|
|
// console.log("调用了消失的方法");
|
|
|
// console.log("5454545454");
|
|
|
|
|
|
|
|
|
if(result.data!==null){
|
|
|
if(result.data.private_messages!==null){
|
|
|
if(result.data.private_messages.length>0){
|
|
|
for (var i=0;i<result.data.private_messages.length;i++){
|
|
|
this.state.datay.push(result.data.private_messages[i]);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
this.setState({
|
|
|
page:page,
|
|
|
isSpins:false,
|
|
|
datay:this.state.datay,
|
|
|
data:result.data.private_messages===null?undefined:result.data.private_messages===undefined?undefined:result.data.private_messages===[]?undefined:result.data.private_messages==="[]"?undefined:result.data.private_messages.length===0?undefined:result.data.private_messages,
|
|
|
});
|
|
|
// console.log(this.state.datay);
|
|
|
}
|
|
|
}).catch((error) => {
|
|
|
console.log(error);
|
|
|
this.setState({
|
|
|
isSpins:false,
|
|
|
})
|
|
|
})
|
|
|
};
|
|
|
//获取数据地方
|
|
|
getdatatwo=(page)=>{
|
|
|
|
|
|
let{limits}=this.state;
|
|
|
let url = `/users/${this.props.match&&this.props.match.params.userid}/private_messages.json`;
|
|
|
// let url = `/users/71519/private_messages.json`;
|
|
|
axios.get((url),{params:{
|
|
|
page:page,
|
|
|
per_page:limits,
|
|
|
}}).then((result) => {
|
|
|
if (result) {
|
|
|
// console.log(types);
|
|
|
// console.log(result);
|
|
|
if(result.data.message!==undefined){
|
|
|
// console.log("5151515151");
|
|
|
return;
|
|
|
}
|
|
|
// console.log("调用了消失的方法");
|
|
|
// console.log("5454545454");
|
|
|
|
|
|
//
|
|
|
// if(result.data!==null){
|
|
|
// if(result.data.private_messages!==null){
|
|
|
// if(result.data.private_messages.length>0){
|
|
|
// for (var i=0;i<result.data.private_messages.length;i++){
|
|
|
// this.state.datay.push(result.data.private_messages[i]);
|
|
|
// }
|
|
|
// }
|
|
|
// }
|
|
|
// }
|
|
|
this.setState({
|
|
|
page:page,
|
|
|
isSpins:false,
|
|
|
datay:result.data.private_messages===null?undefined:result.data.private_messages===undefined?undefined:result.data.private_messages===[]?undefined:result.data.private_messages==="[]"?undefined:result.data.private_messages.length===0?undefined:result.data.private_messages,
|
|
|
});
|
|
|
// console.log(this.state.datay);
|
|
|
}
|
|
|
}).catch((error) => {
|
|
|
console.log(error);
|
|
|
this.setState({
|
|
|
isSpins:false,
|
|
|
})
|
|
|
})
|
|
|
};
|
|
|
// 跳转页面
|
|
|
smyJump =(i)=>{
|
|
|
// console.log("跳转页面");
|
|
|
// console.log(i);
|
|
|
this.props.Modifyur(i);
|
|
|
};
|
|
|
|
|
|
// 点击了用户
|
|
|
Clickedontheuser=(user)=>{
|
|
|
// debugger
|
|
|
// console.log("点击了用户");
|
|
|
// console.log(user);
|
|
|
// this.setState({
|
|
|
// myyslusers:user,
|
|
|
// mess:true,
|
|
|
// })
|
|
|
|
|
|
this.props.history.replace(`/message/${this.props.current_user.user_id}/${user.id}/message_detail`);
|
|
|
// this.getdatatwo(this.state.page);
|
|
|
this.getChatListtwo(this.state.pages,this.state.mypagey,user.id);
|
|
|
|
|
|
}
|
|
|
|
|
|
setreplyfun=()=>{
|
|
|
let contents=this.messageRef.current.getValue().trim();
|
|
|
let target_ids=this.props.match.params.private
|
|
|
let url = `/users/${this.props.match.params.userid}/private_messages.json`;
|
|
|
axios.post(url, {
|
|
|
target_id: target_ids,
|
|
|
content: contents
|
|
|
})
|
|
|
.then((response) => {
|
|
|
// console.log(response);
|
|
|
})
|
|
|
.catch(function (error) {
|
|
|
console.log(error);
|
|
|
});
|
|
|
}
|
|
|
|
|
|
|
|
|
render() {
|
|
|
let{isSpins,datay,myyslusers,mess,limits,myuserl,messages}=this.state;
|
|
|
// console.log(mess);
|
|
|
// console.log(myyslusers);
|
|
|
// console.log("MessagChat");
|
|
|
// console.log(this.state);
|
|
|
// console.log("112");
|
|
|
console.log(limits);
|
|
|
console.log(myuserl);
|
|
|
console.log(messages);
|
|
|
return (
|
|
|
<div className="edu-back-white ml20">
|
|
|
{/*私信对话框*/}
|
|
|
<div className="df clearfix">
|
|
|
{/*左边*/}
|
|
|
<div className="flex1">
|
|
|
<p className="clearfix pt30 pb30 edu-txt-center font-16 bor-bottom-greyE">
|
|
|
<a onClick={()=>this.smyJump(2)}><i className="iconfont icon-zuojiantou font-14 fl ml25 color-grey-9"
|
|
|
data-tip-down="返回到列表"></i></a>
|
|
|
{myuserl!==undefined?myuserl.name:""}与你的私信
|
|
|
</p>
|
|
|
{/*聊天页面*/}
|
|
|
<div className="dialogPanel">
|
|
|
<div >
|
|
|
<div>
|
|
|
{
|
|
|
messages===undefined?
|
|
|
""
|
|
|
:messages.map((item,key)=>{
|
|
|
console.log("-----------------================-=-==-==");
|
|
|
console.log(item.sender_id);
|
|
|
console.log(this.props.match.params.userid);
|
|
|
return(
|
|
|
<div key={key}>
|
|
|
{
|
|
|
item.send_day===undefined?"":item.send_day===null?"":item.send_day===""?"":
|
|
|
<p className="mt30 edu-txt-center"><span className="letter-time">{item.send_day}</span></p>
|
|
|
}
|
|
|
{
|
|
|
parseInt(item.sender_id)===parseInt(this.props.match.params.userid)?
|
|
|
<Rightdialogue objeysl={item}>
|
|
|
{/*自己的*/}
|
|
|
|
|
|
|
|
|
</Rightdialogue>
|
|
|
:<Leftdialogue objeysl={item}>
|
|
|
{/*他人的*/}
|
|
|
|
|
|
|
|
|
</Leftdialogue>
|
|
|
}
|
|
|
|
|
|
</div>
|
|
|
)
|
|
|
})
|
|
|
}
|
|
|
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|
|
|
|
|
|
{/*回复*/}
|
|
|
<div className="bor-top-greyE padding20">
|
|
|
<style>
|
|
|
{`
|
|
|
.rememberTip{
|
|
|
display:none;
|
|
|
}
|
|
|
`}
|
|
|
</style>
|
|
|
<TPMMDEditor ref={this.messageRef}
|
|
|
placeholder={'请输入您的回复'}
|
|
|
watch={false}
|
|
|
initValue={""}
|
|
|
mdID={'courseMessageMD'}
|
|
|
className="courseMessageMD"
|
|
|
height={200}
|
|
|
></TPMMDEditor>
|
|
|
|
|
|
<div className={"msheight30"}>
|
|
|
<span className="fl ml5 color-orange font-12">在问题反馈时,请同时发送问题发生页的网址链接,以便我们高效的为您服务</span>
|
|
|
<a className="fr task-btn task-btn-orange" onClick={this.setreplyfun}>回复</a>
|
|
|
</div>
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
{/*右边*/}
|
|
|
<div className="bor-left-greyE" style={{width:"290px"}}>
|
|
|
{/*右边头部*/}
|
|
|
<p className="pt30 pb30 pl30 edu-txt-left font-16 bor-bottom-greyE">私信列表</p>
|
|
|
<Spin size="large" className="myw100baifenbi" spinning={isSpins}>
|
|
|
<div className="private-list" onScroll={this.contentViewScrolledit}>
|
|
|
{/*列表数据*/}
|
|
|
{
|
|
|
datay===undefined?
|
|
|
""
|
|
|
:datay.map((item,key)=>{
|
|
|
return(
|
|
|
<div className="private-part clearfix" key={key} onClick={(i)=>this.Clickedontheuser(item.target)}>
|
|
|
<div className="part-line df">
|
|
|
<img src={getImageUrl("/images/"+item.target.image_url)} className="radius mr10 myimgw48 myimgh48"/>
|
|
|
<div className="flex1">
|
|
|
<p className="clearfix mb15 lineh-17">
|
|
|
<span className="fl pr">
|
|
|
<span className="task-hide privatePartName">{item.target.name}</span>
|
|
|
{item.unread === true?
|
|
|
<span className="newLetter"></span>
|
|
|
:""}
|
|
|
</span>
|
|
|
<span className="color-grey-c fr">{moment(item.send_time).fromNow()}</span>
|
|
|
</p>
|
|
|
<p className="color-grey-6 lineh-20 justify break_word task-hide-2" style={{wordBreak:"break-word"}} dangerouslySetInnerHTML={{__html:item.content}}></p>
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
</div>
|
|
|
)
|
|
|
})}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
</Spin>
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
</div>
|
|
|
)
|
|
|
}
|
|
|
}
|
|
|
export default MessagChat;
|
|
|
|
|
|
|
|
|
// onClick="delete_confirm_box('/users/innov/delete_message?mess_id=25137', '确定要删除该条记录吗?')"
|
|
|
//
|
|
|
// {/*左边*/}
|