325 lines
7.4 KiB
JavaScript
325 lines
7.4 KiB
JavaScript
// pages/irentPark/irentPark.js
|
|
var WxParse = require('../../wxParse/wxParse.js');
|
|
var app = getApp()
|
|
var miucms = require('../../utils/miucms.js');
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
showPage:'guide',
|
|
guide:{
|
|
button:'',
|
|
image:'',
|
|
title:'',
|
|
|
|
},
|
|
uniqid:'',
|
|
token:'',
|
|
note: null,
|
|
title:'学生公寓',
|
|
data:{},
|
|
fields:{},
|
|
info:{},
|
|
selectBox:{},
|
|
noteBox:{},
|
|
qrcode:"",
|
|
needing:{
|
|
date:"",
|
|
datetype:"",
|
|
day:'',
|
|
message:[],
|
|
more:"",
|
|
step1:'',
|
|
step2:"",
|
|
tips:'',
|
|
title:"",
|
|
url:"",
|
|
way:"",
|
|
wechat:'',
|
|
},
|
|
isAuthorization:0
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad: function (options) {
|
|
|
|
this.setData({
|
|
|
|
options: options || {}
|
|
})
|
|
this.get_config()
|
|
},
|
|
// 如果用户已经同意授权。则开始获取数据
|
|
islogin() {
|
|
wx.showLoading({
|
|
title: '加载中',
|
|
})
|
|
this.get_config()
|
|
},
|
|
get_config() {
|
|
var that = this;
|
|
if (app.globalData.config.iRent) {
|
|
this.get_content();
|
|
} else {
|
|
setTimeout(function () {
|
|
that.get_config()
|
|
}, 200)
|
|
}
|
|
},
|
|
/**
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
*/
|
|
onReady: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
onShow: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面隐藏
|
|
*/
|
|
onHide: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面卸载
|
|
*/
|
|
onUnload: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
*/
|
|
onPullDownRefresh: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面上拉触底事件的处理函数
|
|
*/
|
|
onReachBottom: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 用户点击右上角分享
|
|
*/
|
|
onShareAppMessage: function () {
|
|
|
|
},
|
|
onShareTimeline() {
|
|
|
|
},
|
|
get_content(){
|
|
let that = this;
|
|
var sendData = Object.assign({}, this.data.options, {
|
|
session: wx.getStorageSync('session'),
|
|
})
|
|
wx.request({
|
|
url: app.globalData.config.iRent.details,
|
|
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);
|
|
wx.hideLoading()
|
|
that.setData({
|
|
isAuthorization:data.code==401 ? 1 :0,
|
|
guide: {
|
|
button: data.data.button,
|
|
image: data.data.image,
|
|
title: data.data.title,
|
|
},
|
|
uniqid:data.data.uniqid,
|
|
needing:data.needing
|
|
})
|
|
if (data.data.note && data.data.note.length > 0) {
|
|
WxParse.wxParse('note', 'html', '<div>' + data.data.note + '</div>', that, 0);
|
|
}
|
|
}
|
|
})
|
|
},
|
|
previewImg(){
|
|
let url = this.data.showPage == 'guide' ? this.data.guide.image : this.data.needing.qrcode;
|
|
wx.previewImage({
|
|
current: url, // 当前显示图片的http链接
|
|
urls: [url] // 需要预览的图片http链接列表
|
|
})
|
|
},
|
|
getForm(){
|
|
let that = this;
|
|
this.setData({
|
|
showPage:'success'
|
|
})
|
|
wx.pageScrollTo({
|
|
scrollTop: 0,
|
|
})
|
|
return false;
|
|
var sendData = Object.assign({}, this.data.options, {
|
|
session: wx.getStorageSync('session'),
|
|
uniqid:this.data.uniqid
|
|
})
|
|
wx.request({
|
|
url: app.globalData.config.iRent.form,
|
|
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);
|
|
for(let i in data.fields){
|
|
if(data.fields[i]['type'] =='radio'){
|
|
that.data.selectBox[i] = {
|
|
title: i,
|
|
value: data.fields[i].defalt,
|
|
name: '',
|
|
show: false,
|
|
list: data.fields[i].choices
|
|
}
|
|
} else if (data.fields[i]['type'] == 'textarea'){
|
|
that.data.noteBox = {};
|
|
that.changeToWxml(data.fields[i].message)
|
|
}
|
|
|
|
}
|
|
data.data.about = data.data.about.split('\n');
|
|
data.data.notice = data.data.notice.split('\n');
|
|
that.setData({
|
|
uniqid:data.uniqid,
|
|
token:data.token,
|
|
data:data.data,
|
|
fields:data.fields,
|
|
info:data.info,
|
|
selectBox: that.data.selectBox
|
|
})
|
|
}
|
|
})
|
|
|
|
},
|
|
changeToWxml(message){
|
|
let that = this;
|
|
let div = '';
|
|
div += '<div>' + message + '</div>';
|
|
// let noteBox = 'noteBox.' + box;
|
|
WxParse.wxParse('noteBox', 'html', '<div>' + div + '</div>', that, 0);
|
|
},
|
|
select_shows: function (e) {
|
|
let box = e.currentTarget.dataset.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) {
|
|
console.log(e)
|
|
let letter = e.currentTarget.dataset.letter;
|
|
this.data.fields[letter].defalt = 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].defalt;
|
|
} 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].defalt;
|
|
}
|
|
}
|
|
var sendData = Object.assign( this.data.options, {
|
|
session: wx.getStorageSync('session'),
|
|
info:info,
|
|
uniqid:that.data.uniqid,
|
|
token:that.data.token
|
|
})
|
|
wx.request({
|
|
url: app.globalData.config.iRent.submit,
|
|
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'){
|
|
// 成功
|
|
that.setData({
|
|
showPage: 'success',
|
|
qrcode: data.data.qrcode,
|
|
needing: data.data.needing
|
|
})
|
|
wx.pageScrollTo({
|
|
scrollTop: 0,
|
|
})
|
|
|
|
}else{
|
|
wx.showModal({
|
|
title: '提示',
|
|
content: data.message,
|
|
})
|
|
}
|
|
}
|
|
|
|
|
|
|
|
},
|
|
fail:function(err){
|
|
that.isSubmit = false;
|
|
}
|
|
})
|
|
|
|
},
|
|
copy(e){
|
|
const content = e.currentTarget.dataset.content;
|
|
miucms.copy(content).then((res)=>{
|
|
}).catch(err=>{
|
|
})
|
|
|
|
},
|
|
|
|
}) |