index.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. var app = getApp();
  2. var util = require('../../utils/util.js');
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. needAuth: false,
  9. virtualcard_layout: '',
  10. virtcard_publish: '',
  11. virtcard_top_banner: '',
  12. share_img: '',
  13. share_title: '',
  14. loadMore: true,
  15. loadText: "加载中...",
  16. loadOver: false,
  17. showEmpty: false,
  18. rushList: [],
  19. },
  20. pageNum: 1,
  21. onLoad: function (options) {
  22. this.getData();
  23. this.getList();
  24. },
  25. onShow: function () {
  26. let that = this;
  27. util.check_login_new().then((res) => {
  28. if(res) {
  29. that.setData({ needAuth: false })
  30. } else {
  31. this.setData({ needAuth: true });
  32. }
  33. })
  34. },
  35. authSuccess: function () {
  36. let that = this;
  37. this.pageNum = 1;
  38. this.setData({
  39. slider_list: [],
  40. loadMore: true,
  41. loadText: "加载中...",
  42. loadOver: false,
  43. showEmpty: false,
  44. rushList: []
  45. }, () => {
  46. that.getData();
  47. that.getList();
  48. })
  49. },
  50. authModal: function () {
  51. if (this.data.needAuth) {
  52. this.setData({ showAuthModal: !this.data.showAuthModal });
  53. return false;
  54. }
  55. return true;
  56. },
  57. getData: function () {
  58. app.util.ProReq('virtualcard.index', {}).then(res => {
  59. let { virtcard_top_banner, virtcard_share_img, virtcard_share_title, virtualcard_layout, virtcard_publish, virtualcard_name_modify } = res.data;
  60. wx.setNavigationBarTitle({
  61. title: virtualcard_name_modify || '礼品卡中心',
  62. })
  63. this.setData({
  64. virtualcard_layout,
  65. virtcard_publish,
  66. virtcard_top_banner,
  67. share_img: virtcard_share_img,
  68. share_title: virtcard_share_title
  69. })
  70. })
  71. },
  72. /**
  73. * 获取商品列表
  74. */
  75. getList: function () {
  76. let that = this;
  77. let token = wx.getStorageSync('token');
  78. let community = wx.getStorageSync('community');
  79. let head_id = community.communityId || 0;
  80. app.util.request({
  81. url: 'entry/wxapp/index',
  82. data: {
  83. controller: 'virtualcard.load_goods_list',
  84. pageNum: this.pageNum,
  85. token,
  86. head_id,
  87. pre_page: 10
  88. },
  89. dataType: 'json',
  90. success: function (res) {
  91. wx.hideLoading();
  92. wx.stopPullDownRefresh();
  93. if (res.data.code == 0) {
  94. let oldRushList = that.data.rushList;
  95. if (that.pageNum == 1) oldRushList = [];
  96. let h = {}, list = res.data.list;
  97. if (that.pageNum == 1 && list.length == 0) h.showEmpty = true;
  98. list = that.calcEndTime(list);
  99. let rushList = oldRushList.concat(list);
  100. let rdata = res.data;
  101. let reduction = { full_money: rdata.full_money, full_reducemoney: rdata.full_reducemoney, is_open_fullreduction: rdata.is_open_fullreduction }
  102. h.rushList = rushList;
  103. h.reduction = reduction;
  104. h.loadOver = true;
  105. let loadMore = that.data.loadMore;
  106. if(res.data.list.length<10) { loadMore = false }
  107. h.loadMore = loadMore;
  108. h.loadText = loadMore ? "加载中..." : "没有更多商品了~";
  109. // h.pintuan_show_type = rdata.pintuan_show_type;
  110. that.setData(h, function () {
  111. that.pageNum += 1;
  112. })
  113. } else if (res.data.code == 1) {
  114. let s = { loadMore: false }
  115. if (that.pageNum == 1) s.showEmpty = true;
  116. that.setData(s);
  117. } else if (res.data.code == 2) {
  118. //no login
  119. that.setData({ needAuth: true })
  120. }
  121. }
  122. })
  123. },
  124. calcEndTime: function(list) {
  125. var timestamp = Date.parse(new Date())/1000;
  126. let newList = [];
  127. if(Object.keys(list).length) {
  128. list.forEach(item=>{
  129. (item.end_time<timestamp)&&(item.actEnd = 1);
  130. newList.push(item);
  131. })
  132. }
  133. return newList;
  134. },
  135. /**
  136. * 幻灯片跳转
  137. */
  138. goBannerUrl: function (t) {
  139. let idx = t.currentTarget.dataset.idx;
  140. let { slider_list, needAuth } = this.data;
  141. if (slider_list.length > 0) {
  142. let url = slider_list[idx].link;
  143. let type = slider_list[idx].linktype;
  144. if (util.checkRedirectTo(url, needAuth)) {
  145. this.authModal();
  146. return;
  147. }
  148. if (type == 0) {
  149. // 跳转webview
  150. url && wx.navigateTo({ url: '/lionfish_comshop/pages/web-view?url=' + encodeURIComponent(url) })
  151. } else if (type == 1) {
  152. if (url.indexOf('lionfish_comshop/pages/index/index') != -1 || url.indexOf('lionfish_comshop/pages/order/shopCart') != -1 || url.indexOf('lionfish_comshop/pages/user/me') != -1 || url.indexOf('lionfish_comshop/pages/type/index') != -1) {
  153. url && wx.switchTab({ url: url })
  154. } else {
  155. url && wx.navigateTo({ url: url })
  156. }
  157. } else if (type == 2) {
  158. // 跳转小程序
  159. let appid = slider_list[idx].appid;
  160. appid && wx.navigateToMiniProgram({
  161. appId: slider_list[idx].appid,
  162. path: url,
  163. extraData: {},
  164. envVersion: 'release',
  165. success(res) {
  166. // 打开成功
  167. },
  168. fail(error) {
  169. console.log(error)
  170. }
  171. })
  172. } else if (type == 6) {
  173. //领券
  174. wx.navigateTo({
  175. url: '/lionfish_comshop/moduleA/coupon/getCoupon?id='+url
  176. })
  177. }
  178. }
  179. },
  180. /**
  181. * 页面相关事件处理函数--监听用户下拉动作
  182. */
  183. onPullDownRefresh: function () {
  184. this.getData();
  185. let that = this;
  186. this.pageNum = 1;
  187. this.setData({
  188. loadMore: true,
  189. loadText: "加载中...",
  190. loadOver: false,
  191. showEmpty: false,
  192. rushList: []
  193. }, () => {
  194. that.getList();
  195. })
  196. },
  197. /**
  198. * 页面上拉触底事件的处理函数
  199. */
  200. onReachBottom: function () {
  201. console.log('这是我的底线');
  202. this.data.loadMore && (this.setData({ loadOver: false }), this.getList());
  203. },
  204. goLink: function(event) {
  205. let url = event.currentTarget.dataset.link;
  206. url && wx.navigateTo({ url })
  207. },
  208. /**
  209. * 用户点击右上角分享
  210. */
  211. onShareAppMessage: function () {
  212. var member_id = wx.getStorageSync('member_id');
  213. let { share_title, share_img } = this.data;
  214. return {
  215. title: share_title,
  216. path: "lionfish_comshop/moduleB/presale/index?share_id=" + member_id,
  217. imageUrl: share_img,
  218. success: function () { },
  219. fail: function () { }
  220. };
  221. }
  222. })