效果图如下:

实例代码如下:
type_add.js

// pages/detail_add/detail_add.js
Page({ /**
* 页面的初始数据
*/
data: {
selectData: "", //下拉列表的数据
height: ,
focus: false
},
checkboxChange: function(e) {
console.log('checkbox发生change事件,携带value值为:', e.detail.value)
console.log("长度:" + e.detail.value.length);
this.setData({
typeId: e.detail.value,
length: e.detail.value.length
}) },
formSubmit: function(e) {
console.log('form发生了submit事件,携带数据为:' + e.detail.value.amount + ", " + e.detail.value.typeId + ", " + this.data.remark + ", " + this.data.date + ", " + this.data.time); var amount = e.detail.value.amount;
var typeId = this.data.typeId; var date = this.data.date;
var time = this.data.time;
var remark = e.detail.value.remark;
var createDate = date + " " + time;
var length = this.data.length;
console.log("length:" + length);
console.log("date:" + date);
console.log("time:" + time);
console.log("createDate:" + createDate) if (amount == null || amount == "") {
wx.showToast({
title: "支出金额不能为空",
icon: 'none',
duration:
})
} else if (typeId == null || typeId == "") {
wx.showToast({
title: "支出类型不能为空",
icon: 'none',
duration:
}) } else if (length >= ) {
wx.showToast({
title: "支出类型只能选择一种",
icon: 'none',
duration:
})
} else if (date == null || date == "") {
wx.showToast({
title: "日期不能为空",
icon: 'none',
duration:
})
} else if (time == null || time == "") {
wx.showToast({
title: "时间不能为空",
icon: 'none',
duration:
})
} else if (remark == null || remark == "") {
wx.showToast({
title: "备注不能为空",
icon: 'none',
duration:
})
} else { wx.request({ url: getApp().globalData.urlPath + "spendingDetail/add",
method: "POST",
data: {
amount: amount,
typeId: typeId,
createDate: createDate,
remark: remark
},
header: {
"Content-Type": "application/x-www-form-urlencoded"
},
success: function(res) {
console.log(res.data.code);
if (res.statusCode == ) { //访问正常
if (res.data.code == "") {
wx.showToast({
title: "添加支出详情成功",
icon: 'success',
duration: ,
success: function() { wx.navigateTo({
url: '../detail/detail'
})
}
}) }
} else { wx.showLoading({
title: '系统异常',
fail
}) setTimeout(function() {
wx.hideLoading()
}, )
} }
})
} },
formReset: function() {
console.log('form发生了reset事件')
},
bindDateChange: function(e) {
console.log('picker发送选择改变,携带值为', e.detail.value)
this.setData({
date: e.detail.value
})
},
bindTimeChange: function(e) {
console.log('picker发送选择改变,携带值为', e.detail.value)
this.setData({
time: e.detail.value
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function(options) {
wx.setNavigationBarTitle({ title: "添加支出详情" }) var userCode = wx.getStorageSync('userId').toString();
var self = this;
wx.request({
url: getApp().globalData.urlPath + "spendingType/types", //json数据地址
data: {
userCode: userCode
},
headers: {
"Content-Type": "application/x-www-form-urlencoded"
},
success: function(res) {
console.log("res.data.data.typeName:" + res.data.data) self.setData({ selectData: res.data.data }) }
})
}, /**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function() { }, /**
* 生命周期函数--监听页面显示
*/
onShow: function() { }, /**
* 生命周期函数--监听页面隐藏
*/
onHide: function() { }, /**
* 生命周期函数--监听页面卸载
*/
onUnload: function() { }, /**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function() { }, /**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function() { }, /**
* 用户点击右上角分享
*/
onShareAppMessage: function() { }
})

type_add.wxml:

<form bindsubmit="formSubmit" bindreset="formReset">
<view class="section">
<text>支出金额</text>
<input name="input" name="amount" placeholder="请输入支出金额" />
</view> <view class="section">
<text>支出类型</text>
<checkbox-group bindchange="checkboxChange">
<label class="checkbox" wx:for="{{selectData}}">
<checkbox value="{{item.typeId}}" checked="{{item.checked}}" />{{item.typeName}}
</label>
</checkbox-group> </view> <view>
<text>创建时间</text>
<view class="section">
<picker mode="date" value="{{date}}" start="2018-09-01" end="2030-09-01" bindchange="bindDateChange">
<view class="picker">
选择日期: {{date}}
</view>
</picker>
</view>
<view class="section">
<picker mode="time" value="{{time}}" start="00:00=" end="23:59" bindchange="bindTimeChange">
<view class="picker">
选择时间: {{time}}
</view>
</picker>
</view>
</view>
<view class="section">
<text>备注</text>
<input name="input" name="remark" placeholder="请输入备注" />
</view>
<view>
<text>\n</text>
</view>
<view class="btn-area">
<button form-type="submit">提交</button>
<view>
<text>\n</text>
</view>
<button form-type="reset">重置</button>
</view>
</form>

bindchange=”checkboxChange” 相当于js中的onchange事件。
上述中的form表单基本就是参考官方文档改的。
有一段代码还是要提一下:

self.setData({

    selectData: res.data.data

  })

self其实相当于this,意为当前。每次触发事件,对应的值都会进行存储,用于与后台通信进行数组传递,

type_add.wxss:

/* pages/login/login.wxss */
form{
width: 310px;
height: 240px;
line-height: 40px;
/* border: 1px solid red; */
}
input{
border: 1px solid #ccc;
width: 310px;
height: 40px;
}
.button{
margin-top: 20px;
}
.header text{
font-size: 25px;
color: #;
}
form text{
font-size: 20px;
color: #;
}

最新文章

  1. theano sparse_block_dot
  2. wdk中ramdisk代码解读
  3. 在ASP.NET Core中怎么使用HttpContext.Current
  4. eclipse 相同变量高亮显示 颜色修改 变量着色
  5. free(): invalid next size (fast/normal)问题
  6. Apache Spark源码走读之17 -- 如何进行代码跟读
  7. django 简单的邮件系统
  8. IOS聊天对话界面
  9. css显示出三角形
  10. hdu 1063 Exponentiation
  11. android各种适配器的用法(转)
  12. Jquery效果代码--(二)
  13. svn删除用户
  14. Ubuntu下deb包的解压、打包、安装、卸载及常用命令参数
  15. unity 如何在botton AddListen中传递参数调用函数
  16. centos7查看网卡UUID
  17. MVC 验证规则扩展(当RoleID 属性值为A,B 时,Email 属性必填)
  18. 【代码笔记】Web-JavaScript-JavaScript正则表达式
  19. android开发(1):底部导航条的实现 | navigation tab | activity的创建
  20. 51Nod 1815 调查任务

热门文章

  1. iOS开发,导入c文件引发的Could not build module &#39;UIKit&#39;问题
  2. pandas-08 pd.cut()的功能和作用
  3. day 02 预科
  4. 【转】Vsftpd-3.0.2服务器arm-linux移植—mini2440开发板
  5. 191017 虚拟机centos修改IP
  6. Cloudera Certified Associate Administrator案例之Configure篇
  7. X.509_2
  8. Four subspaces - Prof. Strang
  9. 《Java程序设计实验》 软件工程18-1,3 OO实验2
  10. Android Binder机制彻底梳理一