首页 > 热点 > 微信 > 正文

微信小程序实现留言板功能

2024-07-22 01:17:24
字体:
来源:转载
供稿:网友

本文实例为大家分享了微信小程序实现留言板功能,可以手写,可以删除,可以快速留言,供大家参考,具体内容如下

const app = getApp();Page({  /** * 页面的初始数据 */ data: {  msgData: [  {  child_id: 1,  msg:  "泡澡水不要太热。",  checked:''  },//双引号  {  child_id: 2,  msg:  "面部比较干,想补个水。",  checked: ''  },  {  child_id: 3,  msg:  "我只有2小时,您看着安排吧。",  checked: ''  },  {  child_id: 4,  msg:  "我想把眉毛在修下。",  checked: ''  },  {  child_id: 5,  msg:  "给我清个痘痘。",  checked: ''  },  {  child_id: 6,  msg:  "头疼,能轻点按。",   checked:''  } ], message: '', message_id:[], }, bindTextAreaChange: function(e){ var that = this that.setData({  message:e.detail.value }) },  click:function(e){ var that = this; let id = e.currentTarget.dataset.id; let index = e.currentTarget.dataset.index; var value = []; value = this.data.message_id; var array_i = this.in_array(id, value); var chekeds = that.data.msgData; var msg = chekeds[index].msg; var message = that.data.message; if (!e.currentTarget.dataset.checked){   chekeds[index].checked = true  that.setData({  message: message + msg  }) }else{  chekeds[index].checked = false  that.setData({  message: message.replace(msg, '')  }) } that.setData({  msgData: chekeds }) if (array_i) {  value.splice(array_i, 1); } else {  value.push(id); } this.setData({  message_id: value, }) }, in_array: function (search, array) { for (var i in array) {  if (array[i] == search) {  return i;  } } return false; }, submit:function(){ var value = []; var message = this.data.message; var msgData = this.data.msgData; if (message == '' && !value.length) {  wx.showToast({  title: '暂无选择项目',  icon:'none'  })  return; } app.globalData.message = message; for (var i = 0; i < msgData.length; i++) {  if(message.indexOf(msgData[i].msg) > -1){  value[i] = msgData[i].child_id;  } } wx.request({  url: 'https://www.njnrkj.com/app/public/index.php/index/index/server',  method: 'POST',  data: {message_id: value, openId: app.globalData.openId, message: message},  header: {  'Accept': 'application/json'  },  success: function (res) {  if(res){   // wx.showToast({   // title: '捎话成功',   // success:function(){       // }   // })   wx.switchTab({   url: '/pages/order/order',   success: function (e) {    var page = getCurrentPages().pop();    if (page == undefined || page == null) return;    page.onLoad();   }   })   app.globalData.message = message;  }    console.log(res)  } }) },  /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { var that = this; wx.request({  url: 'https://www.njnrkj.com/app/public/index.php/index/index/serversle',  method: 'POST',  data: { openId: app.globalData.openId },  header: {  'Accept': 'application/json'  },  success: function (res) {  if (res.data){   var message_id = res.data.message_id;   var value = that.data.msgData;   var message = res.data.message;   that.setData({   message: message   });   for (var i = 0; i < value.length;i++) {   if (that.in_array(value[i].child_id, message_id)) {    value[i].checked = true;    that.setData({    msgData: value,    });   }   }  }  } })  },  /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () {  },  /** * 生命周期函数--监听页面显示 */ onShow: function () {  },  /** * 生命周期函数--监听页面隐藏 */ onHide: function () {  },  /** * 生命周期函数--监听页面卸载 */ onUnload: function () {   },  /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () {  },  /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () {  },  /** * 用户点击右上角分享 */ onShareAppMessage: function () {  }})            
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表