activity.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. var api = require('../../config/api.js');
  2. var util = require('../../utils/util.js');
  3. var app = getApp();
  4. Page({
  5. data: {
  6. couponList: [],
  7. referrer: 0,
  8. sourceKey: '',
  9. scrollTop: 0
  10. },
  11. onLoad: function (options) {
  12. let that = this;
  13. // 页面初始化 options为页面跳转所带来的参数
  14. if (options.referrer) {
  15. that.setData({
  16. referrer: parseInt(options.referrer),
  17. sourceKey: options.sourceKey
  18. });
  19. }
  20. let code = null;
  21. if (null == wx.getStorageInfoSync('userInfo')) {
  22. util.login().then((res) => {
  23. code = res.code;
  24. return util.getUserInfo();
  25. }).then((userInfo) => {
  26. //登录远程服务器,不用
  27. wx.request({
  28. url: api.AuthLoginByWeixin,
  29. data: {
  30. code: code, userInfo: userInfo
  31. },
  32. method: 'POST',
  33. header: {
  34. 'Content-Type': 'application/json'
  35. },
  36. success: function (res) {
  37. if (res.errno === 0) {
  38. //存储用户信息
  39. wx.setStorageSync('userInfo', res.data.userInfo);
  40. wx.setStorageSync('token', res.data.token);
  41. wx.setStorageSync('userId', res.data.userId);
  42. that.getCouponList();
  43. }
  44. },
  45. fail: function (err) {
  46. reject(err)
  47. console.log("failed")
  48. }
  49. })
  50. })
  51. } else {
  52. that.getCouponList();
  53. }
  54. },
  55. onReady: function () {
  56. },
  57. onShow: function () {
  58. },
  59. onHide: function () {
  60. // 页面隐藏
  61. },
  62. onUnload: function () {
  63. // 页面关闭
  64. },
  65. getCouponList() {
  66. let that = this;
  67. util.request(api.CouponTransActivit).then(function (res) {
  68. if (res.errno === 0) {
  69. that.setData({
  70. couponList: res.data
  71. });
  72. } else if (res.errno === 2) {
  73. util.showErrorToast(res.errmsg)
  74. that.setData({
  75. couponList: res.data
  76. });
  77. }
  78. });
  79. }
  80. })