xz_mini/pages/newVolunteerActivity/newVolunteerActivity.js

252 lines
5.6 KiB
JavaScript
Raw Normal View History

2020-06-23 19:14:44 +08:00
// pages/newVolunteerActivity/newVolunteerActivity.js
2020-06-26 18:51:28 +08:00
var app = getApp();
2020-06-23 19:14:44 +08:00
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();
}
})
})
},
2020-06-26 14:06:35 +08:00
startDateChange: function(e) {
2020-06-23 19:14:44 +08:00
console.log('picker发送选择改变携带值为', e.detail.value)
this.setData({
2020-06-26 14:06:35 +08:00
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
2020-06-23 19:14:44 +08:00
})
},
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
2020-06-26 18:51:28 +08:00
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() {
2020-06-23 19:14:44 +08:00
})
}
})
},
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
};
2020-06-26 18:51:28 +08:00
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('活动发布成功!');
2020-06-23 19:14:44 +08:00
wx.navigateTo({
url: '../volunteer/volunteer',
})
}
2020-06-26 18:51:28 +08:00
}, function(code, data) {
app.dialog.msg(data.msg);
}, function() {
2020-06-23 19:14:44 +08:00
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.dateDafault();
this.getToken();
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})