team_show.js 28.4 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069
var t = require("../../../utils/util.js"),
  ut = t,
  e = require("../../../utils/common.js"),
  a = require("../../../utils/wxParse/wxParse.js"),
  s = getApp(),
  i = s.request,
  rq = i,
  oo = s.globalData,
  o = s.globalData.setting,
  os = o;
var regeneratorRuntime = require('../../../utils/runtime.js');


Page({
  data: {
   
    num: 1, //输入框值 加减之间的值
    minusStatus: 'disable', //禁用按钮
    ii_endname: 'disable', //吐司的禁用按钮
    pd_xx: false, //弹框
    buy_start_date: null, //转换完的时间
    ssl: null,
    yijian: false, //一键参加按钮显示隐藏

    //选择门店
    qh: true, //取货
    xz: false, //选择
    one: false, //第一层显示隐藏
    se: false, //已选择的值
    list: false, //第二层显示隐藏
    ssl_child: null, //第二层的值
    sele_dl_name: "", //选择的值
    end_name: "", //最后显示的值

    ii: 0, //选择门店显示隐藏
    zk: true, //展开列表显示隐藏
    stoid: o.stoid,
    hiddenName: false, //收起列表显示隐藏
    teamlist: null, //活动主表
    teamgroup: null, //活动从表
    goods: null, //商品数据
    pindGoods: null, //拼单数据
    imageurl: os.imghost, //有礼派图片地址
    team_id: 0, //支付是否成功
    listno: "", //订单编号
	
	  //选择的门店id
  	pick_id:0,
    //会员团满团时的判断
    tg_arr:null,
    //是否显示
    is_show:0,
    //是不是团结束
    is_group_end:0,
    //团结束的提示语句
    end_text:"",
    //是开团或者参团,0参团,1开团(但是,商家团还是参团)
    is_kt_or_ct:0,
    //判断redis的数组
    redis_arr:null,

    iurl:os.imghost,
		
		
		openSpecModal: !1,
		openSpecModal_pt: !1, //拼单的弹起,
		
		showStore: true,
		selectStore: 0,
  },
  onLoad: function(options) {

      wx.setNavigationBarTitle({ title: "拼团订单",})
      //var postdata=getApp().globalData.to_group;
      var postdata=options;
      var tg_id = postdata.tg_id, first_leader=options.first_leader;
      //如果tg_id是空的话
      if(tg_id==undefined || tg_id==null || tg_id==""){
        var tg_id_str=decodeURIComponent(postdata.scene);
        tg_id_str=tg_id_str.split("_");
        tg_id=tg_id_str[0];
        if(tg_id_str.length>1){
          first_leader=tg_id_str[1];
        }
      }
      //--判断一下是不是导购--
      if(first_leader){
      getApp().globalData.first_leader=first_leader;
      //调用接口判断是不是会员
      getApp().request.promiseGet("/api/weshop/shoppingGuide/get/"+os.stoid+"/"+first_leader,{}).then(res=>{
        if(res.data.code==0){
          getApp().globalData.guide_id=res.data.data.id;
        }
      })
    }


    this.setData({tg_id: tg_id });
      getApp().globalData.to_group=null;
  },

  //显示加载
  onShow:function(){
    var tg_id = this.data.tg_id,th=this;
    this.init(tg_id);

		getApp().get_user_store(function (e) {
			if(e)
				th.setData({ pick_id: e.pickup_id, end_name: e.pickup_name,ii:1 })	
		})
  },

  //c点击打开拼团弹窗
  cpd: function() {
    this.setData({  pd_xx: true,})
  },

  //点击关闭拼团弹窗
  close_pt_xx: function() {
    this.setData({ pd_xx: false, })
  },

  //按钮点击一键参加团按钮
  cyijian: function(e) {
    //--先判断会员状态--
    var user_info=getApp().globalData.userInfo;
    if(user_info==null || user_info.mobile==undefined || user_info.mobile=="" || user_info.mobile==null){
      wx.navigateTo({ url: '/pages/getphone/getphone', })
      return false;
    }

    var is_kt_or_ct=e.currentTarget.dataset.isct;
    this.setData({
      yijian: true,is_kt_or_ct:is_kt_or_ct,
    })
  },
  //关闭展开列表
  click: function(e) {
    this.setData({
      hiddenName: !this.data.hiddenName,
      zk: !this.data.zk,
    })
  },
  //打开收起拼团列表
  czk: function(e) {
    this.setData({
      zk: !this.data.zk,
      hiddenName: !this.data.hiddenName,
    })
  },
  //关闭购买页面
  cbcou: function(e) {
    this.setData({
      yijian: false,
    })

  },
  //qh点击取货
  cqh: function(e) {	  
	if(this.data.ssl)  {		
		this.setData({
		  qh: false,
		  xz: true,
		  one: true,
		})
	}else{
		this.setData({
		  qh: false,
		  xz: true,
		  one: false,
		  list:1,
		})
	}
	
  },

  //cxz点击选择门店
  cxz: function(e) {
    this.setData({
      qh: true,
      xz: false,
      one: false,
    })
  },
  //ccc点击选择的
  sel: function(e) {
    this.setData({
      list: false,
      se: false,
      one: true,
      xz: true,
    })
  },
  //list点击底二层
  clist: function(e) {
    var i = e.currentTarget.dataset.end;
    var pick_id = e.currentTarget.dataset.pick_id;
    var pick_dis = e.currentTarget.dataset.pick_dis;

    this.setData({
      end_name: i,
      pick_id: pick_id,
      ii: 1,
      qh: true,
      se: false,
      list: false,
      pick_dis: pick_dis
    })
  },

  //点击第一层
  setchild: function(e) {
    var ind = e.currentTarget.dataset.bindex;
    var nn = e.currentTarget.dataset.bname;
    console.log(nn);
    var list = this.data.ssl[ind].s_arr;
    this.setData({
      ssl_child: list,
      sele_dl_name: nn,
      xz: false,
      one: false,
      list: true,
      se: true
    });
  },

  //事件处理函数
  /*点击减号*/
  bindMinus: function() {
    var num = this.data.num;
    if (num > 1) {
      num--;
    }
    var minusStatus = num > 1 ? 'normal' : 'disable';
    this.setData({
      num: num,
      minusStatus: minusStatus,
    })
  },

  /*点击加号*/
  bindPlus: function() {
    var th=this;
    var num = this.data.num;
    var ii = this.data.ii;
    var minusStatus = num > 1 ? 'normal' : 'disable';
    if (ii == 0) {
      getApp().showWarning("请选择门店"); return false;
    }
    if (ii == 1) {
      num++;
      //要判断库存数量,限购数量
      th.check_num(num,minusStatus);
    }
  },

  async check_num(num,minusStatus){

    var gd=this.data.goods;
    var th=this;
    var user_id=getApp().globalData.user_id;
    var promgoodsbuynum=0;
    var goodsbuynum=0;
    getApp().request.promiseGet("/api/weshop/ordergoods/getUserBuyGoodsNum", {
      data: {
        store_id: os.stoid,
        user_id: user_id,
        goods_id: gd.goods_id,
        prom_type: gd.prom_type,
        prom_id: gd.prom_id

      },
    }).then(res=>{
       var buy_num_data=res.data.data;
       if(buy_num_data.promgoodsbuynum) promgoodsbuynum=buy_num_data.promgoodsbuynum;
       goodsbuynum=buy_num_data.goodsbuynum;
    })

    //先判断限购
    if (num+goodsbuynum>gd.viplimited && gd.viplimited>0) {
      getApp().confirmBox("超出商品限购");
      return false;
    }
    if (num+promgoodsbuynum>th.data.teamlist.buy_limit && th.data.teamlist.buy_limit>0) {
      getApp().confirmBox("超出活动限购");
      return false;
    }
    //判断库存
    if ( num>gd.store_count) {
      getApp().confirmBox("超出商品库存");
      return false;
    }
    var r_num=0;
    await  getApp().request.promiseGet("/api/weshop/activitylist/getActLen/" + os.stoid + "/6/" + th.data.teamlist.id, {
      1: 1
    }).then(res => {
      var em = res;
      if (em.data.code == 0) {
        r_num=em.data.data;
      }
    })
    //--判断库存---
    if ( num>r_num) {
      getApp().confirmBox("超出商品库存");
      return false;
    }

    this.setData({
      num: num,
      minusStatus: minusStatus,
    })

  },

  /*输入框事件*/
  bindManual: function(e) {
    var num = e.detail.value;
    var minusStatus = num > 1 ? 'normal' : 'disable';
    this.setData({
      num: num,
      minusStatus: minusStatus
    })
  },

  //---------------初始化代码----------------
  async init(tg_id) {
    var goods_id = 0, //商品ID,
      pageteam = null, //
      original_img = null, //商品图片
      ee = this,
      ordertx = [],
      teamlist = null,  //活动表
      goods = null,     //商品
      teamgroup = null, //活動从表
      max_num = 0,
      min_price = 0,
      th=this;

    //获取活动从表信息team_id,listno团编号(券号)
    await getApp().request.promiseGet("/api/weshop/teamgroup/get/"+os.stoid+"/"+tg_id, {
    }).then(res => {
      teamgroup = res.data.data;
      //获取当前时间,并且判断剩余时间
      var nt = ut.gettimestamp();
      var buy_start_date = ut.formatTime(teamgroup.buy_start_date, "yyyy-MM-dd hh:mm:ss");
      ee.setData({
        pindGoods: teamgroup,
        buy_start_date: buy_start_date
      });

      if(nt>teamgroup.kt_end_time) {
        th.setData({is_group_end:1,end_text:"团期已经结束"})
      }
      if(teamgroup.state==1) {
        th.setData({is_group_end:1,end_text:"团期已经结束"})
      }
      if(teamgroup.state==3 || teamgroup.state==4 || teamgroup.state==5 ) {
        th.setData({is_group_end:2,end_text:"团期已满"})
      }

    })

    //判断是不是要继续的开关
    var is_ok=1;

    //要先读取订单,看自己有没有买过该团的商品
    await getApp().request.promiseGet("/api/weshop/order/page", {
      data: {
        pt_prom_id:teamgroup.team_id,
        user_id: oo.user_id,
        store_id: os.stoid,
        pageSize: 1,
        page: 1
      }
    }).then(res => {
      var e=res;
      if (e.data.code != 0) {
        getApp().showWarning("读取订单失败");
        th.go_back();
        is_ok=0;
        return fasle;
      }
      //--跳转到已经购买的情况--
      if (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,
          });
          is_ok=0;
        }else if (odr.pt_status == 1 && odr.order_status == 1){
          wx.navigateTo({
            url: "/pages/team/team_success/team_success?ordersn=" + odr.order_sn,
          });
          is_ok=0;
        }
      }
    })
    if(!is_ok) return false;

    //获取活动表的信息根据活动team_id
    await getApp().request.promiseGet("/api/weshop/teamlist/get/" + os.stoid + "/" + teamgroup.team_id, {
      data: {}
    }).then(res => {
      if (res.data.code == 0) {
        teamlist = res.data.data;
        goods_id = res.data.data.goods_id;

        //----------查看阶梯团------------
        if (teamlist.ct_rylist != "" && teamlist.ct_rylist != null && teamlist.ct_rylist != undefined) {
          var ct_rylist = JSON.parse(teamlist.ct_rylist);
          var max = 0; var pri = 0;
          ct_rylist.forEach(function (val, ind) {
            if (val.rynum > max) {
              max = val.rynum;
              pri = val.price;
            }
          })
          max_num = max;
          min_price = pri;
        }

      }
    })

    if(!teamlist){
        getApp().showWarning("未找到活动");
        is_ok=0;
    }else{
       if(teamlist.is_end==1){
          getApp().showWarning("拼单活动已经结束"); is_ok=0;
       }
       var now=ut.gettimestamp();
       if(teamlist.end_time<now && is_ok){
         getApp().showWarning("拼单活动已经结束"); is_ok=0;
       }
    }
    if(!is_ok) {
        th.go_back();
        return false;
    }

    //多少人参团头像
    await getApp().request.promiseGet("/api/weshop/order/pagePtList", {
      data: {
        store_id: o.stoid,
        pt_listno: teamgroup.listno,
      }
    }).then(res => {
      ordertx = res.data.data.pageData;
    })

    //获取商品信息
    await getApp().request.promiseGet("/api/weshop/goods/get/" + os.stoid + "/" + goods_id, {
    }).then(res => {
      //商品地址
      original_img = ee.data.imageurl + res.data.data.original_img,
        goods = res.data.data
    })

    //只装5个
    var ordertx2 = [], sf_num = 0, ct_nun = teamlist.ct_num;
    if (max_num) {
      ct_nun = parseInt(max_num);
      if (ct_nun < ordertx.length) ct_nun = ordertx.length;
    }

    if (ct_nun > 5) ct_nun = 5;
    for (var i = 0; i < ct_nun; i++) {
      if (i >= ordertx.length) sf_num++
      else
        ordertx2.push(ordertx[i]);
    }

    var sf_arr = [];
    for (var i = 0; i < sf_num; i++) {
      sf_arr.push(i);
    }



    if(th.data.is_group_end==1 || th.data.is_group_end==2 ){
        getApp().confirmBox(th.data.end_text);
        wx.redirectTo({
          url: "/pages/goods/goodsInfo/goodsInfo?goods_id=" + goods.goods_id,
        });
        return false;
    }

    //--当是会员团的时候才显示倒计时多久可以参团--
    if(teamlist.kttype==2) {
        //显示判断多久才能购买商品,获取没有支付的会员
        await getApp().request.promiseGet("/api/weshop/teamgroup/getTeamUser/" + os.stoid + "/" + teamgroup.id, {
          1: 1
        }).then(res => {
          var em = res;
          if (em.data.code == 0) {
            var tg_list = em.data.data.split("|");
            var t_obj = {};
            t_obj.order_id = tg_list[0];
            t_obj.time = parseFloat(tg_list[1]) + 5 * 60; //五分钟后
            t_obj.user_name = tg_list[2];
            th.setData({tg_arr: t_obj})
          }
        })
    }

    //获取大家都在团信息
    await getApp().request.promiseGet("/api/weshop/teamlist/pageteam/"+os.stoid, {
      data: {
        pageSize: 2,
        page: 1,
        store_id: 1,
        is_end: 0,
        is_show: 1
      }
    }).then(res => {
       pageteam = res.data.data.pageData;
    });

    //获取下redis长度,如果团已经弄完,或者拼单已经卖完
    //设置值
    ee.setData({
      ordertx2: ordertx2,
      ordertx: ordertx,
      teamlist: teamlist,
      teamgroup: teamgroup,
      goods: goods,
      pageteam: pageteam,
      image: original_img,
      is_show:1,
      sf_arr: sf_arr
    });
    ee.countDown2();
	  //---设置门店---
	  ee.get_sto();

    //---定时设置一下待支付的订单---
	  ee.time_out();
  },

  onHide:function(){
    this.setData({is_show:0,});
  },
  go_back:function(){
    if(getCurrentPages()>1)
      wx.navigateBack({delta: 1})
    else
      wx.navigateTo({
        url: "/pages/index/index/index"
      });
  },
  //---小于10的格式化函数----
  timeFormat(param) {
    return param < 10 ? '0' + param : param;
  },
  countDown2() {
    var th = this;
    // 获取当前时间,同时得到活动结束时间数组
    var newTime = ut.gettimestamp();
    var o = this.data.pindGoods;
    var endTime = o.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 = "pindGoods.djs";
    th.setData({
      obj: obj
    });
    setTimeout(th.countDown2, 1000);
  },
  //--获取门店---
  async get_sto(e) {
    var th = this, dd = null,i=getApp().request;
    var g_distr_type = this.data.goods.distr_type;
    if (g_distr_type != 0) {
      dd = {
        store_id: o.stoid,
        distr_type: g_distr_type,
        isstop: 0,
        pageSize: 300
      }
    } else {
      dd = {
        store_id: o.stoid,
        isstop: 0,
        pageSize: 300
      }
    }
    //----------获取门店----------------
    await getApp().request.promiseGet("/api/weshop/pickup/list", {
      data: dd,
    }).then(res => {
      var e = res;
      if (e.data.code == 0) {
        //单总量超出5个的时候
        if (e.data.data.total > 5) {
          i.get("/api/weshop/storagecategory/page", {
            data: {
              store_id: o.stoid,
              is_show: 1,
              pageSize: 300
            },
            success: function(ee) {
              if (ee.data.code == 0) {
                if (ee.data.data.pageData.length > 0) {
                  var sto_cate = ee.data.data.pageData;
                  var sto_arr = e.data.data.pageData;
                  var newarr = new Array();
                  var qita = new Array();
                  //----要进行门店分组--------
                  for (var i = 0; i < sto_arr.length; i++) {
                    //找一下这个门店有没有在分类数组内
                    var find2 = 0,
                      find2name = "";
                    for (var m = 0; m < sto_cate.length; m++) {
                      if (sto_arr[i].category_id == sto_cate[m].cat_id) {
                        find2 = sto_cate[m].cat_id;
                        find2name = sto_cate[m].cat_name;
                        break;
                      }
                    }

                    if (newarr.length > 0) {
                      var find = 0;
                      //如果有找到,那门店就在这个分组内,否则,分类就要排在其他
                      if (find2 != 0) {
                        for (var ii = 0; ii < newarr.length; ii++) {
                          if (sto_arr[i].category_id == newarr[ii].cat_id) {
                            newarr[ii].s_arr.push(sto_arr[i]);
                            find = 1;
                            break;
                          }
                        }
                        if (find == 0) {
                          var arr0 = new Array();
                          arr0.push(sto_arr[i]);
                          var item = {
                            cat_id: find2,
                            name: find2name,
                            s_arr: arr0
                          };
                          newarr.push(item);
                        }
                      } else {
                        qita.push(sto_arr[i]);
                      }
                    } else {
                      //如果有找到,那门店就在这个分组内,否则,分类就要排在其他
                      if (find2 != 0) {
                        var arr0 = new Array();
                        arr0.push(sto_arr[i]);
                        var item = {
                          cat_id: find2,
                          name: find2name,
                          s_arr: arr0
                        };
                        newarr.push(item);
                      } else {
                        qita.push(sto_arr[i]);
                      }
                    }
                  }

                  //----安排其他的分类-----
                  if (qita.length > 0) {
                    var item = {
                      cat_id: -1,
                      name: "其他",
                      s_arr: qita
                    };
                    newarr.push(item);
                  }
                  //--给门店赋值--
                  th.setData({
                    is_show_sto_cat: 1,
                    ssl: newarr
                  });

                } else {
                  //--只留第二层---
                  th.setData({
                    is_show_sto_cat: 0,
                    ssl_child: e.data.data.pageData,					
                  });
                }
              } else {
                //--只留第二层---
                th.setData({
                  is_show_sto_cat: 0,
                  ssl_child: e.data.data.pageData,				 				  
                });
              }
            }
          });
        } else {
          //--只留第二层---
          th.setData({
            is_show_sto_cat: 0,
            ssl_child: e.data.data.pageData
          });
        }
      }
    })
  },

  //------去支付,购买-------
  go_pay:function () {
      var th=this;
      if (th.data.pick_id == 0) return s.my_warnning("请选择门店", 0, th);

      //----判断起购数----
      var qnum=parseFloat(th.data.teamlist.minbuynum);
      if(qnum>0 && qnum>th.data.num ){
        getApp().confirmBox("拼团商品至少要买"+qnum+"件!");
        return false;
      }
      //先判断团的redis数量
      this.buy_check_redis(function () {
        var arr=th.data.redis_arr;
        if(th.data.num>arr[0]){
          if(arr[0]>0){
            getApp().showWarning("超出活动库存");
          }else{
            getApp().showWarning("拼单已经抢光");
          }
           return false;
        }
        if(th.data.teamlist.kttype==2 && 1>arr[1]){
          getApp().showWarning("拼团已满");
          return false;
        }

        //--------------此时操作的数据------------
        var newd = {
          goods_id: th.data.goods.goods_id,
          goods_num: th.data.num,
          pick_id: th.data.pick_id,
          user_id: oo.user_id,
          store_id: th.data.stoid,
          goods_name: th.data.goods.goods_name,
          goods_sn: th.data.goods.goods_sn,
        };

        //---是不是从收藏夹出来的---
        if(th.data.c_guide_id){
          newd['guide_id'] = th.data.c_guide_id;
          newd['guide_type']=2;

        }else{
          if(getApp().globalData.guide_id){
            newd['guide_id'] = getApp().globalData.guide_id;
            newd['guide_type']=0;

          }
        }

        //-----拼团-----
        newd.goods_price = th.data.teamlist.price;
        newd.prom_type = 6;
        newd.prom_id = th.data.teamlist.id;
        newd.kt_type = th.data.teamlist.kttype; //开团类型
        newd.is_pt_tz = 0;
        newd.pick_name = th.data.end_name;
        newd.pick_dis = 1;
        newd.is_normal = 0;
        //判断开团还是参团
        switch (th.data.is_kt_or_ct) {
          case "0":
            //如果不是商家团,就要带团期号
            if(th.data.teamlist.kttype>1){
              newd.qh=th.data.teamgroup.listno;
            }
            break;
          case "1":
            //阶梯团和会员团都要设置is_pt_tz
            if (newd.kt_type > 1) {
              newd.is_pt_tz = 1; //开团类型
            }
            break;
        }
        newd['pick_dis'] = th.data.pick_dis;

        if(getApp().globalData.guide_id){
          newd['guide_id'] = getApp().globalData.guide_id;
          newd['guide_type']=0;
        }

        s.set_b_now(newd);
        wx.navigateTo({
          url: "/pages/cart/cart2_pt/cart2_pt?is_bnow=1&goods_id=" + th.data.goods.goods_id,
        });
      });
  },

  //购买前的判断redis
  async buy_check_redis(func){
      //获取redis中的数量
      var r_num=0,prom_type=6,prom_id=this.data.teamlist.id;
      await  getApp().request.promiseGet("/api/weshop/activitylist/getActLen/" + os.stoid + "/" + prom_type + "/" + prom_id, {
        1: 1
      }).then(res => {
        var em = res;
        if (em.data.code == 0) {
          r_num=em.data.data;
        }
      })

      //只有会员团要判断团的人数
      var gr_num=0,grp_id=this.data.teamgroup.id;
      if(this.data.teamlist.kttype==2){
        await  getApp().request.promiseGet("/api/weshop/activitylist/getActTuanLen/" + os.stoid + "/" + grp_id, {
          1: 1
        }).then(res => {
          var em = res;
          if (em.data.code == 0) {
            gr_num=em.data.data;
          }
        })
      }
      var arr=[];arr.push(r_num);arr.push(gr_num);
      this.data.redis_arr=arr;
      func();
  },

  //定时设置一下待支付的订单
  time_out:function () {
    var list=this.data.tg_arr,th=this;
    if(!list) return false;
    // 获取当前时间,同时得到活动结束时间数组
    var newTime = ut.gettimestamp();
    var endTime = list.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: th.timeFormat(day),
        hou: th.timeFormat(hou),
        min: th.timeFormat(min),
        sec: th.timeFormat(sec)
      }
    } else {
      //活动已结束,全部设置为'00'
      obj = {
        day: '00',
        hou: '00',
        min: '00',
        sec: '00'
      }

      //调用接口清理订单,并且返回redis数量
      th.back_order(function () {
         th.setData({ tg_arr: null});
      });
      return false;
    }
    var txt = "pindGoods.djs";
    th.setData({
      r_obj: obj
    });
    setTimeout(th.time_out, 1000);
  },

  //清理订单,并且返回redis数量ss
  back_order:function (func) {
      var th=this;
      //---取消订单---
      getApp().request.delete("/api/weshop/order/cancelTeamOrder/"+th.data.stoid+"/"+th.data.tg_arr.order_id,{
            data:{},
            success: function(t) {
                if(t.data.code==0){
                  th.setData({tg_arr:null})
                }
            },
      })
  },

  go_goodsinfo:function (e) {
    var gid=e.currentTarget.dataset.gid;
    var url="/pages/goods/goodsInfo/goodsInfo?goods_id="+gid;
    wx.navigateTo({ url: url, })  //跳到非tabbar页
  },

  gohome:function(){
    getApp().goto("/pages/index/index/index");
  },

  //-----图片失败,默认图片-----
  bind_bnerr: function (e) {
    var _errImg = e.target.dataset.errorimg;
    var _errObj = {};
    _errObj[_errImg] = this.data.iurl + "/miniapp/images/default_g_img.gif";
    this.setData(_errObj) //注意这里的赋值方式,只是将数据列表中的此项图片路径值替换掉 ;
  },

  //------ 分享配置 --------
  onShareAppMessage: function (e) {
    var curPage=this;
    var pagePath = curPage.route; //当前页面url
    if (pagePath.indexOf('/') != 0) {
      pagePath = '/' + pagePath;
    }
    var url=pagePath;

    //--分享图片--
    img=th.data.iurl+th.data.teamlist.share_imgurl;
    //--把会员分享出去--
    if(getApp().globalData.user_id){
      if(url.indexOf("?")>0)
        url+="&first_leader="+getApp().globalData.user_id;
      else
        url+="?first_leader="+getApp().globalData.user_id;
    }

    return {
      path:url,
      title: "商品分类",
      imageUrl: img,
    }
  },
	
	
	
	
	
	closeSpecModal: function() {
		this.setData({
		  yijian: false
		});
	},
	
	close_popup: function() {
		this.setData({
		  showStore: true
		});
	},
	
	
	
	// 选择门店
	choice_store: function(ee) {
		
		// console.log('1');
		this.setData({
			// store: 1,
			yijian: false,
			showStore: false,
		});
		
	//   var th = this;
	//   var ind=ee.currentTarget.dataset.ind;
	//   var bconfig = th.data.bconfig;
	
	//   if(!th.data.only_pk && !th.data.def_pickpu_list){
	//     getApp().confirmBox("门店库存不足", null, 25000, !1);
	//     return false;
	//   }
	
	//   if(th.data.only_pk && !th.data.only_pk.length){
	//     getApp().confirmBox("门店库存不足", null, 25000, !1);
	//     return false;
	//   }
	//   if(th.data.def_pickpu_list &&  !th.data.def_pickpu_list.length){
	//     getApp().confirmBox("门店库存不足", null, 25000, !1);
	//     return false;
	//   }
	
	
	//   if (bconfig.is_sort_storage) {
	//     wx.getLocation({
	//       type: 'wgs84',
	//       success: function(res) {
	
	//         th.data.lat = res.latitude;
	//         th.data.lon = res.longitude;
	//         th.data.is_get_local_ok = 1;
	//         th.setData({
	//           is_gps: 1
	//         });
	//         //th.onShow();
	//         th.get_sto();
	//       },
	//       fail: function(res) {
	//         //th.onShow();
	//         th.data.is_get_local_ok = 1;
	//         th.get_sto();
	//         if (res.errCode == 2) {
	//           th.setData({
	//             is_gps: 0
	//           });
	//           if (th.data.is_gps == 0) {
	//             getApp().confirmBox("请开启GPS定位", null, 25000, !1);
	//           }
	//         } else {
	//           th.setData({
	//             is_gps: "3"
	//           });
	//         }
	
	//       }
	//     })
	//   }else{
	//     th.data.is_get_local_ok = 1;
	//     th.get_sto();
	//   }
	
	//   if(ind!=undefined && ind!=null ){
	//     this.setData({
	//       open_ind_store: ind,
	//       store: 1,
	//       openSpecModal: !1,
	//       openSpecModal_pt: !1
	//     })
	//   }else{
	//     this.setData({
	//       store: 1,
	//       openSpecModal: !1,
	//       openSpecModal_pt: !1
	//     })
	//   }
	},
	
	
	
	//选择更多门店
	more_store: function() {
	  this.setData({
	    selectStore: 1
	  });
	},
	
	// 返回按钮
	returns: function() {
	  this.setData({
	    selectStore: 0,
	  });
	},

})