studentInfo.js 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  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 {studentTypes} from "../../model/enum";
  7. Page({
  8. data: {
  9. logicData: [
  10. {dictLabel: '是', dictValue: '1'},
  11. {dictLabel: '否', dictValue: '0'}
  12. ],
  13. studentTypesEnum: studentTypes,
  14. sexData: [],
  15. eduExpData: [],
  16. nationData: [],
  17. specialtyData: [],
  18. socialWorkLevelData: [],
  19. advantageData: [],
  20. socialWorkYearData: [],
  21. studentTypeData: [],
  22. parentIds: '',
  23. errMsg: '',
  24. sexIndex: -1,
  25. eduExpIndex: -1,
  26. famousSchoolIndex: -1,
  27. nationIndex: -1,
  28. specialtyIndex: -1,
  29. isFullTimeIndex: -1,
  30. socialWorkLevelIndex: -1,
  31. ispartyIndex: -1,
  32. ishonorIndex: -1,
  33. socialWorkYearIndex: -1,
  34. gridLeaderIndex: -1,
  35. buildLeaderIndex: -1,
  36. unitLeaderIndex: -1,
  37. welFareIndex: -1,
  38. formData: {
  39. teamId: '',
  40. id: '',
  41. idCard: '',
  42. picUrl: '',
  43. name: '',
  44. sex: '',
  45. education: '',
  46. graduate: '',
  47. isEmphasis: '',
  48. nation: '',
  49. specialtyId: '',
  50. isFullTime: '',
  51. jobTime: '',
  52. socialWorkLevel: '',
  53. advantage: '',
  54. isParty: '',
  55. isReceiveHonor: '',
  56. code: '',
  57. perType: -1,
  58. jobId: -1,
  59. socialWorkYear: '',
  60. isGridLeader: '',
  61. isBuildLeader: '',
  62. isUnitLeader: '',
  63. isWelfare: '',
  64. }
  65. },
  66. async onLoad(options) {
  67. const teamId = options.teamId;
  68. const eduStuId = options.eduStuId;
  69. const user = User.getUserInfoByLocal();
  70. showLoading();
  71. const [res1, res2, res3, res4, res5, res6, res7, res8] = 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. ])
  81. wx.hideLoading()
  82. const sexData = res1.data;
  83. const eduExpData = res2.data;
  84. const nationData = res3.data;
  85. const specialtyData = res4.data;
  86. const socialWorkLevelData = res5.data;
  87. const advantageData = res6.data;
  88. const socialWorkYearData = res7.data;
  89. const studentTypeData = res8.data;
  90. this.setData({
  91. 'formData.teamId': teamId,
  92. 'formData.id': eduStuId,
  93. 'formData.idCard': user.idCard,
  94. 'formData.picUrl': user.picUrl,
  95. 'formData.name': user.name,
  96. 'formData.sex': user.sex,
  97. 'formData.education': user.education,
  98. 'formData.graduate': user.graduate,
  99. 'formData.isEmphasis': user.isEmphasis,
  100. 'formData.nation': user.nation,
  101. 'formData.specialtyId': user.specialtyId,
  102. 'formData.isFullTime': user.isFullTime,
  103. 'formData.jobTime': user.jobTime,
  104. 'formData.socialWorkLevel': user.socialWorkLevel,
  105. 'formData.advantage': user.advantage,
  106. 'formData.isParty': user.isParty,
  107. 'formData.isReceiveHonor': user.isReceiveHonor,
  108. 'formData.code': user.code,
  109. 'formData.perType': user.perType,
  110. 'formData.jobId': user.jobId,
  111. 'formData.socialWorkYear': user.socialWorkYear,
  112. 'formData.isGridLeader': user.isGridLeader,
  113. 'formData.isBuildLeader': user.isBuildLeader,
  114. 'formData.isUnitLeader': user.isUnitLeader,
  115. 'formData.isWelfare': user.isWelfare,
  116. 'sexIndex': this.findIndex(sexData, user.sex),
  117. 'eduExpIndex': this.findIndex(eduExpData, user.education),
  118. 'famousSchoolIndex': this.findIndex(this.data.logicData, user.isEmphasis),
  119. 'nationIndex': this.findIndex(nationData, user.nation),
  120. 'specialtyIndex': this.findIndex(specialtyData, user.specialtyId),
  121. 'isFullTimeIndex': this.findIndex(this.data.logicData, user.isFullTime),
  122. 'socialWorkLevelIndex': this.findIndex(socialWorkLevelData, user.socialWorkLevel),
  123. 'ispartyIndex': this.findIndex(this.data.logicData, user.isParty),
  124. 'ishonorIndex': this.findIndex(this.data.logicData, user.isReceiveHonor),
  125. 'socialWorkYearIndex': this.findIndex(socialWorkYearData, user.socialWorkYear),
  126. 'gridLeaderIndex': this.findIndex(this.data.logicData, user.isGridLeader),
  127. 'buildLeaderIndex': this.findIndex(this.data.logicData, user.isBuildLeader),
  128. 'unitLeaderIndex': this.findIndex(this.data.logicData, user.isUnitLeader),
  129. 'welFareIndex': this.findIndex(this.data.logicData, user.isWelfare),
  130. 'parentIds': user.parentIds,
  131. sexData, eduExpData, nationData, specialtyData,
  132. socialWorkLevelData, advantageData, socialWorkYearData,
  133. studentTypeData,
  134. })
  135. },
  136. onChange(e) {
  137. const field = getDataSet(e, "field");
  138. this.setData({
  139. [field]: getEventParam(e)
  140. })
  141. },
  142. bindChange(e) {
  143. const field = getDataSet(e, "field");
  144. const key = getDataSet(e, "key");
  145. const arr = getDataSet(e, "arr");
  146. const value = getEventParam(e, 'value');
  147. let obj = {};
  148. if (arr && value) {
  149. obj = {[key]: this.data[arr][value].dictValue}
  150. }
  151. this.setData({
  152. [field]: value,
  153. ...obj
  154. })
  155. },
  156. async chooseImg(e) {
  157. const img = await wx.chooseImage({count: 1});
  158. const file = {url: img.tempFilePaths[0]};
  159. await Upload.uploadRes(Config.UPLOAD_PATH.AVATER, file);
  160. this.setData({
  161. 'formData.picUrl': file.url
  162. })
  163. },
  164. async changeStuAreaInfo(e) {
  165. const {perType, code, jobId, errMsg} = getEventParam(e);
  166. let obj = {}
  167. if (jobId) {
  168. obj["formData.jobId"] = jobId;
  169. }
  170. this.setData({
  171. "formData.perType": perType,
  172. "formData.code": code || '',
  173. ...obj,
  174. errMsg
  175. })
  176. },
  177. changeInfo(e) {
  178. let eventParam = getEventParam(e);
  179. this.setData({
  180. ...eventParam
  181. })
  182. },
  183. // 提交
  184. submit: throttle(async function (e) {
  185. if (!this.data.formData.picUrl.trim()) {
  186. toast('请上传头像')
  187. return;
  188. }
  189. if (!this.data.formData.name.trim()) {
  190. toast('请输入姓名')
  191. return;
  192. }
  193. if (this.data.sexIndex == -1) {
  194. toast('请选择性别')
  195. return;
  196. }
  197. if (this.data.eduExpIndex == -1) {
  198. toast('请选择文化程度')
  199. return;
  200. }
  201. if (!this.data.formData.graduate.trim()) {
  202. toast('请输入毕业院校')
  203. return;
  204. }
  205. if (this.data.famousSchoolIndex == -1) {
  206. toast('请选择是否211.985')
  207. return;
  208. }
  209. if (this.data.nationIndex == -1) {
  210. toast('请选择民族')
  211. return;
  212. }
  213. if (this.data.specialtyIndex == -1) {
  214. toast('请选择专业')
  215. return;
  216. }
  217. if (this.data.isFullTimeIndex == -1) {
  218. toast('请选择是否全日制')
  219. return;
  220. }
  221. if (!this.data.formData.jobTime.trim()) {
  222. toast('请选择任职时间')
  223. return;
  224. }
  225. if (this.data.socialWorkLevelIndex == -1) {
  226. toast('请选择社工证等级')
  227. return;
  228. }
  229. if (!this.data.formData.advantage.trim()) {
  230. toast('请选择特长优势')
  231. return;
  232. }
  233. if (this.data.ispartyIndex == -1) {
  234. toast('请选择是否中共党员')
  235. return;
  236. }
  237. if (this.data.ishonorIndex == -1) {
  238. toast('请选择是否有市级以上荣誉')
  239. return;
  240. }
  241. if (this.data.formData.perType == -1) {
  242. toast('请选择学员类别')
  243. return;
  244. }
  245. if (!this.data.formData.code.trim()) {
  246. let errMsg = this.data.errMsg;
  247. toast(errMsg || '请选择单位所在的行政区域')
  248. return;
  249. }
  250. if (this.data.formData.jobId == -1) {
  251. toast('请选择现任职务')
  252. return;
  253. }
  254. if (this.data.socialWorkYearIndex == -1) {
  255. toast('请选择社区工作年限')
  256. return;
  257. }
  258. if (this.data.gridLeaderIndex == -1) {
  259. toast('请选择是否网格长')
  260. return;
  261. }
  262. if (this.data.buildLeaderIndex == -1) {
  263. toast('请选择是否楼栋长')
  264. return;
  265. }
  266. if (this.data.unitLeaderIndex == -1) {
  267. toast('请选择是否单元长')
  268. return;
  269. }
  270. if (this.data.welFareIndex == -1) {
  271. toast('请选择是否公益岗')
  272. return;
  273. }
  274. showLoading();
  275. await Api.submitStudentForm(this.data.formData);
  276. await User.updateUserInfo();
  277. await User.bindWechat();
  278. wx.hideLoading();
  279. toast("提交成功")
  280. wx.navigateBack();
  281. }),
  282. findIndex(arr, value) {
  283. return arr.findIndex(item => item.dictValue == value);
  284. },
  285. });