studentInfo.js 13 KB

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