123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439 |
- const app = getApp();
- const api = app.api;
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- isChinesePeople: true,
- statusOptions: [
- {id: '0', value: '藏家 Collector'},
- {id: '1', value: '艺术行业 Art Professional'},
- {id: '2', value: '院校师生 Academic'},
- {id: '3', value: '媒体 Media'},
- {id: '4', value: '合作方 Partner'},
- {id: '5', value: '其他 Other '}
- ],
- idTypeOptions: [
- {id: '0', value: '身份证 ID Card'},
- {id: '1', value: '护照 Passport'},
- {id: '2', value: '回乡证 Home Return Certificate'},
- {id: '3', value: '台胞证 MTP'}
- ],
- countryOptions: [
- {id: '0', value: '中国 China'},
- {id: '1', value: '外籍 Foreigners'}
- ],
- genderOptions: [
- {id: '0', value: '男 Male'},
- {id: '1', value: '女 Female'},
- {id: '2', value: '其他 Other'}
- ],
- isSign: false, // 已核验
- navigatePageCode: '', // 请求来源页编号
- dataForm: {
- id: '',
- status: '0',
- statusOther: '',
- realName: '',
- idType: '0',
- idNumber: '',
- country: '0',
- liveCity: ['北京市', '北京市', '东城区'],
- liveCityNotChina: '',
- gender: '0',
- emailAddress: '',
- company: '',
- position: ''
- }
- },
- /**
- * 选择身份
- * @param {*} event
- */
- changeStatusOptions: function (event) {
- const self = this;
- const value = parseInt(event.detail.value);
- self.setData({
- ['dataForm.status']: value
- });
- if (self.data.dataForm.statusOther === 5 && value !== 5) {
- self.setData({
- ['dataForm.statusOther']: ''
- });
- }
- },
- /**
- * 选择证件类型
- * @param {*} event
- */
- changeIdTypeOptions: function (event) {
- const self = this;
- self.setData({
- ['dataForm.idType']: event.detail.value
- });
- },
- /**
- * 选择国家
- * @param {*} event
- */
- changeCountryOptions: function (event) {
- const self = this;
- const value = parseInt(event.detail.value);
- const isChinesePeople = value === 1 ? false : true;
- // 外籍切换至中国
- if (self.data.dataForm.country === 1 && value === 0) {
- self.setData({
- ['dataForm.liveCity']: ['北京市', '北京市', '东城区'],
- ['dataForm.liveCityNotChina']: ''
- });
- }
- // 中国切换至外籍
- if (self.data.dataForm.country === 0 && value === 1) {
- self.setData({
- ['dataForm.liveCity']: [],
- ['dataForm.liveCityNotChina']: ''
- });
- }
- self.setData({
- ['dataForm.country']: value,
- ['isChinesePeople']: isChinesePeople
- });
- },
- /**
- * 选择居住城市
- * @param {*} event
- */
- changeLiveCityOptions: function (event) {
- const self = this;
- self.setData({
- ['dataForm.liveCity']: event.detail.value
- });
- },
- /**
- * 选择性别
- * @param {*} event
- */
- changeGenderOptions: function (event) {
- const self = this;
- self.setData({
- ['dataForm.gender']: event.detail.value
- });
- },
- /**
- * 输入框值变化
- * @param {*} event
- */
- changeInput: function (event) {
- const self = this;
- const inputType = event.currentTarget.dataset.inputtype;
- const value = event.detail.value;
- // 身份
- if (inputType === 'status') {
- self.setData({
- ['dataForm.statusOther']: value
- });
- }
- // 真实姓名
- if (inputType === 'realName') {
- self.setData({
- ['dataForm.realName']: value
- });
- }
- // 证件号
- if (inputType === 'idNumber') {
- self.setData({
- ['dataForm.idNumber']: value
- });
- }
- // 居住城市
- if (inputType === 'liveCity') {
- self.setData({
- ['dataForm.liveCityNotChina']: value
- });
- }
- // 邮箱
- if (inputType === 'emailAddress') {
- self.setData({
- ['dataForm.emailAddress']: value
- });
- }
- // 公司
- if (inputType === 'company') {
- self.setData({
- ['dataForm.company']: value
- });
- }
- // 职位
- if (inputType === 'position') {
- self.setData({
- ['dataForm.position']: value
- });
- }
- },
- /**
- * 提交表单
- */
- submitDataForm: function () {
- const self = this;
- if (self.valiator()) {
- const dataForm = {
- id: self.data.dataForm.id,
- roles: self.data.dataForm.status,
- roleOther: self.data.dataForm.statusOther,
- name: self.data.dataForm.realName,
- types: self.data.dataForm.idType,
- nums: self.data.dataForm.idNumber,
- country: self.data.dataForm.country,
- states: self.data.dataForm.liveCityNotChina,
- province: parseInt(self.data.dataForm.country) === 0 ? self.data.dataForm.liveCity[0] : '',
- city: parseInt(self.data.dataForm.country) === 0 ? self.data.dataForm.liveCity[1] : '',
- district: parseInt(self.data.dataForm.country) === 0 ? self.data.dataForm.liveCity[2] : '',
- gender: self.data.dataForm.gender,
- mail: self.data.dataForm.emailAddress,
- company: self.data.dataForm.company,
- position: self.data.dataForm.position
- }
- app.post(dataForm.id === '' ? api.InvitationSave : api.InvitationUpdate, dataForm).then(response => {
- if (response.success) {
- // 登记
- if (dataForm.id === '') {
- wx.showToast({
- title: '登记成功',
- mask: true,
- complete: function () {
- setTimeout(() => {
- wx.redirectTo({
- url: '../navigation/index',
- })
- }, 1500)
- }
- })
- }
- // 修改
- if (dataForm.id !== '') {
- wx.showToast({
- title: '修改成功',
- mask: true,
- complete: function () {
- setTimeout(() => {
- wx.navigateBack({
- delta: 0,
- })
- }, 1500)
- }
- })
- }
- }
- }).catch(() => {
- wx.showToast({
- title: '系统繁忙,请稍后再试',
- icon: 'none',
- complete: function () {
- setTimeout(self.getData, 1500)
- }
- })
- })
- }
- },
- /**
- * 查询已登记信息
- */
- getData() {
- const self = this;
- app.post(api.InvitationGet, {}).then(response => {
- if (response.success) {
- self.setData({
- ['dataForm.id']: response.data.id,
- ['dataForm.status']: response.data.roles,
- ['dataForm.statusOther']: response.data.roleOther,
- ['dataForm.realName']: response.data.name,
- ['dataForm.idType']: response.data.types,
- ['dataForm.idNumber']: response.data.nums,
- ['dataForm.country']: response.data.country,
- ['dataForm.liveCity']: response.data.country === 0 ? [response.data.province, response.data.city, response.data.district] : [],
- ['dataForm.liveCityNotChina']: response.data.country === 1 ? response.data.states : '',
- ['dataForm.gender']: response.data.gender + '',
- ['dataForm.emailAddress']: response.data.mail,
- ['dataForm.company']: response.data.company,
- ['dataForm.position']: response.data.position
- })
- // 已核验校验
- if (response.data.signTime !== null && response.data.signTime !== '') {
- self.setData({
- isSign: true
- })
- }
- }
- }).catch(() => {
- // 若请求来自中转页,且没有查询到登记信息,则关闭此页面
- const navigatePageCode = self.data.navigatePageCode
- if (navigatePageCode === 'navigation') {
- wx.showModal({
- content: '没有查询到您的登记信息',
- cancelText: '返回',
- confirmText: '去登记',
- success: function (response) {
- if (response.confirm) {
- wx.redirectTo({
- url: '../index/index',
- })
- } else {
- wx.navigateBack({
- delta: 0,
- })
- }
- }
- })
- }
- })
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- const self = this
- /**
- * 请求来源
- * protocol 不处理
- * navigation 如果没有查询到登记信息则关闭此页面
- */
- const navigatePageCode = options.pageCode
- self.setData({
- navigatePageCode: navigatePageCode
- })
- // 查询已登记信息
- self.getData()
- // 修改页面标题
- wx.setNavigationBarTitle({
- title: '个人信息',
- })
- },
- /**
- * 表单校验
- */
- valiator: function () {
- const self = this;
- if (self.data.dataForm.status === '') {
- wx.showToast({
- title: '请选择身份/Status',
- icon: 'none',
- mask: true
- });
- return false;
- } else {
- if (parseInt(self.data.dataForm.status) === 5 && self.data.dataForm.statusOther === '') {
- wx.showToast({
- title: '请填写身份/Status',
- icon: 'none',
- mask: true
- });
- return false;
- }
- }
- if (self.data.dataForm.realName === '') {
- wx.showToast({
- title: '请填写真实姓名/Real Name',
- icon: 'none',
- mask: true
- });
- return false;
- }
- if (self.data.dataForm.idType === '') {
- wx.showToast({
- title: '请选择证件类型/ID Type',
- icon: 'none',
- mask: true
- });
- return false;
- }
- if (self.data.dataForm.idNumber === '') {
- wx.showToast({
- title: '请填写证件号/ID Number',
- icon: 'none',
- mask: true
- });
- return false;
- }
- if (self.data.dataForm.country === '') {
- wx.showToast({
- title: '请选择国家/Country',
- icon: 'none',
- mask: true
- });
- return false;
- } else {
- if (parseInt(self.data.dataForm.country) === 0 && self.data.dataForm.liveCity.length === 0) {
- wx.showToast({
- title: '请选择居住城市/Live City',
- icon: 'none',
- mask: true
- });
- return false;
- }
- if (parseInt(self.data.dataForm.country) === 1 && self.data.dataForm.liveCityNotChina === '') {
- wx.showToast({
- title: '请填写居住城市/Live City',
- icon: 'none',
- mask: true
- });
- return false;
- }
- }
- if (self.data.dataForm.gender === '') {
- wx.showToast({
- title: '请选择性别/Gender',
- icon: 'none',
- mask: true
- });
- return false;
- }
- if(self.data.dataForm.emailAddress === '') {
- // wx.showToast({
- // title: '请填写邮箱/Email Address',
- // icon: 'none',
- // mask: true
- // });
- // return false;
- } else {
- const regex = /^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/;
- if(!regex.test(self.data.dataForm.emailAddress)) {
- wx.showToast({
- title: '邮箱/Email Address不合法,请重新填写',
- icon: 'none'
- });
- return false;
- }
- }
- if (self.data.dataForm.company === '') {
- wx.showToast({
- title: '请填写公司/Company',
- icon: 'none',
- mask: true
- });
- return false;
- }
- if (self.data.dataForm.position === '') {
- wx.showToast({
- title: '请填写职位/Position',
- icon: 'none',
- mask: true
- });
- return false;
- }
- return true;
- }
- })
|