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.
xzjl-ui/pages/home/jl/jlai/jlai.js

180 lines
4.9 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

// 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
},
addClick(){
console.log('点击了加号11')
this.setData({
isAdd:true,
showChat: !this.data.showChat
})
},
noaddClick(){
console.log('点击了加号')
this.setData({
isAdd:false,
showChat: !this.data.showChat
})
},
dovipTips(){
this.setData({showChatToast: !this.data.showChatToast})
},
go2Member(){
wx.navigateTo({
url: '/pages/home/me/member/member'
})
},
go2BB(e){/**鼠标回显事件 */
// this.setData({ltinfo:e.detail.value})
},
go2Send(e){/**发送消息 */
this.setData({isBlank:false})
if(e.target.dataset.lt==''){
wx: wx.showToast({
title: '聊天内容不能为空',
icon:'none',
})
}else{
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: 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})
if(!res.data.data.isChatVip){
this.setData({times:res.data.data.freeChatCount})
}
console.log(this.data.times)
}
console.log(this.userInfo);
}).catch((err)=>{
console.log(err);
})
},
go2Reback(){
wx.navigateBack({ changed: true });
},
// 获取聊天气泡内容
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: '我需要写一封情书,但我不太会表达。我会告诉你我们之间的经历和我想表达的心意,你可以帮我整理成一封动人的情书吗?'})
}
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
this.getUserInfo()
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
this.getUserInfo()
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})