personalInfoPreview.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  1. // pages/user/personalInfo/personalInfo.js
  2. const app = getApp();
  3. const api = app.api;
  4. import WxValidate from '../../../utils/WxValidate'
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. // 性别 0 - 未知的性别,1 - 男性,2 - 女性,5 - 女性改(变)为男性,6 - 男性改(变)为女性,9 - 未说明的性别
  11. // 最高学历 0初中,1高中/中专,2大专,3本科,4硕士,5博士
  12. //性别字典
  13. sexPickList:[
  14. {
  15. name:"男",
  16. value:1,
  17. },
  18. {
  19. name:"女",
  20. value:2,
  21. }
  22. ],
  23. sexPickListValue:'',
  24. //学历
  25. EducationPickList:[],
  26. EducationPickValue:null,
  27. //学历状态
  28. EducationStatePickList:[],
  29. EducationStatePickValue:null,
  30. upFileInfo:null,
  31. referrerFileInfo:null,
  32. //展览记录
  33. showHistory:{
  34. id:"",
  35. name:"",
  36. organ:"",
  37. time:"",
  38. },
  39. //获奖记录
  40. awardHistory:{
  41. id:"",
  42. organ:"",
  43. prize:"",
  44. time:"",
  45. },
  46. //缺少艺名
  47. formData:{
  48. type:0,
  49. photoId:"",
  50. name:"",
  51. artistName:"",
  52. sex:"",
  53. birthday:"",
  54. nationality:"",
  55. referrerName:"",
  56. referrerPosition:"",
  57. referrerFileId:"",
  58. mobile:"",
  59. email:"",
  60. address:"",
  61. weixinNo:"",
  62. highestDegreeOrg:"",
  63. highestDegreeStartTime:"",
  64. highestDegreeEndTime:"",
  65. highestDegree:"",
  66. highestDegreeStatus:"",
  67. awardHistoryList:[],
  68. showHistoryList:[],
  69. },
  70. rules: {
  71. photoId:{
  72. required: true,
  73. },
  74. name:{
  75. required: true,
  76. },
  77. artistName:{
  78. required: true,
  79. },
  80. sex:{
  81. required: true,
  82. },
  83. birthday:{
  84. required: true,
  85. },
  86. nationality:{
  87. required: true,
  88. },
  89. referrerName:{
  90. required: true,
  91. },
  92. referrerPosition:{
  93. required: true,
  94. },
  95. referrerFileId:{
  96. required: true,
  97. },
  98. mobile: {
  99. required: true,
  100. tel:true,
  101. },
  102. email: {
  103. required: true,
  104. email:true,
  105. },
  106. address:{
  107. required: true,
  108. },
  109. weixinNo:{
  110. required: true,
  111. },
  112. highestDegreeOrg:{
  113. required: true
  114. },
  115. highestDegreeStartTime:{
  116. required: true
  117. },
  118. highestDegreeEndTime:{
  119. required: true
  120. },
  121. highestDegree:{
  122. required: true
  123. },
  124. highestDegreeStatus:{
  125. required: true
  126. }
  127. },
  128. awardRules:{
  129. organ:{
  130. required: true,
  131. },
  132. prize:{
  133. required: true,
  134. },
  135. time:{
  136. required: true,
  137. },
  138. },
  139. awardMessages:{
  140. organ:{
  141. required:'请输入奖项名称'
  142. },
  143. prize:{
  144. required:'请输入奖项机构'
  145. },
  146. time:{
  147. required:'请输入获奖时间'
  148. }
  149. },
  150. showRules:{
  151. name:{
  152. required: true,
  153. },
  154. organ:{
  155. required: true,
  156. },
  157. time:{
  158. required: true,
  159. },
  160. },
  161. showMessages:{
  162. name:{
  163. required: '请输入展展览名称',
  164. },
  165. organ:{
  166. required: '请输入展展览机构',
  167. },
  168. time:{
  169. required: '请输入展览时间',
  170. },
  171. },
  172. messages: {
  173. photoId:{
  174. required: '请上传个人形象照',
  175. },
  176. name:{
  177. required: '请输入姓名',
  178. },
  179. artistName:{
  180. required: '请输入艺名',
  181. },
  182. sex:{
  183. required: '请选择性别',
  184. },
  185. birthday:{
  186. required: '请选择出生日期',
  187. },
  188. nationality:{
  189. required: '请选择国籍',
  190. },
  191. referrerName:{
  192. required: '请输入推荐人姓名',
  193. },
  194. referrerPosition:{
  195. required: '请输入推荐人职业',
  196. },
  197. referrerFileId:{
  198. required: '请上传推荐信',
  199. },
  200. mobile: {
  201. required: '请输入手机号',
  202. tel:"请输入正确的手机号"
  203. },
  204. email: {
  205. required: '请输入邮箱地址',
  206. tel:"请输入正确的邮箱"
  207. },
  208. address:{
  209. required: '请输入地址',
  210. },
  211. weixinNo:{
  212. required: '请输入微信号',
  213. },
  214. highestDegreeOrg:{
  215. required: '请输入最高学历机构'
  216. },
  217. highestDegreeStartTime:{
  218. required: '请输入最高学历开始时间'
  219. },
  220. highestDegreeEndTime:{
  221. required: '请输入最高学历结束时间'
  222. },
  223. highestDegree:{
  224. required: '请选择最高学历',
  225. },
  226. highestDegreeStatus:{
  227. required: '请选择最高学历状态'
  228. }
  229. },
  230. },
  231. /**
  232. * 生命周期函数--监听页面加载
  233. */
  234. onLoad: function (options) {
  235. const type=options.type||0
  236. const {
  237. formData,
  238. rules,
  239. messages,
  240. showHistory,
  241. awardHistory,
  242. awardRules,
  243. awardMessages,
  244. showRules,
  245. showMessages
  246. }
  247. = this.data;
  248. this.WxValidate = new WxValidate(rules, messages);
  249. this.awardValidate = new WxValidate(awardRules, awardMessages);
  250. this.showValidate = new WxValidate(showRules, showMessages);
  251. if(formData.awardHistoryList.length==0){
  252. this.setData({
  253. 'formData.awardHistoryList':[{...awardHistory}]
  254. })
  255. }
  256. if(formData.showHistoryList.length==0){
  257. this.setData({
  258. 'formData.showHistoryList':[{...showHistory}]
  259. })
  260. }
  261. //类型 0 个人 2策展
  262. formData.type=type
  263. Promise.all([
  264. this.findByCode('education'),
  265. this.findByCode('education_status')
  266. ]).then((res)=>{
  267. console.log(res);
  268. const EducationPickList=res[0].data.dicInfoList;
  269. const EducationStatePickList=res[1].data.dicInfoList;
  270. this.setData({
  271. EducationPickList:EducationPickList,
  272. EducationStatePickList:EducationStatePickList
  273. },this.getData());
  274. });
  275. //加载保存数据
  276. //this.getData();
  277. },
  278. /**
  279. * 生命周期函数--监听页面初次渲染完成
  280. */
  281. onReady: function () {
  282. },
  283. /**
  284. * 生命周期函数--监听页面显示
  285. */
  286. onShow: function () {
  287. },
  288. getData(){
  289. const {formData}=this.data;
  290. app.post(api.getPersonalSettledInfo).then(res=>{
  291. console.log(res);
  292. const saveData=res.data;
  293. Object.keys(saveData).forEach(key=>{
  294. if(saveData[key]==null){
  295. delete saveData[key]
  296. }
  297. })
  298. const formDataNew=Object.assign(formData,res.data);
  299. this.setData({
  300. formData:formDataNew,
  301. upFileInfo:formDataNew.photoInfo,
  302. referrerFileInfo:formDataNew.referrerFile,
  303. sexPickListValue:formDataNew.sex==1?0:1,
  304. EducationPickValue:formDataNew.highestDegree,
  305. EducationStatePickValue:formDataNew.highestDegreeStatus
  306. });
  307. })
  308. },
  309. saveData() {
  310. const {formData} = this.data;
  311. let flagAward=false;
  312. let flagShow=false;
  313. // 传入表单数据
  314. if (!this.WxValidate.checkForm(formData)) {
  315. const error = this.WxValidate.errorList[0];
  316. wx.showToast({
  317. title: error.msg,
  318. icon: 'none',
  319. duration: 2000
  320. })
  321. return false
  322. }
  323. //验证获奖经历表单
  324. formData.awardHistoryList.forEach(item=>{
  325. if(flagAward){
  326. return
  327. }
  328. if (!this.awardValidate.checkForm(item)) {
  329. const error = this.awardValidate.errorList[0];
  330. wx.showToast({
  331. title: error.msg,
  332. icon: 'none',
  333. duration: 2000
  334. });
  335. flagAward=true;
  336. return false
  337. }
  338. });
  339. if(flagAward){
  340. return
  341. }
  342. //验证展览经历表单
  343. formData.showHistoryList.forEach(item=>{
  344. if(flagShow){
  345. return
  346. }
  347. if (!this.showValidate.checkForm(item)) {
  348. const error = this.showValidate.errorList[0];
  349. wx.showToast({
  350. title: error.msg,
  351. icon: 'none',
  352. duration: 2000
  353. });
  354. flagShow=true;
  355. return false
  356. }
  357. });
  358. if(flagShow){
  359. return
  360. }
  361. app.post(api.addPersonalDetails, formData).then(res => {
  362. console.log(res);
  363. wx.navigateTo({
  364. url:"/pages/user/success/success",
  365. })
  366. /* wx.redirectTo({
  367. url:"/pages/invoice/contract/contract"
  368. })*/
  369. });
  370. },
  371. changeInput(e){
  372. console.log(e);
  373. const id = e.currentTarget.id;
  374. const value = e.detail.value;
  375. this.setData({
  376. [id]: value
  377. });
  378. },
  379. changePicker(e){
  380. console.log(e);
  381. const id = e.currentTarget.id;
  382. const value = e.detail.value;
  383. this.setData({
  384. [id]: value
  385. });
  386. },
  387. /**上传形象**/
  388. chooseFile(){
  389. app.uploadFile({
  390. extension:['jpg','png','jpeg']
  391. }).then(res=>{
  392. console.log(res)
  393. const data=JSON.parse(res.data);
  394. this.setData({
  395. upFileInfo:data,
  396. 'formData.photoId':data.id
  397. })
  398. }).catch(error=>{
  399. console.log(error)
  400. });
  401. },
  402. /**删除形象**/
  403. removeChooseFile(){
  404. this.setData({
  405. upFileInfo:null,
  406. 'formData.photoId':''
  407. })
  408. },
  409. /** 上传推荐信 **/
  410. chooseReferrerFile(){
  411. app.uploadFile({
  412. extension:['jpg','png','jpeg']
  413. }).then(res=>{
  414. console.log(res)
  415. const data=JSON.parse(res.data);
  416. this.setData({
  417. referrerFileInfo:data,
  418. 'formData.referrerFileId':data.id
  419. })
  420. }).catch(error=>{
  421. console.log(error)
  422. });
  423. },
  424. /**删除推荐信**/
  425. removeReferrerFile(){
  426. this.setData({
  427. referrerFileInfo:null,
  428. 'formData.referrerFileId':''
  429. })
  430. },
  431. findByCode(code){
  432. return app.post(api.findByCode,{
  433. "code": code
  434. })
  435. },
  436. /**
  437. * 添加奖励
  438. * */
  439. addAward() {
  440. const awardHistoryList=this.data.formData.awardHistoryList;
  441. awardHistoryList.push(this.data.awardHistory)
  442. this.setData({
  443. 'formData.awardHistoryList':awardHistoryList
  444. })
  445. },
  446. /**
  447. * 删除奖励
  448. * */
  449. removeAward(e) {
  450. const {index}=e.currentTarget.dataset;
  451. const awardHistoryList=this.data.formData.awardHistoryList;
  452. awardHistoryList.splice(index,1);
  453. this.setData({
  454. 'formData.awardHistoryList':awardHistoryList
  455. })
  456. },
  457. /**
  458. * 添加展览记录
  459. * */
  460. addShow() {
  461. const showHistoryList=this.data.formData.showHistoryList;
  462. showHistoryList.push(this.data.showHistory);
  463. this.setData({
  464. 'formData.showHistoryList':showHistoryList
  465. })
  466. },
  467. /**
  468. * 删除展览记录
  469. * */
  470. removeShow(e) {
  471. const {index}=e.currentTarget.dataset;
  472. const showHistoryList=this.data.formData.showHistoryList;
  473. showHistoryList.splice(index,1);
  474. this.setData({
  475. 'formData.showHistoryList':showHistoryList
  476. })
  477. },
  478. /**
  479. *
  480. * */
  481. sexPickHandler(e){
  482. const {value}=e.detail;
  483. const {sexPickList}=this.data;
  484. this.setData({
  485. sexPickListValue:value,
  486. 'formData.sex':sexPickList[value].value
  487. });
  488. },
  489. /**
  490. * 学历picker 选择
  491. * **/
  492. educationPickHandler(e){
  493. const {value}=e.detail;
  494. const {EducationPickList}=this.data;
  495. this.setData({
  496. EducationPickValue:value,
  497. 'formData.highestDegree':EducationPickList[value].code
  498. })
  499. },
  500. /**
  501. * 学历状态picker 选择
  502. * **/
  503. educationStatePickHandler(e){
  504. const {value}=e.detail;
  505. const {EducationStatePickList}=this.data;
  506. this.setData({
  507. EducationStatePickValue:value,
  508. 'formData.highestDegreeStatus':EducationStatePickList[value].code,
  509. })
  510. },
  511. /**
  512. * 生命周期函数--监听页面隐藏
  513. */
  514. onHide: function () {
  515. },
  516. /**
  517. * 生命周期函数--监听页面卸载
  518. */
  519. onUnload: function () {
  520. },
  521. /**
  522. * 页面相关事件处理函数--监听用户下拉动作
  523. */
  524. onPullDownRefresh: function () {
  525. },
  526. /**
  527. * 页面上拉触底事件的处理函数
  528. */
  529. onReachBottom: function () {
  530. },
  531. /**
  532. * 用户点击右上角分享
  533. */
  534. onShareAppMessage: function () {
  535. }
  536. })