register.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. import Api from "../../model/api";
  2. import {getDataSet, getEventParam, isMobile, toast, isIdCard} from "../../utils/utils";
  3. import Config from "../../model/config";
  4. import {logicStatus, studentTypes} from "../../model/enum";
  5. Page({
  6. data: {
  7. formData: {
  8. name: "",
  9. phone: "",
  10. verify: '',
  11. idCard: "",
  12. perType: 3,
  13. code: "",
  14. },
  15. errMsg: "",
  16. studentTypeData: [],
  17. parentIds: '', //清空行政区划选择
  18. },
  19. async onLoad(options) {
  20. const res = await Api.getPulishDict(Config.DICT.STUDENT_TYPE);
  21. const studentTypeData = res.data;
  22. this.setData({studentTypeData})
  23. },
  24. changeInfo(e) {
  25. // let eventParam = getEventParam(e);
  26. // this.setData({
  27. // ...eventParam
  28. // })
  29. let eventParam = getEventParam(e);
  30. //额外处理一下联动
  31. if (eventParam['formData.perType'] && eventParam['formData.perType'] != this.data.formData.perType) {
  32. this.setData({
  33. // 'formData.jobId': -1,
  34. 'formData.code': '',
  35. parentIds:'',
  36. })
  37. }
  38. this.setData({
  39. ...eventParam
  40. })
  41. },
  42. onChange(e) {
  43. const field = getDataSet(e, "field");
  44. this.setData({
  45. [field]: getEventParam(e)
  46. })
  47. },
  48. async submit() {
  49. if (!this.data.formData.name.trim()) {
  50. toast('请输入姓名')
  51. return;
  52. }
  53. if (!isMobile(this.data.formData.phone)) {
  54. toast('请输入正确的手机号')
  55. return;
  56. }
  57. if (!this.data.formData.verify) {
  58. toast('请输入验证码')
  59. return;
  60. }
  61. // if (!this.data.formData.idCard) {
  62. // toast('请输入身份证号')
  63. // return;
  64. // }
  65. if (!isIdCard(this.data.formData.idCard)) {
  66. toast('身份证号格式不正确')
  67. return;
  68. }
  69. // if (this.data.formData.perType == -1) {
  70. // toast('请选择学员类别')
  71. // return;
  72. // }
  73. // let isCommunityWorker = this.data.formData.perType == studentTypes.COMMUNITY_WORKER;
  74. // console.log('isCommunityWorker -> ', isCommunityWorker);
  75. if (!this.data.formData.code || !this.data.formData.code.trim()) {
  76. // wx.showModal({
  77. // title: "单位所在的行政区域提示",
  78. // content: "吉林省社区工作者必须选择到社区一级,非吉林省社区工作者必须选择到市一级!",
  79. // showCancel:false
  80. // })
  81. // let unitChooseTipContent = isCommunityWorker? '吉林省社区工作者必须选择到社区一级,非吉林省社区工作者必须选择到市一级!' : '请选择单位所在的行政区域!';
  82. // wx.showModal({
  83. // title: "单位所在的行政区域提示",
  84. // content: unitChooseTipContent,
  85. // showCancel: false
  86. // });
  87. let unitChooseTipContent = '请选择单位所在的行政区域!';
  88. wx.showModal({
  89. title: "单位所在的行政区域提示",
  90. content: unitChooseTipContent,
  91. showCancel: false
  92. });
  93. return;
  94. }
  95. let submitForm = {...this.data.formData, perType: 10};
  96. // await Api.register(this.data.formData, true);
  97. await Api.register(submitForm, true);
  98. toast("注册成功")
  99. wx.navigateBack();
  100. },
  101. })