Files
income_payments_applet/pages/signUpPage/signUpPage.js
T

633 lines
14 KiB
JavaScript

// pages/signUpPage/signUpPage.js
import signUpApi from '../../assets/js/http/signUp'
import MeetingApi from '../../assets/js/http/meetingApi'
import {
phoneReg,
postcode,
compareDate
} from '../../utils/validate'
Page({
/**
* 页面的初始数据
*/
data: {
// 参会身份数组
identifyList: [{
value: '2',
name: '参会人'
},
{
value: '1',
name: '嘉宾'
},
{
value: '3',
name: '内部企业'
},
],
// 缴费方式
paymentMethodList: [{
value: '1',
name: '汇款'
},
{
value: '2',
name: '现场缴费(仅支持扫码支付)'
},
{
value: '3',
name: '打包'
},
],
// 是否需要发票
needInvoiceList: [{
value: '0',
name: '不需要'
},
{
value: '1',
name: '增值税普通发票'
},
{
value: '2',
name: '增值税专用发票'
},
],
// 是否住酒店
needCheckInHotel: [{
value: '1',
name: '是'
},
{
value: '0',
name: '否'
},
],
// 选中的参会身份 默认参会人
selectedIdentity: '2',
// 是否选择发票的选中的索引 默认需要
index: -1,
paymentMethod: '1',
// 抵达时间
arrivalTime: '请选择抵达时间',
// 离开时间
departureTime: '请选择离开时间',
// 选中的参会单位
selectedCompany: {},
// 选中的联系人
selectedPerson: {},
// 选中的邮寄联系人
selectedPostPerson: {},
// 选中的会议
selectedMeeting: {},
// 会议id
meetingId: '',
// 是否正确填写信息
flag: false,
// 是否是首页消息进来的
indexMsgBool: false,
// 首页消息
indexMsg: '',
// 扫码报名的 需要调用无限制接口
nolimitBool: false,
// 会议费用
meetingCost: ''
},
// 是否需要发票的选择
needInvoiceChange(e) {
this.setData({
index: e.detail.value
})
},
// 抵达时间选择
bindDateChangeArriveTime(e) {
this.setData({
arrivalTime: e.detail.value
})
},
// 离开时间选择
bindDateChangeLeaveTime(e) {
this.setData({
departureTime: e.detail.value
})
},
// 选择参会身份
changeIdentity(e) {
const that = this
this.setData({
selectedIdentity: e.detail.value
})
console.log(e.detail.value);
// 参会身份选择嘉宾和内部企业 会议费用为 0
if (e.detail.value === '2') {
// 标协会议需要判断选中的企业是否是标协成员
if (this.data.selectedMeeting.meetingType === '2') {
signUpApi.validateStandard({
companyName: that.data.selectedCompany.companyName
}).then(result => {
if (result.result) {
that.setData({
meetingCost: that.data.selectedMeeting.meetingCostsVip
})
} else {
that.setData({
meetingCost: that.data.selectedMeeting.meetingCosts
})
}
})
} else {
this.setData({
meetingCost: that.data.selectedMeeting.meetingCosts
})
}
} else {
this.setData({
meetingCost: '0.00'
})
}
},
// 缴费方式的选择
paymentMethodRadioChange(e) {
this.setData({
paymentMethod: e.detail.value
})
},
// 确定
formSubmit(e) {
const formData = Object.assign({}, e.detail.value)
// 会议id
if (this.data.selectedMeeting.id) {
formData.meetingId = this.data.selectedMeeting.id
} else {
wx.getStorage({
key: "meetingId",
success(res) {
formData.meetingId = res.data
}
})
}
// 参会人id
formData.companyContactId = this.data.selectedPerson.id
// 邮寄联系人id
formData.postContactId = this.data.selectedPostPerson.id
// 参会企业id
formData.companyId = this.data.selectedCompany.id
// 会议类型
formData.meetingType = this.data.selectedMeeting.meetingType
console.log(formData);
if (this.data.flag) {
wx.showToast({
title: '信息输入有误',
icon: 'error',
duration: 2000
})
return
}
// 参会身份验证
if (formData.identity === '') {
wx.showToast({
title: '请选择参会身份',
icon: 'none',
duration: 2000
})
return
}
// 手机号验证
if (formData.phone === '' || formData.phone === undefined) {
wx.showToast({
title: '请输入手机号',
icon: 'none',
duration: 2000
})
return
}
// 缴费方式
if (formData.payMode === '') {
wx.showToast({
title: '请选择缴费方式',
icon: 'none',
duration: 2000
})
return
}
// 是否需要发票
if (formData.needInvoice === -1) {
wx.showToast({
title: '请选择是否需要发票',
icon: 'none',
duration: 2000
})
return
}
// 邮寄联系人
if (this.data.selectedPostPerson.id && formData.postContactId === undefined) {
wx.showToast({
title: '请选择邮寄联系人',
icon: 'none',
duration: 2000
})
return
}
// 邮寄地址
if (formData.postContactAddress === '') {
wx.showToast({
title: '请输入邮寄地址',
icon: 'none',
duration: 2000
})
return
}
// 邮编
if (formData.postCode === '') {
wx.showToast({
title: '请输入邮编',
icon: 'none',
duration: 2000
})
return
}
// 校验时间
if (formData.arrivalTime && formData.departureTime) {
let flag = compareDate(formData.arrivalTime, formData.departureTime)
if (flag) {
// 抵达时间大于离开时间
wx.showToast({
title: '抵达时间不能大于离开时间',
icon: 'none',
duration: 2000
})
return
}
}
wx.showLoading({
title: '加载中',
mask: true
})
signUpApi.signUpMeeting(formData).then(res => {
if (res.success) {
wx.hideLoading({
})
wx.showToast({
title: '报名成功',
icon: 'loading',
duration: 1500
})
// 成功 清除缓存 跳转报名成功页面
wx.removeStorage({
key: 'selectedCompany',
})
wx.removeStorage({
key: 'meetingId',
})
wx.removeStorage({
key: 'currentMeetingInfo',
success() {
// 跳转报名成功页面
if (formData.payMode) {
wx.navigateTo({
url: `../signUpSuccess/signUpSuccess?payMode=${formData.payMode}`,
})
} else {
wx.navigateTo({
url: `../signUpSuccess/signUpSuccess`,
})
}
}
})
} else {
wx.showToast({
title: res.message,
icon: 'none',
duration: 2000
})
}
}).catch(e => {
wx.showToast({
title: '操作失败',
icon: 'error',
duration: 2000
})
})
},
// 选择参会单位
selectCompany() {
let flag
wx.getStorage({
key: 'companyDisabled',
success(res) {
if (res.data) {
flag = res.data
}
}
})
if (flag) {
return
}
console.log('选择参会单位', this.data.nolimitBool);
if (this.data.nolimitBool) {
wx.navigateTo({
url: `../companyList/companyList?nolimit=nolimt`,
})
} else {
wx.navigateTo({
url: `../companyList/companyList`,
})
}
},
// 选择参会人
selectPerson(e) {
const that = this
if (!!this.data.selectedCompany.id) {
wx.navigateTo({
url: `../personList/personList?companyId=${this.data.selectedCompany.id}&selectType=${e.currentTarget.dataset.selecttype}&nolimit=${that.data.nolimitBool}`,
})
} else {
wx.showToast({
title: '请先选择参会单位',
icon: "none",
duration: 800,
});
}
},
// 根据会议id查询会议信息
queryMeetingInfo(id) {
MeetingApi.meetingDetail({
id: id
}).then(res => {
console.log(res);
if (res.success) {
this.setData({
selectedMeeting: res.result,
meetingCost: res.result.meetingCosts
})
// 存储会议信息
wx.setStorage({
key: 'currentMeetingInfo',
data: res.result
})
}
}).catch(() => {
wx.showToast({
title: '加载失败',
icon: 'none',
duration: 1000
})
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
if (options.type) {
this.setData({
indexMsg: options.type,
})
}
if (options.nolimit) {
this.setData({
nolimitBool: true
})
}
// this.queryMeetingInfo('1455359606691979265')
if (options.meetingId) {
console.log(options.meetingId, 'options.meetingId');
this.queryMeetingInfo(options.meetingId)
this.setData({
meetingId: options.meetingId
})
wx.setStorage({
key: 'meetingId',
data: options.meetingId
})
}
const that = this
// 是否是从首页消息进来的报名
if (options.type === 'indexMsg') {
this.setData({
indexMsgBool: true
})
// 默认填写个人信息
// 从缓存中拿个人信息
wx.getStorage({
key: 'userInfo',
success(res) {
console.log(res);
that.setData({
'selectedCompany.companyName': res.data.companyName,
'selectedPerson.name': res.data.name,
'selectedPerson.id': res.data.id,
'selectedCompany.id': res.data.companyId,
phone: res.data.phone,
'selectedPostPerson.id': res.data.id,
'selectedPostPerson.name': res.data.name,
'selectedPostPerson.contactAddress': res.data.contactAddress,
'selectedPostPerson.postalCode': res.data.postalCode,
})
}
})
}
},
// 手机号验证
validatePhone(e) {
console.log(e);
let value = e.detail.value
let {
message,
errmsg
} = e.currentTarget.dataset
if (value === '' || value === undefined) {
wx.showToast({
title: message,
icon: 'none',
duration: 800
})
this.setData({
flag: true
})
return
} else if (phoneReg(value)) {
this.setData({
flag: false
})
} else {
wx.showToast({
title: errmsg,
icon: 'none',
duration: 800
})
this.setData({
flag: true
})
}
},
// 邮编验证
validatePostCode(e) {
let value = e.detail.value
let {
message,
errmsg
} = e.currentTarget.dataset
if (value === '' || value === undefined) {
wx.showToast({
title: message,
icon: 'none',
duration: 800
})
this.setData({
flag: true
})
return
} else if (postcode(value)) {
this.setData({
flag: false
})
} else {
wx.showToast({
title: errmsg,
icon: 'none',
duration: 800
})
this.setData({
flag: true
})
}
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
console.log(this.data.selectedMeeting, 'this.selectedMeeting');
const that = this
// 是否是从首页消息进来的报名
if (this.data.type === 'indexMsg') {
// 默认填写个人信息
// 从缓存中拿个人信息
wx.getStorage({
key: 'userInfo',
success(res) {
console.log(res);
that.setData({
'selectedCompany.companyName': res.data.companyName,
'selectedPerson.name': res.data.name,
'selectedCompany.id': res.data.companyId,
phone: res.data.phone,
})
}
})
}
// 从缓存中拿选中的企业
wx.getStorage({
key: 'selectedCompany',
success(res) {
that.setData({
selectedCompany: JSON.parse(res.data)
})
}
})
// 从缓存中拿选中的联系人
wx.getStorage({
key: 'selectedPerson',
success(res) {
that.setData({
selectedPerson: res.data
})
}
})
// 从缓存中拿选中的邮寄联系人
wx.getStorage({
key: 'selectedPostPerson',
success(res) {
that.setData({
selectedPostPerson: res.data
})
}
})
// 从缓存中拿选中的会议的信息
wx.getStorage({
key: 'currentMeetingInfo',
success(res) {
that.setData({
selectedMeeting: res.data
})
// 标协会议需要判断单位是否是会员单位
if (that.data.selectedCompany.companyName && res.data.meetingType + '' === '2') {
signUpApi.validateStandard({
companyName: that.data.selectedCompany.companyName
}).then(result => {
if (result.result) {
that.setData({
meetingCost: res.data.meetingCostsVip
})
} else {
that.setData({
meetingCost: res.data.meetingCosts
})
}
})
}
}
})
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})