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.
321 lines
6.4 KiB
321 lines
6.4 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,
|
|
index: null,
|
|
multiIndex: [0, 0, 0],
|
|
time: '12:01',
|
|
region: ['安徽省', '合肥市', '高新区'],
|
|
status: ['未出租', '出租中'],
|
|
imgList: [],
|
|
photo: '',
|
|
modalName: null,
|
|
textareaAValue: '',
|
|
textareaBValue: '',
|
|
housingAllocation: [{
|
|
id: 1,
|
|
name: '空调'
|
|
},
|
|
{
|
|
id: 2,
|
|
name: '床'
|
|
}, {
|
|
id: 3,
|
|
name: '阳台'
|
|
},
|
|
{
|
|
id: 4,
|
|
name: '卫生间'
|
|
}, {
|
|
id: 5,
|
|
name: 'WIFI'
|
|
},
|
|
{
|
|
id: 6,
|
|
name: '热水器'
|
|
}, {
|
|
id: 7,
|
|
name: '洗衣机'
|
|
},
|
|
{
|
|
id: 8,
|
|
name: '冰箱'
|
|
}, {
|
|
id: 9,
|
|
name: '电视'
|
|
},
|
|
{
|
|
id: 10,
|
|
name: '燃气灶'
|
|
}, {
|
|
id: 11,
|
|
name: '油烟机'
|
|
},
|
|
{
|
|
id: 12,
|
|
name: '沙发'
|
|
}, {
|
|
id: 13,
|
|
name: '书桌'
|
|
},
|
|
{
|
|
id: 14,
|
|
name: '微波炉'
|
|
}, {
|
|
id: 15,
|
|
name: '电饭煲'
|
|
},
|
|
{
|
|
id: 16,
|
|
name: '衣柜'
|
|
}
|
|
]
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad: function(options) {
|
|
this.initValidate()
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
*/
|
|
onReady: function() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
onShow: function() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面隐藏
|
|
*/
|
|
onHide: function() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面卸载
|
|
*/
|
|
onUnload: function() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
*/
|
|
onPullDownRefresh: function() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面上拉触底事件的处理函数
|
|
*/
|
|
onReachBottom: function() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 用户点击右上角分享
|
|
*/
|
|
onShareAppMessage: function() {
|
|
|
|
},
|
|
|
|
formSubmit: function(e) {
|
|
console.log(e);
|
|
const params = e.detail.value
|
|
console.log(params)
|
|
// 传入表单数据,调用验证方法
|
|
if (!this.WxValidate.checkForm(params)) {
|
|
const error = this.WxValidate.errorList[0]
|
|
this.showModal(error)
|
|
return false
|
|
}
|
|
//执行入库
|
|
this.insertData(params);
|
|
},
|
|
|
|
//插入用户数据
|
|
insertData: function(data) {
|
|
var self = this;
|
|
var url = app.globalData.requestUrl + 'index/house/add';
|
|
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) {
|
|
console.log(e);
|
|
wx.showToast({
|
|
title: e.msg,
|
|
icon: 'none',
|
|
duration: 2000
|
|
})
|
|
},
|
|
|
|
//地域选择
|
|
RegionChange: function(e) {
|
|
this.setData({
|
|
region: e.detail.value
|
|
})
|
|
},
|
|
//图片选择
|
|
ChooseImage() {
|
|
var self = this;
|
|
var url = app.globalData.requestUrl + 'index/upload/plupload';
|
|
wx.chooseImage({
|
|
count: 4, //默认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
|
|
})
|
|
}
|
|
}
|
|
})
|
|
},
|
|
initValidate() {
|
|
// 验证字段的规则
|
|
const rules = {
|
|
name: {
|
|
required: true,
|
|
},
|
|
door_number: {
|
|
required: true,
|
|
},
|
|
rent: {
|
|
required: true,
|
|
},
|
|
apartment: {
|
|
required: true,
|
|
},
|
|
measure: {
|
|
required: true,
|
|
},
|
|
water_money: {
|
|
required: true,
|
|
},
|
|
gas_money: {
|
|
required: true,
|
|
},
|
|
floor_num: {
|
|
required: true,
|
|
},
|
|
}
|
|
|
|
// 验证字段的提示信息,若不传则调用默认的信息
|
|
const messages = {
|
|
name: {
|
|
required: "请输入小区名称",
|
|
},
|
|
door_number: {
|
|
required: "请输入房屋门牌号",
|
|
},
|
|
rent: {
|
|
required: "请输入租金",
|
|
},
|
|
apartment: {
|
|
required: "请输入房屋户型",
|
|
},
|
|
measure: {
|
|
required: "请输入房屋面积",
|
|
},
|
|
water_money: {
|
|
required: "请输入水费",
|
|
},
|
|
gas_money: {
|
|
required: "请输入燃气费",
|
|
},
|
|
floor_num: {
|
|
required: "请输入小区楼层",
|
|
},
|
|
}
|
|
|
|
// 创建实例对象
|
|
this.WxValidate = new WxValidate(rules, messages)
|
|
},
|
|
})
|