123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470 |
- import Api from "../../model/api";
- import User from "../../model/user";
- import {getDataSet, getEventParam, showLoading, throttle, toast} from "../../utils/utils";
- import Config from "../../model/config";
- import Upload from "../../model/upload";
- import {logicStatus, studentTypes} from "../../model/enum";
- Page({
- data: {
- isCommunityWorker: false,
- plusImageUrl: '/images/plus2.png',
- iCanUseAvatarButton: wx.canIUse('button.open-type.chooseAvatar'),
- isPC: false,
- contactPhone: '',
- studentTypesEnum: studentTypes,
- logicStateEnum: logicStatus,
- sexData: [],
- eduExpData: [],
- nationData: [],
- specialtyData: [],
- socialWorkLevelData: [],
- advantageData: [],
- socialWorkYearData: [],
- studentTypeData: [],
- jobData: [],
- communityJobData: [],
- otherJobData: [],
- parentIds: '',
- // defaultAvatarUrl: 'https://college-file-1302740389.cos.ap-beijing.myqcloud.com/QJVCVcHsaNcK2bc17026cd7f3f710b5de7748f8f9194.jpg',
- formData: {
- teamId: '',
- id: '',
- idCard: '',
- picUrl: '',
- name: '',
- sex: '',
- education: '',
- graduate: '',
- nation: '',
- jobTime: '',
- socialWorkYear: '',
- advantage: '',
- //是否提任
- isPromote: -1,
- //原任职务
- formerPost: "",
- code: '',
- perType: -1,
- isEmphasis: -1,
- specialtyId: -1,
- isFullTime: -1,
- socialWorkLevel: -1,
- isParty: -1,
- isReceiveHonor: -1,
- jobId: -1,
- isGridLeader: -1,
- isBuildLeader: -1,
- isUnitLeader: -1,
- isWelfare: -1,
- }
- },
- async onLoad(options) {
- this.setData({
- isPC: getApp().globalData.isPC
- });
- const {teamId, eduStuId} = options;
- showLoading();
- const {
- data: user
- } = await Api.getUserInfoByTeam({
- teamId
- });
- const [res1, res2, res3, res4, res5, res6, res7, res8, res9, res10] = await Api.promiseAllSettled([
- Api.getPulishDict(Config.DICT.SEX),
- Api.getPulishDict(Config.DICT.EDU_EXP),
- Api.getPulishDict(Config.DICT.NATION),
- Api.getPulishDict(Config.DICT.SPECIALTY),
- Api.getPulishDict(Config.DICT.SOCIAL_WORK_LEVEL),
- Api.getPulishDict(Config.DICT.ADVANTAGE),
- Api.getPulishDict(Config.DICT.SOCIAL_WORK_YEAR),
- Api.getPulishDict(Config.DICT.STUDENT_TYPE),
- Api.getPulishDict(Config.DICT.COMMUNITY_WORKER_TYPE),
- Api.getPulishDict(Config.DICT.OTHER_WORKER_TYPE),
- ])
- wx.hideLoading()
- const sexData = res1.data;
- const eduExpData = res2.data;
- const nationData = res3.data;
- const specialtyData = res4.data;
- const socialWorkLevelData = res5.data;
- const advantageData = res6.data;
- const socialWorkYearData = res7.data;
- const studentTypeData = res8.data;
- const communityJobData = res9.data;
- const otherJobData = res10.data;
- let arrays = [];
- // 如果学员类别是游客 不会显学员单位 不必拼接 arrays
- if (user.perType != studentTypes.VISITOR && (!!user.code || !!user.parentIds)) {
- if (user.code && user.perType == studentTypes.COMMUNITY_WORKER && user.code.startsWith('22')) {
- arrays = user.parentIds.split(",").filter((item, index) => index > 1);
- arrays.push(user.code);
- }else{
- arrays = user.parentIds.split(",").filter((item, index) => index > 0);
- arrays.push(user.regionId);
- }
- }
- let parentIds = arrays.join(",");
- const {
- idCard,
- picUrl,
- name,
- sex,
- education,
- graduate,
- nation,
- jobTime,
- socialWorkYear,
- advantage,
- isPromote,
- formerPost,
- code,
- perType,
- isEmphasis,
- specialtyId,
- isFullTime,
- socialWorkLevel,
- isParty,
- isReceiveHonor,
- jobId,
- isGridLeader,
- isBuildLeader,
- isUnitLeader,
- isWelfare
- } = user;
- // let userAvatar = picUrl ? picUrl : this.data.defaultAvatarUrl; //给一个默认头像
- this.setData({
- formData: {
- idCard,
- // picUrl: userAvatar,
- picUrl,
- name,
- sex,
- education,
- graduate,
- nation,
- jobTime,
- socialWorkYear,
- advantage,
- isPromote,
- formerPost,
- // 如果学员类别是游客 将学员类别和学员单位(且 parentIds 应为空串)置空
- code: perType == studentTypes.VISITOR ? null : code,
- perType: perType == studentTypes.VISITOR ? null : perType,
- isEmphasis,
- specialtyId,
- isFullTime,
- socialWorkLevel,
- isParty,
- isReceiveHonor,
- jobId,
- isGridLeader,
- isBuildLeader,
- isUnitLeader,
- isWelfare,
- teamId,
- id: eduStuId,
- },
- isCommunityWorker: perType == studentTypes.COMMUNITY_WORKER,
- sexData,
- eduExpData,
- nationData,
- specialtyData,
- socialWorkLevelData,
- advantageData,
- socialWorkYearData,
- studentTypeData,
- communityJobData,
- otherJobData,
- parentIds
- })
- const teacherInfo = await Api.getTeamTeacherPhone({
- teamId
- });
- this.setData({
- contactPhone: teacherInfo.data.teacherPhone
- });
- },
- onChooseAvatar(e){
- console.log('e -> ', e);
- const { avatarUrl } = e.detail;
- console.log('myAvatar -> ', avatarUrl);
- if(!avatarUrl) {
- toast('请上传用户头像');
- return;
- }
- this.uploadAvatarToCos({
- url: avatarUrl
- });
- },
- onChange(e) {
- const field = getDataSet(e, "field");
- const value = getDataSet(e, "value");
- this.setData({
- [field]: getEventParam(e, value)
- })
- },
- async chooseImg(e) {
- const img = await wx.chooseImage({
- count: 1
- });
- const file = {
- url: img.tempFilePaths[0]
- };
- this.uploadAvatarToCos(file);
- },
- async uploadAvatarToCos(file){
- wx.showLoading({
- title: '正在上传...',
- mask: true
- });
- await Upload.uploadRes(Config.UPLOAD_PATH.AVATER, file);
- this.setData({
- 'formData.picUrl': file.url
- })
- wx.hideLoading();
- },
- changeInfo(e) {
- let eventParam = getEventParam(e);
- //额外处理一下联动
- if (eventParam['formData.perType'] && eventParam['formData.perType'] != this.data.formData.perType) {
- this.setData({
- 'formData.jobId': -1,
- 'formData.code': '',
- parentIds:'',
- isCommunityWorker: eventParam['formData.perType'] == studentTypes.COMMUNITY_WORKER
- })
- }
- this.setData({
- ...eventParam
- })
- },
- checkEmpty(field, data){
- const value = data || this.data.formData[field];
- return !value || !value.trim();
- },
- checkUNChoose(field){
- const value = this.data.formData[field];
- if (typeof value !== 'number' && this.checkEmpty(field, value)) {
- return true;
- }
- return value == -1;
- },
- // 提交
- submit: throttle(async function (e) {
- let perType = this.data.formData.perType;
- let isCommunityWorker = perType == studentTypes.COMMUNITY_WORKER;
- // if (this.checkEmpty('picUrl')) {
- // toast('请上传头像')
- // return;
- // }
- if (this.checkEmpty('name')) {
- toast('请输入姓名')
- return;
- }
- if (this.checkEmpty('sex')) {
- toast('请选择性别')
- return;
- }
- if (this.checkEmpty('nation')) {
- toast('请选择民族')
- return;
- }
- if (this.checkUNChoose('perType')) {
- toast('请选择学员类别')
- return;
- }
- // if (this.checkEmpty('education')) {
- // toast('请选择文化程度')
- // return;
- // }
- // if (this.checkEmpty('graduate')) {
- // toast('请输入毕业院校')
- // return;
- // }
- // if (this.checkUNChoose('isEmphasis')) {
- // toast('请选择是否211、985')
- // return;
- // }
-
- // if (this.checkUNChoose('specialtyId')) {
- // toast('请选择专业')
- // return;
- // }
- // if (this.checkUNChoose('isFullTime')) {
- // toast('请选择是否全日制')
- // return;
- // }
- // if (this.checkEmpty('advantage')) {
- // toast('请选择特长优势')
- // return;
- // }
- // if (this.checkUNChoose('isParty')) {
- // toast('请选择是否中共党员')
- // return;
- // }
- // if (this.checkUNChoose('isReceiveHonor')) {
- // toast('请选择是否有区级以上荣誉')
- // return;
- // }
-
- // //社区工作者相关内容 start
- // if (this.checkEmpty('code')) {
- // let unitChooseTipContent = isCommunityWorker? '吉林省社区工作者必须选择到社区一级,非吉林省社区工作者必须选择到市一级!' : '请选择单位所在的行政区域!';
- // wx.showModal({
- // title: "单位所在的行政区域提示",
- // content: unitChooseTipContent,
- // showCancel: false
- // })
- // return;
- // }
- // if (isCommunityWorker && this.checkUNChoose('socialWorkLevel')) {
- // toast('请选择社工证等级')
- // return;
- // }
- // if (isCommunityWorker && this.checkEmpty('socialWorkYear')) {
- // toast('请选择社区工作年限')
- // return;
- // }
- // if (isCommunityWorker && this.checkUNChoose('isPromote')) {
- // toast('请选择是否在本年度提任社区书记')
- // return;
- // }
- // if (isCommunityWorker && this.data.formData.isPromote == logicStatus.YES && this.checkEmpty('formerPost')) {
- // toast('请输入原职务')
- // return;
- // }
- // if (this.checkUNChoose('jobId')) {
- // toast('请选择现任职务')
- // return;
- // }
- // if (this.checkEmpty('jobTime')) {
- // toast('请选择任职时间')
- // return;
- // }
- if (isCommunityWorker) {
- if (this.checkEmpty('education')) {
- toast('请选择文化程度')
- return;
- }
- if (this.checkEmpty('graduate')) {
- toast('请输入毕业院校')
- return;
- }
- if (this.checkUNChoose('isEmphasis')) {
- toast('请选择是否211、985')
- return;
- }
- if (this.checkUNChoose('specialtyId')) {
- toast('请选择专业')
- return;
- }
- if (this.checkUNChoose('isFullTime')) {
- toast('请选择是否全日制')
- return;
- }
- if (this.checkEmpty('advantage')) {
- toast('请选择特长优势')
- return;
- }
- if (this.checkUNChoose('isParty')) {
- toast('请选择是否中共党员')
- return;
- }
- if (this.checkUNChoose('isReceiveHonor')) {
- toast('请选择是否有区级以上荣誉')
- return;
- }
- //社区工作者相关内容 start
- if (this.checkEmpty('code')) {
- let unitChooseTipContent = isCommunityWorker? '吉林省社区工作者必须选择到社区一级,非吉林省社区工作者必须选择到市一级!' : '请选择单位所在的行政区域!';
- wx.showModal({
- title: "单位所在的行政区域提示",
- content: unitChooseTipContent,
- showCancel: false
- })
- return;
- }
- if (isCommunityWorker && this.checkUNChoose('socialWorkLevel')) {
- toast('请选择社工证等级')
- return;
- }
- if (isCommunityWorker && this.checkEmpty('socialWorkYear')) {
- toast('请选择社区工作年限')
- return;
- }
- if (isCommunityWorker && this.checkUNChoose('isPromote')) {
- toast('请选择是否在本年度提任社区书记')
- return;
- }
- if (isCommunityWorker && this.data.formData.isPromote == logicStatus.YES && this.checkEmpty('formerPost')) {
- toast('请输入原职务')
- return;
- }
- if (this.checkUNChoose('jobId')) {
- toast('请选择现任职务')
- return;
- }
- if (this.checkEmpty('jobTime')) {
- toast('请选择任职时间')
- return;
- }
- if (this.checkUNChoose('isGridLeader')) {
- toast('请选择是否网格长')
- return;
- }
- if (this.checkUNChoose('isBuildLeader')) {
- toast('请选择是否楼栋长')
- return;
- }
- if (this.checkUNChoose('isUnitLeader')) {
- toast('请选择是否单元长')
- return;
- }
- if (this.checkUNChoose('isWelfare')) {
- toast('请选择是否公益岗')
- return;
- }
- }
- if (!isCommunityWorker) {
- //如果是非社区工作者 将社区工作者相关字段置空
- this.data.formData.socialWorkLevel = '';
- this.data.formData.socialWorkYear = '';
- this.data.formData.isPromote = '';
- this.data.formData.formerPost = '';
- this.data.formData.isGridLeader = null;
- this.data.formData.isBuildLeader = null;
- this.data.formData.isUnitLeader = null;
- this.data.formData.isWelfare = null;
- }
- if (this.data.formData.isPromote == logicStatus.NO) {
- this.data.formData.formerPost = '';
- }
- console.log(this.data.formData);
- showLoading();
- await Api.submitStudentForm(this.data.formData);
- await User.bindWechat(); //提交登记表绑定微信
- await User.updateUserInfo(); //更新本地缓存的用户信息
- wx.hideLoading();
- toast("提交成功", "success");
- const eventChannel = this.getOpenerEventChannel();
- eventChannel.emit('refresh');
- setTimeout(() => {
- wx.navigateBack();
- }, 300);
- }),
- });
|