assistance.js 4.74 KB
var t = getApp(),
  a = t.request,
  o = t.globalData.setting,
  os = o,
  i = require("../../../utils/util.js"),
  ut = i,
  s = require("../../../utils/common.js");
var regeneratorRuntime = require('../../../utils/runtime.js');
var oo = t.globalData.setting,os=oo, ut= require("../../../utils/util.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    url: os.url, //接口网址
    iurl: os.imghost, //图片前缀网址
    switch_head: 0, //0:我的任务,1:活动说明
    zl_act: null, //助力活动
    zl_user_list: [], //任务列表
    is_load: 0, //是否已经加载 
    cur_page: 1, //页码
    page_num: 5, //每页多少个
    is_show_more: 0, //是否加载更多
    help_id:"",//助力活动的id
    timer:"",//任务列表的定时器
	  s_num:"",//多少人已经领取任务
    page:1,//我的任务的当前页
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var th = this;
    var nav_b = th.selectComponent("#nav_b"); //组件的id
    nav_b.set_name("助力", "");
    // 助力活动
    this.assistance();
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
 
  },
  // 助力活动
   assistance() {
    var th=this;
    var user_id = getApp().globalData.user_id;
    var store_id = os.stoid;
   
    getApp().request.promiseGet("/api/weshop/marketing/help/act/judge", {
      data: {
        storeId: store_id,
        userId: user_id
      }
    }).then(res => {
      if (res.data.code == 0) {
        var help_data=res.data.data;
        th.setData({ zl_act:help_data, help_id:help_data.id });  
        if (th.data.help_id != "" && th.data.help_id!=null) {
           //我的任务
          th.get_list();
         }
       
		return getApp().request.promiseGet("/api/weshop/marketing/help/involve/help/act/people/count", {
		    data: {
		      helpId: help_data.id, storeId: store_id
		    }
		  })

      }
	  return ut.null_promise();	   
    }).then(res=>{
		if(res.data.code==0)
	     	th.setData({s_num:res.data.data.countAll})
	})
	
	
  },

  //--点击获取用户任务列表--会员的任务列表
  get_list:function() {
    
    
    var th = this;
    var page=th.data.page;
    console.log("page是什么", page);
    var help_id=this.data.help_id;
    t.request.get("/api/weshop/marketing/help/help/user/page", {
      data: {
        userId:getApp().globalData.user_id,
        storeId: os.stoid,
        helpId: help_id,
        page: page,
        pageSize:5
      },
      success: function(res) {
        clearTimeout(th.data.timer);
        
        if (!th.data.is_load) 
        th.setData({
          is_load: 1
        })
     
      
        if (res.data.code == 0) {
          var page=th.data.page+1;
          var list = th.data.zl_user_list;
          //连接数组	
          list = list.concat(res.data.data.pageData); 
          th.setData({
            zl_user_list: list,
            is_load: 1,
            page: page
          });
          if (res.data.data.total <= 5) {
            th.setData({
              is_show_more: 1
            })
          }
          // var n_all_num = th.data.cur_page * th.data.page_num;
          // if (res.data.data.total > n_all_num) th.setData({
          //   is_show_more: 1
          // })
          // else th.setData({
          //   is_show_more: 0
          // })
          //页吗要更新一下
          // th.data.cur_page++;
        } else {
          getApp().showWarning("暂无更多内容");
          th.setData({
            is_show_more: 1
          })
        }

      }
    })
  },

  //-----跳转到领取礼包的页面------
  go_task: function() {
   
    var help_id=this.data.help_id;
    getApp().goto("/pages/user/assistance/task_assistance?help_id="+help_id);
  },
  switch_head: function (e) {
    var th = this;
    var index = e.currentTarget.dataset.index; //获取当前选择的是任务还是活动说明
    var switch_head = th.data.switch_head; //0任务,1活动说明
    if (index != switch_head) {
      th.setData({
        switch_head: index
      })
    }
  },

  //关闭导航
  close: function () {
    var th = this;
    var nav_b = th.selectComponent("#nav_b"); //组件的id
    nav_b.close_box();
  },
  // 领取礼包
  get_libao:function(e){
    var libao_id=e.currentTarget.dataset.libaoid;
    var completeid= e.currentTarget.dataset.completeid;
    
    getApp().goto("/pages/user/assistance/giftpacklist?libao_id=" + libao_id + "&is_libao=" + 1 + "&completeid=" + completeid);    
  },
  //查看礼包id
  select_libao:function(){
    var libao_id = e.currentTarget.dataset.libaoid;
    var ordersn = e.currentTarget.dataset.orderid;
    getApp().goto("/pages/user/assistance/giftpacklist?libao_id=" + libao_id + "&is_libao=" + 0 + "&ordersn=" + ordersn );    
  }
})