user-info.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. import {
  2. imgServerUrl,
  3. imgServerUrl_new
  4. } from '../../config/config.js'
  5. import {
  6. resumeBase} from '../../services/index.js'
  7. import {
  8. uploadImg
  9. } from '../../services/uploadFile.js'
  10. import {
  11. showToast
  12. } from '../../utils/tips.js'
  13. import {
  14. updataStorageData
  15. } from '../../utils/storage.js'
  16. const app = getApp();
  17. Page({
  18. data: {
  19. imgServerUrl: imgServerUrl,
  20. imgServerUrl_new: imgServerUrl_new,
  21. sex: ["男", "女"],
  22. sex_index: 0,
  23. eduList: ["请选择", "小学", "中学", "高中", "大专", "本科", "研究生", "博士", "博士后"],
  24. eduIndex: 0,
  25. avatar: '',
  26. headImg: '',
  27. name: '',
  28. year: '',
  29. iphone: '',
  30. hpUserResumeId: null,
  31. wechatNumber: '',
  32. disabled: false
  33. },
  34. onLoad: function (options) {
  35. let {
  36. hpUserResumeId = null } = options
  37. this.setData({
  38. hpUserResumeId
  39. })
  40. this.setData({
  41. avatar: `${imgServerUrl}/images/avatar/man.png`,
  42. endDate: new Date().getFullYear(),
  43. year: '请选择'
  44. })
  45. let phone = updataStorageData('phone')
  46. if (phone) {
  47. this.setData({
  48. iphone: phone
  49. })
  50. }
  51. if (hpUserResumeId) {
  52. let userResume = wx.getStorageSync('userResume')
  53. if (userResume.id) {
  54. this.setData({
  55. hpUserResumeId: userResume.id,
  56. avatar: userResume.headImg,
  57. name: userResume.realName,
  58. sex_index: userResume.gender == 1 ? 0 : 1,
  59. year: userResume.birthYear,
  60. iphone: userResume.phone,
  61. wechatNumber:userResume.wechatNumber,
  62. eduIndex: userResume.highestQualification ? Number(userResume.highestQualification) : 0
  63. }, () => {
  64. this.check()
  65. })
  66. }
  67. }
  68. },
  69. //改变学历
  70. bindPickerChange(e) {
  71. let {
  72. value
  73. } = e.detail
  74. this.setData({
  75. eduIndex: value
  76. }, _ => {
  77. this.check()
  78. })
  79. },
  80. //改变性别
  81. bindSexChange(e) {
  82. let {
  83. value
  84. } = e.detail
  85. this.setData({
  86. sex_index: value
  87. }, _ => {
  88. this.check()
  89. })
  90. },
  91. //姓名改变
  92. changeName(e) {
  93. let {
  94. value
  95. } = e.detail
  96. this.setData({
  97. name: value.excludeSpecial().excludeSpace()
  98. }, _ => {
  99. this.check()
  100. })
  101. },
  102. //改变出生年月
  103. changeYear(e) {
  104. let {
  105. value
  106. } = e.detail
  107. this.setData({
  108. year: value
  109. }, _ => {
  110. this.check()
  111. })
  112. },
  113. //手机号改变
  114. changeIphone(e) {
  115. let {
  116. value
  117. } = e.detail
  118. this.setData({
  119. iphone: value.excludeSpecial().excludeSpace()
  120. }, _ => {
  121. this.check()
  122. })
  123. },
  124. changeWechatNumber(e) {
  125. let {
  126. value
  127. } = e.detail
  128. this.setData({
  129. wechatNumber: value
  130. }, _ => {
  131. this.check()
  132. })
  133. },
  134. //上传图片
  135. changeImg() {
  136. var up_type = '0';
  137. uploadImg(up_type).then(res => {
  138. let image = res.data.imgUrl
  139. this.setData({
  140. avatar: `${imgServerUrl_new}` + image,
  141. headImg: image
  142. })
  143. })
  144. },
  145. //验证
  146. check(status = false) {
  147. // let {
  148. // avatar,
  149. // name,
  150. // year,
  151. // iphone
  152. // } = this.data
  153. // if (avatar == (imgServerUrl + "/images/avatar/man.png")) {
  154. // showToast('请上传头像');
  155. // return false;
  156. // }
  157. this.setData({
  158. disabled: false
  159. })
  160. if (this.data.name == "") {
  161. status && showToast('请输入用户名');
  162. return false;
  163. }
  164. // if (this.data.iphone == "" || this.data.iphone.length != 11) {
  165. // status && showToast('请输入11位手机号');
  166. // return false;
  167. // }
  168. if (this.data.year == "" || this.data.year == '请选择') {
  169. status && showToast('请选择出生年月');
  170. return false;
  171. }
  172. if (this.data.eduIndex == "" || this.data.eduIndex == '0') {
  173. status && showToast('请选择您的最高学历');
  174. return false;
  175. }
  176. // if (this.data.wechatNumber === '') {
  177. // status && showToast('请输入微信号');
  178. // return false;
  179. // }
  180. this.setData({
  181. disabled: true
  182. })
  183. return true
  184. },
  185. //保存
  186. submit() {
  187. let flag = this.check(true)
  188. if (!flag) {
  189. return
  190. }
  191. let {
  192. sex_index,
  193. eduIndex,
  194. headImg,
  195. name,
  196. year,
  197. iphone,
  198. wechatNumber } = this.data
  199. let paramsObj = {
  200. highestQualification: eduIndex,
  201. birthYear: year,
  202. gender: sex_index == 0 ? 1 : 2,
  203. realName: name,
  204. phone: iphone,
  205. wechatNumber,
  206. avatar: headImg,
  207. user_id: app.globalData.userId,
  208. user_token: app.globalData.userToken,
  209. member_id: app.globalData.memberId
  210. }
  211. Object.assign(paramsObj);
  212. resumeBase(paramsObj).then(data => {
  213. showToast('保存成功', 'success');
  214. wx.setStorageSync("userResume", data.data.userResume);
  215. wx.navigateBack();
  216. })
  217. },
  218. onError(err) {
  219. app.aldstat.sendEvent('报错', {
  220. 'err': err
  221. });
  222. },
  223. })