accredit.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. import common from '../../utils/util';
  2. import main from '../../utils/main';
  3. const app = getApp();
  4. var urlRedirectTo = "";
  5. Page({
  6. data: {
  7. ShowNotice: false,
  8. },
  9. onLoad: function (options) {
  10. urlRedirectTo = options.url;
  11. this.setData({
  12. Containnerheight: main.getWindowHeight(),
  13. IsShow: app.globalData.userInfo.IsShow,
  14. });
  15. this.init();
  16. if (!app.globalData.userInfo)
  17. app.globalData.userInfo = {};
  18. },
  19. init: function () {
  20. var that = this;
  21. main.getData("GetAccreditInfo?IsShow=" + app.globalData.userInfo.IsShow, function (data) {
  22. that.setData({
  23. Info: data,
  24. });
  25. });
  26. },
  27. goto: function () {
  28. var that = this;
  29. wx.getSetting({
  30. success(res) {
  31. if (!res.authSetting['scope.userInfo']) {
  32. wx.authorize({
  33. scope: 'scope.userInfo',
  34. success() {
  35. that.getUserInfo();
  36. },
  37. })
  38. } else {
  39. that.getUserInfo();
  40. }
  41. }
  42. });
  43. },
  44. //得到用户信息
  45. getUserInfo: function () {
  46. var that = this
  47. wx.getUserProfile({
  48. desc: "沟通需要",
  49. success: function (res2) {
  50. app.globalData.userInfo.NickName = res2.userInfo.nickName;
  51. app.globalData.userInfo.AvatarUrl = res2.userInfo.avatarUrl;
  52. //调用登录接口
  53. wx.login({
  54. success: function (res0) {
  55. // wx.getUserInfo({
  56. // withCredentials: true,
  57. // success: function (res) {
  58. app.globalData.userInfo.Code = res0.code;
  59. // app.globalData.userInfo.iv = res.iv;
  60. // app.globalData.userInfo.encryptedData = res.encryptedData;
  61. that.login(app.globalData.userInfo, res2.userInfo);
  62. // },
  63. // fail: function (res) {
  64. // that.gotoReturn();
  65. // }
  66. // });
  67. }
  68. });
  69. },
  70. fail: function (res) {
  71. console.log(res);
  72. }
  73. });
  74. },
  75. login: function (param, param2) {
  76. var that = this;
  77. var url = "MiaoguoLogin";
  78. main.postData(url, {
  79. Code: param.Code,
  80. NickName: param2.nickName,
  81. AvatarUrl: param2.avatarUrl,
  82. Language: param2.language,
  83. Gender: param2.gender,
  84. City: param2.city,
  85. Province: param2.province,
  86. Country: param2.country,
  87. ProgramVersion: app.globalData.Version,
  88. Introducer: app.globalData.introducer,
  89. UserSource: app.globalData.userSource,
  90. SourceID: app.globalData.SourceID,
  91. LastUserSource: app.globalData.userSource,
  92. iv: param.iv,
  93. encryptedData: param.encryptedData,
  94. }, function (data) {
  95. app.globalData.userInfo.NickName = data.NickName;
  96. app.globalData.userInfo.AvatarUrl = data.AvatarUrl;
  97. app.globalData.userInfo.Language = data.Language;
  98. app.globalData.userInfo.Gender = data.Gender;
  99. app.globalData.userInfo.City = data.City;
  100. app.globalData.userInfo.Province = data.Province;
  101. app.globalData.userInfo.Country = data.Country;
  102. app.globalData.userInfo.IsMember = data.IsMember;
  103. if (app.globalData.userInfo.UserID)
  104. main.buildInitData(function () {
  105. that.gotoReturn();
  106. });
  107. else {
  108. app.globalData.userInfo.UserID = data.UserID;
  109. that.gotoReturn();
  110. }
  111. });
  112. },
  113. gotoReturn: function () {
  114. wx.navigateBack({
  115. delta: 1
  116. });
  117. },
  118. onShareAppMessage: function () {
  119. return {
  120. title: app.globalData.ShareTitle,
  121. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  122. imageUrl: app.globalData.ShareImage,
  123. }
  124. },
  125. })