index.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. is_local: 1
  17. },
  18. /**
  19. * 授权回调
  20. */
  21. onLoadFun:function(){
  22. this.getUserInfo();
  23. this.imageStorage();
  24. },
  25. /**
  26. * 生命周期函数--监听页面加载
  27. */
  28. onLoad: function (options) {
  29. },
  30. /**
  31. * 获取图片储存位置
  32. */
  33. imageStorage: function () {
  34. var that = this;
  35. app.baseGet(app.U({ c: "user_api", a: 'picture_storage_location' }), function (res) {
  36. that.setData({ is_local: res.data });
  37. });
  38. },
  39. getPhoneNumber:function(e){
  40. var detail = e.detail, cache_key = wx.getStorageSync('cache_key'),that=this;
  41. if (detail.errMsg =='getPhoneNumber:ok'){
  42. if (!cache_key){
  43. app.globalData.token='';
  44. app.globalData.isLog=false;
  45. return false;
  46. }
  47. app.basePost(app.U({ c: 'user_api', a: 'bind_mobile' }), {
  48. iv: detail.iv,
  49. cache_key: cache_key,
  50. encryptedData: detail.encryptedData
  51. },function(res){
  52. that.setData({ 'userInfo.phone': res.data.phone});
  53. return app.Tips({ title: res.msg, icon: 'success' });
  54. },function(res){
  55. return app.Tips({ title: '绑定失败'});
  56. });
  57. }else{
  58. app.Tips({ title:'取消授权'});
  59. }
  60. },
  61. /**
  62. * 获取用户详情
  63. */
  64. getUserInfo:function(){
  65. var that=this;
  66. app.baseGet(app.U({ c: 'user_api', a:'get_my_user_info'}),function(res){
  67. that.setData({userInfo:res.data});
  68. });
  69. },
  70. /**
  71. * 上传文件
  72. *
  73. */
  74. uploadpic: function () {
  75. var that = this;
  76. util.uploadImageOne(app.U({ c: 'public_api', a: 'upload' }), function (res) {
  77. if (that.data.is_local == 1) {
  78. that.setData({ 'userInfo.avatar': app.globalData.url + res.data.url });
  79. } else {
  80. that.setData({ 'userInfo.avatar': res.data.url });
  81. }
  82. });
  83. },
  84. /**
  85. * 提交修改
  86. */
  87. formSubmit:function(e){
  88. var that = this, value = e.detail.value, formId = e.detail.formId;
  89. if (!value.nickname) return app.Tips({title:'用户姓名不能为空'});
  90. value.avatar = that.data.userInfo.avatar;
  91. app.basePost(app.U({ c: 'user_api', a: 'edit_user' }), value,function(res){
  92. return app.Tips({title:res.msg,icon:'success'},{tab:3,url:1});
  93. },function(res){
  94. return app.Tips({title:res.msg || '保存失败,您并没有修改'},{tab:3,url:1});
  95. });
  96. },
  97. })