index.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. var app = getApp();
  2. var util = require('../../utils/util.js');
  3. var status = require('../../utils/index.js');
  4. Page({
  5. mixins: [require('../../mixin/cartMixin.js')],
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. list: [],
  11. info: {},
  12. cartNum: 0,
  13. needAuth: false
  14. },
  15. specialId: 0,
  16. /**
  17. * 生命周期函数--监听页面加载
  18. */
  19. onLoad: function (options) {
  20. app.setShareConfig();
  21. status.setNavBgColor();
  22. let id = options.id || 0;
  23. this.specialId = id;
  24. if (options.share_id != 'undefined' && options.share_id > 0) wx.setStorageSync('share_id', options.share_id);
  25. this.getData(id);
  26. },
  27. /**
  28. * 授权成功回调
  29. */
  30. authSuccess: function () {
  31. this.getData(this.specialId);
  32. this.setData({
  33. needAuth: false
  34. })
  35. },
  36. getData: function (id) {
  37. wx.showLoading();
  38. var token = wx.getStorageSync('token');
  39. var that = this;
  40. var cur_community = wx.getStorageSync('community');
  41. app.util.request({
  42. url: 'entry/wxapp/index',
  43. data: {
  44. controller: 'marketing.get_special',
  45. token,
  46. head_id: cur_community.communityId,
  47. id
  48. },
  49. dataType: 'json',
  50. success: function (res) {
  51. wx.stopPullDownRefresh();
  52. wx.hideLoading();
  53. if (res.data.code == 0) {
  54. let list = res.data.list;
  55. let info = res.data.data;
  56. let ishowShareBtn = res.data.ishow_special_share_btn || 0;
  57. wx.setNavigationBarTitle({
  58. title: info.special_title || '专题'
  59. })
  60. let { full_money, full_reducemoney, is_open_fullreduction, is_open_vipcard_buy, is_vip_card_member, is_member_level_buy } = res.data;
  61. let reduction = { full_money, full_reducemoney, is_open_fullreduction }
  62. let noData = (list.length==0)? true : false;
  63. that.setData({ list, info, ishowShareBtn, noData, reduction })
  64. } else if (res.data.code == 1) {
  65. wx.showModal({
  66. title: '提示',
  67. content: res.data.msg,
  68. showCancel: false,
  69. success(ret){
  70. if (ret.confirm) {
  71. wx.switchTab({
  72. url: '/lionfish_comshop/pages/index/index',
  73. })
  74. }
  75. }
  76. })
  77. } else if(res.data.code == 2) {
  78. // 未登录
  79. that.setData({ needAuth: true });
  80. }
  81. }
  82. })
  83. },
  84. /**
  85. * 生命周期函数--监听页面显示
  86. */
  87. onShow: function () {
  88. let that = this;
  89. util.check_login_new().then((res) => {
  90. if (res) {
  91. this.setData({ needAuth: false });
  92. (0, status.cartNum)('', true).then((res) => {
  93. res.code == 0 && that.setData({ cartNum: res.data })
  94. });
  95. } else {
  96. let id = this.specialId;
  97. this.setData({ needAuth: true, navBackUrl: `/lionfish_comshop/pages/supply/index?id=${id}` });
  98. }
  99. })
  100. },
  101. /**
  102. * 页面相关事件处理函数--监听用户下拉动作
  103. */
  104. onPullDownRefresh: function () {
  105. this.getData(this.specialId);
  106. },
  107. onShareAppMessage: function (res) {
  108. var share_title = this.data.info.special_title || '活动专题';
  109. var share_id = wx.getStorageSync('member_id');
  110. var id = this.specialId;
  111. var share_path = `lionfish_comshop/moduleA/special/index?id=${id}&share_id=${share_id}`;
  112. return {
  113. title: share_title,
  114. path: share_path,
  115. success: function (res) {
  116. // 转发成功
  117. },
  118. fail: function (res) {
  119. // 转发失败
  120. }
  121. }
  122. },
  123. onShareTimeline: function (res) {
  124. var share_title = this.data.info.special_title || '活动专题';
  125. var share_id = wx.getStorageSync('member_id');
  126. var id = this.specialId;
  127. var query= `id=${id}&share_id=${share_id}`;
  128. return {
  129. title: share_title,
  130. query,
  131. success: function (res) {
  132. // 转发成功
  133. },
  134. fail: function (res) {
  135. // 转发失败
  136. }
  137. }
  138. }
  139. })