score.js 1.7 KB

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