// pages/newVolunteerActivity/newVolunteerActivity.js var app = getApp(); var util = require('../../utils/util.js'); Page({ /** * 页面的初始数据 */ data: { token: '', startDate: '', endDate: '', serviceName: '', // 名称 serviceContent: '', // 活动内容 address: '', // 活动地址 serviceReward: '', // 服务奖补 linkMan: '', // 联系人 linkTel: '', // 联系人联系方式 count: '', // 志愿者数量 introduce: '', // 活动介绍 voluntaryType: 1, // 类型 tempFilePaths: '', // 宣传图片 photo: '', // 宣传图片 serviceRequirement: '', // 服务要求 }, getToken: function() { var self = this; return new Promise(resolve =>{ wx.getStorage({ key: 'token', success(res) { self.setData({ token: res.data }) return resolve(); } }) }) }, startDateChange: function(e) { console.log('picker发送选择改变,携带值为', e.detail.value) this.setData({ startDate: e.detail.value }) }, endDateChange: function(e) { var self = this; console.log('picker发送选择改变,携带值为', e.detail.value) if(self.data.startDate > e.detail.value) { wx.showToast({ title: '结束时间不能早于开始时间', icon: 'none', duration: 1500 }) return false; } this.setData({ endDate: e.detail.value }) }, dateDafault: function() { // 设置日期选择框为当前日期 var self = this; var TIME = util.formatDate(new Date()); self.setData({ startDate: TIME, endDate: TIME }) }, /** * 选择志愿者或者团队类型 */ changeType: function(e) { if(e.detail.value == 1){ this.setData({ voluntaryType : 1 }) }else{ this.setData({ voluntaryType : 2 }) } }, /** * 上传活动照片 */ uploadPhoto: function () { var self = this wx.chooseImage({ success (res) { const tempFilePaths = res.tempFilePaths app.restAjax.file(app.restAjax.path(app.volunteerUrl + 'app/file/uploadimage', []), tempFilePaths[0], 'image', { headers: { token: self.data.token } }, function(code, data) { if('200' == code) { var data = data.substr(9, data.length); data = data.substr(0, data.length - 2); self.setData({ photo: data }) } }, function(code, data) { app.dialog.msg(data.msg) }, function() { }) } }) }, submitRegister: function () { var self = this; if(!self.data.serviceName) { wx.showToast({ title: '活动名称不能为空', icon: 'none', duration: 1500 }) return false; } if(!self.data.serviceContent) { wx.showToast({ title: '活动内容不能为空', icon: 'none', duration: 1500 }) return false; } if(!self.data.address) { wx.showToast({ title: '活动地址不能为空', icon: 'none', duration: 1500 }) return false; } if(!self.data.linkMan) { wx.showToast({ title: '活动联系人不能为空', icon: 'none', duration: 1500 }) return false; } if(!self.data.address) { wx.showToast({ title: '联系方式不能为空', icon: 'none', duration: 1500 }) return false; } if(!self.data.count) { wx.showToast({ title: '数量不能为空', icon: 'none', duration: 1500 }) return false; } var volunteerServiceVO = { serviceName: self.data.serviceName, serviceContent: self.data.serviceContent, address: self.data.address, serviceReward: self.data.serviceReward, linkMan: self.data.linkMan, linkTel: self.data.linkTel, voluntaryType: self.data.voluntaryType, count: self.data.count, introduce: self.data.introduce, startTime: self.data.startDate, endTime: self.data.endDate, photo: self.data.photo, serviceRequirement: self.data.serviceRequirement }; app.restAjax.post(app.restAjax.path(app.volunteerUrl + 'wxminiapp/volunteerservice/savevolunteerservice', []), volunteerServiceVO, { headers: { 'token': self.data.token } }, function(code, data) { if('200' == code) { app.dialog.msg('活动发布成功!'); wx.navigateTo({ url: '../volunteer/volunteer', }) } }, function(code, data) { app.dialog.msg(data.msg); }, function() { }) }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.dateDafault(); this.getToken(); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })