personalInfo.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651
  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. cnAndEg: true
  77. },
  78. artistName:{
  79. required: true,
  80. cnAndEg: true
  81. },
  82. sex:{
  83. required: true,
  84. },
  85. birthday:{
  86. required: true,
  87. },
  88. // nationality:{
  89. // required: true,
  90. // },
  91. // referrerName:{
  92. // required: true,
  93. // },
  94. // referrerPosition:{
  95. // required: true,
  96. // },
  97. // referrerFileId:{
  98. // required: true,
  99. // },
  100. mobile: {
  101. required: true,
  102. tel:true,
  103. },
  104. email: {
  105. required: true,
  106. email:true,
  107. },
  108. /* address:{
  109. required: true,
  110. },
  111. weixinNo:{
  112. required: true,
  113. },*/
  114. highestDegreeOrg:{
  115. required: true
  116. },
  117. highestDegreeStartTime:{
  118. required: true
  119. },
  120. highestDegreeEndTime:{
  121. required: true
  122. },
  123. highestDegree:{
  124. required: true
  125. },
  126. highestDegreeStatus:{
  127. required: true
  128. }
  129. },
  130. awardRules:{
  131. organ:{
  132. required: true,
  133. },
  134. prize:{
  135. required: true,
  136. },
  137. time:{
  138. required: true,
  139. },
  140. },
  141. awardMessages:{
  142. organ:{
  143. required:'请输入奖项名称'
  144. },
  145. prize:{
  146. required:'请输入奖项机构'
  147. },
  148. time:{
  149. required:'请输入获奖时间'
  150. }
  151. },
  152. showRules:{
  153. name:{
  154. required: true,
  155. },
  156. organ:{
  157. required: true,
  158. },
  159. time:{
  160. required: true,
  161. },
  162. },
  163. showMessages:{
  164. name:{
  165. required: '请输入展展览名称',
  166. },
  167. organ:{
  168. required: '请输入展展览机构',
  169. },
  170. time:{
  171. required: '请输入展览时间',
  172. },
  173. },
  174. messages: {
  175. photoId:{
  176. required: '请上传个人形象照',
  177. },
  178. name:{
  179. required: '请输入姓名',
  180. cnAndEg: '只能输入英文和中文'
  181. },
  182. artistName:{
  183. required: '请输入艺名',
  184. cnAndEg: '只能输入英文和中文'
  185. },
  186. sex:{
  187. required: '请选择性别',
  188. },
  189. birthday:{
  190. required: '请选择出生日期',
  191. },
  192. nationality:{
  193. required: '请选择国籍',
  194. },
  195. // referrerName:{
  196. // required: '请输入推荐人姓名',
  197. // },
  198. // referrerPosition:{
  199. // required: '请输入推荐人职业',
  200. // },
  201. // referrerFileId:{
  202. // required: '请上传推荐信',
  203. // },
  204. mobile: {
  205. required: '请输入手机号',
  206. tel:"请输入正确的手机号"
  207. },
  208. email: {
  209. required: '请输入邮箱地址',
  210. tel:"请输入正确的邮箱"
  211. },
  212. address:{
  213. required: '请输入地址',
  214. },
  215. weixinNo:{
  216. required: '请输入微信号',
  217. },
  218. highestDegreeOrg:{
  219. required: '请输入最高学历机构'
  220. },
  221. highestDegreeStartTime:{
  222. required: '请输入最高学历开始时间'
  223. },
  224. highestDegreeEndTime:{
  225. required: '请输入最高学历结束时间'
  226. },
  227. highestDegree:{
  228. required: '请选择最高学历',
  229. },
  230. highestDegreeStatus:{
  231. required: '请选择最高学历状态'
  232. }
  233. },
  234. isValidate:false,
  235. isSubmit:false
  236. },
  237. /**
  238. * 生命周期函数--监听页面加载
  239. */
  240. onLoad: function (options) {
  241. const type=options.type||0
  242. const {
  243. formData,
  244. rules,
  245. messages,
  246. showHistory,
  247. awardHistory,
  248. awardRules,
  249. awardMessages,
  250. showRules,
  251. showMessages
  252. }
  253. = this.data;
  254. this.WxValidate = new WxValidate(rules, messages);
  255. this.awardValidate = new WxValidate(awardRules, awardMessages);
  256. this.showValidate = new WxValidate(showRules, showMessages);
  257. if(formData.awardHistoryList.length==0){
  258. this.setData({
  259. 'formData.awardHistoryList':[{...awardHistory}]
  260. })
  261. }
  262. if(formData.showHistoryList.length==0){
  263. this.setData({
  264. 'formData.showHistoryList':[{...showHistory}]
  265. })
  266. }
  267. //类型 0 个人 2策展
  268. formData.type=type
  269. Promise.all([
  270. this.findByCode('education'),
  271. this.findByCode('education_status')
  272. ]).then((res)=>{
  273. const EducationPickList=res[0].data.dicInfoList;
  274. const EducationStatePickList=res[1].data.dicInfoList;
  275. this.setData({
  276. EducationPickList:EducationPickList,
  277. EducationStatePickList:EducationStatePickList
  278. },()=>{
  279. //加载保存数据
  280. /** todo 更新数据 **/
  281. //this.getData();
  282. });
  283. });
  284. },
  285. /**
  286. * 生命周期函数--监听页面初次渲染完成
  287. */
  288. onReady: function () {
  289. },
  290. /**
  291. * 生命周期函数--监听页面显示
  292. */
  293. onShow: function () {
  294. },
  295. getData(){
  296. const {formData}=this.data;
  297. app.post(api.getPersonalSettledInfo).then(res=>{
  298. console.log(res);
  299. const saveData=res.data;
  300. Object.keys(saveData).forEach(key=>{
  301. if(saveData[key]==null){
  302. delete saveData[key]
  303. }
  304. })
  305. const formDataNew=Object.assign(formData,res.data);
  306. formDataNew.photoId=formDataNew.photoInfo?formDataNew.photoInfo.id:"";
  307. formDataNew.referrerFileId=formDataNew.referrerFile?formDataNew.referrerFile.id:"";
  308. this.setData({
  309. formData:formDataNew,
  310. upFileInfo:formDataNew.photoInfo,
  311. referrerFileInfo:formDataNew.referrerFile,
  312. sexPickListValue:formDataNew.sex==1?0:1,
  313. EducationPickValue:formDataNew.highestDegree,
  314. EducationStatePickValue:formDataNew.highestDegreeStatus
  315. },()=>{
  316. this.validateForm()
  317. });
  318. });
  319. },
  320. validateForm(showInfo=false){
  321. // 传入表单数据
  322. const {formData} = this.data;
  323. let flag=true;
  324. // let flagAward=false;
  325. // let flagShow=false;
  326. if (!this.WxValidate.checkForm(formData)) {
  327. flag=false
  328. if(showInfo===true) {
  329. const error = this.WxValidate.errorList[0];
  330. wx.showToast({
  331. title: error.msg,
  332. icon: 'none',
  333. duration: 2000
  334. })
  335. }
  336. }
  337. this.setData({
  338. isValidate:flag
  339. });
  340. return flag
  341. /*//验证获奖经历表单
  342. formData.awardHistoryList.forEach(item=>{
  343. if(flagAward){
  344. return
  345. }
  346. if (!this.awardValidate.checkForm(item)) {
  347. const error = this.awardValidate.errorList[0];
  348. wx.showToast({
  349. title: error.msg,
  350. icon: 'none',
  351. duration: 2000
  352. });
  353. flagAward=true;
  354. return false
  355. }
  356. });
  357. if(flagAward){
  358. return
  359. }
  360. //验证展览经历表单
  361. formData.showHistoryList.forEach(item=>{
  362. if(flagShow){
  363. return
  364. }
  365. if (!this.showValidate.checkForm(item)) {
  366. const error = this.showValidate.errorList[0];
  367. wx.showToast({
  368. title: error.msg,
  369. icon: 'none',
  370. duration: 2000
  371. });
  372. flagShow=true;
  373. return false
  374. }
  375. });
  376. if(flagShow){
  377. return
  378. }*/
  379. },
  380. saveData() {
  381. const {formData,isSubmit} = this.data;
  382. if(isSubmit){
  383. return
  384. }
  385. let flag=this.validateForm(true);
  386. if(!flag){
  387. return;
  388. }
  389. const submit=function(){
  390. this.setData({
  391. isSubmit:true
  392. })
  393. app.post(api.addPersonalDetails, formData).then(res => {
  394. console.log(res);
  395. this.setData({
  396. isSubmit:false,
  397. });
  398. wx.navigateTo({
  399. url:`/pages/user/success/success?type=${formData.type}`,
  400. })
  401. }).catch(()=>{
  402. this.setData({
  403. isSubmit:false
  404. })
  405. })
  406. }.bind(this);
  407. //策展入驻增加消息订阅
  408. if(formData.type==2){
  409. wx.requestSubscribeMessage({
  410. tmplIds: [
  411. 'EnF59db6rv1QhwUc67GuKNQBw-R-VZNAB5xVXyP40A4',
  412. ],
  413. success: (res)=> {
  414. submit()
  415. }
  416. });
  417. }else{
  418. submit()
  419. }
  420. },
  421. changeInput(e){
  422. console.log(e);
  423. const id = e.currentTarget.id;
  424. const value = e.detail.value;
  425. this.setData({
  426. [id]: value
  427. });
  428. },
  429. changePicker(e){
  430. console.log(e);
  431. const id = e.currentTarget.id;
  432. const value = e.detail.value;
  433. this.setData({
  434. [id]: value
  435. });
  436. },
  437. /**上传形象**/
  438. chooseFile(){
  439. app.uploadFile({
  440. extension:['jpg','png','jpeg'],
  441. validate:(imgInfo)=>{
  442. console.log('validate',imgInfo)
  443. return true;
  444. // if(imgInfo.width&&imgInfo.height){
  445. // const ratio=imgInfo.width/imgInfo.height;
  446. // if(ratio>0.99&ratio<1.1){
  447. // return true
  448. // }else{
  449. // wx.showToast({
  450. // title:"请上传长宽比为1:1的图片",
  451. // icon:"none",
  452. // duration:2000,
  453. // })
  454. // return false
  455. // }
  456. // }else{
  457. // wx.showToast({
  458. // title:"图片信息错误",
  459. // icon:"none",
  460. // duration:2000,
  461. // })
  462. // return false
  463. // }
  464. }
  465. }).then(res=>{
  466. console.log(res)
  467. const data=JSON.parse(res.data);
  468. this.setData({
  469. upFileInfo:data,
  470. 'formData.photoId':data.id,
  471. })
  472. }).catch(error=>{
  473. console.log(error)
  474. });
  475. },
  476. /**删除形象**/
  477. removeChooseFile(){
  478. this.setData({
  479. upFileInfo:null,
  480. 'formData.photoId':''
  481. })
  482. },
  483. /** 上传推荐信 **/
  484. chooseReferrerFile(){
  485. app.uploadFile({
  486. extension:['jpg','png','jpeg']
  487. }).then(res=>{
  488. console.log(res)
  489. const data=JSON.parse(res.data);
  490. this.setData({
  491. referrerFileInfo:data,
  492. 'formData.referrerFileId':data.id
  493. })
  494. }).catch(error=>{
  495. console.log(error)
  496. });
  497. },
  498. /**删除推荐信**/
  499. removeReferrerFile(){
  500. this.setData({
  501. referrerFileInfo:null,
  502. 'formData.referrerFileId':''
  503. })
  504. },
  505. findByCode(code){
  506. return app.post(api.findByCode,{
  507. "code": code
  508. })
  509. },
  510. /**
  511. * 添加奖励
  512. * */
  513. addAward() {
  514. const awardHistoryList=this.data.formData.awardHistoryList;
  515. awardHistoryList.push(this.data.awardHistory)
  516. this.setData({
  517. 'formData.awardHistoryList':awardHistoryList
  518. })
  519. },
  520. /**
  521. * 删除奖励
  522. * */
  523. removeAward(e) {
  524. const {index}=e.currentTarget.dataset;
  525. const awardHistoryList=this.data.formData.awardHistoryList;
  526. awardHistoryList.splice(index,1);
  527. this.setData({
  528. 'formData.awardHistoryList':awardHistoryList
  529. })
  530. },
  531. /**
  532. * 添加展览记录
  533. * */
  534. addShow() {
  535. const showHistoryList=this.data.formData.showHistoryList;
  536. showHistoryList.push(this.data.showHistory);
  537. this.setData({
  538. 'formData.showHistoryList':showHistoryList
  539. })
  540. },
  541. /**
  542. * 删除展览记录
  543. * */
  544. removeShow(e) {
  545. const {index}=e.currentTarget.dataset;
  546. const showHistoryList=this.data.formData.showHistoryList;
  547. showHistoryList.splice(index,1);
  548. this.setData({
  549. 'formData.showHistoryList':showHistoryList
  550. })
  551. },
  552. /**
  553. *
  554. * */
  555. sexPickHandler(e){
  556. const {value}=e.detail;
  557. const {sexPickList}=this.data;
  558. this.setData({
  559. sexPickListValue:value,
  560. 'formData.sex':sexPickList[value].value
  561. },()=>{
  562. this.validateForm()
  563. });
  564. },
  565. /**
  566. * 学历picker 选择
  567. * **/
  568. educationPickHandler(e){
  569. const {value}=e.detail;
  570. const {EducationPickList}=this.data;
  571. this.setData({
  572. EducationPickValue:value,
  573. 'formData.highestDegree':EducationPickList[value].code
  574. },()=>{
  575. this.validateForm()
  576. })
  577. },
  578. /**
  579. * 学历状态picker 选择
  580. * **/
  581. educationStatePickHandler(e){
  582. const {value}=e.detail;
  583. const {EducationStatePickList}=this.data;
  584. this.setData({
  585. EducationStatePickValue:value,
  586. 'formData.highestDegreeStatus':EducationStatePickList[value].code,
  587. },()=>{
  588. this.validateForm()
  589. })
  590. },
  591. /**
  592. * 生命周期函数--监听页面隐藏
  593. */
  594. onHide: function () {
  595. },
  596. /**
  597. * 生命周期函数--监听页面卸载
  598. */
  599. onUnload: function () {
  600. },
  601. /**
  602. * 页面相关事件处理函数--监听用户下拉动作
  603. */
  604. onPullDownRefresh: function () {
  605. },
  606. /**
  607. * 页面上拉触底事件的处理函数
  608. */
  609. onReachBottom: function () {
  610. },
  611. /**
  612. * 用户点击右上角分享
  613. */
  614. onShareAppMessage: function () {
  615. }
  616. })