studentInfo.js 16 KB

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