// pages/fzpxInfo/fzpxInfo.js
|
var app = getApp();
|
var Validator = require("../../utils/validate.tools.js");
|
const verify = Validator.Validator;
|
|
Page({
|
|
/**
|
* 页面的初始数据
|
*/
|
data: {
|
user: app.globalData.imgUrl + '/image/user.svg',
|
loading: false,
|
peopleInfo: {},
|
signStatus: '',
|
id: "",
|
topattList: [],
|
bottomattList: [],
|
statequeId: ''
|
},
|
|
/**
|
* 生命周期函数--监听页面加载
|
*/
|
onLoad: function(options) {
|
var that = this;
|
that.setData({
|
id: options.id,
|
signStatus: options.signStatus || '',
|
flag: options.flag || '',
|
loading: true
|
});
|
wx.showLoading({
|
title: '加载中',
|
})
|
wx.request({
|
url: app.globalData.url + '/api/activity/find?id=' + options.id,
|
success: function(res) {
|
console.log(res);
|
that.setData({
|
loading: false
|
});
|
wx.hideLoading();
|
if (res.data.code == 0) {
|
res.data.data.startTime = app.formatDate(res.data.data.startTime)
|
if (res.data.data.activityStatus == 3) {
|
if (res.data.data.queId) {
|
that.setData({
|
statequeId: res.data.data.queId
|
})
|
}
|
} else {
|
that.setData({
|
statequeId: ''
|
})
|
}
|
that.setData({
|
activity: res.data.data,
|
bottomattList: res.data.data.attList.filter((item) => (item.associateType == 1020)),
|
topattList: res.data.data.attList.filter((item) => (item.associateType == 1000))
|
})
|
console.log('传过来', options.flag)
|
console.log('传过来', options.signStatus)
|
// 处理报名状态
|
if (options.signStatus) {
|
that.setData({
|
signStatus: options.signStatus
|
})
|
} else {
|
if (options.flag == 'true') {
|
//可报名
|
console.log('可报名')
|
if (res.data.data.activityPersonNum < res.data.data.activityPersonQuota) {
|
if (res.data.data.activityStatus == 1) {
|
that.setData({
|
canApply: true
|
})
|
}
|
if (res.data.data.activityStatus == 2) {
|
that.setData({
|
canApply: false,
|
statusWord: '活动正在进行'
|
})
|
}
|
if (res.data.data.activityStatus == 3) {
|
that.setData({
|
canApply: false,
|
statusWord: '活动已结束'
|
})
|
}
|
} else {
|
that.setData({
|
canApply: false,
|
statusWord: '报名人数已满'
|
})
|
}
|
|
} else {
|
//不可报名
|
console.log('不可报名')
|
that.setData({
|
canApply: false,
|
statusWord: '您已报名'
|
})
|
}
|
}
|
|
}
|
}
|
})
|
},
|
|
// 跳转
|
linkFunction: function() {
|
wx.showToast({
|
title: '抱歉,报名人数已满',
|
icon: 'none',
|
duration: 2000
|
})
|
},
|
|
// 呼叫组织方
|
makePhoneCall: function(e) {
|
var phone = e.currentTarget.dataset['phone'];
|
wx.makePhoneCall({
|
phoneNumber: phone
|
})
|
},
|
|
//跳转问卷调查
|
businessSchedule: function(e) {
|
var id = e.currentTarget.dataset['id'];
|
wx.navigateTo({
|
url: '/pages/createSub/createSub?id=' + id,
|
})
|
},
|
|
inputChange: function(e) {
|
var name = e.currentTarget.dataset.name;
|
this.setData({
|
peopleInfo: {
|
...this.data.peopleInfo,
|
[name]: e.detail.value
|
}
|
})
|
},
|
|
// 签到
|
sign: function() {
|
var id = this.data.id;
|
var userinfo = wx.getStorageSync("user");
|
var userId = userinfo.id;
|
// 只允许从相机扫码
|
wx.scanCode({
|
onlyFromCamera: true,
|
success(res) {
|
console.log(res)
|
wx.showLoading({
|
title: '识别中',
|
})
|
wx.request({
|
url: app.globalData.url + '/api/activity/sign?id=' + id + '&code=' + res.result + '&userId=' + userId,
|
method: 'GET',
|
header: {
|
"Content-Type": "application/json"
|
},
|
success: function(res) {
|
wx.hideLoading();
|
if (res.data.code == 0) {
|
wx.showToast({
|
title: '签到成功!',
|
icon: 'success',
|
duration: 2000
|
})
|
} else {
|
wx.showToast({
|
title: '签到失败,请稍后重试!',
|
icon: 'none'
|
})
|
}
|
}
|
})
|
}
|
})
|
},
|
|
// 返回
|
goBack: function() {
|
wx.navigateBack({
|
delta: 1
|
});
|
},
|
|
// 提交报名
|
submit: function() {
|
var peopleInfo = this.data.peopleInfo;
|
var userinfo = wx.getStorageSync("user");
|
var personId = userinfo.id;
|
|
peopleInfo.personId = personId;
|
peopleInfo.activityInfoId = this.data.id;
|
peopleInfo.isHit = 0;
|
if (!peopleInfo.proposerName) {
|
return wx.showToast({
|
title: '请填写姓名',
|
icon: 'none'
|
})
|
}
|
if (!peopleInfo.proposerPhone) {
|
return wx.showToast({
|
title: '请填写联系电话',
|
icon: 'none'
|
})
|
} else {
|
if (!verify.phone(peopleInfo.proposerPhone)) {
|
return wx.showToast({
|
title: '联系电话格式不正确',
|
icon: 'none'
|
})
|
}
|
}
|
var that = this;
|
wx.showLoading({
|
title: '报名中',
|
})
|
wx.request({
|
url: app.globalData.url + '/api/activity/activityApply',
|
data: peopleInfo,
|
method: 'POST',
|
header: {
|
"Content-Type": "application/json"
|
},
|
success: function(res) {
|
wx.hideLoading();
|
if (res.data.code == 0) {
|
wx.reLaunch({
|
url: '../index/index',
|
}, wx.showToast({
|
title: '报名成功!',
|
icon: 'success',
|
duration: 2000
|
}))
|
} else {
|
wx.showToast({
|
title: '报名失败,请稍后重试!',
|
icon: 'none'
|
})
|
}
|
}
|
})
|
}
|
})
|