You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
182 lines
4.6 KiB
182 lines
4.6 KiB
// pages/home/xx/index.js
|
|
const app = getApp();//新建页面时 默认引入
|
|
const req = app.xzjlReq();//初始化一个的request() 实例
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
ztDetial:{},//打开纸条弹窗详情
|
|
dkZtVisible:false,//打开纸条弹窗
|
|
ztText:"",
|
|
ztVisible:false,//写纸条弹窗
|
|
messages:[],
|
|
loverInfo:{},
|
|
hasLover:false,// 是否单身
|
|
userInfo:{}
|
|
|
|
},go2Reback(){
|
|
wx.switchTab({
|
|
url: '/pages/home/xy/index',
|
|
})
|
|
},
|
|
//bindtap="dKztDetial" data-xq="{{item}}"
|
|
dKztDetial(e){/**查看详情 */
|
|
let detail = e.currentTarget.dataset['xq']
|
|
console.log(detail)
|
|
if(!detail.isSelf&&detail.status=='unread'){
|
|
// 不是自己发的消息,且消息状态为未读,需要设置消息状态为已读
|
|
///api/user/curt/message/{id}/read
|
|
req.patchRequest('/api/user/curt/message/'+detail.id+'/read',{}).then((res)=>{
|
|
if(res.data.code==200){
|
|
console.log(this.data.messages)
|
|
}
|
|
}).catch((err)=>{
|
|
console.log(err);
|
|
})
|
|
}
|
|
if(detail.isSelf){
|
|
console.log('是自己发的消息,不做操作')
|
|
}
|
|
this.setData({dkZtVisible:true,tDetial:e.currentTarget.dataset['xq']})
|
|
},
|
|
doCancelDkZt(){
|
|
this.setData({dkZtVisible:false})
|
|
},
|
|
openZtVisible(){/**点击纸条按钮 */
|
|
this.setData({ztVisible:true})
|
|
},
|
|
doCancelZt(){/**点击纸条里面取消按钮 */
|
|
this.setData({ztVisible:false})
|
|
},
|
|
doFSZt(){/**点击纸条里面发送按钮 */
|
|
if(!this.data.ztText){
|
|
wx.showToast({
|
|
title:'纸条内容不能为空!',
|
|
icon: 'none',
|
|
duration: 1000
|
|
})
|
|
}else{
|
|
req.postRequest('/api/user/curt/message/lover',{"type": "text","content": this.data.ztText}).then((res)=>{
|
|
this.onLoad()
|
|
if(res.data.code==200){
|
|
|
|
console.log(this.data.messages)
|
|
}
|
|
}).catch((err)=>{
|
|
console.log(err);
|
|
})
|
|
this.setData({ztVisible:false,ztText:''})
|
|
}
|
|
|
|
},
|
|
go2Huiyi(){/**跳转到回忆页面 */
|
|
wx.navigateTo({
|
|
url: '/pages/home/xx/hy/index'
|
|
})
|
|
},
|
|
doMessageInfo(){/**查询聊天信息 */
|
|
req.getRequest('/api/user/curt/message/lover',{}).then((res)=>{
|
|
if(res.data.code==200){
|
|
this.setData({messages:res.data.data.records.reverse()})
|
|
console.log("这是打印,。。。。")
|
|
console.log(this.data.messages)
|
|
}
|
|
}).catch((err)=>{
|
|
console.log(err);
|
|
})
|
|
},
|
|
doQueryInit(){
|
|
req.getRequest('/api/user/curt',{}).then((res)=>{
|
|
if(res.data.code==200){
|
|
this.setData({hasLover:res.data.data.hasLover})
|
|
this.setData({userInfo:res.data.data})
|
|
console.log(this.data.userInfo)
|
|
if(!res.data.data.hasLover){
|
|
wx.navigateTo({
|
|
url: '/pages/home/xx/index'
|
|
})
|
|
}
|
|
|
|
}
|
|
}).catch((err)=>{
|
|
console.log(err);
|
|
})
|
|
|
|
req.getRequest('/api/user/curt/lover',{}).then((res)=>{
|
|
if(res.data.code==200){
|
|
this.setData({loverInfo:res.data.data})
|
|
}
|
|
}).catch((err)=>{
|
|
console.log(err);
|
|
})
|
|
|
|
///api/user/curt/lover
|
|
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad(options) {
|
|
this.doQueryInit()
|
|
this.doMessageInfo()
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
*/
|
|
onReady() {
|
|
this.doQueryInit()
|
|
this.doMessageInfo()
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
onShow() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面隐藏
|
|
*/
|
|
onHide() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面卸载
|
|
*/
|
|
onUnload() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
*/
|
|
onPullDownRefresh() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面上拉触底事件的处理函数
|
|
*/
|
|
onReachBottom() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 用户点击右上角分享
|
|
*/
|
|
onShareAppMessage() {
|
|
|
|
},
|
|
toSend(){
|
|
wx.redirectTo({
|
|
url: 'xz/xz'
|
|
})
|
|
}
|
|
}) |