membercenter.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. import common from '../../utils/util';
  2. import server from '../../utils/main';
  3. const app = getApp();
  4. Page({
  5. data: {
  6. IsAccredit:false,
  7. },
  8. onLoad: function (options) {
  9. var member="非会员";
  10. if (app.globalData.userInfo.IsMember==1)
  11. member = "付费会员";
  12. this.setData({
  13. Height: common.getSystemHeight(),
  14. Member: member,
  15. });
  16. this.init();
  17. },
  18. init:function(){
  19. var that = this;
  20. server.getData('GetWXUsersAllTime?ProductID=' + app.globalData.ProgramID+'&UserID=' + app.globalData.userInfo.UserID, function (data) {
  21. if (data) {
  22. for(var i=0;i<data.length;i++){
  23. if (data[i].ID==app.globalData.ProgramID){
  24. if (that.data.Member=="非会员"){
  25. data[i].Time = common.formatDateCHS(app.globalData.userInfo.CreateTime);
  26. }
  27. }
  28. }
  29. that.setData({
  30. ProductList: data,
  31. });
  32. }
  33. });
  34. wx.getSetting({
  35. success(res) {
  36. if (res.authSetting['scope.userInfo']) {
  37. that.setData({
  38. IsAccredit: true,
  39. });
  40. }
  41. }
  42. });
  43. },
  44. gotoPaylist:function(){
  45. var that=this;
  46. wx.getSetting({
  47. success(res) {
  48. if (res.authSetting['scope.userInfo']) {
  49. wx.navigateTo({
  50. url: '../about/paylist',
  51. });
  52. }
  53. else{
  54. that.getAccredit();
  55. }
  56. }
  57. });
  58. },
  59. getAccredit: function () {
  60. if (!this.data.IsAccredit) {
  61. var that = this;
  62. wx.getSetting({
  63. success(res) {
  64. if (!res.authSetting['scope.userInfo']) {
  65. wx.authorize({
  66. scope: 'scope.userInfo',
  67. success() {
  68. that.getUserInfo();
  69. },
  70. fail() {
  71. wx.openSetting({
  72. success(res) {
  73. that.getUserInfo();
  74. }
  75. });
  76. }
  77. })
  78. }
  79. }
  80. })
  81. }
  82. },
  83. //得到用户信息
  84. getUserInfo: function () {
  85. var that = this
  86. //调用登录接口
  87. wx.login({
  88. success: function (res0) {
  89. wx.getUserInfo({
  90. withCredentials: true,
  91. success: function (res) {
  92. var userID = app.globalData.userInfo.UserID;
  93. app.globalData.userInfo = res.userInfo;
  94. app.globalData.userInfo.UserID = userID;
  95. app.globalData.userInfo.NickName = app.globalData.userInfo.nickName;
  96. app.globalData.userInfo.AvatarUrl = app.globalData.userInfo.avatarUrl;
  97. // that.hasGetShareInfo(app.globalData.userInfo);
  98. that.setData({
  99. IsAccredit: true,
  100. NickName: app.globalData.userInfo.NickName,
  101. AvatarUrl: app.globalData.userInfo.AvatarUrl
  102. });
  103. app.globalData.userInfo.Code = res0.code;
  104. app.globalData.userInfo.iv = res.iv;
  105. app.globalData.userInfo.encryptedData = res.encryptedData;
  106. that.login(app.globalData.userInfo);
  107. },
  108. fail: function (res) {
  109. }
  110. });
  111. },
  112. fail: function () {
  113. }
  114. });
  115. },
  116. login: function (param) {
  117. var that = this;
  118. server.postData('HanziLogin', {
  119. Code: param.Code,
  120. NickName: param.nickName,
  121. Language: param.language,
  122. Gender: param.gender,
  123. City: param.city,
  124. Province: param.province,
  125. Country: param.country,
  126. AvatarUrl: param.avatarUrl,
  127. ProgramVersion: app.globalData.Version,
  128. Introducer: app.globalData.introducer,
  129. UserSource: app.globalData.userSource,
  130. SourceID: app.globalData.SourceID,
  131. LastUserSource: app.globalData.userSource,
  132. iv: param.iv,
  133. encryptedData: param.encryptedData,
  134. }, function (data) {
  135. });
  136. },
  137. })