const util = require('../../../utils/util.js');
const app = getApp();
var updateTimer;
Page({
  data: {
    vip_Info: {},
    showGoodsRecom: false,
    securityShow: '', //安全保障
    physicalForCardTitle: '点击查看活动前所需准备的物品',
    countDown: { //倒计时任务
      show: false,
      time: 20,
      taskId: ''
    },
    show: {
      chat: false,
      sku: false,
      growup: false,
      tips: false,
      official: false
    },
    showConvert: false, //特权兑换弹窗
    checkedTime: 5, //选中时间
    city: '', //选中城市
    showNextConvert: false, //特权兑换二次提醒弹窗
    showPaymentPopup: false, //支付尾款弹窗
    showEnrollPopup: false, //邀请报名弹窗
    showAlternatePopup: false, //候补弹窗
    showGrouPopup: false, //拼团弹窗
    channel: 0, //渠道码
    channelTimes: 0, //渠道码分享次数
    isBuy: true,
    copyCanbuy: 1, //用于预售存储会员是否可购买字段
    aid: '',
    title: '',
    groupid: '', //拼团id
    orderid: '', //拼团才有的订单id
    current: 0,
    buttonText: "",
    buttonClass: "button-theme",
    buttonClass1: "button-theme",
    buttonPTClass: "button-danger",
    showTimer: false,
    processTimer: null,
    privilegeTime: 0,
    getBalanceData: true,
    showPrivilege: true,
    updateTime: {
      isPayInfo: true
    },
    datas: {},
    score: 0,
    comments: [], //评论
    imgUrl: util.config.imgPath,
    userInfo: {},
    viode: [], //视频
    isColumn: false, //导航条是否到顶部
    datasetHeight: 0, //目标节点的高度
    showBack: false, //是否显示返回顶部
    temCountId: '',
    total: 0,
    onshow: true,
    url: "/",
    isScroll: false,
    officialText: '',
    baseStatus: '',
    remainTime: {},
    CompletedOrderInfo: {},
    alternateData: {},
    alternateBol: true,
    marvellousList: [], //活动详情往期精彩列表
    shareInfo: {
      sid: '',
      pid: '',
      sharer: '',
      groupid: '',
      sessionName: '',
      mealsName: ''
    },
    inviteEnroll: false, //是否参与拼团及同场次排期
    refundShow: false,
    type: 0,
    detailParams: {},
    autoplay: false, //自动播放
    shareInvite: '',//分享过来的邀请码（用于非机构用户二次分享）
  },
  // 点击往期精彩后跳转
  goPrevious(e) {
    console.log(e);
    let psId = e.currentTarget.dataset.psid
    console.log(psId);
    wx.navigateTo({
      url: '/pages/product/Previous/index?psId=' + JSON.stringify(psId) + '&aid=' + this.data.datas.aid,
    })
  },
  // 点击安全保障
  jumpPage(e) {
    wx.navigateTo({
      url: '/pages/product/security/index?id=' + JSON.stringify(this.data.securityShow),
    })
  },
  jumpGoodsPage() {
    wx.navigateTo({
      url: '/pages/public/showGoodsList/index?aid=' + this.data.aid,
    })
  },
  onLoad(options) {
    console.log('options', options)
    if (!util.isEmpty(options.sharesid)) {
      this.setData({
        'shareInfo.sid': options.sharesid,
        'shareInfo.pid': options.sharepid,
        'shareInfo.sharer': options.sharer,
        'shareInfo.groupid': util.isEmpty(options.groupid) || options.groupid == 'undefined' || options.groupid == 'null' ? '' : options.groupid
      })
      if (!util.config.invitePopupTime) {
        util.config.invitePopupTime = true;
      }
    }
    this.setData({
      showPopup: options.showPopup
    })
    let aid = options.aid,
      orderid = options.orderid || '',
      groupid = util.isEmpty(options.groupid) || options.groupid == 'undefined' || options.groupid == 'null' ? '' : options.groupid,
      that = this;
    if (options.invite) {
      wx.setStorageSync("WX-invite", options.invite);
      this.setData({
        shareInvite: options.invite
      })
      // this.isRecomCode()
    }
    if (options.channel) {
      this.setData({
        channel: options.channel,
        channelTimes: options.channelTimes || 1
      })
      util.config.channelInfo = {
        channel: options.channel,
        channelTimes: options.channelTimes || 1
      }
      this.getChannelMsg(options)
    }
    if (!options.channel && util.config.channelInfo.channel) {
      let getChannel = util.config.channelInfo.channel;
      this.setData({
        channel: getChannel.channel,
        channelTimes: getChannel.channelTimes
      })
      this.getChannelMsg(getChannel)
    }
    this.setData({
      aid: aid,
      orderid: orderid,
      groupid: !util.isEmpty(groupid) ? groupid : '',
      userInfo: app.globalData.userInfo
    })

    util.refreshCount();
    //  —————————————— 从二维码扫码进去活动详情页面 ——————————————————
    if (!util.isEmpty(options.scene)) {
      // let scene = decodeURIComponent(options.scene);
      let pa = this.getSceneParam(options.scene);
      if (util.isObjEmpty(pa)) {
        util.showTips("二维码已过期，请重新获取！");
        this.setData({
          onshow: false
        });
        return false;
      }
      if (!util.isEmpty(pa.paramsCode)) { //code不为空时，通过code获取对应活动分享参数
        this.setData({
          onshow: false
        });
        util.ajax({
          func: "params",
          data: {
            "code": pa.paramsCode
          },
          load: false
        }, function (res) {
          if (res.code == 0 && !util.isEmpty(res.data)) {
            if (!util.isEmpty(res.data.code)) {
              wx.setStorageSync("WX-invite", res.data.code);
              // that.isRecomCode() //通过邀请码判断邀请者身份
            }
            aid = res.data.aid || '';
            groupid = util.isEmpty(res.data.groupid) || res.data.groupid == 'undefined' || res.data.groupid == 'null' ? '' : res.data.groupid;
            orderid = res.data.orderid || '';

            that.setData({
              aid,
              orderid,
              groupid,
              'shareInfo.sid': res.data.sharesid || '',
              'shareInfo.pid': res.data.sharepid || '',
              'shareInfo.sharer': res.data.sharer || '',
              'shareInfo.groupid': groupid,
            });
            that.saveAndSendCode(res.data);
            // util.promise().then(function (value) {
            that.getData();
            // });
          }
        });
      } else {
        if (!util.isEmpty(pa.aid)) {
          util.codeGetAid(pa.aid).then(res => {
            that.setData({
              aid: res.data
            })
          })
        } else {
          wx.reLaunch({
            url: '/pages/home/index'
          });
        }
      }
    } else if (util.isEmpty(aid)) {
      wx.reLaunch({
        url: 'pages/home/index'
      });
      return false;
    }
    // this.isRecomCode()
  },
  // 点击无忧报名弹框中确定
  closeRefund() {
    this.setData({
      refundShow: false
    })
  },
  // 点击报名无忧事件
  changeRefund() {
    console.log(Number(this.data.datas.refundRule));
    this.setData({
      refundShow: true,
      type: Number(this.data.datas.refundRule)
    })
  },
  getSceneParam(e) {
    if ((e != undefined || e != '') && e.indexOf('urlcode') == -1) {
      let scene = decodeURIComponent(e),
        data = {};
      if (scene.indexOf(",") != -1) {
        let params = scene.split(',');
        for (let i in params) {
          var val = params[i].split('=');
          val.length > 0 && val[0] && (data[val[0]] = val[1] || null)
        }
        return data;
      } else {
        if (scene.indexOf('paramsCode') != -1) {
          let val = scene.split('=');
          data[val[0]] = val[1];
        } else {
          data.aid = scene;
        }
        return data;
      }
    } else {
      return {};
    }
    let data = {};
    for (let i in params) {
      var val = params[i].split('=');
      val.length > 0 && val[0] && (data[val[0]] = val[1] || null)
    }
    return data;
  },
  openConvertPopup() {
    this.setData({
      showConvert: true
    })
  },
  closeConvertPopup() {
    this.setData({
      showConvert: false,
      showNextConvert: false
    })
  },
  // 任务倒计时完成
  finishedTime() {
    this.setData({
      'countDown.show': false
    })
  },
  // 宝贝币最高可兑换时长
  maxPrivilegeTime(e) {
    this.maxTime = e.time && e.time > 0 ? e.time : 0;
  },
  // 获取特权兑换时长
  changePrivilege(e) {
    this.closeConvertPopup()
    this.getData()
  },
  // 兑换二次提醒
  showPrompt(e) {
    this.setData({
      showConvert: false,
      checkedTime: e.detail.checkedTime,
      showNextConvert: true
    })
  },
  // 关闭二次弹窗
  closeNextPopup() {
    this.setData({
      showNextConvert: false,
    })
  },
  // 获取分享家是否停用
  stat() {
    // console.log(this.data.userInfo.roleType);
    // console.log(this.data.datas.shareCommission);
    let that = this;
    if (!util.isObjEmpty(this.data.userInfo)) {
      util.stat().then(res => {
        let data = util.getCoinLevel(res.allCoin)
        that.setData({
          'userInfo.shareStatus': res.shareStatus,
          showfloatWin: that.data.userInfo.roleType == 'sharer' && that.data.userInfo.shareStatus == 1 && that.data.datas.shareCommission > 0 && that.data.datas.rebate != 1 ? true : false,
          vip_Info: data
        })
      })
    }
  },
  // 通过小程序码进入的获取活动aid
  codeGetAid(aid) {
    let that = this;
    util.ajax({
      func: "v2/article/aid",
      data: {
        "aid": aid
      }
    }, function (res) {
      if (res.code == 0) {
        that.setData({
          aid: res.data
        })
      }
    });
  },
  // 支付尾款弹窗（继续报名）
  paymentPay(e) {
    if (this.data.inviteEnroll) {
      let data = {
        type: "makeUpGroup",
        currentTarget: {
          dataset: {
            alone: "0",
            item: {
              sid: this.data.shareInfo.sessionName ? this.data.shareInfo.sid : -1,
              pid: this.data.shareInfo.sessionName ? this.data.shareInfo.pid : -1
            }
          }
        }
        //套餐选中取决于场次有无
      }
      this.goPay(data)
    } else {
      this.goPay(e)
    }
  },
  // 点击评论跳转至全部评论页
  showAllComment() {
    wx.navigateTo({
      url: '/pages/product/comment/index?aid=' + this.data.datas.aid,
    })
  },
  // 候补弹窗
  alternateEmit(e) {
    let data = e.detail;
    this.setData({
      'show.sku': false,
      showAlternatePopup: true,
      alternateData: data
    })
  },
  // 关闭拼团弹窗
  closeGroupPopup(e) {
    this.setData({
      showGrouPopup: e.detail
    })
  },
  // 关闭约伴邀请拼团弹窗(我再看看)
  closeinviteEnroll() {
    util.config.invitePopupTime = false;
    this.setData({
      showEnrollPopup: false,
      inviteEnroll: false,
      isBuy: false
    })
  },
  //  约伴邀请弹窗（同场次及拼团）
  inviteEnrollSignup() {
    util.config.invitePopupTime = false;
    this.setData({
      showEnrollPopup: false,
      inviteEnroll: true,
      isBuy: true
    })
    this.goPay({
      type: "inviteEnroll",
      currentTarget: {
        dataset: {
          alone: '1',
          item: {
            sid: this.data.shareInfo.sid,
            pid: this.data.shareInfo.pid,
          }
        }
      }
    })
  },
  // 通过邀请码判断邀请者身份
  isRecomCode() {
    let that = this,
      code = wx.getStorageSync("WX-invite");
    if (!util.isEmpty(code) && !app.globalData.userInfo) {
      util.ajax({
        func: "inviter/info",
        data: {
          "code": code
        }
      }, function (res) {
        if (res.code == 0) {
          if (res.data.roleType == 'sharer' || res.data.roleType == 'organ') {
            clearTimeout(updateTimer);
            let updateTimer = setTimeout(() => {
              wx.navigateTo({
                url: '/pages/home/login'
              });
            }, 1000);
          }
        }
      });
    }
  },
  // 返回首页
  gohome() {
    wx.reLaunch({
      url: '/pages/home/index',
    })
  },
  // 扫二维码存储并传递渠道码参数值
  saveAndSendCode(params) {
    console.log('channel', params)
    let arr = params,
      op = {}; //格式转换
    op.channel = params.channelId;
    op.channelTimes = params.channelCount;
    this.getChannelMsg(op); //创建渠道记录
    if (op.channel) {
      this.setData({
        channel: op.channel,
        channelTimes: op.channelTimes ? op.channelTimes : 1
      })
      util.config.channelInfo = {
        channel: op.channel,
        channelTimes: op.channelTimes ? op.channelTimes : 1
      }
      return false;
    }
    if (!op.channel && !op.channelTimes && util.config.channelInfo.channel != 0) {
      let getChannel = util.config.channelInfo;
      if (getChannel.channel) {
        this.setData({
          channel: getChannel.channel,
          channelTimes: getChannel.channelTimes
        })
        return false;
      } else {
        this.setData({
          channelTimes: 0
        })
      }
    }
  },
  // 跳转至表单详情页（支付尾款）
  jumpBalancePayment(e) {
    let that = this;
    this.setData({
      showPaymentPopup: false
    })
    if (this.data.CompletedOrderInfo.status == 1) {
      wx.navigateTo({
        url: '/pages/product/balancePayment/balancePayment?aid=' + that.data.aid + '&otype=1' + '&orderid=' + that.data.CompletedOrderInfo.orderid + '&presellstatus=' + (this.data.CompletedOrderInfo.status != 0 ? 1 : 0),
      })
    }
    if (this.data.CompletedOrderInfo.status == 2) {
      wx.navigateTo({
        url: '/pages/order/index/order?otype=1',
      })
    }
  },
  // 详情页调用渠道创建记录接口
  getChannelMsg(options) {
    if (options.channel) {
      let channelParam = options.channel,
        that = this;
      util.getChannelMsg(channelParam).then((res) => { });
    }
  },
  // 获取是否显示尾款信息
  getBalance() {
    let that = this;
    util.ajax({
      func: "v2/article/presellOrder",
      data: {
        "aid": that.data.aid
      }
    }, function (res) {
      if (res.code == 0) {
        that.setData({
          CompletedOrderInfo: res.data
        })
      }
    })
  },
  onShow() {
    // 没有版本字段或字段与写入不一致强制重新登录
    if (!app.globalData.userInfo || !app.globalData.userInfo.VERSION || app.globalData.userInfo.VERSION != 9) {
      // 静默登录
      util.silentLogin().then(res => { })
    }
    var that = this
    // getLocation = util.promise();
    this.safetyTip(this.data.showPopup);
    this.setData({
      showConvert: false,
      showNextConvert: false
    })
    setTimeout(() => {
      if (that.data.onshow) {
        if (!util.isObjEmpty(app.globalData.city)) {
          that.getData();
        } else {
          // getLocation.then(function (value) {
          that.getData();
          // });
        }
      }
    }, 800);
  },
  safetyTip(showPopup) {
    let that = this,
      safeTips = wx.getStorageSync("safeTips"),
      getInfo = {};
    util.ajax({
      func: 'v2/index/advert/popup',
      load: false
    }, function (res) {
      if (res.code == 0) {
        // 不使用接口返回，展示默认
        // getInfo.data = res.data;
        getInfo.entryPage = 'articleInfo';
        getInfo.showPopup = (showPopup == 0 ? false : true) || true;
        that.safeTip = that.selectComponent('#safeTip');
        that.safeTip.getSafeTips(getInfo);
      }
    })
    this.data.show.tips = safeTips.show;
    this.setData({
      show: this.data.show
    });
  },
  onUnload() {
    this.pageCount();
    this.setData({
      show: this.defaultShow(),
      'countDown.show': false
    });
    clearTimeout(this.data.processTimer);
  },
  onHide() {
    this.pageCount();
    this.setData({
      show: this.defaultShow(),
      'countDown.show': false
    });
  },
  skuClose(e) {
    this.data.show.sku = e.detail;
    this.setData({
      show: this.data.show
    });
  },
  defaultShow() {
    this.data.show = {
      chat: false,
      sku: false,
      tips: false,
      growup: false,
      official: false
    };
    return this.data.show;
  },
  onPageScroll(e) {
    var query = wx.createSelectorQuery();
    var isColumn = this.data.isColumn,
      that = this,
      showBack = this.data.showBack;
    query.select('#content').boundingClientRect();
    query.select('#safeTrip').boundingClientRect();
    query.select('#notes').boundingClientRect();
    query.exec(function (res) {
      if (res && !that.data.isScroll) {
        if (res[2].top <= 0) {
          that.setData({
            current: 2
          });
        } else if (res[1].top <= 0) {
          that.setData({
            current: 1
          });
        } else if (res[0].top <= 37) {
          that.setData({
            current: 0
          });
        }
        that.setData({
          isColumn: res[0].top <= 0 ? true : false
        });
      }
    });
    if (e.scrollTop > 500 && !showBack) {
      this.setData({
        showBack: true
      })
    } else if (e.scrollTop <= 500 && showBack) {
      this.setData({
        showBack: false
      })
    }
  },
  chooseNav(e) {
    let current = e.currentTarget.dataset.id,
      that = this;
    that.setData({
      current,
      isScroll: true
    });
    var arr = ['content', 'safeTrip', 'notes'];
    wx.pageScrollTo({
      selector: "#" + arr[current],
      success: () => {
        that.setData({
          isColumn: true
        });
        clearTimeout(updateTimer);
        let updateTimer = setTimeout(() => {
          that.setData({
            isScroll: false
          });
        }, 1000);
      }
    });
    let reportStr;
    switch (current) {
      case 0:
        reportStr = "active_tips";
        break;
      case 1:
        reportStr = "safe_trip";
        break;
      case 2:
        reportStr = "active_instructions";
        break;
    }
    wx.reportAnalytics(reportStr, {
      aid: that.data.aid,
      title: that.data.title,
    });
  },
  getData() {
    let that = this,
      userInfo = app.globalData.userInfo;
    util.ajax({
      func: "v2/article/detail",
      data: {
        "aid": that.data.aid,
        "groupid": (that.data.groupid != 'null' ? that.data.groupid : ''),
        'orderid': that.data.orderid || ''
      },
      load: false
    }, function (res) {
      if (res.code == 0) {
        let datas = res.data;
        that.data.paramsDetail = res.data.psId
        datas.isTuan = datas.discountStatus;
        that.setData({
          securityShow: datas.articleType ? datas.articleType : '',
          copyCanbuy: datas.canbuy,
          privilegeTime: datas.aheadTimeLong ? that.timeToDate(datas.aheadTimeLong) : 0,
          'shareInfo.groupid': !util.isEmpty(datas.gdiscount.groupid) ? datas.gdiscount.groupid : '',
          marvellousList: datas.productSystemHistoryList
        })
        console.log(that.data.marvellousList);
        that.setData({
          baseStatus: datas.status,
          buttonText: util.decode(datas.status, 0, (!util.isObjEmpty(res.data.gdiscount) ? (!util.isEmpty(that.data.groupid) ? '立即购买' : "单独报名") : (userInfo && userInfo.membered == 1 ? "会员报名" : "立即报名")), 1, "已结束", 2, "已满额", 3, "已下架", 4, "待审核", 6, "未开始", "")
        });
        let buttonClass = '',
          buttonClass1 = '',
          buttonPTClass = '';
        if (datas.presellOpen != 0) {
          datas.canbuy = 1;
          buttonClass = datas.presellOpen == 1 ? 'button-theme' : 'disabled';
          buttonClass1 = (datas.gdiscount.items && datas.gdiscount.status == 0 && datas.presellOpen == 1) ? 'button-theme' : 'disabled';
        } else {
          buttonClass = datas.status == 0 ? (datas.gdiscount.items || datas.gdiscount.status == 0 ? 'button-theme' : 'button-theme') : 'disabled';

          buttonClass1 = (datas.status == 0) ? ((datas.gdiscount.items && datas.gdiscount.status == 0) ? 'button-theme' : 'disabled') : 'disabled';

          buttonPTClass = datas.status == 0 && datas.canbuy == 0 ? (datas.gdiscount.items || datas.gdiscount.status == 0 ? 'button-danger' : 'button-danger') : 'disabled';
        }

        if (!util.isObjEmpty(datas.users)) {
          for (let i in datas.users) {
            datas.users[i].avatar = !util.isEmpty(datas.users[i].avatar) ? datas.users[i].avatar : '/images/default_logo.jpg';
          }
        }
        res.data.role = userInfo && userInfo['role'] ? userInfo['role'] : util.userRole(Math.round(res.data.score));
        res.data.sdiscountText = res.data.sdiscount ? res.data.sdiscount.toString().replace("0.", "") : '';
        console.log(datas, '数据')
        // 分成两行
        if (datas.tags && datas.tags.length >= 5) {
          const middleIndex = Math.ceil(datas.tags.length / 2);
          datas.tags1 = datas.tags.splice(0, middleIndex);
          datas.tags2 = datas.tags.splice(-middleIndex);
        } else {
          datas.tags1 = datas.tags;
        }
        console.log(datas.tags1, datas.tags2);
        that.setData({
          city: res.data.city,
          datas,
          buttonClass,
          buttonClass1,
          buttonPTClass,
          title: datas.title,
          currentPages: getCurrentPages().length,
          groupid: datas.gdiscount.groupid ? datas.gdiscount.groupid : that.data.groupid,
          growupInfo: {
            otype: (datas.gdiscount ? datas.gdiscount.otype : 0),
            price: (datas.gdiscount ? datas.gdiscount.maxGPrice : 0.00),
            type: (datas.gdiscount ? datas.gdiscount.type : 0),
            createGroup: 0 //1--新开拼团 0--一键参团
          },
          integralConfig: {
            discount: datas.discount,
            aid: datas.aid
          },
          showPrivilege: (datas.presellOpen == 2 || (datas.presellOpen == 0 && datas.status == 6) ? true : false)
        });
        if (((datas.showStartTimer == 1 || datas.showEndTimer == 1)) || (datas.presellOpen != 0 && (datas.showPresellStartTimer == 1 || datas.showPresellEndTimer == 1))) {
          that.updateTime();
        }
        console.log(datas.qptype);
        // console.log(datas.qptype, datas.showStartTimer, datas.showEndTimer, datas.presellOpen, datas.showPresellStartTimer, datas.showPresellEndTimer);
        // console.log(datas.qptype == 1 && (datas.showStartTimer == 0 && datas.showEndTimer == 0));
        if (((datas.showStartTimer == 0 && datas.showEndTimer == 0)) || (datas.presellOpen != 0 && (datas.showPresellStartTimer == 1 || datas.showPresellEndTimer == 1))) {
          that.updateTime();
        }
        // if ((datas.qptype == 1 && (datas.saleTimeLong >0 || datas.endSaleTimeLong >0)) || (datas.presellOpen != 0 && (datas.presellStartTimeLong >0 || datas.presellEndTimeLong >0))) {
        //   that.updateTime();
        // }
        if (datas.presellOpen == 0) {
          that.getBalance();
        }
        that.remainTime();
        that.getSkuInfo();
        that.getFeedbook();
        that.getContent();
        that.pageCount();
        that.stat();
        that.getGoodsRecommend();
        that.countDownTask();
      } else {
        util.showTips(res.reason);
      }
    })
  },
  getGoodsRecommend() {
    let that = this;
    util.getGoodsRecommend(this.data.datas.aid).then(res => {
      that.setData({
        showGoodsRecom: res
      })
    })
  },
  // 宝贝币任务倒计时
  countDownTask() {
    let that = this;
    let oldData = wx.getStorageSync('task_viewAct'),
      nowDate = util.getNowFormatDate();
    if (nowDate && oldData.date == nowDate) {
      let timer = setTimeout(() => {
        util.ajax({
          func: "v2/user_coin/task/detail",
          data: {
            code: 'browseArticle'
          },
          load: false
        }, function (res) {
          if (res.code == 0) {
            if (res.data.passCount < res.data.maxPassCount) {
              that.setData({
                'countDown.show': true,
                'countDown.taskId': res.data.id
              })
            }
            clearTimeout(timer)
          }
        })
      }, 1000);
    }
  },
  // 特权时间
  timeToDate(time) {
    var date = new Date();
    if (time) {
      date.date = Math.floor(time / (1000 * 60 * 60 * 24));
      date.hours = Math.floor((time / (1000 * 60 * 60)) % 24);
      date.minutes = Math.floor((time / (1000 * 60)) % 60);
      if (date.date <= 0 && date.hours > 0) {
        return date.hours + '小时' + date.minutes + '分钟';
      } else if (date.date <= 0 && date.hours <= 0 && date.minutes > 0) {
        return date.minutes + '分钟';
      } else {
        return date.date + '天' + date.hours + '小时' + date.minutes + '分钟';
      }
    } else {
      return 0;
    }
  },
  // 拼团剩余时间数据处理
  remainTime() {
    let self = this,
      data = this.data.datas,
      lag = data.gdiscount.times / 1000;
    data.remainTime = {};

    data.remainTime.day = Math.floor(lag / (3600 * 24));
    let mo = lag % (3600 * 24);
    data.remainTime.hour = Math.floor(mo / 3600);
    mo = mo % 3600;
    data.remainTime.minite = Math.floor(mo / 60);
    data.remainTime.second = Math.floor(mo % 60);

    data.remainTime.hour = isTimeLeng(data.remainTime.hour);
    data.remainTime.minite = isTimeLeng(data.remainTime.minite);
    data.remainTime.second = isTimeLeng(data.remainTime.second);
    data.gdiscount.times = data.gdiscount.times - 1000;
    self.setData({
      remainTime: data.remainTime
    });
    clearTimeout(updateTimer);
    let updateTimer = setTimeout(function () {
      self.remainTime();
    }, 1000);

    function isTimeLeng(val) {
      var s = val.toString();
      return s.length == 1 ? "0" + val : val;
    }
  },
  getContent() {
    let that = this;
    util.ajax({
      func: "v2/article/content",
      data: {
        "aid": that.data.aid
      },
      load: false
    }, function (res) {
      if (res.code == 0) {
        let datas = res.data;
        that.data.datas.content = datas.content.replace(/section/g, "div");
        that.data.datas.content = that.data.datas.content.replace(/<img/g, "<img style='max-width:100%'");
        //datas.content = datas.content.replace(/<!--[^%]*-->/g, "");
        let str = datas.content.match(/<source src="(\S*)"/g);
        if (str) {
          let viode = [];
          for (let i in str) {
            if (i < 3) { //只显示三个视频
              let src = str[i].match(/<source src="(\S*)"/)[1];
              viode.push(src.toString())
            }
          }
          that.setData({
            viode
          });
        }
        that.data.datas.notes = datas.notes ? datas.notes.replace(/section/g, "div") : '';
        that.data.datas.notes = that.data.datas.notes.replace(/<img/g, "<img style='max-width:100%'");
        that.data.datas.safeTrip = datas.safeTrip ? datas.safeTrip.replace(/section/g, "div") : '';
        that.data.datas.safeTrip = that.data.datas.safeTrip.replace(/<img/g, "<img style='max-width:100%'");
        // console.log(that.data.datas.safeTrip);
        // console.log(that.data.datas.notes);
        // console.log(that.data.datas.content);
        that.setData({
          datas: that.data.datas
        });
      }
    })
  },
  getFeedbook() { //获取评论
    let that = this;
    util.ajax({
      func: "comments/list",
      data: {
        "aid": this.data.aid,
        "pageIndex": 1,
        "pageSize": 1,
        "sort": 1,
        "keyword": ''
      }
    }, function (res) {
      if (res.code == 0) {
        for (let i in res.data.comments) {
          res.data.comments[i].contented = res.data.comments[i].content.replace(/#([^#]+)#/g, "").replace(/<br\/>/g, '\n');
          res.data.comments[i].option = res.data.comments[i].content.match(/#([^#]+)#/g);
          res.data.comments[i].fcontent = res.data.comments[i].fcontent.replace(/<br\/>/g, '\n');
        }
        that.setData({
          comments: res.data,
          score: res.data.score
        });
      } else {
        util.showTips(res.reason);
      }
    })
  },
  setRemind(e) {
    console.log(e)
    if (e.type == "salesReminder") {
      this.data.show.growup = false;
    }
    let that = this;
    wx.showModal({
      content: this.data.datas.status == 6 ? `确定设置提醒？活动${that.data.datas.presellOpen == 0 ? '开售' : '预售'}前通过小程序或短信通知您。` : '确定设置提醒？活动有名额时通过小程序或短信通知您。',
      confirmColor: '#EE3A43',
      success: function (res) {
        if (res.confirm) {
          util.requestMsg('hv74W2gdjlzupQGuN_BgFpyv7VDQxuXf9YhdxlR8His').then(e => {
            util.ajax({
              func: "v2/articleRemind/confirm",
              data: {
                aid: that.data.datas.aid,
                saleType: that.data.datas.presellOpen == 0 ? 0 : 1
              }
            }, function (res) {
              if (res.code == 0) {
                // that.data.show.official = true;
                // that.data.officialText = data.data.msg;
                // that.setData({ show: that.data.show, officialText: that.data.officialText});
                util.showTips(res.data.msg);
              } else
                util.showTips(res.reason);
            });
          })
        }
      }
    });
  },
  gofriend() {
    let that = this;
    if (util.isEmpty(that.data.aid)) {
      util.showTips('aid不存在');
      return false;
    }
    wx.reportAnalytics('together_proper', {
      aid: that.data.aid,
      title: that.data.datas.title,
    });
    wx.navigateTo({
      url: '/pages/product/activity/partner?aid=' + that.data.aid
    })
  },
  // 活动倒计时
  updateTime() {
    var self = this,
      that = this.data.datas,
      userInfo = app.globalData.userInfo,
      member_time = 0,
      lag = '',
      lag2 = '',
      memberSale = false;
    if (that.presellOpen == 0) { //开售未开始 提前时间
      member_time = (!util.isEmpty(that.memberSaleTime) ? that.memberSaleTime / 1000 : null); //会员提前时间
    }
    if (that.presellOpen == 2) { //预售未开始 提前时间
      let t = that.presellStartTimeLong - that.aheadTimeLong;
      member_time = ((that.presellStartTimeLong && that.aheadTimeLong) ? t : 0) / 1000;
    }
    // 设定倒计时时间
    if (that.presellOpen == 0) { //正常开售
      self.setData({
        'datas.canbuy': self.data.copyCanbuy
      })
      lag = 0;
      lag2 = 0;
      lag = (that.saleTimeLong ? that.saleTimeLong : 0) / 1000,
        lag2 = (that.endSaleTimeLong ? that.endSaleTimeLong : 0) / 1000;
    } else { //预售
      lag = 0;
      lag2 = 0;
      lag = (that.presellStartTimeLong ? that.presellStartTimeLong : 0) / 1000,
        lag2 = (that.presellEndTimeLong ? that.presellEndTimeLong : 0) / 1000;

      that.presellPayStartTime = util.formatDate(util.formatUnixtimestamp(that.saleTime), 'MM月dd日 hh:mm', false);
      that.presellPayEndTime = util.formatDate(util.formatUnixtimestamp(that.presellPaymentDeadline), 'MM月dd日 hh:mm', false);
    }

    let second, minite, hour, day,
      buttonClass = self.data.buttonClass,
      buttonPTClass = self.data.buttonPTClass,
      buttonText = self.data.buttonText,
      buttonClass1 = self.data.buttonClass1;

    if (lag > 0) { //距离开始
      this.setData({
        showPrivilege: true
      })
      day = Math.floor(lag / (3600 * 24));
      let mo = lag % (3600 * 24);
      hour = Math.floor(mo / 3600);
      mo = mo % 3600;
      minite = Math.floor(mo / 60);
      second = Math.floor(mo % 60);
      self.data.updateTime.title = '距开始';
      self.data.updateTime.isQp = 0;
      if (that.status == 0 || that.status == 6) {
        self.data.updateTime.isPayInfo = true;
      } else {
        self.data.updateTime.isPayInfo = false;
      }

      if (that.presellOpen == 0) {
        self.data.showTimer = that.showStartTimer == 0 ? false : true;
        that.saleTimeLong = that.saleTimeLong - 1000;
        self.data.updateTime.saleTime = util.formatDate(util.formatUnixtimestamp(that.saleTime), 'MM月dd日 hh:mm', false);
        memberSale = true;
      } else {
        self.data.showTimer = that.showPresellStartTimer == 0 ? false : true;
        that.presellStartTimeLong = that.presellStartTimeLong - 1000;
        self.data.updateTime.saleTime = util.formatDate(util.formatUnixtimestamp(that.presellStartTime), 'MM月dd日 hh:mm', false);
      }
    } else if (lag2 > 0 && lag <= 0) { // 距离结束
      this.setData({
        showPrivilege: false
      })
      day = Math.floor(lag2 / (3600 * 24));
      let mo = lag2 % (3600 * 24);
      hour = Math.floor(mo / 3600);
      mo = mo % 3600;
      minite = Math.floor(mo / 60);
      second = Math.floor(mo % 60);
      self.data.updateTime.title = "距结束";
      self.data.updateTime.isQp = 1;
      self.data.updateTime.isPayInfo = true;
      if (that.presellOpen == 0) {
        self.data.showTimer = that.showEndTimer == 0 ? false : true;
        that.endSaleTimeLong = that.endSaleTimeLong - 1000;
        self.data.updateTime.saleTime = util.formatDate(util.formatUnixtimestamp(that.endSaleTime), 'MM月dd日 hh:mm', false);
        if (self.data.getBalanceData) {
          // 倒计时结束刷新页面
          if (!util.isObjEmpty(app.globalData.city)) {
            self.getData();
          } else {
            getLocation.then(function (value) {
              self.getData();
            });
          }
          self.setData({
            getBalanceData: false
          })
        }
      } else {
        self.data.showTimer = that.showPresellEndTimer == 0 ? false : true;
        if (that.presellOpen == 2) {
          that.presellOpen = 1
          let sessionStatus = self.data.sku.sessions.find((el) => (el.status == 0));
          // that.status = sessionStatus?0:2;
          buttonClass = sessionStatus ? 'button-theme' : 'disabled';
          buttonClass1 = sessionStatus ? 'button-theme' : 'disabled';
        }
        that.presellEndTimeLong = that.presellEndTimeLong - 1000;
        self.data.updateTime.saleTime = util.formatDate(util.formatUnixtimestamp(that.presellEndTime), 'MM月dd日 hh:mm', false);
      }
      if (that.status == 0 || that.status == 6) {
        if (that.membered == 1) {

        } else {
          buttonClass = "button-theme";
          buttonPTClass = "button-danger";
        }
        if (self.data.sku && that.presellOpen == 1) {
          let sessionStatus = self.data.sku.sessions.find((el) => (el.status == 0));
          that.status = sessionStatus ? 0 : 2;
        } else {
          that.status = 0;
        }

        if (that.status == 2) {
          buttonText = "已满额";
        }
        if (self.data.baseStatus != 2 && that.presellOpen == 0) buttonText = "立即报名";
      }

      // buttonClass = datas.status == 0 && datas.canbuy == 0 ? (datas.gdiscount.items || datas.gdiscount.status == 0 ? 'button-theme' :'button-theme') : 'disabled';
    } else { //活动结束/预售结束
      if (that.presellOpen == 1) {
        that.presellOpen = 0
        that.canbuy = self.data.copyCanbuy;
        that.status = 6;
        self.data.baseStatus = 6;
        buttonText = "未开始";
        buttonClass = 'disabled';
        buttonClass1 = 'disabled';
        console.log(!util.isEmpty(that.memberSaleTime), that.memberSaleTime)
        member_time = (that.memberSaleTime ? that.memberSaleTime : 0) / 1000;
        // self.setData({'datas.presellOpen':0})
      } else {
        that.qptype = 0;
        that.status = 1;
        buttonText = "已结束";
        if (that.presellOpen == 0) {
          buttonClass = "disabled";
          buttonPTClass = "disabled";
          buttonClass1 = 'disabled'
        }
      }
    }
    that.isTuan = 0;
    if (self.data.baseStatus == 6 && userInfo && (userInfo['role']['level'] > 1 || that.membered == 1 || that.aheadTimeLong > 0) && (that.presellOpen == 0 || that.presellOpen == 2) && that.status == 6) { //会员时间倒计时（距离开始时间开始计时）
      if (member_time != null && member_time <= 0) {
        member_time = 0;
        if (that.presellOpen == 0) {
          buttonClass = "button-theme";
          buttonClass1 = "button-theme";
          buttonPTClass = "button-danger";
          buttonText = !util.isEmpty(self.data.groupid) ? '立即购买' : "单独报名";
          self.data.updateTime.isPayInfo = true;
          that.status = 0;
          // this.getBalance()
          // self.setData({getBalanceData:false})
        } else {
          that.status = 0;
          buttonClass = "button-theme";
          self.data.updateTime.isPayInfo = true;
        }
        self.setData({
          buttonClass: buttonClass,
          buttonPTClass: buttonPTClass,
          buttonText,
          datas: that
        });
      } else {
        // if (that.presellOpen == 0) {
        //   that.memberSaleTime = that.memberSaleTime - 1000;
        // }
      }
    }
    if (that.presellOpen != 0 || (that.presellOpen == 0 && that.status == 6) && !util.isEmpty(that.memberSaleTime)) {
      that.memberSaleTime = that.memberSaleTime - 1000;
    }
    if (lag > 0 || lag2 > 0) {
      self.data.updateTime.day = isTimeLeng(day);
      self.data.updateTime.hour = isTimeLeng(hour);
      self.data.updateTime.minite = isTimeLeng(minite);
      self.data.updateTime.second = isTimeLeng(second);
    }
    if (that.status == 0 && (member_time <= 0 || lag <= 0)) {
      that.canbuy = 0;
      that.isTuan = 1;
    }
    let datasPresellOpen = 'datas.presellOpen';
    self.setData({
      datasPresellOpen: that.presellOpen,
      showTimer: self.data.showTimer,
      datas: that,
      updateTime: self.data.updateTime,
      buttonClass: buttonClass,
      buttonPTClass: buttonPTClass,
      buttonClass1: buttonClass1,
      buttonText,
      'datas.status': that.status
    });
    clearTimeout(self.data.processTimer);
    let updateTimer = setTimeout(function () {
      self.updateTime();
    }, 1000);
    self.setData({
      processTimer: updateTimer
    })
    if (that.presellOpen == 0 && that.status == 1) {
      clearTimeout(self.data.processTimer);
    }

    function isTimeLeng(val) {
      var s = val.toString();
      return s.length == 1 ? "0" + val : val;
    }
  },
  goPay(e) { //点击报名活动
    console.log(e)
    if (!util.isObjEmpty(this.data.CompletedOrderInfo) && this.data.CompletedOrderInfo.status != 0 && (e.type == "tap" || e.type == "inviteEnroll" || e.type == "close")) {
      this.setData({
        showPaymentPopup: true
      })
    } else {
      // if (!util.isEmpty(this.data.groupid)&&!e.detail.pop && this.data.alternateBol && e.type=="tap") {
      //   this.setData({showGrouPopup:true})
      //   return false;
      // }
      if (this.data.showPaymentPopup) {
        this.setData({
          showPaymentPopup: false
        });
      }
      if (this.data.showGrouPopup) {
        this.setData({
          showGrouPopup: false
        })
      }
      this.data.show = this.defaultShow();
      this.data.show.growup = false;
      this.data.show.integral = false;
      if (this.data.datas.canbuy == 0 && this.data.datas.status == 0) {
        this.data.show.sku = true;
        let data = JSON.stringify(e.currentTarget.dataset) != "{}" ? e.currentTarget.dataset : e.detail;
        this.data.growupInfo.createGroup = data.alone ? data.alone : (this.data.growupInfo.createGroup != undefined ? this.data.growupInfo.createGroup : 0);
        let isBuy = this.data.growupInfo.createGroup == 0 ? false : true;
        this.setData({
          url: '/page/registration.html',
          show: this.data.show,
          isBuy,
          growupInfo: this.data.growupInfo,
          skuIndex: data.alone != 1 && data.item ? data.item.sid : -1,
          mealsIndex: data.alone != 1 && data.item ? data.item.pid : -1,
        });
      }
    }
  },
  // 新开拼团/一键参团弹窗确认购买
  growupToPay(e) {
    if (this.data.inviteEnroll) {
      let data = {
        dataset: {
          alone: this.data.growupInfo.createGroup,
          item: {
            sid: this.data.shareInfo.sessionName ? this.data.shareInfo.sid : -1,
            pid: this.data.shareInfo.sessionName ? this.data.shareInfo.pid : -1,
          }
        }
      };
      e.currentTarget = data;
    }
    this.goPay(e)
  },
  chat() {
    this.data.show = this.defaultShow();
    this.data.show.chat = true;
    this.setData({
      url: '/page/baodada.html',
      show: this.data.show
    });
  },
  alternatePopup(e) {
    this.setData({
      showAlternatePopup: false
    })
  },
  toTop() {
    wx.pageScrollTo({
      scrollTop: 0,
      duration: 300
    })
  },
  pageCount() {
    let userInfo = app.globalData.userInfo,
      that = this,
      aid = this.data.aid,
      temCountId = this.data.temCountId;
    if (userInfo) {
      if (temCountId) {
        util.ajax({
          func: "user/browhistory_out",
          data: {
            'id': temCountId,
            'url': that.data.url,
            'timeOut': Date.parse(new Date()),
            'source': 'applet'
          },
          load: false
        }, function (res) {
          if (res.code == 0) that.setData({
            temCountId: ''
          })
        })
      } else {
        let length = getCurrentPages().length,
          dataArr = {
            'rid': userInfo.rid,
            'aid': aid,
            'url': length == 1 ? '/page/product_detail.html' : '/',
            'timeIn': Date.parse(new Date()),
            'source': 'applet'
          };
        util.ajax({
          func: "user/browhistory_in",
          data: dataArr,
          load: false
        },
          function (res) {
            if (res.code == 0) that.setData({
              temCountId: res.data
            })
          });
      }
    }
  },
  // 出行人列表图片加载失败显示默认图片
  errorPic(e) {
    let index = e.currentTarget.dataset.i,
      url = 'datas.users[' + index + '].avatar';
    this.data.datas.users[index].avatar = '/images/default_logo.jpg';
    this.setData({
      datas: this.data.datas
    })
  },
  navigatorTo(e) {
    util.navigator(e.currentTarget.dataset.url);
  },
  invite() {
    let getChannel = util.config.channelInfo;
    if (getChannel.channel) {
      this.setData({
        channel: getChannel.channel,
        channelTimes: getChannel.channelTimes
      })
    }
    this.data.show = this.defaultShow();
    this.data.show.share = true;
    this.setData({
      show: this.data.show
    });
  },
  newGroup(e) {
    if (this.data.showEnrollPopup) {
      util.config.invitePopupTime = false;
      this.setData({
        showEnrollPopup: false,
        inviteEnroll: true
      });
    }
    if (e.currentTarget.dataset.creategroup) {
      this.data.growupInfo.createGroup = parseInt(e.currentTarget.dataset.creategroup);
    } else {
      this.data.growupInfo.createGroup = parseInt(e.detail);
      if (this.data.showGrouPopup) {
        this.setData({
          showGrouPopup: false
        });
      }
    }
    this.data.show = this.defaultShow();
    this.data.show.growup = true;
    this.setData({
      growupInfo: this.data.growupInfo,
      show: this.data.show,
      isBuy: Boolean(this.data.growupInfo.createGroup)
    });
  },
  integral() {
    this.data.show = this.defaultShow();
    this.data.show.integral = true;
    this.setData({
      show: this.data.show
    });
  },
  previewImage(e) {
    let index = e.currentTarget.dataset.index,
      i = e.target.dataset.i,
      comments = this.data.comments.comments;
    this.setData({
      onshow: false
    });
    wx.previewImage({
      current: comments[index].imageList[i], // 当前显示图片的http链接
      urls: comments[index].imageList // 需要预览的图片http链接列表
    })
  },
  previewFimages(e) {
    let index = e.currentTarget.dataset.index,
      i = e.target.dataset.i,
      comments = this.data.comments.comments;
    this.setData({
      onshow: false
    });
    wx.previewImage({
      current: comments[index].fcomments.fimages[i], // 当前显示图片的http链接
      urls: comments[index].fcomments.fimages // 需要预览的图片http链接列表
    })
  },
  getSkuInfo() {
    let that = this;
    util.ajax({
      func: "v2/article/payinfo",
      data: {
        "aid": that.data.aid
      },
      load: false
    }, function (res) {
      if (res.code == 0) {
        let obj = res.data.sessions.find((el) => (el.status == 0));
        that.setData({
          sku: res.data,
          alternateBol: (res.data.sessions && res.data.sessions.length > 0) ? (obj ? true : false) : false
        });
        if (util.config.invitePopupTime) {
          that.findSku()
        }
        // if ((that.data.shareInfo.sid && that.data.shareInfo.pid && that.data.shareInfo.sharer) || that.data.shareInfo.groupid) {
        //   setTimeout(() => {
        //     that.setData({showEnrollPopup:true})
        //   }, 500);
        // }
      }
    })
  },
  // 判断好友邀请的场次排期是否存在
  findSku() {
    let list = this.data.sku.sessions,
      data = {},
      sid = this.data.shareInfo.sid,
      pid = this.data.shareInfo.pid;
    for (let i = 0; i < list.length; i++) {
      if (list[i].sid == sid) {
        data.sessionName = list[i].name;
        for (let index = 0; index < list[i].meals.length; index++) {
          if (list[i].meals[index].pid == pid) {
            data.mealsName = list[i].meals[index].policyName;
            // return false;
          }
        }
      }
    }
    setTimeout(() => {
      if ((!util.isEmpty(data.mealsName) && !util.isEmpty(data.sessionName)) || !util.isEmpty(this.data.shareInfo.groupid)) {
        this.setData({
          showEnrollPopup: true,
          'shareInfo.sessionName': data.sessionName,
          'shareInfo.mealsName': data.mealsName
        })
      }
    }, 500);
  },
  onShareAppMessage() {
    var datas = this.data.datas,
      that = this,
      inviteCode = '',
      channelInfo = util.config.channelInfo;
    this.shareRecord(datas);
    // 判断当前用户是机构，是使用当前用户邀请码，不是使用分享过来的
    if (this.data.userInfo.roleType == 'organ') {
      if (!util.isEmpty(datas.inviteCode)) {
        inviteCode = datas.inviteCode;
      } else {
        inviteCode = app.globalData.userInfo ? app.globalData.userInfo.code : '';
      }
    } else {
      inviteCode = this.data.shareInvite ? this.data.shareInvite : app.globalData.userInfo ? app.globalData.userInfo.code : '';
    }
    wx.reportAnalytics('active_share', {
      aid: datas.aid,
      title: datas.title,
    });
    return {
      title: (that.data.groupid || that.data.orderid ? '约吗？快来和我家孩子一起拼团挑战' : '约吧，邀请你家宝贝一起参加活动'),
      path: '/pages/product/activity/index?aid=' +
        datas.aid +
        ('&invite=' + inviteCode) + ((channelInfo.channel != 0 && !util.isEmpty(channelInfo.channel) && channelInfo.channelTimes == 1) ? ('&channel=' + channelInfo.channel) : '') +
        ((channelInfo.channel != 0 && channelInfo.channelTimes == 1) ? ('&channelTimes=' + (parseInt(channelInfo.channelTimes) + 1)) : '')
    }
  },
  // 分享到朋友圈 不支持自定义
  onShareTimeline() {
    var datas = this.data.datas,
      that = this,
      inviteCode = '',
      channelInfo = util.config.channelInfo;
    this.shareRecord(datas);
    // 判断当前用户是机构，是使用当前用户邀请码，不是使用分享过来的
    if (this.data.userInfo.roleType == 'organ') {
      if (!util.isEmpty(datas.inviteCode)) {
        inviteCode = datas.inviteCode;
      } else {
        inviteCode = app.globalData.userInfo ? app.globalData.userInfo.code : '';
      }
    } else {
      inviteCode = this.data.shareInvite ? this.data.shareInvite : app.globalData.userInfo ? app.globalData.userInfo.code : '';
    }
    wx.reportAnalytics('active_share', {
      aid: datas.aid,
      title: datas.title,
    });
    return {
      title: (that.data.groupid || that.data.orderid ? '约吗？快来和我家孩子一起拼团挑战' : '约吧，邀请你家宝贝一起参加活动'),
      path: '/pages/product/activity/index?aid=' +
        datas.aid +
        ('&invite=' + inviteCode) + ((channelInfo.channel != 0 && !util.isEmpty(channelInfo.channel) && channelInfo.channelTimes == 1) ? ('&channel=' + channelInfo.channel) : '') +
        ((channelInfo.channel != 0 && channelInfo.channelTimes == 1) ? ('&channelTimes=' + (parseInt(channelInfo.channelTimes) + 1)) : '')
    }
  },
  // 记录分享次数
  shareRecord(data) {
    if (!util.isEmpty(data.aid)) {
      util.ajax({
        func: 'article/share',
        data: {
          "aid": data.aid
        },
        load: false
      }, function (res) {
        if (res.code == 0) {
          console.log(res.reason)
        }
      })
    }
  },
  // 自动播放
  previewVideo(e) {
    console.log(e);
    wx.previewMedia({
      sources: [{
        url: e.currentTarget.dataset.vdurl, //视频播放路径
        type: 'video' //video视频 image图片
      }]
    })
  },
  //视频号
  channelVideo(e) {
    let feedId = e.currentTarget.dataset.vdnum
    let finderUserName = e.currentTarget.dataset.uname
    wx.openChannelsActivity({
      finderUserName,
      feedId,
      success: function (res) {
        console.log(res)
      },
      complete: function () {
        console.log('调用');
      }
    })
  },
  // 图片预览
  actPreviewImage(e) {
    console.log(e);
    let index = e.currentTarget.dataset.index
    let urls = []
    let actDetail = this.data.marvellousList
    actDetail.forEach((e) => {
      if (e.type == 4) {
        urls.push(e.logo)
      }
    })
    let imgUrl = e.currentTarget.dataset.imgurl
    // urls.push(imgUrl)
    wx.previewImage({
      current: e.currentTarget.dataset.imgurl, // 当前显示图片的http链接
      urls,
    })
  }
})