const db = wx.cloud.database()
const app= getApp()
const util = require('../../utils/util.js')
Page({
/**
* 页面的初始数据
*/
data: {
recordId:'',
hasRecordId:false,
message:'',
placeHolder:'请输入...',
chatList:[],
height:'',
another_recordId:'',
msg1:'',
flag:false,
userA_openid:'1'
},
input_message:function(e){
var that = this
that.setData({
message:e.detail.value
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
var that = this
that.setData({
height: wx.getSystemInfoSync().windowHeight-50,
userA_openid:app.globalData.userA_openid
})
if(app.globalData.userA_openid=='undefined'){
that.setData({
flag:false
})
}
if(app.globalData.userA_openid!='undefined'){
that.setData({
flag:true
})
console.log(that.data.flag)
that.getRecordId()
}
},
AddanotherRecord:function(){
var that = this
console.log('执行添加记录'),
db.collection('ChatRecord').add({
data:{
record:[],
userB_faceImg:app.globalData.userA_faceImg,
userB_nickname:app.globalData.userA_nickname,
userA_faceImg:app.globalData.userB_faceImg,
userA_nickname:app.globalData.userB_nickname,
userA_openid:app.globalData.userB_openid,
userB_openid:app.globalData.userA_openid,
text_status:1
}
}).then({
success(res){
that.getanotherRecordId()
}
})
},
gomine:function(){
wx.switchTab({
url: '../mine/mine',
})
},
getanotherRecordId:function(){
var that = this
db.collection('ChatRecord').where({
userA_openid:app.globalData.userB_openid,
userB_openid:app.globalData.userA_openid,
}).get({
success(res){
that.setData({
another_recordId:res.data[0]._id,
hasanotherRecordId:true
})
that.getChatRecord()
}
})
},
getRecordId:function(){
var that = this
db.collection('ChatRecord').where({
userA_openid:app.globalData.userA_openid,
userB_openid:app.globalData.userB_openid
}).get({
success(res){
if(res.data.length==0){
that.AddRecord(),
that.AddanotherRecord()
}
else{
that.setData({
recordId:res.data[0]._id
})
}
that.getChatRecord()
that.getanotherRecordId()
}
})
},
AddRecord:function(){
var that = this
db.collection('ChatRecord').add({
data:{
record:[],
userA_faceImg:app.globalData.userA_faceImg,
userA_nickname:app.globalData.userA_nickname,
userB_faceImg:app.globalData.userA_faceImg,
userB_nickname:app.globalData.userB_nickname,
userA_openid:app.globalData.userA_openid,
userB_openid:app.globalData.userB_openid,
text_status:1
}
}).then({
success(res){
that.getRecordId()
console.log('添加成功')
}
})
},
getChatRecord:function(){
var that = this
db.collection('ChatRecord').doc(that.data.recordId).get({
success(res){
that.setData({
chatList:res.data.record,
message:'',
placeHolder:"请输入..."
})
}
})
db.collection('ChatRecord').doc(that.data.recordId).update({
data:{
text_status:1
}
}).then(res=>{
})
},
publishChat(){
this.getRecordId()
var that = this
db.collection('ChatRecord').doc(that.data.recordId).get({
success(res){
var record = res.data.record
console.log(res.data.record)
var msg={
nickname:app.globalData.userA_nickname,
faceImg:app.globalData.userA_faceImg,
openid:app.globalData.userA_openid,
text:that.data.message,
tonickname:app.globalData.userB_nickname,
time:util.formatTime(new Date)
}
that.setData({
msg1:msg.time
})
// 在chat里面找到record 追加msg
record.push(msg)
db.collection('ChatRecord').doc(that.data.recordId).update({
data:{
record:record,
text_status:1,
time:that.data.msg1
},}).then({
success(res){
db.collection('ChatRecord').doc(that.data.another_recordId).get({
success(res){
var record = res.data.record
var msg={
nickname:app.globalData.userA_admin,
faceImg:app.globalData.userA_faceImg,
openid:app.globalData.userA_openid,
text:that.data.messag,
time:that.data.msg1
}
// 在chat里面找到record 追加msg
record.push(msg)
console.log(msg)
console.log(record)
db.collection('ChatRecord').doc(that.data.another_recordId).update({
data:{
record:record,
text_status:0,
time:that.data.msg1
},
success(res){
that.getChatRecord()
}
})
}
})
console.log(res.data)
that.getChatRecord()
console.log(that.data.msg1)
}
})
}
})
},
getScollBottom() {
this.setData({
scrollLast: 'item' + this.data.chatList.length
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
console.log(app.globalData.userB_nickname)
wx.setNavigationBarTitle({
title:app.globalData.userB_nickname,
})
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
this.getChatRecord()
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})
没有合适的资源?快使用搜索试试~ 我知道了~
基于JavaScript开发微信小程序的农产品销售信息平台源码(课程大作业).zip
共102个文件
js:28个
json:24个
wxss:19个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
5星 · 超过95%的资源 2 下载量 94 浏览量
2022-12-26
16:57:38
上传
评论
收藏 131KB ZIP 举报
温馨提示
基于JavaScript开发微信小程序的农产品销售信息平台源码.zip 基于JavaScript开发微信小程序的农产品销售信息平台源码.zip 基于JavaScript开发微信小程序的农产品销售信息平台源码.zip 【备注】 主要针对计算机相关专业的正在做毕设的学生和需要项目实战的Java学习者。 也可作为课程设计、期末大作业。包含:项目源码、项目说明等,该项目可以直接作为毕设使用。 也可以用来学习参考借鉴!
资源推荐
资源详情
资源评论
收起资源包目录
基于JavaScript开发微信小程序的农产品销售信息平台源码(课程大作业).zip (102个子文件)
uploadCloudFunction.bat 189B
chat.js 6KB
shopcart.js 5KB
productDetail.js 4KB
mine.js 4KB
orderDetail.js 3KB
orders.js 3KB
message.js 2KB
category.js 2KB
feedback.js 2KB
home.js 2KB
first.js 2KB
index.js 1KB
index.js 915B
app.js 860B
paySuccess.js 772B
bannersDetail.js 771B
util.js.js 751B
index.js 713B
index.js 637B
search.js 600B
.eslintrc.js 587B
index.js 497B
util.js 460B
index.js 394B
index.js 348B
index.js 291B
envList.js 134B
index.js 0B
project.private.config.json 3KB
project.config.json 2KB
app.json 2KB
package.json 270B
sitemap.json 195B
home.json 72B
search.json 72B
message.json 71B
config.json 69B
mine.json 59B
index.json 48B
index.json 30B
feedback.json 27B
shopcart.json 27B
chat.json 27B
category.json 27B
orders.json 27B
paySuccess.json 27B
orderDetail.json 27B
first.json 27B
productDetail.json 27B
bannersDetail.json 27B
util.js.json 27B
util.json 27B
项目说明.md 583B
头像.png 10KB
我的2.png 10KB
消息2.png 8KB
我的1.png 7KB
购物车2.png 7KB
消息1.png 6KB
分类2.png 6KB
购物车1.png 5KB
首页2.png 5KB
分类1.png 4KB
首页1.png 4KB
orderDetail.wxml 3KB
shopcart.wxml 2KB
productDetail.wxml 2KB
chat.wxml 2KB
orders.wxml 2KB
feedback.wxml 1KB
home.wxml 1KB
category.wxml 1KB
mine.wxml 1KB
message.wxml 893B
search.wxml 792B
first.wxml 746B
index.wxml 647B
paySuccess.wxml 125B
bannersDetail.wxml 98B
util.js.wxml 58B
util.wxml 52B
index.wxml 0B
orders.wxss 2KB
orderDetail.wxss 2KB
productDetail.wxss 2KB
chat.wxss 2KB
home.wxss 2KB
shopcart.wxss 2KB
search.wxss 1KB
category.wxss 1KB
mine.wxss 946B
index.wxss 921B
first.wxss 817B
feedback.wxss 694B
message.wxss 560B
app.wxss 330B
paySuccess.wxss 45B
bannersDetail.wxss 44B
util.js.wxss 24B
共 102 条
- 1
- 2
资源评论
- Celibacy5792023-05-28感谢大佬分享的资源,对我启发很大,给了我新的灵感。Make程序设计2023-11-08感谢支持~~
- 叨叨4542023-02-21资源使用价值高,内容详实,给了我很多新想法,感谢大佬分享~
Make程序设计
- 粉丝: 5638
- 资源: 3568
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功