index.js 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. var app = getApp();
  2. var util = require('../../utils/util.js');
  3. var status = require('../../utils/index.js');
  4. Page({
  5. mixins: [require('../../mixin/globalMixin.js')],
  6. data: {
  7. list: [],
  8. loadText: "加载中...",
  9. noData: 0,
  10. loadMore: true,
  11. groupInfo: {
  12. group_name: '社区',
  13. owner_name: '团长'
  14. },
  15. },
  16. page: 1,
  17. /**
  18. * 生命周期函数--监听页面加载
  19. */
  20. onLoad: function(options) {
  21. app.setShareConfig();
  22. let that = this;
  23. status.setNavBgColor();
  24. status.setGroupInfo().then((groupInfo) => { that.setData({ groupInfo }) });
  25. let { share_id, community_id } = options;
  26. this.options = options;
  27. if (share_id != 'undefined' && share_id > 0) wx.setStorageSync('share_id', share_id);
  28. this.compareCommunity(community_id)
  29. this.getData(community_id);
  30. },
  31. initFn(community_id) {
  32. let that = this;
  33. this.page = 1;
  34. this.setData({
  35. list: [],
  36. loadText: "加载中...",
  37. noData: 0,
  38. loadMore: true,
  39. }, ()=>{
  40. that.getData(community_id);
  41. })
  42. },
  43. /**
  44. * 比较社区
  45. */
  46. compareCommunity: function (shareCommunityId) {
  47. let that = this;
  48. // 原来社区
  49. let currentCommunity = wx.getStorageSync('community');
  50. let currentCommunityId = currentCommunity.communityId || '';
  51. const token = wx.getStorageSync('token');
  52. shareCommunityId && util.getCommunityById(shareCommunityId).then(res => {
  53. let { hide_community_change_btn, default_head_info } = res;
  54. let { groupInfo } = that.data;
  55. if (res.open_danhead_model == 1) {
  56. // 开启单社区
  57. app.globalData.community = default_head_info;
  58. app.globalData.changedCommunity = true;
  59. wx.setStorage({ key: "community", data: default_head_info })
  60. token && util.addhistory(default_head_info);
  61. if(shareCommunityId!=default_head_info.communityId) {
  62. let { groupInfo } = that.data;
  63. app.util.message(`您只能访问自己${groupInfo.group_name}`, 'switchTo:/lionfish_comshop/pages/index/index', 'error', '知道了');
  64. return;
  65. }
  66. } else {
  67. // 社区是否存在
  68. if (currentCommunityId != '' && shareCommunityId) {
  69. // 存在并且不相同
  70. console.log('currentCommunityId存在 比较社区')
  71. if (currentCommunityId != shareCommunityId) {
  72. console.log('currentCommunityId存在 社区不同')
  73. //如果禁止切换
  74. // if (hide_community_change_btn == 1) {
  75. console.log('禁止切换');
  76. app.util.message(`您只能访问自己${groupInfo.group_name}`, 'switchTo:/lionfish_comshop/pages/index/index', 'error', '知道了');
  77. return;
  78. // }
  79. // that.setData({
  80. // hide_community_change_btn,
  81. // showChangeCommunity: res.data ? true : false,
  82. // changeCommunity: res.data,
  83. // currentCommunity: currentCommunity
  84. // })
  85. }
  86. } else {
  87. // 不存在社区id
  88. //token 是否存在
  89. if (token) {
  90. util.getCommunityInfo().then(function (ret) {
  91. //比较社区
  92. console.log('token存在 比较社区')
  93. if (ret.community_id && ret.community_id != shareCommunityId) {
  94. app.util.message(`您只能访问自己${groupInfo.group_name}`, 'switchTo:/lionfish_comshop/pages/index/index', 'error', '知道了');
  95. // that.setData({
  96. // showChangeCommunity: true,
  97. // currentCommunity: ret
  98. // })
  99. }
  100. }).catch((param) => {
  101. console.log('step4 新人')
  102. if (Object.keys(param) != '') util.addhistory(param, true);
  103. });
  104. } else {
  105. console.log('token不存在 存社区')
  106. // 直接存本地
  107. app.globalData.community = res.data;
  108. app.globalData.changedCommunity = true;
  109. wx.setStorage({ key: "community", data: res.data })
  110. }
  111. }
  112. }
  113. });
  114. },
  115. /**
  116. * 切换提示
  117. */
  118. confrimChangeCommunity: function () {
  119. let community = this.data.changeCommunity;
  120. let token = wx.getStorageSync('token');
  121. app.globalData.community = community;
  122. app.globalData.changedCommunity = true;
  123. wx.setStorage({
  124. key: "community",
  125. data: community
  126. })
  127. token && util.addhistory(community);
  128. this.initFn(community.communityId);
  129. this.setData({ showChangeCommunity: false })
  130. console.log('用户点击确定')
  131. },
  132. /**
  133. * 取消切换
  134. */
  135. cancelChangeCommunity: function () {
  136. let currentCommunity = this.data.currentCommunity;
  137. let communityId = currentCommunity.communityId || '';
  138. communityId && this.initFn(communityId);
  139. },
  140. /**
  141. * 生命周期函数--监听页面显示
  142. */
  143. onShow: function() {
  144. let that = this;
  145. util.check_login_new().then((res) => {
  146. if (!res) {
  147. that.setData({
  148. needAuth: true
  149. })
  150. } else {
  151. (0, status.cartNum)('', true).then((res) => {
  152. that.setData({
  153. cartNum: res.data
  154. })
  155. });
  156. }
  157. })
  158. },
  159. /**
  160. * 获取列表
  161. */
  162. getData: function (head_id) {
  163. let that = this;
  164. wx.showLoading();
  165. if (!head_id) {
  166. let community = wx.getStorageSync('community');
  167. head_id = community.communityId || '';
  168. }
  169. app.util.request({
  170. url: 'entry/wxapp/index',
  171. data: {
  172. controller: 'solitaire.get_head_index_solitairelist',
  173. head_id,
  174. page: this.page
  175. },
  176. dataType: 'json',
  177. success: function(res) {
  178. wx.stopPullDownRefresh();
  179. wx.hideLoading();
  180. let showTabbar = res.data.showTabbar;
  181. if (res.data.code == 0) {
  182. let h = {};
  183. let list = res.data.data;
  184. let head_data = res.data.head_data;
  185. if (list.length < 20) h.noMore = true;
  186. let oldList = that.data.list;
  187. list = oldList.concat(list);
  188. that.page++;
  189. that.setData({
  190. list,
  191. ...h,
  192. head_data,
  193. showTabbar
  194. })
  195. } else if (res.data.code == 1) {
  196. // 无数据
  197. let head_data = res.data.head_data || '';
  198. if (that.page == 1) that.setData({
  199. noData: 1
  200. })
  201. that.setData({
  202. loadMore: false,
  203. noMore: false,
  204. head_data,
  205. loadText: "没有更多记录了~",
  206. showTabbar
  207. })
  208. } else if (res.data.code == 2) {
  209. // 您还未登录
  210. } else if (res.data.code == 3) {
  211. // 团长不存在
  212. app.util.message(res.data.msg, '/lionfish_comshop/pages/position/community', 'error');
  213. return;
  214. } else {
  215. app.util.message(res.data.msg, '', 'error');
  216. return;
  217. }
  218. }
  219. })
  220. },
  221. goDetails: function (event){
  222. var id = event ? event.currentTarget.dataset.id : '';
  223. if(!id) return;
  224. var pages_all = getCurrentPages();
  225. let link = `/lionfish_comshop/moduleA/solitaire/details?id=${id}`;
  226. if (pages_all.length > 3) {
  227. wx.redirectTo({
  228. url: link
  229. })
  230. } else {
  231. wx.navigateTo({
  232. url: link
  233. })
  234. }
  235. },
  236. showImgPrev: function (event) {
  237. var idx = event ? event.currentTarget.dataset.idx : '';
  238. var sidx = event ? event.currentTarget.dataset.sidx : '';
  239. let list = this.data.list;
  240. let urls = list[sidx].images_list;
  241. wx.previewImage({
  242. current: urls[idx],
  243. urls
  244. });
  245. },
  246. /**
  247. * 页面相关事件处理函数--监听用户下拉动作
  248. */
  249. onPullDownRefresh: function() {
  250. let that = this;
  251. this.page = 1;
  252. this.setData({
  253. list: [],
  254. loadText: "加载中...",
  255. noData: 0,
  256. loadMore: true,
  257. }, ()=>{
  258. that.getData();
  259. })
  260. },
  261. /**
  262. * 页面上拉触底事件的处理函数
  263. */
  264. onReachBottom: function() {
  265. if (!this.data.loadMore) return false;
  266. this.getData();
  267. },
  268. /**
  269. * 用户点击右上角分享
  270. */
  271. onShareAppMessage: function () {
  272. let community = wx.getStorageSync('community');
  273. let head_id = community.communityId || '';
  274. let share_id = wx.getStorageSync('member_id') || '';
  275. let share_path = `lionfish_comshop/moduleA/solitaire/index?share_id=${share_id}&community_id=${head_id}`;
  276. let title = '';
  277. return {
  278. title,
  279. path: share_path,
  280. success: function (res) {
  281. // 转发成功
  282. },
  283. fail: function (res) {
  284. // 转发失败
  285. }
  286. }
  287. },
  288. onShareTimeline: function () {
  289. let community = wx.getStorageSync('community');
  290. let head_id = community.communityId || '';
  291. let share_id = wx.getStorageSync('member_id') || '';
  292. let title = '';
  293. var query= `share_id=${share_id}&community_id=${head_id}`;
  294. return {
  295. title,
  296. query,
  297. success: function (res) {
  298. // 转发成功
  299. },
  300. fail: function (res) {
  301. // 转发失败
  302. }
  303. }
  304. }
  305. })