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.
138 lines
2.8 KiB
138 lines
2.8 KiB
import WxValidate from '../../utils/WxValidate';
|
|
var netUtil = require("../../utils/requestUtil.js"); //require引入
|
|
const app = getApp();
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
StatusBar: app.globalData.StatusBar,
|
|
CustomBar: app.globalData.CustomBar,
|
|
startTime: '2020-01-01',
|
|
endTime: '2021-01-01',
|
|
id: '',
|
|
data: [],
|
|
status: [
|
|
'禁用', '启用'
|
|
]
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad: function(options) {
|
|
this.initValidate();
|
|
var id = options.id
|
|
var house_id = options.house_id
|
|
//判断是否含有id
|
|
if (id) {
|
|
this.getDetail(id);
|
|
}
|
|
this.setData({
|
|
id: id
|
|
})
|
|
},
|
|
|
|
//开始日期
|
|
startTimeChange(e) {
|
|
this.setData({
|
|
startTime: e.detail.value
|
|
})
|
|
},
|
|
//结束日期
|
|
endTimeChange(e) {
|
|
this.setData({
|
|
endTime: e.detail.value
|
|
})
|
|
},
|
|
|
|
/**
|
|
* 用户点击右上角分享
|
|
*/
|
|
onShareAppMessage: function() {
|
|
|
|
},
|
|
|
|
formSubmit: function(e) {
|
|
const params = e.detail.value
|
|
// 传入表单数据,调用验证方法
|
|
if (!this.WxValidate.checkForm(params)) {
|
|
const error = this.WxValidate.errorList[0]
|
|
this.showModal(error)
|
|
return false
|
|
}
|
|
//执行入库
|
|
this.insertData(params);
|
|
},
|
|
|
|
//获取数据详情
|
|
getDetail: function(id) {
|
|
var self = this;
|
|
var url = app.globalData.requestUrl + 'index/subaccount/view/' + id;
|
|
netUtil.sendGet(url)
|
|
.then((res) => {
|
|
console.log(res)
|
|
var result = res.data.data
|
|
this.setData({
|
|
data: result
|
|
})
|
|
})
|
|
},
|
|
|
|
//插入用户数据
|
|
insertData: function(data) {
|
|
var self = this;
|
|
var method_url = self.data.id > 0 ? 'index/subaccount/edit' : 'index/subaccount/add';
|
|
var url = app.globalData.requestUrl + method_url;
|
|
netUtil.sendPost(url, data)
|
|
.then((res) => {
|
|
if (res.statusCode == 200 && res.data.code == 200) {
|
|
wx.showToast({
|
|
title: '数据操作成功',
|
|
icon: 'success',
|
|
duration: 2000
|
|
})
|
|
} else {
|
|
wx.showToast({
|
|
title: res.data.msg,
|
|
icon: 'none',
|
|
duration: 3000
|
|
})
|
|
}
|
|
})
|
|
},
|
|
|
|
showModal: function(e) {
|
|
wx.showToast({
|
|
title: e.msg,
|
|
icon: 'none',
|
|
duration: 2000
|
|
})
|
|
},
|
|
|
|
initValidate() {
|
|
// 验证字段的规则
|
|
const rules = {
|
|
username: {
|
|
required: true,
|
|
},
|
|
password: {
|
|
required: true,
|
|
}
|
|
}
|
|
|
|
// 验证字段的提示信息,若不传则调用默认的信息
|
|
const messages = {
|
|
username: {
|
|
required: "请输入登录用户名",
|
|
},
|
|
password: {
|
|
required: "请输入登录密码",
|
|
}
|
|
}
|
|
|
|
// 创建实例对象
|
|
this.WxValidate = new WxValidate(rules, messages)
|
|
},
|
|
})
|