home.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. const app = getApp();
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. userInfo:{},
  8. getUserInfo: false,
  9. },
  10. /**
  11. * 生命周期函数--监听页面加载
  12. */
  13. onShow: function () {
  14. this.setData({
  15. userInfo: app.globalData.userInfo
  16. })
  17. if (wx.getUserProfile) {
  18. this.setData({
  19. getUserInfo: true
  20. })
  21. }
  22. },
  23. /**
  24. * 页面相关事件处理函数--监听用户下拉动作
  25. */
  26. onPullDownRefresh: function () {
  27. wx.stopPullDownRefresh();
  28. },
  29. /**
  30. * 页面上拉触底事件的处理函数
  31. */
  32. onReachBottom: function () {
  33. },
  34. /**
  35. * 用户点击右上角分享
  36. */
  37. onShareAppMessage: function () {
  38. return {
  39. title: "晋爱人才",
  40. path: "/pages/home/home/home",
  41. };
  42. },
  43. getUserInfo: function(e) {
  44. let self = this;
  45. let userInfo = app.globalData.userInfo ? app.globalData.userInfo : {};
  46. app.post('user/profile/userInfo',{user_nickname:e.detail.userInfo.nickName,avatar:e.detail.userInfo.avatarUrl},function(res){
  47. userInfo.user_nickname = e.detail.userInfo.nickName;
  48. userInfo.avatar = e.detail.userInfo.avatarUrl;
  49. app.globalData.userInfo = userInfo;
  50. self.setData({userInfo:userInfo});
  51. });
  52. },
  53. getUserProfile: function(e) {
  54. let self = this;
  55. wx.getUserProfile({
  56. desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  57. success: (e) => {
  58. let userInfo = app.globalData.userInfo ? app.globalData.userInfo : {};
  59. app.post('user/profile/userInfo',{user_nickname:e.userInfo.nickName,avatar:e.userInfo.avatarUrl},function(res){
  60. userInfo.user_nickname = e.userInfo.nickName;
  61. userInfo.avatar = e.userInfo.avatarUrl;
  62. app.globalData.userInfo = userInfo;
  63. self.setData({userInfo:userInfo});
  64. });
  65. }
  66. })
  67. },
  68. uploadAvatar(e) {
  69. let self = this;
  70. const { avatarUrl } = e.detail;
  71. wx.showLoading({
  72. mask: true,
  73. });
  74. var token = wx.getStorageSync('token');
  75. wx.uploadFile({
  76. url: app.globalData.api_host + 'user/profile/avatarUpload',
  77. filePath: avatarUrl,
  78. name: 'file',
  79. header: { 'X-Requested-With': 'XMLHttpRequest' , 'XX-Device-Type': 'wxapp' , 'XX-Token': token},
  80. success(res) {
  81. var json = JSON.parse(res.data)
  82. if (json.code == 1) {
  83. wx.hideLoading();
  84. self.setData({"userInfo.avatar": json.data});
  85. app.globalData.userInfo = self.data.userInfo;
  86. } else {
  87. wx.showToast({
  88. title: '上传失败,请重试',
  89. icon: 'none'
  90. });
  91. }
  92. },
  93. fail() {
  94. wx.showToast({
  95. title: '上传失败,请重试',
  96. icon: 'none'
  97. });
  98. }
  99. });
  100. },
  101. //跳转
  102. toInfo() {
  103. if (!this.data.userInfo.user_nickname) {
  104. app.msg('请先授权登录');
  105. } else {
  106. wx.navigateTo({
  107. url: '/pages/my/info/info',
  108. })
  109. }
  110. },
  111. toJoin() {
  112. if (!this.data.userInfo.user_nickname) {
  113. app.msg('请先授权登录');
  114. } else {
  115. wx.navigateTo({
  116. url: '/pages/my/join/join',
  117. })
  118. }
  119. },
  120. toBaidu() {
  121. wx.navigateTo({
  122. url: '/pages/home/webview/webview',
  123. })
  124. },
  125. toFeedback() {
  126. if (!this.data.userInfo.user_nickname) {
  127. app.msg('请先授权登录');
  128. } else {
  129. wx.navigateTo({
  130. url: '/pages/my/feedback/feedback',
  131. })
  132. }
  133. },
  134. toRob() {
  135. if (!this.data.userInfo.user_nickname) {
  136. app.msg('请先授权登录');
  137. } else {
  138. wx.navigateTo({
  139. url: '/pages/my/rob/rob',
  140. })
  141. }
  142. },
  143. toBind() {
  144. if (!this.data.userInfo.user_nickname) {
  145. app.msg('请先授权登录');
  146. } else {
  147. wx.navigateTo({
  148. url: '/pages/my/bind/bind',
  149. })
  150. }
  151. },
  152. toScore() {
  153. if (!this.data.userInfo.user_nickname) {
  154. app.msg('请先授权登录');
  155. } else {
  156. wx.navigateTo({
  157. url: '/pages/my/score/score',
  158. })
  159. }
  160. },
  161. //扫码
  162. scan() {
  163. if (!this.data.userInfo.user_nickname) {
  164. app.msg('请先授权登录');
  165. return false;
  166. }
  167. let self = this;
  168. wx.scanCode({
  169. success ({result}) {
  170. let arr = result.split(':');
  171. console.log(arr);
  172. if (arr[0] == 'signin') {
  173. self.signin(arr[1]);
  174. } else if (arr[0] == 'business') {
  175. self.business(arr[1]);
  176. } else {
  177. app.msg('未知二维码!');
  178. }
  179. },
  180. fail(res) {
  181. if (res.errMsg != "scanCode:fail cancel") {
  182. app.msg('扫码错误,请重新扫码!');
  183. }
  184. }
  185. });
  186. },
  187. signin(param) {
  188. let data = param.split(',');
  189. app.post('activity/activity/signin',{activity_id:data[0],code:data[1]},function(res){
  190. app.msg(res.msg);
  191. });
  192. },
  193. business(id) {
  194. if (!this.data.userInfo.user_nickname) {
  195. app.msg('请先授权登录');
  196. return false;
  197. }
  198. wx.navigateTo({
  199. url: '/pages/business/detail/detail?is_scan=1&id='+id,
  200. })
  201. }
  202. })