|
|
// pages/home/jl/jlai/jlai.js
|
|
|
const app = getApp();//新建页面时 默认引入
|
|
|
const req = app.xzjlReq();//初始化一个的request() 实例
|
|
|
Page({
|
|
|
|
|
|
/**
|
|
|
* 页面的初始数据
|
|
|
*/
|
|
|
data: {
|
|
|
isAdd:false,
|
|
|
times:0,//非会员聊天次数
|
|
|
chatList:[],
|
|
|
ltinfo:'',
|
|
|
isBlank:true,//没有聊天
|
|
|
userInfo:{},
|
|
|
stxx:false,
|
|
|
showChat:true,
|
|
|
showChatToast:false,
|
|
|
list: [], // 默认头像
|
|
|
isShow: false
|
|
|
},
|
|
|
addClick(){
|
|
|
this.setData({
|
|
|
isAdd: !this.data.isAdd
|
|
|
})
|
|
|
},
|
|
|
noaddClick(){
|
|
|
console.log('点击了加号')
|
|
|
this.setData({
|
|
|
isAdd:false,
|
|
|
showChat: !this.data.showChat
|
|
|
})
|
|
|
},
|
|
|
go2Member(){
|
|
|
wx.navigateTo({
|
|
|
url: '/pages/home/me/member/member'
|
|
|
})
|
|
|
},
|
|
|
go2BB(e){/**鼠标回显事件 */
|
|
|
// this.setData({ltinfo:e.detail.value})
|
|
|
},
|
|
|
// 发送消息
|
|
|
go2Send(e){
|
|
|
// 非vip并且聊天次数为0
|
|
|
if (!this.data.userInfo.isChatVip && !this.data.times) {
|
|
|
return this.setData({showChatToast: true})
|
|
|
}
|
|
|
|
|
|
if(e.target.dataset.lt==''){
|
|
|
wx.showToast({
|
|
|
title: '聊天内容不能为空',
|
|
|
icon:'none',
|
|
|
})
|
|
|
}else{
|
|
|
this.setData({isBlank:false})
|
|
|
this.setData({
|
|
|
chatList:this.data.chatList.concat({'type':1,'value':e.target.dataset.lt})
|
|
|
})
|
|
|
let that = this
|
|
|
req.postRequest('/api/v1/chat-records/completions',{'content':e.target.dataset.lt}).then((res)=>{
|
|
|
console.log(res)
|
|
|
console.log(res.data)
|
|
|
if(res.data.code==500){
|
|
|
console.log('500状态码')
|
|
|
wx.showToast({
|
|
|
title: '获取星座精灵AI聊天消息超时',
|
|
|
icon:'none',
|
|
|
})
|
|
|
}
|
|
|
if(res.data.code==200){
|
|
|
this.setData({times:res.data.data.freeChatCount})
|
|
|
console.log(res)
|
|
|
this.setData({
|
|
|
chatList:this.data.chatList.concat({'type':2,'value':res.data.data.content})
|
|
|
})
|
|
|
}
|
|
|
console.log(this.userInfo);
|
|
|
}).catch((err)=>{
|
|
|
console.log(err);
|
|
|
})
|
|
|
this.setData({ltinfo:''})
|
|
|
}
|
|
|
},
|
|
|
getUserInfo(){
|
|
|
req.getRequest('/api/user/curt',{}).then((res)=>{
|
|
|
if(res.data.code==200){
|
|
|
this.setData({
|
|
|
userInfo:res.data.data,
|
|
|
isShow: true
|
|
|
})
|
|
|
if(!res.data.data.isChatVip){
|
|
|
this.setData({times:res.data.data.freeChatCount})
|
|
|
}
|
|
|
this.getDetaile()
|
|
|
}
|
|
|
}).catch((err)=>{
|
|
|
console.log(err);
|
|
|
})
|
|
|
},
|
|
|
go2Reback(){
|
|
|
wx.switchTab({
|
|
|
url: '/pages/home/jl/index',
|
|
|
})
|
|
|
},
|
|
|
// 获取聊天气泡内容
|
|
|
getContent(e){
|
|
|
// 判断两天次数
|
|
|
if (!this.data.times && !this.data.userInfo.isChatVip) {
|
|
|
return wx.showToast({
|
|
|
title: '开通会员继续聊天',
|
|
|
icon: 'none'
|
|
|
})
|
|
|
}
|
|
|
const ctn = e.currentTarget.dataset.ctn
|
|
|
if (ctn === '1') {
|
|
|
this.setData({ltinfo: '请告诉我未来一个月的星座运势'})
|
|
|
}else if(ctn === '2'){
|
|
|
this.setData({ltinfo: '你可以帮我占卜星骰吗?'})
|
|
|
}else if(ctn === '3'){
|
|
|
this.setData({ltinfo: '你可以帮我占卜塔罗吗?'})
|
|
|
}else if(ctn === '4'){
|
|
|
this.setData({ltinfo: '我有一些情感上的问题,你能帮我解答吗?'})
|
|
|
}else if(ctn === '5'){
|
|
|
this.setData({ltinfo: '我和ta未来会怎样?'})
|
|
|
}else if(ctn === '6'){
|
|
|
this.setData({ltinfo: '请跟我一起玩文字冒险游戏吧'})
|
|
|
}else if(ctn === '7'){
|
|
|
this.setData({ltinfo: '我需要写一封情书,但我不太会表达。我会告诉你我们之间的经历和我想表达的心意,你可以帮我整理成一封动人的情书吗?'})
|
|
|
}
|
|
|
},
|
|
|
|
|
|
// 获取默认头像
|
|
|
getDetaile(){
|
|
|
const list = wx.getStorageSync('xy-static-img')
|
|
|
const type = this.data.userInfo.constellation
|
|
|
this.setData({
|
|
|
list: list[type]
|
|
|
})
|
|
|
console.log(this.data.list);
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 生命周期函数--监听页面加载
|
|
|
*/
|
|
|
onLoad(options) {
|
|
|
this.getUserInfo()
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
|
*/
|
|
|
onReady() {
|
|
|
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 生命周期函数--监听页面显示
|
|
|
*/
|
|
|
onShow() {
|
|
|
this.getUserInfo()
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 生命周期函数--监听页面隐藏
|
|
|
*/
|
|
|
onHide() {
|
|
|
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 生命周期函数--监听页面卸载
|
|
|
*/
|
|
|
onUnload() {
|
|
|
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
|
*/
|
|
|
onPullDownRefresh() {
|
|
|
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 页面上拉触底事件的处理函数
|
|
|
*/
|
|
|
onReachBottom() {
|
|
|
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 用户点击右上角分享
|
|
|
*/
|
|
|
onShareAppMessage() {
|
|
|
|
|
|
}
|
|
|
}) |