index.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. const util = require("../../../../utils/util.js");
  2. const app = getApp();
  3. Page({
  4. data: {
  5. scrollTop:0,
  6. index:0,
  7. height:[0,0,0,0,0,0],
  8. info:{},
  9. config:util.config,
  10. userInfo:{
  11. nickname:'',
  12. avatar:''
  13. },
  14. score:0,
  15. },
  16. onShow: function () {
  17. this.info();
  18. },
  19. jumpPage(){
  20. wx.reLaunch({
  21. url: '/pages/home/index'
  22. });
  23. },
  24. info(){
  25. let that = this, userInfo = app.globalData.userInfo;
  26. util.ajax({
  27. func: "score/info"
  28. }, function (res) {
  29. if (res.code == 0) {
  30. that.setData({score:res.data.score})
  31. res.data.score = Math.round(res.data.score);
  32. res.data.role = userInfo['role'] || util.userRole(res.data.score);
  33. if (res.data.role.level < 6) {
  34. res.data.nextLevel = util.config.userRole[res.data.role.level + 1];
  35. res.data.nextLevel.nextscore = Math.round(parseFloat(res.data.nextLevel.startPoint - res.data.score));
  36. }
  37. that.setData({info: res.data,'userInfo.avatar':userInfo.avatar,'userInfo.nickname':userInfo.nickname});
  38. that.linearAnim(res.data.role, res.data.score);
  39. }else
  40. util.showTips(res.reason);
  41. });
  42. },
  43. // 积分动画
  44. linearAnim(data, score){
  45. let that = this,
  46. height = this.data.index < data.level ?
  47. 62 : (data.level == 6 ? 100 : Math.round(100 * ((score - util.config.userRole[data.level].startPoint) / (util.config.userRole[data.level].endPoint - util.config.userRole[data.level].startPoint))));
  48. this.data.height[this.data.index] = height > 100 ? 100 : height;
  49. if (this.data.index <= data.level){
  50. this.setData({ index: this.data.index + 1, height: this.data.height});
  51. setTimeout(function(){
  52. that.linearAnim(data, score);
  53. that.scrollLeft();
  54. },1000);
  55. }
  56. },
  57. scrollLeft(){
  58. this.setData({ scrollTop: parseFloat((this.data.index - 2) * 62) });
  59. },
  60. onShareAppMessage() {
  61. return {
  62. title: '积分等级--分享自@宝贝走天下微信小程序',
  63. path: '/pages/account/vip/index/index'
  64. }
  65. }
  66. })