home.js 3.7 KB

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