team_more.js 5.51 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');


Page({
  data: {
    ylburl: "https://mshopimg.yolipai.net/",//有礼派图片地址
    pt_act: null,//拼单数据
    baseUrl: "/api/weshop/teamgroup/page?1=1",
    resourceUrl: t.globalData.setting.resourceUrl,
    currentPage: 1,
    requestData: null,
    store_id: 1,
    team_id:0,
    requestUrl: "",
    teamgroup:null,
    pt_act:null,
  },

  onLoad: function (t) {

    wx.setNavigationBarTitle({ title: "开团列表", })

    var th=this;
    //初始化加載更多
    th.data.requestData=new Array();  
    var team_id=t.team_id;
    var teamlist=null;
    th.data.team_id = team_id;

   //获取活动表的ct_num
    getApp().request.promiseGet("/api/weshop/teamlist/get/" + os.stoid + "/" + team_id, {
      data: {}
    }).then(res => {
      if (res.data.code == 0) {
        teamlist = res.data.data;
        var jt_team_num=teamlist.ct_rylist;
        if (jt_team_num != "" && jt_team_num != null && jt_team_num!= undefined) {
          var team_num_arr = JSON.parse(jt_team_num);
          var max_num = 0;
          team_num_arr.forEach(function (val, ind) {
            if (val.rynum > max_num) max_num = val.rynum;
          })
          teamlist.max_num = max_num;
        }

         th.setData({ pt_act: teamlist });
         th.init(team_id);
      }
    })
  },

  //加载更多的函数
  async init(team_id) {
         
     var teamgroup = null,//活動从表
      user = null,
      ee = this, th=ee,
      pt_status = 1;//已支付
    
    //获取活动从表信息team_id
    await getApp().request.promiseGet("/api/weshop/teamgroup/page", {
      data: { store_id: os.stoid, pageSize:6,page:ee.data.currentPage,
      state: 2, team_id: team_id }
    }).then(res => {
      teamgroup = res.data.data.pageData;
      console.log(teamgroup);
      ee.data.currentPage++;
    })

    //获取订单的总数这个接口不能用
    for (i = 0; i < teamgroup.length; i++) {
      await getApp().request.promiseGet("/api/weshop/order/page", {
        data: { store_id: os.stoid, pt_status: 1, pt_listno: teamgroup[i].listno }
      }).then(res => {
        var order = res.data.data.pageData;
        teamgroup[i].open_num = order.length;
      })

      await getApp().request.promiseGet("/api/weshop/users/get/" + os.stoid + "/" + teamgroup[i].openvipid, {
      }).then(res => {
        var user = res.data.data;
        teamgroup[i].user = user;
      })
    }
    //设置值
    for(var ii=0;ii<teamgroup.length;ii++){
      th.data.requestData.push(teamgroup[ii]);
    }
    th.setData({ teamgroup: th.data.requestData});
    ee.countDown2();

  },
   //滚动到底部
  onReachBottom: function () {
    this.init(th.data.team_id);
  },

  resetData: function () {
    n.resetConfig(), this.data.teamgroup = null, this.data.currentPage = 1;
  },

  //---小于10的格式化函数----
  timeFormat(param) {
    return param < 10 ? '0' + param : param;
  },

  //----拼单倒计时函数-----
  countDown2() {
    var th = this;
    // 获取当前时间,同时得到活动结束时间数组
    var newTime = ut.gettimestamp();
    var List = this.data.teamgroup;
	if(!List || List.length<=0) return false;

    for (var j = 0; j < List.length; j++) {
      // 对结束时间进行处理渲染到页面
      var endTime = List[j].kt_end_time;
      let obj = null;
      // 如果活动未结束,对时间进行处理
      if (endTime - newTime > 0) {
        let time = (endTime - newTime);
        // 获取天、时、分、秒
        let day = parseInt(time / (60 * 60 * 24));
        let hou = parseInt(time % (60 * 60 * 24) / 3600);
        let min = parseInt(time % (60 * 60 * 24) % 3600 / 60);
        let sec = parseInt(time % (60 * 60 * 24) % 3600 % 60);
        obj = {
          day: this.timeFormat(day),
          hou: this.timeFormat(hou),
          min: this.timeFormat(min),
          sec: this.timeFormat(sec)
        }
      } else {
        //活动已结束,全部设置为'00'
        obj = {
          day: '00',
          hou: '00',
          min: '00',
          sec: '00'
        }
      }
      var txt = "teamgroup[" + j + "].djs";
      th.setData({
        [txt]: obj
      });
    }

    setTimeout(th.countDown2, 1000);
  },

  //--跳转到加载更多--
  go_team_show:function (e) {

    var tid=e.currentTarget.dataset.tid;
    var team_id=e.currentTarget.dataset.team_id;
    var oo=getApp().globalData;

    getApp().request.get("/api/weshop/order/page", {
      data: {
        pt_prom_id: team_id,
        user_id: oo.user_id,
        store_id: os.stoid,
        pageSize: 1,
        page: 1
      },
      success: function(e) {
        //--跳转到已经购买的情况--
        if (e.data.code == 0 && e.data.data.pageData.length > 0) {
          var odr = e.data.data.pageData[0];
          //还未支付
          if (odr.pt_status == 0 && odr.order_status == 1) {
            wx.navigateTo({
              url: "/pages/user/order_detail/order_detail?order_id=" + odr.order_id,
            });
          }else if (odr.pt_status == 1 && odr.order_status == 1){
            wx.navigateTo({
              url: "/pages/team/team_success/team_success?ordersn=" + odr.order_sn,
            });
          }
        }
        //--跳转到参团--
        else if(e.data.code == 0){
          wx.navigateTo({
            url: "/pages/team/team_show/team_show?tg_id="+tid,
          });
        }

      }
    });

  }
 
})