equity.js 4.5 KB
const app = getApp()
const navStyle = "background-color: transparent;";
import { shopmallApi } from '../../../api/api'
// import util from '../../../utils/util'
Page({
  /**
   * 页面的初始数据
   */
  data: {
    isNeedFresh: false,
    showLogin: false,
    navStyle,
    showPageTitle: "",
    scrollTop: 0,
    loadingMore: false,
    freshMember: true,
    loadOver: false,
    pageParam: {
      appearance: 1,
      pageSize: 0,
      pageCount: 10,
    },
    pageCount: 0,
    curTabIndex: 0,
    showPageFlag: false,
    freshVIP: false,
    freshPre:false
  },
  navbarReady(e) {
    let {
      height
    } = e.detail;
    this.setData({
      user_box_style: `padding-top:${height + 20}px`,
    });
  },
  // toRefreshMember() {
  //   this.setData({
  //     isNeedFresh: true,
  //   });
  //   setTimeout(() => {
  //     this.setData({
  //       isNeedFresh: false,
  //     });
  //   }, 1500)
  // },
  // init() {
  //   this.toRefreshMember()
  // },
  onShow() {
    this.setData({
      freshPre:false
    },()=>{
      this.setData({
        freshPre:true
      })
    })
    const sessionId = wx.$util.getSessionId();
    if (sessionId) {
      this.setData({
        freshVIP: false
      },()=>{
        this.setData({
          freshVIP: true
        })
      })
    }
  },
  onLoad: function (options) {
    this.freecardPageOptions();
    setTimeout(() => {
      this.setData({
        showPageFlag: true,
        freshPre:true
      })
    })
  },
  // 获取会员商城商品总数量
  getPageCount(e) {
    this.setData({
      pageCount: e.detail.pageCount,
    });
  },
  // 获取页面滚动距离
  onPageScroll: function (e) {
    this.setData({
      navStyle: e.scrollTop >= 38 ? "" : navStyle,
      showPageTitle: e.scrollTop >= 38 ? "权益中心" : "",
    });
  },
  // 免费领取页面参数
  freecardPageOptions() {
    let freecard = wx.getStorageSync("bindInfo");
    if (freecard) {
      let bingInfo = JSON.parse(decodeURIComponent(freecard));
      const sid = bingInfo.data.sessionId;
      wx.$util.setSessionId(sid);
      this.handleFreeCard(bingInfo);
      // this.setData({
      //   isNeedFresh: wx.$util.getSessionId() ? true : false,
      // });
    }
  },
  // 免费领取结果处理
  handleFreeCard(bindInfo) {
    wx.removeStorageSync("bindInfo");
    const {
      code,
      errId,
      message
    } = bindInfo;
    if (code == 0) {
      wx.showModal({
        title: "提示",
        content: "领取成功",
        confirmText: "确定",
        showCancel: false,
        confirmColor: "#F13C3D",
      });
      // wx.$eventbus.emit('EQUITY')
    } else if (code == -1 && errId == 20321) {
      wx.showModal({
        title: "提示",
        content: message,
        confirmText: "续费开通",
        cancelText: "不用了",
        confirmColor: "#F13C3D",
      }).then((res) => {
        if (res.confirm) {
          wx.navigateTo({
            url: "/packageEquity/pages/open/open",
          });
        }
      });
    } else if (errId == 20320 || errId == 20322) {
      wx.showModal({
        title: "提示",
        content: message,
        confirmText: "确定",
        showCancel: false,
        confirmColor: "#F13C3D",
      });
    }
  },

  // 获取当前tab栏页面
  getCurrentTab(e) {
    this.setData({
      curTabIndex: e.detail.tabIndex,
    });
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    const merchantId = wx.$util.getStorageSync("srcm_shopmall_merchant_id");
    let path = this.route;
    if (merchantId) path = `${path}?merchantId=${merchantId}`;
    return {
      path,
    };
  },
  onPullDownRefresh: function () {
    app.globalData.commodityList = []
    app.globalData.loaded = false
    app.globalData.latesParam.pageSize = 0
    this.setData({
        freshMember: false
    },()=>{
        this.setData({
            freshMember: true
        })
    })
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    let {
      pageParam,
      pageCount
    } = this.data;
    pageParam.pageSize++;
    this.setData({
      pageParam,
      loadingMore: true,
    });
    const discountLocation = wx.getStorageSync("location");
    if (this.data.curTabIndex == 1 &&  discountLocation.lat) {
      this.selectComponent("#merchant-box").toGetCommodity(
        discountLocation.lat,
        discountLocation.lng
      );
    }
    if (pageParam.pageSize < pageCount) {
      this.selectComponent("#merchant-box").getGoodsList(this.data.loadingMore, pageParam.pageSize);
    }
  },
});