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.
249 lines
5.7 KiB
249 lines
5.7 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',
|
|
house_id: '',
|
|
id: '',
|
|
data: [],
|
|
rent_type: {
|
|
1: "押一付一",
|
|
3: "押一付三",
|
|
6: "押一付六",
|
|
12: "押一付十二"
|
|
},
|
|
imgList: [],
|
|
photo: ''
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad: function(options) {
|
|
this.initValidate();
|
|
var id = options.id
|
|
var house_id = options.house_id
|
|
//判断是否含有id
|
|
if (id) {
|
|
this.getDetail(id);
|
|
}
|
|
this.setData({
|
|
house_id: house_id,
|
|
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/house/viewRoom/' + id;
|
|
netUtil.sendGet(url)
|
|
.then((res) => {
|
|
var result = res.data.data
|
|
this.setData({
|
|
data: result,
|
|
startTime: result.room.start_time,
|
|
endTime: result.room.end_time,
|
|
imgList: result.room.imgList,
|
|
photo: result.room.photo
|
|
})
|
|
})
|
|
},
|
|
|
|
//插入用户数据
|
|
insertData: function(data) {
|
|
var self = this;
|
|
var method_url = self.data.id > 0 ? 'index/house/editRoom' : 'index/house/addRoom';
|
|
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
|
|
})
|
|
},
|
|
//图片选择
|
|
ChooseImage() {
|
|
var self = this;
|
|
var url = app.globalData.requestUrl + 'index/upload/plupload';
|
|
wx.chooseImage({
|
|
count: 10, //默认9
|
|
sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
|
|
sourceType: ['album', 'camera'], //从相册选择
|
|
success: (res) => {
|
|
//上传到服务器
|
|
wx.showToast({
|
|
title: '正在上传...',
|
|
icon: 'loading',
|
|
mask: true,
|
|
duration: 30000
|
|
})
|
|
let tempFilePaths = res.tempFilePaths;
|
|
for (var i in tempFilePaths) {
|
|
wx.uploadFile({
|
|
url: url,
|
|
filePath: tempFilePaths[i],
|
|
name: 'file',
|
|
success: function(res) {
|
|
//赋值操作
|
|
var data = JSON.parse(res.data);
|
|
self.setData({
|
|
imgList: self.data.imgList.length != 0 ? self.data.imgList.concat([data.url]) : [data.url]
|
|
})
|
|
//赋值图片隐藏域
|
|
self.setData({
|
|
photo: self.data.imgList.join(',')
|
|
})
|
|
|
|
},
|
|
fail: function(res) {
|
|
wx.showModal({
|
|
title: '错误提示',
|
|
content: '上传图片失败',
|
|
showCancel: false,
|
|
success: function(res) {}
|
|
})
|
|
}
|
|
})
|
|
}
|
|
wx.hideToast();
|
|
}
|
|
});
|
|
|
|
},
|
|
ViewImage(e) {
|
|
wx.previewImage({
|
|
urls: this.data.imgList,
|
|
current: e.currentTarget.dataset.url
|
|
});
|
|
},
|
|
DelImg(e) {
|
|
wx.showModal({
|
|
title: '图片删除',
|
|
content: '确定要删除这张图片吗?',
|
|
cancelText: '再看看',
|
|
confirmText: '确认',
|
|
success: res => {
|
|
if (res.confirm) {
|
|
this.data.imgList.splice(e.currentTarget.dataset.index, 1);
|
|
this.setData({
|
|
imgList: this.data.imgList,
|
|
photo: this.data.imgList.join(',')
|
|
})
|
|
}
|
|
}
|
|
})
|
|
},
|
|
initValidate() {
|
|
// 验证字段的规则
|
|
const rules = {
|
|
room_number: {
|
|
required: true,
|
|
},
|
|
rent: {
|
|
required: true,
|
|
},
|
|
property_fee: {
|
|
required: true,
|
|
},
|
|
key_deposit: {
|
|
required: true,
|
|
},
|
|
broadband_fee: {
|
|
required: true,
|
|
},
|
|
measure: {
|
|
required: true,
|
|
},
|
|
rent_type: {
|
|
required: true,
|
|
}
|
|
}
|
|
|
|
// 验证字段的提示信息,若不传则调用默认的信息
|
|
const messages = {
|
|
room_number: {
|
|
required: "请输入子房间编号",
|
|
},
|
|
rent: {
|
|
required: "请输入租金",
|
|
},
|
|
property_fee: {
|
|
required: "请输入物业费",
|
|
},
|
|
key_deposit: {
|
|
required: "请输入钥匙押金",
|
|
},
|
|
broadband_fee: {
|
|
required: "请输入宽带费",
|
|
},
|
|
measure: {
|
|
required: "请输入面积",
|
|
},
|
|
rent_type: {
|
|
required: "请选择收租方式",
|
|
}
|
|
}
|
|
|
|
// 创建实例对象
|
|
this.WxValidate = new WxValidate(rules, messages)
|
|
},
|
|
})
|