433 lines
11 KiB
JavaScript
433 lines
11 KiB
JavaScript
// pages/irentPark/irentPark.js
|
|
var WxParse = require('../../wxParse/wxParse.js');
|
|
var app = getApp()
|
|
var miucms = require('../../utils/miucms.js');
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
showPage: 'form',
|
|
guide: {
|
|
button: '',
|
|
image: '',
|
|
title: '',
|
|
|
|
},
|
|
uniqid: '',
|
|
token: '',
|
|
note: null,
|
|
|
|
title: '公寓预定',
|
|
data: {},
|
|
fields: {},
|
|
info: {},
|
|
studentapartment: {},
|
|
|
|
selectBox: {},
|
|
noteBox: {},
|
|
qrcode: "",
|
|
submit_uniqid: '',
|
|
//
|
|
housetype: '',
|
|
'from': '',
|
|
imgSave: "",
|
|
isAuthorization: 0,
|
|
customerservice: ''
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad: function (options) {
|
|
console.log("options", options);
|
|
this.setData({
|
|
uniqid: options.uniqid || "",
|
|
options: options || {},
|
|
housetype: options.housetype || '',
|
|
'from': options['from'] || '',
|
|
customerservice: options.customerservice || ''
|
|
})
|
|
wx.showLoading({
|
|
title: '',
|
|
})
|
|
this.get_config()
|
|
},
|
|
// 如果用户已经同意授权。则开始获取数据
|
|
islogin() {
|
|
wx.showLoading({
|
|
title: '加载中',
|
|
})
|
|
this.get_config()
|
|
},
|
|
get_config() {
|
|
var that = this;
|
|
if (app.globalData.config.lists) {
|
|
console.log('this.from', this.from)
|
|
if (!!this.data.customerservice) {
|
|
this.getcustomerservice()
|
|
return false;
|
|
}
|
|
if (this.data['from'] == 'list') {
|
|
this.getFormNew();
|
|
} else {
|
|
this.getForm();
|
|
}
|
|
|
|
} else {
|
|
setTimeout(function () {
|
|
that.get_config()
|
|
}, 200)
|
|
}
|
|
},
|
|
|
|
/**
|
|
* 用户点击右上角分享
|
|
*/
|
|
// onShareAppMessage: function () {
|
|
|
|
// },
|
|
|
|
previewImg() {
|
|
let url = this.data.showPage == 'guide' ? this.data.guide.image : this.data.needing.qrcode;
|
|
wx.previewImage({
|
|
current: url, // 当前显示图片的http链接
|
|
urls: [url] // 需要预览的图片http链接列表
|
|
})
|
|
},
|
|
previewImage() {
|
|
wx.previewImage({
|
|
current: this.data.data.image, // 当前显示图片的http链接
|
|
urls: [this.data.data.image] // 需要预览的图片http链接列表
|
|
})
|
|
},
|
|
getForm() {
|
|
let that = this;
|
|
console.log('getFormgetFormgetFormgetForm')
|
|
var sendData = Object.assign({}, this.data.options, {
|
|
session: wx.getStorageSync('session'),
|
|
uniqid: this.data.uniqid,
|
|
housetype: that.data.housetype
|
|
})
|
|
miucms.request(app.globalData.config.studentapartment.form, sendData).then(data => {
|
|
wx.hideLoading()
|
|
for (let i in data.fields) {
|
|
if (data.fields[i]['type'] == 'radio') {
|
|
that.data.selectBox[i] = {
|
|
title: i,
|
|
value: data.fields[i].default,
|
|
name: '',
|
|
show: false,
|
|
list: data.fields[i].choices
|
|
}
|
|
} else if (data.fields[i]['type'] == 'textarea') {
|
|
that.data.noteBox = {};
|
|
that.changeToWxml(data.fields[i].message)
|
|
} else if (data.fields[i]['type'] == 'checkbox') {
|
|
that.data.selectBox[i] = {
|
|
title: i,
|
|
value: data.fields[i].default || [],
|
|
name: '',
|
|
show: false,
|
|
list: data.fields[i].choices,
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
if (data.data.note && data.data.note.length > 0) {
|
|
WxParse.wxParse('note', 'html', '<div>' + data.data.note + '</div>', that, 0);
|
|
}
|
|
data.data.about = data.data.about.split('\n');
|
|
data.data.notice = data.data.notice.split('\n');
|
|
that.setData({
|
|
isAuthorization: data.code == 401 ? 1 : 0,
|
|
data: data.data,
|
|
fields: data.fields,
|
|
info: data.info,
|
|
studentapartment: data.studentapartment,
|
|
token: data.token,
|
|
submit_uniqid: data.uniqid,
|
|
selectBox: that.data.selectBox,
|
|
title: data.data.title
|
|
})
|
|
}).catch(res => {
|
|
wx.hideLoading()
|
|
})
|
|
|
|
|
|
},
|
|
closePage() {
|
|
var pages = getCurrentPages();
|
|
if (pages.length == 1) {
|
|
wx.reLaunch({
|
|
url: `/pages/irentList/irentList`
|
|
});
|
|
} else {
|
|
wx.navigateBack({
|
|
changed: true
|
|
}); //返回上一页
|
|
}
|
|
},
|
|
saveImg() {
|
|
let that = this;
|
|
let src = that.data.data.image;
|
|
wx.saveImageToPhotosAlbum({
|
|
filePath: src,
|
|
success: function (res) {
|
|
wx.showToast({
|
|
title: '保存成功~',
|
|
})
|
|
},
|
|
complete: function (res) {
|
|
console.log(res)
|
|
}
|
|
})
|
|
},
|
|
downloadImg() {
|
|
var that = this;
|
|
wx.downloadFile({
|
|
url: that.data.data.image, //仅为示例,并非真实的资源
|
|
success: function (res) {
|
|
// 只要服务器有响应数据,就会把响应内容写入文件并进入 success 回调,业务需要自行判断是否下载到了想要的内容
|
|
|
|
if (res.statusCode === 200) {
|
|
that.data.data.image = res.tempFilePath
|
|
that.setData({
|
|
data: that.data.data
|
|
})
|
|
}
|
|
}
|
|
})
|
|
},
|
|
getFormNew() {
|
|
let that = this;
|
|
|
|
var sendData = Object.assign({}, this.data.options, {
|
|
session: wx.getStorageSync('session'),
|
|
uniqid: this.data.uniqid,
|
|
housetype: that.data.housetype
|
|
})
|
|
|
|
miucms.request(app.globalData.config.form.init, sendData).then(data => {
|
|
wx.hideLoading()
|
|
for (let i in data.fields) {
|
|
if (data.fields[i]['type'] == 'radio') {
|
|
that.data.selectBox[i] = {
|
|
title: i,
|
|
value: data.fields[i].default,
|
|
name: '',
|
|
show: false,
|
|
list: data.fields[i].choices
|
|
}
|
|
} else if (data.fields[i]['type'] == 'textarea') {
|
|
that.data.noteBox = {};
|
|
that.changeToWxml(data.fields[i].message)
|
|
} else if (data.fields[i]['type'] == 'checkbox') {
|
|
that.data.selectBox[i] = {
|
|
title: i,
|
|
value: data.fields[i].default || [],
|
|
name: '',
|
|
show: false,
|
|
list: data.fields[i].choices,
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
if (data.data.note && data.data.note.length > 0) {
|
|
WxParse.wxParse('note', 'html', '<div>' + data.data.note + '</div>', that, 0);
|
|
}
|
|
data.data.about = data.data.about.split('\n');
|
|
data.data.notice = data.data.notice.split('\n');
|
|
data.data.post_success = data.data.post_success.split('\n');
|
|
|
|
that.setData({
|
|
isAuthorization: data.code == 401 ? 1 : 0,
|
|
data: data.data,
|
|
fields: data.fields,
|
|
info: data.info,
|
|
// studentapartment: data.studentapartment,
|
|
token: data.token,
|
|
submit_uniqid: data.uniqid,
|
|
selectBox: that.data.selectBox
|
|
})
|
|
that.downloadImg()
|
|
}).catch(res => {
|
|
wx.hideLoading()
|
|
})
|
|
|
|
},
|
|
changeToWxml(message) {
|
|
let that = this;
|
|
let div = '';
|
|
div += '<div>' + message + '</div>';
|
|
// console.log(div)
|
|
// let noteBox = 'noteBox.' + box;
|
|
WxParse.wxParse('noteBox', 'html', '<div>' + div + '</div>', that, 0);
|
|
},
|
|
select_shows: function (e) {
|
|
let box = e.currentTarget.dataset.box;
|
|
// console.log(box)
|
|
this.data.selectBox[box].show = true;
|
|
this.setData({
|
|
selectBox: this.data.selectBox
|
|
})
|
|
if (this.data.types == 'edit' && box == 'style') {
|
|
wx.pageScrollTo({
|
|
scrollTop: 150,
|
|
})
|
|
}
|
|
|
|
},
|
|
select_value: function (e) {
|
|
var that = this;
|
|
let title = e.currentTarget.dataset.title;
|
|
let value = e.currentTarget.dataset.value;
|
|
let name = e.currentTarget.dataset.name;
|
|
this.data.selectBox[title].value = value;
|
|
this.data.selectBox[title].name = name;
|
|
this.data.selectBox[title].show = false;
|
|
this.setData({
|
|
selectBox: this.data.selectBox
|
|
})
|
|
},
|
|
input: function (e) {
|
|
let letter = e.currentTarget.dataset.letter;
|
|
this.data.fields[letter]['default'] = e.detail.value;
|
|
this.setData({
|
|
fields: this.data.fields
|
|
})
|
|
},
|
|
isSubmit: false,
|
|
submit(e) {
|
|
var that = this;
|
|
let formid = e.detail.formId;
|
|
// 防止重复提交
|
|
if (this.isSubmit) {
|
|
return false
|
|
}
|
|
this.isSubmit = true;
|
|
wx.showLoading({
|
|
title: '正在提交...',
|
|
})
|
|
let info = Object.assign({}, this.data.info);
|
|
for (let i in this.data.fields) {
|
|
|
|
if (this.data.fields[i]['type'] == 'text') {
|
|
info[i] = this.data.fields[i].default;
|
|
} else if (this.data.fields[i]['type'] == 'radio') {
|
|
info[i] = this.data.selectBox[i].value;
|
|
} else if (this.data.fields[i]['type'] == 'textarea') {
|
|
info[i] = this.data.fields[i].default;
|
|
}
|
|
}
|
|
var sendData = Object.assign(this.data.options, {
|
|
session: wx.getStorageSync('session'),
|
|
info: info,
|
|
uniqid: that.data.submit_uniqid,
|
|
token: that.data.token,
|
|
formid,
|
|
})
|
|
// console.log(info)
|
|
// return false;
|
|
let url = this.data['from'] == 'list' ? app.globalData.config.form.submit : app.globalData.config.studentapartment.submit;
|
|
wx.request({
|
|
url: url,
|
|
data: sendData,
|
|
method: 'POST', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
|
|
header: app.globalData.header,
|
|
success: function (res) {
|
|
var data = app.return_data(res);
|
|
that.isSubmit = false;
|
|
wx.hideLoading()
|
|
if (data.extraparam) {
|
|
|
|
if (data.extraparam.mode == 'right') {
|
|
// 成功
|
|
if (that.data['from'] == 'list') {
|
|
that.setData({
|
|
'showPage': 'success'
|
|
})
|
|
return false
|
|
}
|
|
wx.showModal({
|
|
title: '提示',
|
|
content: data.message,
|
|
showCancel: false,
|
|
confirmColor: '#a8bed9',
|
|
success(res) {
|
|
if (res.confirm) {
|
|
wx.navigateBack({})
|
|
}
|
|
}
|
|
|
|
})
|
|
|
|
} else {
|
|
wx.showModal({
|
|
title: '提示',
|
|
content: data.message,
|
|
showCancel: false,
|
|
confirmColor: '#a8bed9',
|
|
|
|
})
|
|
}
|
|
}
|
|
|
|
|
|
|
|
},
|
|
fail: function (err) {
|
|
that.isSubmit = false;
|
|
}
|
|
})
|
|
|
|
},
|
|
copy(e) {
|
|
const content = e.currentTarget.dataset.content;
|
|
miucms.copy(content).then((res) => {
|
|
console.log('res', res)
|
|
}).catch(err => {
|
|
console.log(err)
|
|
})
|
|
|
|
},
|
|
getcustomerservice() {
|
|
let that = this;
|
|
wx.request({
|
|
url: 'https://app.gter.net/tenement/apartment/customerservice',
|
|
data: {
|
|
customerservice: this.data.customerservice
|
|
},
|
|
method: 'POST', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
|
|
header: app.globalData.header,
|
|
success: function (res) {
|
|
var data = app.return_data(res);
|
|
wx.hideLoading()
|
|
console.log(data)
|
|
let pagedata = Object.assign({}, data.data.customerservice, {
|
|
title: data.data.info.title
|
|
})
|
|
if (data.data.customerservice.message && data.data.customerservice.message.length > 0) {
|
|
WxParse.wxParse('note', 'html', '<div>' + data.data.customerservice.message + '</div>', that, 0);
|
|
}
|
|
that.setData({
|
|
isAuthorization: data.code == 401 ? 1 : 0,
|
|
data: pagedata,
|
|
|
|
info: data.data.info,
|
|
|
|
title: data.data.info.title
|
|
})
|
|
|
|
|
|
},
|
|
fail: function (err) {
|
|
that.isSubmit = false;
|
|
}
|
|
})
|
|
}
|
|
|
|
}) |