xz_gangba/pages/newVolunteerActivity/newVolunteerActivity.js
2020-06-23 19:14:44 +08:00

246 lines
5.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// pages/newVolunteerActivity/newVolunteerActivity.js
var util = require('../../utils/util.js');
Page({
/**
* 页面的初始数据
*/
data: {
baseUrl: 'http://192.168.0.111:8888/volunteer/',
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();
}
})
})
},
bindDateChange: function(e) {
console.log('picker发送选择改变携带值为', e.detail.value)
this.setData({
date: 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
wx.uploadFile({
url: self.data.baseUrl + 'app/file/uploadimage',
filePath: tempFilePaths[0],
name: 'image',
header: {
'token': self.data.token
},
formData: {
'image': tempFilePaths[0]
},
success (res){
var data = res.data.substr(9, res.data.length);
data = data.substr(0, data.length - 2);
self.setData({
photo: data
})
},
fail: function(res) {
console.log(res)
}
})
}
})
},
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;
}
console.log(self.data.startDate)
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
};
wx.request({
url: self.data.baseUrl + 'wxminiapp/volunteerservice/savevolunteerservice',
method: 'POST',
header: {
'token': self.data.token
},
data: volunteerServiceVO,
success(res) {
if(res.statusCode == 200) {
wx.showToast({
title: '活动发布成功!',
icon: 'none',
duration: 1500
})
wx.navigateTo({
url: '../volunteer/volunteer',
})
}else {
console.log('登陆失败!' + res.errMsg);
}
}
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.dateDafault();
this.getToken();
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})