index.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. var util = require('../../utils/util.js');
  2. // var location = require('../../utils/Location.js');
  3. var wcache = require('../../utils/wcache.js');
  4. var app = getApp();
  5. var flag = true;
  6. Component({
  7. properties: {
  8. needAuth: {
  9. type: Boolean,
  10. value: false
  11. }
  12. },
  13. data: {
  14. btnLoading: false,
  15. isIpx: false,
  16. auth_bg: '',
  17. loaded: false
  18. },
  19. attached: function() {
  20. this.getBg();
  21. app.globalData.isIpx && this.setData({
  22. isIpx: true
  23. });
  24. },
  25. methods: {
  26. getBg: function(){
  27. let that = this;
  28. let auth_bg = wcache.get('auth_bg', false);
  29. if (!auth_bg){
  30. app.util.request({
  31. 'url': 'entry/wxapp/index',
  32. 'data': {
  33. controller: 'index.get_auth_bg'
  34. },
  35. dataType: 'json',
  36. success: function (res) {
  37. that.setData({ loaded: true })
  38. if (res.data.code == 0) {
  39. wcache.put('auth_bg', res.data.data, 600);
  40. res.data.data && that.setData({ auth_bg: res.data.data })
  41. }
  42. }
  43. })
  44. } else {
  45. that.setData({ auth_bg, loaded: true })
  46. }
  47. },
  48. bindGetUserInfo: function (t) {
  49. var that = this;
  50. if (!this.data.btnLoading) {
  51. var n = t.detail;
  52. if(this.setData({btnLoading: true}), "getUserInfo:ok" === n.errMsg){
  53. util.login_prosime().then(function(){
  54. console.log("授权成功")
  55. that.setData({ btnLoading: false });
  56. wx.showToast({
  57. title: '登录成功',
  58. icon: 'success',
  59. duration: 2000
  60. })
  61. that.triggerEvent("authSuccess");
  62. }).catch(function(){
  63. console.log('授权失败')
  64. })
  65. } else {
  66. wx.showToast({
  67. title: "授权失败,为了完整体验,获取更多优惠活动,需要您的授权。",
  68. icon: "none"
  69. });
  70. this.setData({btnLoading: false});
  71. }
  72. }
  73. },
  74. bindGetUserInfoTwo: function (t) {
  75. var that = this;
  76. wx.showLoading({ title: '授权中' });
  77. if (flag) {
  78. flag = false;
  79. var n = t.detail;
  80. if ("getUserInfo:ok" === n.errMsg) {
  81. util.login_prosime().then(function () {
  82. console.log("授权成功")
  83. wx.hideLoading();
  84. flag = true;
  85. wx.showToast({
  86. title: '登录成功',
  87. icon: 'success',
  88. duration: 2000
  89. })
  90. that.triggerEvent("authSuccess");
  91. }).catch(function () {
  92. flag = true;
  93. wx.hideLoading();
  94. console.log('授权失败')
  95. })
  96. } else {
  97. wx.hideLoading();
  98. wx.showToast({
  99. title: "授权失败,为了完整体验,获取更多优惠活动,需要您的授权。",
  100. icon: "none"
  101. });
  102. flag = true;
  103. }
  104. }
  105. }
  106. // openSetting: function () {
  107. // location.openSetting().then(function (t) {
  108. // app.globalData.location = {
  109. // lat: t.latitude,
  110. // lng: t.longitude
  111. // };
  112. // app.globalData.community.communityId || wx.redirectTo({
  113. // url: "/lionfish_comshop/pages/position/communities"
  114. // });
  115. // app.globalData.canGetGPS = true;
  116. // });
  117. // }
  118. }
  119. });