account.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. const util = require('../../utils/util.js');
  2. const app = getApp();
  3. Page({
  4. data: {
  5. userInfo: app.globalData.userInfo,
  6. config: util.config,
  7. isWallet: 0,
  8. isGrowup: 0,
  9. stat: {},
  10. levelName: '普通',
  11. flag: "",
  12. isShow: "1",
  13. tabbar: {}
  14. },
  15. onLoad(options) {
  16. app.editTabbar();
  17. let info = wx.getStorageSync('WXuserInfo')
  18. console.log(info);
  19. if (!info) {
  20. this.logion()
  21. }
  22. console.log(options);
  23. if (options.flags) {
  24. this.setData({
  25. flag: "false"
  26. })
  27. } else {
  28. this.setData({
  29. flag: ""
  30. })
  31. }
  32. // this.updateUserInfo();
  33. },
  34. onUnload(e) {
  35. console.log(e);
  36. this.setData({
  37. flag: "true"
  38. })
  39. },
  40. onShow() {
  41. this.setData({ userInfo: app.globalData.userInfo });
  42. if (this.data.isShow == "1") {
  43. this.updateUserInfo()
  44. }
  45. // this.updateUserInfo();
  46. },
  47. // 跳转至宝贝币中心
  48. jumpPage() {
  49. if (this.data.userInfo) {
  50. wx.navigateTo({
  51. url: '/pages/account/monetaryCenter/index',
  52. })
  53. }
  54. },
  55. isWallet: function () {
  56. let that = this, userInfo = app.globalData.userInfo;
  57. util.ajax({
  58. func: "v2/user/showCoin",
  59. data: { "rid": userInfo ? userInfo['rid'] : '' },
  60. load: false
  61. }, function (res) {
  62. if (res.code == 0) {
  63. that.setData({ isWallet: parseInt(res.data) });
  64. }
  65. }, false);
  66. },
  67. stat() {
  68. let that = this;
  69. util.stat().then(res => {
  70. let data = util.getCoinLevel(res.allCoin)
  71. that.setData({ stat: res, levelName: data.levelName });
  72. })
  73. },
  74. isGrowupCard: function () {
  75. let that = this, userInfo = app.globalData.userInfo;
  76. util.ajax({
  77. func: "v2/user/growthCard/center",
  78. data: { "rid": userInfo ? userInfo['rid'] : '' },
  79. load: false
  80. }, function (res) {
  81. if (res.code == 0) {
  82. that.setData({ isGrowup: res.data });
  83. }
  84. }, false);
  85. },
  86. updateUserInfo() {
  87. let that = this
  88. let self = this, userInfo = app.globalData.userInfo;
  89. console.log(userInfo);
  90. if (util.isObjEmpty(userInfo)) return false;
  91. util.ajax({
  92. func: "user/stat_info",
  93. load: false
  94. }, function (res) {
  95. console.log(res.data);
  96. if (res.code == 0 && res.data) {
  97. if (self.data.flag == "false") {
  98. if (res.data.roleType == "sharer") {
  99. wx.navigateTo({
  100. url: `/pages/sharingHome/index?organStatus=${2}`,
  101. })
  102. } else if (res.data.roleType == "organ") {
  103. wx.navigateTo({
  104. url: `/pages/sharingHome/index?organStatus=${1}`,
  105. })
  106. } else {
  107. wx.navigateTo({
  108. url: '/pages/public/swiper/web?url=https://mp.weixin.qq.com/s/H8WuXW_VeCeWtxQXFBGu2Q&title=宝贝走天下',
  109. })
  110. }
  111. that.setData({
  112. isShow: "2"
  113. })
  114. }
  115. self.isWallet();
  116. self.isGrowupCard();
  117. self.stat();
  118. res.data.score = Math.round(res.data.score);
  119. userInfo['role'] = util.userRole(res.data.score);
  120. userInfo['score'] = res.data.score;
  121. userInfo['coin'] = res.data.coin;
  122. userInfo['membered'] = res.data.membered;
  123. userInfo['roleType'] = res.data.roleType || 'normal';
  124. userInfo['roleTypeDisable'] = res.data.roleTypeDisable || 0;
  125. userInfo['babyCoin'] = util.toMoney(res.data.coin, ",");
  126. userInfo['weixin'] = res.data.weixin || 0;
  127. app.globalData.userInfo = userInfo;
  128. wx.setStorageSync("WXuserInfo", userInfo);
  129. self.setData({ userInfo });
  130. console.log(self.data.flag);
  131. }
  132. });
  133. },
  134. navigatorURl(e) {
  135. let self = this;
  136. // if (e.currentTarget.dataset.url == '/pages/account/growthCourse/index') {
  137. // util.ajax({
  138. // func: "v2/gwcourse/isAttended"
  139. // }, function (res) {
  140. // if (res.code == 0) {
  141. // if (res.data ==1) {
  142. // util.navigator(e.currentTarget.dataset.url);
  143. // }else{
  144. // wx.showModal({
  145. // content: '购买成长课活动后才可预约成长课',
  146. // showCancel:false,
  147. // success (res) {
  148. // if (res.confirm) {
  149. // console.log('用户点击确定')
  150. // }
  151. // }
  152. // })
  153. // }
  154. // } else{
  155. // util.showTips(res.reason);
  156. // }
  157. // });
  158. // }else{
  159. // util.navigator(e.currentTarget.dataset.url);
  160. // }
  161. util.navigator(e.currentTarget.dataset.url);
  162. },
  163. logion() {
  164. let that = this
  165. util.silentLogin().then(res => {
  166. that.setData({
  167. userInfo: app.globalData.userInfo
  168. })
  169. })
  170. },
  171. copy(e) {
  172. let code = e.currentTarget.dataset.code;
  173. wx.setClipboardData({
  174. data: code
  175. });
  176. },
  177. logout() {
  178. let self = this;
  179. wx.showModal({
  180. content: '确定登出吗?',
  181. success: function (res) {
  182. if (res.confirm) {
  183. util.ajax({
  184. func: "login_out"
  185. }, function (res) {
  186. if (res.code == 0) {
  187. wx.removeStorageSync("WXuserInfo");
  188. wx.removeStorageSync("nps");
  189. app.globalData.userInfo = null;
  190. self.setData({ userInfo: app.globalData.userInfo, isGrowup: 0, isWallet: 0, stat: {} });
  191. } else
  192. util.showTips(res.reason);
  193. });
  194. }
  195. }
  196. });
  197. },
  198. onShareAppMessage() {
  199. return {
  200. title: '个人中心-我的信息',
  201. path: '/pages/home/account'
  202. }
  203. }
  204. })