referre.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. const util = require("../../utils/util.js");
  2. const app = getApp();
  3. Page({
  4. data: {
  5. make: false,
  6. type: "",
  7. invite: "",
  8. userInfo: "",
  9. invitePrice: util.config.invitePrice
  10. },
  11. onLoad(options) {
  12. let userInfo = app.globalData.userInfo;
  13. userInfo.recomCode = !util.isEmpty(userInfo.recomCode) ? userInfo.recomCode : '';
  14. this.setData({ type: options.type || '', userInfo });
  15. if (options.type == 'account' && !util.isEmpty(userInfo.recomCode)){
  16. this.data.invite = userInfo.recomCode;
  17. this.setData({ invite: this.data.invite });
  18. this.getUserInfo(1);
  19. } else if (!util.isEmpty(wx.getStorageSync("WX-invite"))){
  20. this.getUserInfo(0);
  21. }
  22. },
  23. inputinvite(e) {
  24. let val = e.detail.value;
  25. if (val.length == 6){
  26. this.setData({ invite: val });
  27. this.getUserInfo(1);
  28. }else{
  29. this.setData({ info: '', invite: val });
  30. }
  31. },
  32. getUserInfo(type) {
  33. let that = this;
  34. util.ajax({
  35. func: "inviter/info",
  36. data: { "code": type == 1 ? that.data.invite : wx.getStorageSync("WX-invite") }
  37. }, function (res) {
  38. if (res.code == 0) {
  39. res.data.avatar = !util.isEmpty(res.data.avatar) ? res.data.avatar : '/images/default_logo.jpg';
  40. if (res.data.roleType == 'sharer' || res.data.roleType == 'organ') {
  41. type == 0 ? that.data.invite = wx.getStorageSync("WX-invite") : '';
  42. that.setData({ info: res.data, invite: that.data.invite });
  43. } else if (type == 1){
  44. that.setData({ info: res.data, invite: that.data.invite });
  45. }
  46. } else{
  47. that.setData({ info: "" });
  48. type == 1 ?util.showTips(res.reason) : "";
  49. }
  50. });
  51. },
  52. submit() {
  53. let that = this;
  54. if (this.data.invite.length != 6) {
  55. util.showTips("请输入有效的6位邀请码。");
  56. return false;
  57. }
  58. if (this.data.info.roleType == 'normal') {
  59. util.showTips("该用户不是分享家/机构。");
  60. return false;
  61. }
  62. if (this.data.info.roleTypeDisable == 1) {
  63. util.showTips("该分享家/机构未启用。");
  64. return false;
  65. }
  66. util.ajax({
  67. func: "user/savecode",
  68. data: { "code": that.data.invite,receiveType:that.data.type?1:0}
  69. }, function (res) {
  70. if (res.code == 0) {
  71. app.globalData.userInfo['recomCode'] = that.data.invite;
  72. wx.setStorageSync("WXuserInfo", app.globalData.userInfo);
  73. if (that.data.info.roleType == 'sharer' || that.data.info.roleType == 'organ'){
  74. that.setData({ make: false, vouchers: res.vouchers,invitePrice:res.invitePrice});
  75. }else{
  76. that.back();
  77. }
  78. } else
  79. util.showTips(res.reason);
  80. });
  81. },
  82. back(e) {
  83. this.setData({
  84. make: true
  85. });
  86. if(this.data.type == "share"){
  87. wx.reLaunch({
  88. url: '/pages/home/index',
  89. });
  90. }else{
  91. wx.navigateBack({
  92. delta: (this.data.type == "account" ? 1 : 2)
  93. });
  94. }
  95. }
  96. })