微信小程序?qū)崿F(xiàn)留言板功能
本文實(shí)例為大家分享了微信小程序?qū)崿F(xiàn)留言板功能,可以手寫(xiě),可以刪除,可以快速留言,供大家參考,具體內(nèi)容如下
const app = getApp();
Page({
/**
* 頁(yè)面的初始數(shù)據(jù)
*/
data: {
msgData:
[
{
child_id: 1,
msg:
"泡澡水不要太熱。",
checked:''
},//雙引號(hào)
{
child_id: 2,
msg:
"面部比較干,想補(bǔ)個(gè)水。",
checked: ''
},
{
child_id: 3,
msg:
"我只有2小時(shí),您看著安排吧。",
checked: ''
},
{
child_id: 4,
msg:
"我想把眉毛在修下。",
checked: ''
},
{
child_id: 5,
msg:
"給我清個(gè)痘痘。",
checked: ''
},
{
child_id: 6,
msg:
"頭疼,能輕點(diǎn)按。",
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: '暫無(wú)選擇項(xiàng)目',
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)
}
})
},
/**
* 生命周期函數(shù)--監(jiān)聽(tīng)頁(yè)面加載
*/
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,
});
}
}
}
}
})
},
/**
* 生命周期函數(shù)--監(jiān)聽(tīng)頁(yè)面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函數(shù)--監(jiān)聽(tīng)頁(yè)面顯示
*/
onShow: function () {
},
/**
* 生命周期函數(shù)--監(jiān)聽(tīng)頁(yè)面隱藏
*/
onHide: function () {
},
/**
* 生命周期函數(shù)--監(jiān)聽(tīng)頁(yè)面卸載
*/
onUnload: function () {
},
/**
* 頁(yè)面相關(guān)事件處理函數(shù)--監(jiān)聽(tīng)用戶下拉動(dòng)作
*/
onPullDownRefresh: function () {
},
/**
* 頁(yè)面上拉觸底事件的處理函數(shù)
*/
onReachBottom: function () {
},
/**
* 用戶點(diǎn)擊右上角分享
*/
onShareAppMessage: function () {
}
})
xml:
<!--pages/order/message/message.wxml-->
<view class='message_nav'>
<form bindsubmit='FormSubmit'>
<view class='section'>
<textarea class='message1' type='text' placeholder="請(qǐng)選擇或者輸入捎話(60字以內(nèi))" maxlength='80' style="word- wrap:break-word" bindinput='bindTextAreaChange' value="{{message}}"></textarea>
</view>
<view class='fast'>快速捎話:</view>
<checkbox-group class="checkboxChange">
<view wx:for="{{msgData}}" wx:key="{{index}}" data-index="{{index}}" data-id="{{item.child_id}}" data-checked='{{item.checked}}' bindtap='click' >
<checkbox value='{{item.msg}}' class='item' checked='{{item.checked}}' >{{item.msg}}</checkbox>
</view>
</checkbox-group>
<button class='submit' bindtap='submit'>捎話</button>
</form>
</view>
CSS:
/* pages/order/message/message.wxss */
/*捎話 */
.message_nav{
position: fixed;
width: 100%;
}
.section{
width:96%;
height:220rpx;
margin-left:5px;
}
.message1{
width:96%;
height:210rpx;
margin-top: 30rpx;
font-size: 68%;
margin-left:20px;
}
.circle{
height:35rpx;
width:35rpx;
border-radius: 50%;
border: 1rpx solid #ccc;
display:inline-block;
margin:28rpx 45rpx auto 50rpx;
}
.fast{
position:relative;
top:-50rpx;
font-size:90%;
background:#f4f4f4;
line-height:100rpx;
text-indent:2em;
}
.item{
position:relative;
border-bottom:1px solid #f4f4f4;
padding-bottom:10px;
top: -60rpx;
}
.item:hover{
background:pink;
color: #f4f4f4;
}
.message_font{
font-size:80%;
font-family:"微軟雅黑";
font-weight:blod;
display:inline-block;
position:relative;
top:-5rpx;
}
.submit{
outline:none;
border:none;
list-style: none;
width:100%;
height: 100rpx;
background: #fed1d6;
position: relative;
top:160rpx;
line-height: 100rpx;
-webkit-border-radius: 1rpx;
-moz-border-radius: 1rpx;
border-radius: 1rpx;
-webkit-appearance : none ;
}
button::after{
border:none;
}
.item{
position:relative;
border-bottom:1px solid #f4f4f4;
padding-top:5px;
top: -60rpx;
width:100%;
padding-left: 45rpx;
}
.checkboxChange{
position:relative;
top:15rpx;
font-size: 68%;
border-radius: 50%;
}
/* .circle{
border-radius: 50%;
} */
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
JS運(yùn)動(dòng)特效之任意值添加運(yùn)動(dòng)的方法分析
這篇文章主要介紹了JS運(yùn)動(dòng)特效之任意值添加運(yùn)動(dòng)的方法,結(jié)合實(shí)例形式分析了javascript針對(duì)多物體運(yùn)動(dòng)通過(guò)參數(shù)控制不同運(yùn)動(dòng)效果的實(shí)現(xiàn)方法,需要的朋友可以參考下2018-01-01
前端利用PrintJs實(shí)現(xiàn)批量打印文件功能
在項(xiàng)目中遇到一個(gè)問(wèn)題需要實(shí)現(xiàn)批量打印功能,研究了測(cè)試了一番解決了,把相關(guān)的功能記錄下,這篇文章主要介紹了前端利用PrintJs實(shí)現(xiàn)批量打印文件功能的相關(guān)資料,需要的朋友可以參考下2025-02-02
基于JavaScript實(shí)現(xiàn)回到頁(yè)面頂部動(dòng)畫(huà)代碼
這篇文章主要介紹了基于JavaScript實(shí)現(xiàn)回到頁(yè)面頂部動(dòng)畫(huà)代碼的相關(guān)資料,代碼簡(jiǎn)單易用,非常實(shí)用,需要的朋友可以參考下2016-05-05
HTML5+Canvas實(shí)現(xiàn)圖片添加水印功能
在現(xiàn)代Web開(kāi)發(fā)中,圖像處理是一個(gè)常見(jiàn)的需求,尤其是為圖片添加水印,下面我們就來(lái)看看如何使用HTML5的Canvas技術(shù)為圖片添加水印,需要的可以了解下2024-11-11
淺談webpack打包生成的bundle.js文件過(guò)大的問(wèn)題
下面小編就為大家分享一篇淺談webpack打包生成的bundle.js文件過(guò)大的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-02-02
js中document.write和document.writeln的區(qū)別
這篇文章主要介紹了js中document.write和document.writeln的區(qū)別,需要的朋友可以參考下2018-03-03
JavaScript數(shù)據(jù)結(jié)構(gòu)中串的表示與應(yīng)用實(shí)例
這篇文章主要介紹了JavaScript數(shù)據(jù)結(jié)構(gòu)中串的表示與應(yīng)用,結(jié)合實(shí)例形式簡(jiǎn)單分析了基于javascript順序操作實(shí)現(xiàn)串結(jié)構(gòu)與串的拼接操作相關(guān)技巧,需要的朋友可以參考下2017-04-04

