// pages/textarea/textarea.js Page({ /** * 页面的初始数据 */ data: { maxlength:-1, content:null, name:'questions', title:'', placeholder:'', index:null, }, distanceObj: {}, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { let that = this; let title_box = { subject:'填写标题', introduction:'填写个人情况介绍', message:'填写更多介绍', questions:'向求租者提问', address:'填写地址', aroundSchool:'填写距离' } if (options.name =='introduction'){ this.data.placeholder = '介绍一下房东/合租人/室友的情况。可以写下作息习惯、性格、是否有养宠物等' } else if (options.name =='message'){ this.data.placeholder = '可以填写如需签约至多久,和谁签约,如何交房租,房子是否断隔房、房租以外的费用项支付规则、户型家具、生活配套、地理位置(距离学校多远)等' } if(options.placeholder){ this.data.placeholder = options.placeholder; } wx.setNavigationBarTitle({ title:title_box[options.name], }) this.setData({ name: options.name, title: title_box[options.name], placeholder: this.data.placeholder }) if (options.name =='subject'){ this.setData({ maxlength:80 }) } wx.getStorage({ key: that.data.name, success: function(res) { if (options.name == 'questions' && res.data.length == 0){ that.setData({ content:[''] }) return false } if (options.name =='aroundSchool'){ that.distanceObj = res.data; that.setData({ content: res.data.distance, }) return false } that.setData({ content: res.data }) }, }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, cle:function(){ wx.navigateBack({ delta: 1, // 回退前 delta(默认为1) 页面 }) }, input: function (e) { let that = this; if (this.data.name=='questions'){ var i = e.currentTarget.dataset.i; this.data.content[i] = e.detail.value; this.setData({ content: that.data.content }) }else{ this.setData({ content: e.detail.value }) } }, del_item:function(e){ var i = e.currentTarget.dataset.i; var that = this; that.data.content.splice(i,1); this.setData({ content: that.data.content }) }, add_item:function(){ var that = this; this.data.content.push(''); this.setData({ content: that.data.content }) }, submit:function(){ let that = this; if (this.data.name =='aroundSchool'){ this.distanceObj.distance = this.data.content; wx.setStorage({ key: that.data.name, data: that.distanceObj, success: function (res) { wx.navigateBack({ delta: 1, // 回退前 delta(默认为1) 页面 }) } }) return false } wx.setStorage({ key: that.data.name, data: that.data.content, success:function(res){ console.log(res) wx.navigateBack({ delta: 1, // 回退前 delta(默认为1) 页面 }) } }) } })