studentInfo.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  1. import Api from "../../model/api";
  2. import User from "../../model/user";
  3. import {getDataSet, getEventParam, showLoading, throttle, toast} from "../../utils/utils";
  4. import Config from "../../model/config";
  5. import Upload from "../../model/upload";
  6. import {logicStatus, studentTypes} from "../../model/enum";
  7. Page({
  8. data: {
  9. isCommunityWorker: false,
  10. plusImageUrl: '/images/plus2.png',
  11. iCanUseAvatarButton: wx.canIUse('button.open-type.chooseAvatar'),
  12. isPC: false,
  13. contactPhone: '',
  14. studentTypesEnum: studentTypes,
  15. logicStateEnum: logicStatus,
  16. sexData: [],
  17. eduExpData: [],
  18. nationData: [],
  19. specialtyData: [],
  20. socialWorkLevelData: [],
  21. advantageData: [],
  22. socialWorkYearData: [],
  23. studentTypeData: [],
  24. jobData: [],
  25. communityJobData: [],
  26. otherJobData: [],
  27. parentIds: '',
  28. // defaultAvatarUrl: 'https://college-file-1302740389.cos.ap-beijing.myqcloud.com/QJVCVcHsaNcK2bc17026cd7f3f710b5de7748f8f9194.jpg',
  29. formData: {
  30. teamId: '',
  31. id: '',
  32. idCard: '',
  33. picUrl: '',
  34. name: '',
  35. sex: '',
  36. education: '',
  37. graduate: '',
  38. nation: '',
  39. jobTime: '',
  40. socialWorkYear: '',
  41. advantage: '',
  42. //是否提任
  43. isPromote: -1,
  44. //原任职务
  45. formerPost: "",
  46. code: '',
  47. perType: -1,
  48. isEmphasis: -1,
  49. specialtyId: -1,
  50. isFullTime: -1,
  51. socialWorkLevel: -1,
  52. isParty: -1,
  53. isReceiveHonor: -1,
  54. jobId: -1,
  55. isGridLeader: -1,
  56. isBuildLeader: -1,
  57. isUnitLeader: -1,
  58. isWelfare: -1,
  59. }
  60. },
  61. async onLoad(options) {
  62. this.setData({
  63. isPC: getApp().globalData.isPC
  64. });
  65. const {teamId, eduStuId} = options;
  66. showLoading();
  67. const {
  68. data: user
  69. } = await Api.getUserInfoByTeam({
  70. teamId
  71. });
  72. const [res1, res2, res3, res4, res5, res6, res7, res8, res9, res10] = await Api.promiseAllSettled([
  73. Api.getPulishDict(Config.DICT.SEX),
  74. Api.getPulishDict(Config.DICT.EDU_EXP),
  75. Api.getPulishDict(Config.DICT.NATION),
  76. Api.getPulishDict(Config.DICT.SPECIALTY),
  77. Api.getPulishDict(Config.DICT.SOCIAL_WORK_LEVEL),
  78. Api.getPulishDict(Config.DICT.ADVANTAGE),
  79. Api.getPulishDict(Config.DICT.SOCIAL_WORK_YEAR),
  80. Api.getPulishDict(Config.DICT.STUDENT_TYPE),
  81. Api.getPulishDict(Config.DICT.COMMUNITY_WORKER_TYPE),
  82. Api.getPulishDict(Config.DICT.OTHER_WORKER_TYPE),
  83. ])
  84. wx.hideLoading()
  85. const sexData = res1.data;
  86. const eduExpData = res2.data;
  87. const nationData = res3.data;
  88. const specialtyData = res4.data;
  89. const socialWorkLevelData = res5.data;
  90. const advantageData = res6.data;
  91. const socialWorkYearData = res7.data;
  92. const studentTypeData = res8.data;
  93. const communityJobData = res9.data;
  94. const otherJobData = res10.data;
  95. let arrays = [];
  96. // 如果学员类别是游客 不会显学员单位 不必拼接 arrays
  97. if (user.perType != studentTypes.VISITOR && (!!user.code || !!user.parentIds)) {
  98. if (user.code && user.perType == studentTypes.COMMUNITY_WORKER && user.code.startsWith('22')) {
  99. arrays = user.parentIds.split(",").filter((item, index) => index > 1);
  100. arrays.push(user.code);
  101. }else{
  102. arrays = user.parentIds.split(",").filter((item, index) => index > 0);
  103. arrays.push(user.regionId);
  104. }
  105. }
  106. let parentIds = arrays.join(",");
  107. const {
  108. idCard,
  109. picUrl,
  110. name,
  111. sex,
  112. education,
  113. graduate,
  114. nation,
  115. jobTime,
  116. socialWorkYear,
  117. advantage,
  118. isPromote,
  119. formerPost,
  120. code,
  121. perType,
  122. isEmphasis,
  123. specialtyId,
  124. isFullTime,
  125. socialWorkLevel,
  126. isParty,
  127. isReceiveHonor,
  128. jobId,
  129. isGridLeader,
  130. isBuildLeader,
  131. isUnitLeader,
  132. isWelfare
  133. } = user;
  134. // let userAvatar = picUrl ? picUrl : this.data.defaultAvatarUrl; //给一个默认头像
  135. this.setData({
  136. formData: {
  137. idCard,
  138. // picUrl: userAvatar,
  139. picUrl,
  140. name,
  141. sex,
  142. education,
  143. graduate,
  144. nation,
  145. jobTime,
  146. socialWorkYear,
  147. advantage,
  148. isPromote,
  149. formerPost,
  150. // 如果学员类别是游客 将学员类别和学员单位(且 parentIds 应为空串)置空
  151. code: perType == studentTypes.VISITOR ? null : code,
  152. perType: perType == studentTypes.VISITOR ? null : perType,
  153. isEmphasis,
  154. specialtyId,
  155. isFullTime,
  156. socialWorkLevel,
  157. isParty,
  158. isReceiveHonor,
  159. jobId,
  160. isGridLeader,
  161. isBuildLeader,
  162. isUnitLeader,
  163. isWelfare,
  164. teamId,
  165. id: eduStuId,
  166. },
  167. isCommunityWorker: perType == studentTypes.COMMUNITY_WORKER,
  168. sexData,
  169. eduExpData,
  170. nationData,
  171. specialtyData,
  172. socialWorkLevelData,
  173. advantageData,
  174. socialWorkYearData,
  175. studentTypeData,
  176. communityJobData,
  177. otherJobData,
  178. parentIds
  179. })
  180. const teacherInfo = await Api.getTeamTeacherPhone({
  181. teamId
  182. });
  183. this.setData({
  184. contactPhone: teacherInfo.data.teacherPhone
  185. });
  186. },
  187. onChooseAvatar(e){
  188. console.log('e -> ', e);
  189. const { avatarUrl } = e.detail;
  190. console.log('myAvatar -> ', avatarUrl);
  191. if(!avatarUrl) {
  192. toast('请上传用户头像');
  193. return;
  194. }
  195. this.uploadAvatarToCos({
  196. url: avatarUrl
  197. });
  198. },
  199. onChange(e) {
  200. const field = getDataSet(e, "field");
  201. const value = getDataSet(e, "value");
  202. this.setData({
  203. [field]: getEventParam(e, value)
  204. })
  205. },
  206. async chooseImg(e) {
  207. const img = await wx.chooseImage({
  208. count: 1
  209. });
  210. const file = {
  211. url: img.tempFilePaths[0]
  212. };
  213. this.uploadAvatarToCos(file);
  214. },
  215. async uploadAvatarToCos(file){
  216. wx.showLoading({
  217. title: '正在上传...',
  218. mask: true
  219. });
  220. await Upload.uploadRes(Config.UPLOAD_PATH.AVATER, file);
  221. this.setData({
  222. 'formData.picUrl': file.url
  223. })
  224. wx.hideLoading();
  225. },
  226. changeInfo(e) {
  227. let eventParam = getEventParam(e);
  228. //额外处理一下联动
  229. if (eventParam['formData.perType'] && eventParam['formData.perType'] != this.data.formData.perType) {
  230. this.setData({
  231. 'formData.jobId': -1,
  232. 'formData.code': '',
  233. parentIds:'',
  234. isCommunityWorker: eventParam['formData.perType'] == studentTypes.COMMUNITY_WORKER
  235. })
  236. }
  237. this.setData({
  238. ...eventParam
  239. })
  240. },
  241. checkEmpty(field, data){
  242. const value = data || this.data.formData[field];
  243. return !value || !value.trim();
  244. },
  245. checkUNChoose(field){
  246. const value = this.data.formData[field];
  247. if (typeof value !== 'number' && this.checkEmpty(field, value)) {
  248. return true;
  249. }
  250. return value == -1;
  251. },
  252. // 提交
  253. submit: throttle(async function (e) {
  254. let perType = this.data.formData.perType;
  255. let isCommunityWorker = perType == studentTypes.COMMUNITY_WORKER;
  256. // if (this.checkEmpty('picUrl')) {
  257. // toast('请上传头像')
  258. // return;
  259. // }
  260. if (this.checkEmpty('name')) {
  261. toast('请输入姓名')
  262. return;
  263. }
  264. if (this.checkEmpty('sex')) {
  265. toast('请选择性别')
  266. return;
  267. }
  268. if (this.checkEmpty('nation')) {
  269. toast('请选择民族')
  270. return;
  271. }
  272. if (this.checkUNChoose('perType')) {
  273. toast('请选择学员类别')
  274. return;
  275. }
  276. // if (this.checkEmpty('education')) {
  277. // toast('请选择文化程度')
  278. // return;
  279. // }
  280. // if (this.checkEmpty('graduate')) {
  281. // toast('请输入毕业院校')
  282. // return;
  283. // }
  284. // if (this.checkUNChoose('isEmphasis')) {
  285. // toast('请选择是否211、985')
  286. // return;
  287. // }
  288. // if (this.checkUNChoose('specialtyId')) {
  289. // toast('请选择专业')
  290. // return;
  291. // }
  292. // if (this.checkUNChoose('isFullTime')) {
  293. // toast('请选择是否全日制')
  294. // return;
  295. // }
  296. // if (this.checkEmpty('advantage')) {
  297. // toast('请选择特长优势')
  298. // return;
  299. // }
  300. // if (this.checkUNChoose('isParty')) {
  301. // toast('请选择是否中共党员')
  302. // return;
  303. // }
  304. // if (this.checkUNChoose('isReceiveHonor')) {
  305. // toast('请选择是否有区级以上荣誉')
  306. // return;
  307. // }
  308. // //社区工作者相关内容 start
  309. // if (this.checkEmpty('code')) {
  310. // let unitChooseTipContent = isCommunityWorker? '吉林省社区工作者必须选择到社区一级,非吉林省社区工作者必须选择到市一级!' : '请选择单位所在的行政区域!';
  311. // wx.showModal({
  312. // title: "单位所在的行政区域提示",
  313. // content: unitChooseTipContent,
  314. // showCancel: false
  315. // })
  316. // return;
  317. // }
  318. // if (isCommunityWorker && this.checkUNChoose('socialWorkLevel')) {
  319. // toast('请选择社工证等级')
  320. // return;
  321. // }
  322. // if (isCommunityWorker && this.checkEmpty('socialWorkYear')) {
  323. // toast('请选择社区工作年限')
  324. // return;
  325. // }
  326. // if (isCommunityWorker && this.checkUNChoose('isPromote')) {
  327. // toast('请选择是否在本年度提任社区书记')
  328. // return;
  329. // }
  330. // if (isCommunityWorker && this.data.formData.isPromote == logicStatus.YES && this.checkEmpty('formerPost')) {
  331. // toast('请输入原职务')
  332. // return;
  333. // }
  334. // if (this.checkUNChoose('jobId')) {
  335. // toast('请选择现任职务')
  336. // return;
  337. // }
  338. // if (this.checkEmpty('jobTime')) {
  339. // toast('请选择任职时间')
  340. // return;
  341. // }
  342. if (isCommunityWorker) {
  343. if (this.checkEmpty('education')) {
  344. toast('请选择文化程度')
  345. return;
  346. }
  347. if (this.checkEmpty('graduate')) {
  348. toast('请输入毕业院校')
  349. return;
  350. }
  351. if (this.checkUNChoose('isEmphasis')) {
  352. toast('请选择是否211、985')
  353. return;
  354. }
  355. if (this.checkUNChoose('specialtyId')) {
  356. toast('请选择专业')
  357. return;
  358. }
  359. if (this.checkUNChoose('isFullTime')) {
  360. toast('请选择是否全日制')
  361. return;
  362. }
  363. if (this.checkEmpty('advantage')) {
  364. toast('请选择特长优势')
  365. return;
  366. }
  367. if (this.checkUNChoose('isParty')) {
  368. toast('请选择是否中共党员')
  369. return;
  370. }
  371. if (this.checkUNChoose('isReceiveHonor')) {
  372. toast('请选择是否有区级以上荣誉')
  373. return;
  374. }
  375. //社区工作者相关内容 start
  376. if (this.checkEmpty('code')) {
  377. let unitChooseTipContent = isCommunityWorker? '吉林省社区工作者必须选择到社区一级,非吉林省社区工作者必须选择到市一级!' : '请选择单位所在的行政区域!';
  378. wx.showModal({
  379. title: "单位所在的行政区域提示",
  380. content: unitChooseTipContent,
  381. showCancel: false
  382. })
  383. return;
  384. }
  385. if (isCommunityWorker && this.checkUNChoose('socialWorkLevel')) {
  386. toast('请选择社工证等级')
  387. return;
  388. }
  389. if (isCommunityWorker && this.checkEmpty('socialWorkYear')) {
  390. toast('请选择社区工作年限')
  391. return;
  392. }
  393. if (isCommunityWorker && this.checkUNChoose('isPromote')) {
  394. toast('请选择是否在本年度提任社区书记')
  395. return;
  396. }
  397. if (isCommunityWorker && this.data.formData.isPromote == logicStatus.YES && this.checkEmpty('formerPost')) {
  398. toast('请输入原职务')
  399. return;
  400. }
  401. if (this.checkUNChoose('jobId')) {
  402. toast('请选择现任职务')
  403. return;
  404. }
  405. if (this.checkEmpty('jobTime')) {
  406. toast('请选择任职时间')
  407. return;
  408. }
  409. if (this.checkUNChoose('isGridLeader')) {
  410. toast('请选择是否网格长')
  411. return;
  412. }
  413. if (this.checkUNChoose('isBuildLeader')) {
  414. toast('请选择是否楼栋长')
  415. return;
  416. }
  417. if (this.checkUNChoose('isUnitLeader')) {
  418. toast('请选择是否单元长')
  419. return;
  420. }
  421. if (this.checkUNChoose('isWelfare')) {
  422. toast('请选择是否公益岗')
  423. return;
  424. }
  425. }
  426. if (!isCommunityWorker) {
  427. //如果是非社区工作者 将社区工作者相关字段置空
  428. this.data.formData.socialWorkLevel = '';
  429. this.data.formData.socialWorkYear = '';
  430. this.data.formData.isPromote = '';
  431. this.data.formData.formerPost = '';
  432. this.data.formData.isGridLeader = null;
  433. this.data.formData.isBuildLeader = null;
  434. this.data.formData.isUnitLeader = null;
  435. this.data.formData.isWelfare = null;
  436. }
  437. if (this.data.formData.isPromote == logicStatus.NO) {
  438. this.data.formData.formerPost = '';
  439. }
  440. console.log(this.data.formData);
  441. showLoading();
  442. await Api.submitStudentForm(this.data.formData);
  443. await User.bindWechat(); //提交登记表绑定微信
  444. await User.updateUserInfo(); //更新本地缓存的用户信息
  445. wx.hideLoading();
  446. toast("提交成功", "success");
  447. const eventChannel = this.getOpenerEventChannel();
  448. eventChannel.emit('refresh');
  449. setTimeout(() => {
  450. wx.navigateBack();
  451. }, 300);
  452. }),
  453. });