home.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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() {
  69. let self = this;
  70. wx.chooseImage({
  71. count: 1,
  72. sizeType: ['original'],
  73. success(res) {
  74. wx.showLoading({
  75. mask: true,
  76. });
  77. var token = wx.getStorageSync('token');
  78. wx.uploadFile({
  79. url: app.globalData.api_host + 'user/profile/avatarUpload',
  80. filePath: res.tempFilePaths[0],
  81. name: 'file',
  82. header: { 'X-Requested-With': 'XMLHttpRequest' , 'XX-Device-Type': 'wxapp' , 'XX-Token': token},
  83. success(res) {
  84. var json = JSON.parse(res.data)
  85. if (json.code == 1) {
  86. wx.hideLoading();
  87. self.setData({"userInfo.avatar": json.data});
  88. app.globalData.userInfo = self.data.userInfo;
  89. } else {
  90. wx.showToast({
  91. title: '上传失败,请重试',
  92. icon: 'none'
  93. });
  94. }
  95. },
  96. fail() {
  97. wx.showToast({
  98. title: '上传失败,请重试',
  99. icon: 'none'
  100. });
  101. }
  102. });
  103. }
  104. });
  105. },
  106. //跳转
  107. toInfo() {
  108. if (!this.data.userInfo.user_nickname) {
  109. app.msg('请先授权登录');
  110. } else {
  111. wx.navigateTo({
  112. url: '/pages/my/info/info',
  113. })
  114. }
  115. },
  116. toJoin() {
  117. if (!this.data.userInfo.user_nickname) {
  118. app.msg('请先授权登录');
  119. } else {
  120. wx.navigateTo({
  121. url: '/pages/my/join/join',
  122. })
  123. }
  124. },
  125. toBaidu() {
  126. wx.navigateTo({
  127. url: '/pages/home/webview/webview',
  128. })
  129. },
  130. toFeedback() {
  131. if (!this.data.userInfo.user_nickname) {
  132. app.msg('请先授权登录');
  133. } else {
  134. wx.navigateTo({
  135. url: '/pages/my/feedback/feedback',
  136. })
  137. }
  138. },
  139. toRob() {
  140. if (!this.data.userInfo.user_nickname) {
  141. app.msg('请先授权登录');
  142. } else {
  143. wx.navigateTo({
  144. url: '/pages/my/rob/rob',
  145. })
  146. }
  147. },
  148. toBind() {
  149. if (!this.data.userInfo.user_nickname) {
  150. app.msg('请先授权登录');
  151. } else {
  152. wx.navigateTo({
  153. url: '/pages/my/bind/bind',
  154. })
  155. }
  156. },
  157. toScore() {
  158. if (!this.data.userInfo.user_nickname) {
  159. app.msg('请先授权登录');
  160. } else {
  161. wx.navigateTo({
  162. url: '/pages/my/score/score',
  163. })
  164. }
  165. },
  166. //扫码
  167. scan() {
  168. if (!this.data.userInfo.user_nickname) {
  169. app.msg('请先授权登录');
  170. return false;
  171. }
  172. let self = this;
  173. wx.scanCode({
  174. success ({result}) {
  175. let arr = result.split(':');
  176. console.log(arr);
  177. if (arr[0] == 'signin') {
  178. self.signin(arr[1]);
  179. } else if (arr[0] == 'business') {
  180. self.business(arr[1]);
  181. } else {
  182. app.msg('未知二维码!');
  183. }
  184. },
  185. fail(res) {
  186. if (res.errMsg != "scanCode:fail cancel") {
  187. app.msg('扫码错误,请重新扫码!');
  188. }
  189. }
  190. });
  191. },
  192. signin(param) {
  193. let data = param.split(',');
  194. app.post('activity/activity/signin',{activity_id:data[0],code:data[1]},function(res){
  195. app.msg(res.msg);
  196. });
  197. },
  198. business(id) {
  199. if (!this.data.userInfo.user_nickname) {
  200. app.msg('请先授权登录');
  201. return false;
  202. }
  203. wx.navigateTo({
  204. url: '/pages/business/detail/detail?is_scan=1&id='+id,
  205. })
  206. }
  207. })