memberConvert.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. var util = require('../../../utils/util.js');
  2. var api = require('../../../config/api');
  3. var user = require('../../../utils/user.js');
  4. var app = getApp();
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. code:'',
  11. userInfo:null,
  12. hasLogin:false,
  13. memberUserInfo:{
  14. nickName: '用户',
  15. avatarUrl: '/static/images/new/icon-user.png',
  16. level:'0'
  17. }
  18. },
  19. /**
  20. * 生命周期函数--监听页面加载
  21. */
  22. onLoad: function (options) {
  23. },
  24. codeInput(e){
  25. this.setData({
  26. code:e.detail.value
  27. })
  28. },
  29. confirmConvert(){
  30. if(this.data.code==''){
  31. wx.showToast({
  32. title: '请输入兑换码',
  33. icon: 'none',
  34. duration: 2000
  35. });
  36. }else{
  37. this.exchangeMemberCoupon();
  38. }
  39. },
  40. exchangeMemberCoupon(){
  41. util.request(api.exchangeMemberCoupon, {
  42. userId:app.globalData.userInfo.id,
  43. memberCode:this.data.code
  44. },'GET')
  45. .then(res=>{
  46. console.info(res);
  47. if (res.errno === 0) {
  48. let endTime=res.data.endTime.substr(0,10);
  49. wx.navigateTo({
  50. url: '/pages/member/becomeMember/becomeMember?endTime='+endTime,
  51. })
  52. } else {
  53. util.showErrorToast(res.errmsg);
  54. }
  55. });
  56. },
  57. /**
  58. * 生命周期函数--监听页面初次渲染完成
  59. */
  60. onReady: function () {
  61. },
  62. /**
  63. * 生命周期函数--监听页面显示
  64. */
  65. onShow: function () {
  66. if (app.globalData.hasLogin) {
  67. let userInfo = wx.getStorageSync('userInfo');
  68. console.info(userInfo)
  69. this.setData({
  70. userInfo: userInfo,
  71. hasLogin: true,
  72. memberUserInfo:app.globalData.memberUserInfo
  73. });
  74. }else{
  75. wx.navigateTo({
  76. url: '/pages/auth/login/login',
  77. })
  78. }
  79. },
  80. /**
  81. * 生命周期函数--监听页面隐藏
  82. */
  83. onHide: function () {
  84. },
  85. /**
  86. * 生命周期函数--监听页面卸载
  87. */
  88. onUnload: function () {
  89. },
  90. /**
  91. * 页面相关事件处理函数--监听用户下拉动作
  92. */
  93. onPullDownRefresh: function () {
  94. },
  95. /**
  96. * 页面上拉触底事件的处理函数
  97. */
  98. onReachBottom: function () {
  99. },
  100. /**
  101. * 用户点击右上角分享
  102. */
  103. onShareAppMessage: function () {
  104. }
  105. })