index.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. var app = getApp();
  2. const util = require('../../utils/util.js');
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. parameter: {
  9. 'navbar': '1',
  10. 'return': '1',
  11. 'title': '个人资料',
  12. 'color': true,
  13. 'class': '0'
  14. },
  15. userInfo:{},
  16. },
  17. /**
  18. * 授权回调
  19. */
  20. onLoadFun:function(){
  21. this.getUserInfo();
  22. },
  23. /**
  24. * 生命周期函数--监听页面加载
  25. */
  26. onLoad: function (options) {
  27. },
  28. getPhoneNumber:function(e){
  29. var detail = e.detail, cache_key = wx.getStorageSync('cache_key'),that=this;
  30. if (detail.errMsg =='getPhoneNumber:ok'){
  31. if (!cache_key){
  32. app.globalData.token='';
  33. app.globalData.isLog=false;
  34. return false;
  35. }
  36. app.basePost(app.U({ c: 'user_api', a: 'bind_mobile' }), {
  37. iv: detail.iv,
  38. cache_key: cache_key,
  39. encryptedData: detail.encryptedData
  40. },function(res){
  41. that.setData({ 'userInfo.phone': res.data.phone});
  42. return app.Tips({ title: res.msg, icon: 'success' });
  43. },function(res){
  44. return app.Tips({ title: '绑定失败'});
  45. });
  46. }else{
  47. app.Tips({ title:'取消授权'});
  48. }
  49. },
  50. /**
  51. * 获取用户详情
  52. */
  53. getUserInfo:function(){
  54. var that=this;
  55. app.baseGet(app.U({ c: 'user_api', a:'get_my_user_info'}),function(res){
  56. that.setData({userInfo:res.data});
  57. });
  58. },
  59. /**
  60. * 上传文件
  61. *
  62. */
  63. uploadpic: function () {
  64. var that = this;
  65. util.uploadImageOne(app.U({ c: 'public_api', a: 'upload' }), function (res) {
  66. that.setData({ 'userInfo.avatar': app.globalData.url +res.data.url });
  67. });
  68. },
  69. /**
  70. * 提交修改
  71. */
  72. formSubmit:function(e){
  73. var that = this, value = e.detail.value, formId = e.detail.formId;
  74. if (!value.nickname) return app.Tips({title:'用户姓名不能为空'});
  75. value.avatar = that.data.userInfo.avatar;
  76. app.basePost(app.U({ c: 'user_api', a: 'edit_user' }), value,function(res){
  77. return app.Tips({title:res.msg,icon:'success'},{tab:3,url:1});
  78. },function(res){
  79. return app.Tips({title:res.msg || '保存失败,您并没有修改'},{tab:3,url:1});
  80. });
  81. },
  82. })