123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238 |
- var app = getApp();
- var util = require('../../utils/util.js');
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- needAuth: false,
- virtualcard_layout: '',
- virtcard_publish: '',
- virtcard_top_banner: '',
- share_img: '',
- share_title: '',
- loadMore: true,
- loadText: "加载中...",
- loadOver: false,
- showEmpty: false,
- rushList: [],
- },
- pageNum: 1,
- onLoad: function (options) {
- this.getData();
- this.getList();
- },
- onShow: function () {
- let that = this;
- util.check_login_new().then((res) => {
- if(res) {
- that.setData({ needAuth: false })
- } else {
- this.setData({ needAuth: true });
- }
- })
- },
- authSuccess: function () {
- let that = this;
- this.pageNum = 1;
- this.setData({
- slider_list: [],
- loadMore: true,
- loadText: "加载中...",
- loadOver: false,
- showEmpty: false,
- rushList: []
- }, () => {
- that.getData();
- that.getList();
- })
- },
- authModal: function () {
- if (this.data.needAuth) {
- this.setData({ showAuthModal: !this.data.showAuthModal });
- return false;
- }
- return true;
- },
- getData: function () {
- app.util.ProReq('virtualcard.index', {}).then(res => {
- let { virtcard_top_banner, virtcard_share_img, virtcard_share_title, virtualcard_layout, virtcard_publish, virtualcard_name_modify } = res.data;
- wx.setNavigationBarTitle({
- title: virtualcard_name_modify || '礼品卡中心',
- })
- this.setData({
- virtualcard_layout,
- virtcard_publish,
- virtcard_top_banner,
- share_img: virtcard_share_img,
- share_title: virtcard_share_title
- })
- })
- },
- /**
- * 获取商品列表
- */
- getList: function () {
- let that = this;
- let token = wx.getStorageSync('token');
- let community = wx.getStorageSync('community');
- let head_id = community.communityId || 0;
-
- app.util.request({
- url: 'entry/wxapp/index',
- data: {
- controller: 'virtualcard.load_goods_list',
- pageNum: this.pageNum,
- token,
- head_id,
- pre_page: 10
- },
- dataType: 'json',
- success: function (res) {
- wx.hideLoading();
- wx.stopPullDownRefresh();
- if (res.data.code == 0) {
- let oldRushList = that.data.rushList;
- if (that.pageNum == 1) oldRushList = [];
-
- let h = {}, list = res.data.list;
- if (that.pageNum == 1 && list.length == 0) h.showEmpty = true;
- list = that.calcEndTime(list);
- let rushList = oldRushList.concat(list);
- let rdata = res.data;
- let reduction = { full_money: rdata.full_money, full_reducemoney: rdata.full_reducemoney, is_open_fullreduction: rdata.is_open_fullreduction }
- h.rushList = rushList;
- h.reduction = reduction;
- h.loadOver = true;
- let loadMore = that.data.loadMore;
- if(res.data.list.length<10) { loadMore = false }
- h.loadMore = loadMore;
- h.loadText = loadMore ? "加载中..." : "没有更多商品了~";
- // h.pintuan_show_type = rdata.pintuan_show_type;
- that.setData(h, function () {
- that.pageNum += 1;
- })
- } else if (res.data.code == 1) {
- let s = { loadMore: false }
- if (that.pageNum == 1) s.showEmpty = true;
- that.setData(s);
- } else if (res.data.code == 2) {
- //no login
- that.setData({ needAuth: true })
- }
- }
- })
- },
- calcEndTime: function(list) {
- var timestamp = Date.parse(new Date())/1000;
- let newList = [];
- if(Object.keys(list).length) {
- list.forEach(item=>{
- (item.end_time<timestamp)&&(item.actEnd = 1);
- newList.push(item);
- })
- }
- return newList;
- },
- /**
- * 幻灯片跳转
- */
- goBannerUrl: function (t) {
- let idx = t.currentTarget.dataset.idx;
- let { slider_list, needAuth } = this.data;
- if (slider_list.length > 0) {
- let url = slider_list[idx].link;
- let type = slider_list[idx].linktype;
- if (util.checkRedirectTo(url, needAuth)) {
- this.authModal();
- return;
- }
- if (type == 0) {
- // 跳转webview
- url && wx.navigateTo({ url: '/lionfish_comshop/pages/web-view?url=' + encodeURIComponent(url) })
- } else if (type == 1) {
- 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) {
- url && wx.switchTab({ url: url })
- } else {
- url && wx.navigateTo({ url: url })
- }
- } else if (type == 2) {
- // 跳转小程序
- let appid = slider_list[idx].appid;
- appid && wx.navigateToMiniProgram({
- appId: slider_list[idx].appid,
- path: url,
- extraData: {},
- envVersion: 'release',
- success(res) {
- // 打开成功
- },
- fail(error) {
- console.log(error)
- }
- })
- } else if (type == 6) {
- //领券
- wx.navigateTo({
- url: '/lionfish_comshop/moduleA/coupon/getCoupon?id='+url
- })
- }
- }
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- this.getData();
- let that = this;
- this.pageNum = 1;
- this.setData({
- loadMore: true,
- loadText: "加载中...",
- loadOver: false,
- showEmpty: false,
- rushList: []
- }, () => {
- that.getList();
- })
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- console.log('这是我的底线');
- this.data.loadMore && (this.setData({ loadOver: false }), this.getList());
- },
- goLink: function(event) {
- let url = event.currentTarget.dataset.link;
- url && wx.navigateTo({ url })
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- var member_id = wx.getStorageSync('member_id');
- let { share_title, share_img } = this.data;
- return {
- title: share_title,
- path: "lionfish_comshop/moduleB/presale/index?share_id=" + member_id,
- imageUrl: share_img,
- success: function () { },
- fail: function () { }
- };
- }
- })
|