Files
income_payments_applet/pages/addCompany/addCompany.js
T

301 lines
5.8 KiB
JavaScript

// pages/addCompany/addCompany.js
import signUpApi from '../../assets/js/http/signUp'
import {appletName} from "../../assets/js/project.config"
import {userServicesAgreementText,perrsonalProtectionPolicyText} from '../../assets/js/acceptProtocolInfo'
import {
dutyCode,
postcode
} from '../../utils/validate'
Page({
/**
* 页面的初始数据
*/
data: {
// 是否是国际研讨会报名的选择
prepage: '',
flag: false,
appletName:appletName,
content:'',// 用户服务与个人隐私 显示的内容
showModal:false // 控制弹窗显示隐藏
},
// 打开用户服务协议与个人信息的弹窗
openPanel(e){
console.log(e);
let type = e.currentTarget.dataset.type
if(type === '1'){
this.setData({
content:userServicesAgreementText
})
}else{
this.setData({
content:perrsonalProtectionPolicyText
})
}
this.setData({
showModal:true
})
},
/**
* 隐藏模态对话框
*/
hideModal: function () {
const that = this
that.setData({
showModal: false,
content: '',
});
},
// 返回选择单位
backCompanyList() {
wx.navigateTo({
url: '../companyList/companyList',
})
},
// 确定
addCompany(e) {
const formData = e.detail.value
console.log(formData);
// 企业名称
if (formData.companyName === '') {
wx.showToast({
title: '请输入企业名称',
icon: 'none',
duration: 800
})
return
}
// 信用代码
if (formData.dutyCode === '') {
wx.showToast({
title: '请输入信用代码',
icon: 'none',
duration: 800
})
return
}
// 公司地址
if (formData.companyAddress === '') {
wx.showToast({
title: '请输入公司地址',
icon: 'none',
duration: 800
})
return
}
// 银行账号
if (formData.bankAccount === '') {
wx.showToast({
title: '请输入银行账号',
icon: 'none',
duration: 800
})
return
}
// 开户行
if (formData.openingBank === '') {
wx.showToast({
title: '请输入开户行',
icon: 'none',
duration: 800
})
return
}
// 同意授权
if (formData.agree.length === 0) {
wx.showToast({
title: '请先同意授权',
icon: 'none',
duration: 800
})
return
}
// if(this.data.flag){
// wx.showToast({
// title: '信息输入有误',
// icon: 'none',
// duration: 800
// })
// return
// }
const that = this
let pages = getCurrentPages()
let prevPage = pages[pages.length - 3];
signUpApi.addCompanyNoLimit(formData).then(res => {
if (res.success) {
wx.showToast({
title: res.message,
icon: "none",
duration: 800,
});
wx.setStorage({
key:'selectedCompany',
data:res.result
})
if (that.data.prepage === 'guoji') {
wx.navigateTo({
url: '../signUpPageGuoji/signUpPageGuoji',
})
} else if(that.data.prepage === 'register'){
prevPage.setData({
'selectedCompany.companyName':res.result.companyName,
'selectedCompany.companyId':res.result.id,
})
wx.navigateBack({
delta: 2,
})
// wx.navigateTo({
// url: '../register/register',
// })
} else{
wx.navigateTo({
url: '../signUpPage/signUpPage',
})
}
}else{
wx.showToast({
title: res.message,
icon:"none",
duration:800
})
}
}).catch(err => {
console.log(err);
})
},
// 信用代码验证
validateDutyCode(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 (dutyCode(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
})
}
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.setData({
prepage: options.prepage
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})