// packageC/video_goods/VideoDetail/VideoDetail.js
var app = getApp();
var int = app.globalData.statusBarHeight * 2;
const storeAlone = "plugin.store-alone-temp.frontend.videoShare.video.get-list";
Page({
  /**
   * 页面的初始数据
   */
  data: {
    isShowADLook: true, //广告列表按钮
    isShowADPut: true, //广告投放按钮
    statusBarHeight: int,
    language: "",
    amount_id: null,
    isLoadMore: true,
    page: 1,
    total_page: 0,
    popularVideo: [],
    heightauto: "auto",
    widthauto: "auto",
    showVideo: {},
    myvideo: "",
    show: false,
    screeheight: 0,
    minStyle: true,
    firstcontent: false,
    cleartime: null,
    realIndex: 0,
    kFootshow: true,
    is_plugins: 0,

    //答题
    AnswerID: 0,
    showVideoAnswer: false,
    successShow: false,
    errorShow: false,
    subject: null,
    integral: 0,
    vid: 0,
    integral_name: "积分",

    //短视频红包
    reward_type: 0, //奖励类型（ 1观看累计时长 2看完视频发放奖励）
    logID: 0, //视频已观看记录的视频id
    maxTime: 0, //视频总时长
    activity_reward_id: 0,
    redpack_info: {
      amount: 0,
    }, //红包设置展示信息
    is_openRedpack: false,
    openRedpackData: [], //短视频红包活动数组
    openRedpackTimes: [], //观看时长集合数组
    showVerification: false, //绑定手机
    showRedpack: false, //红包
    openRedpack: false,
    currentDuration: 0, //当前视频播放时长（重播时复位为0）
    cumulativeDuration: 0, //累计时长
    //绑定手机
    start1: false,
    codetext: "获取验证码",
    bind_mobile: false,
    imgcode: "", //图形验证码
    cationCode: false,
    count: "",
    form: {
      mobile: "",
      //验证码
      code: "",
      captcha: "",
    },
    timer: null,

    loading: false,
    //--------
    dataList:[],
    BasicSet:{},
    activeType: 0,
    currentVideoIndex: 0,
    swiperDuration: 500,

    showCommentInput: false,
    commentInputOptiones: {},
    showSheet: false,
    actions: [{
      name: "回复",
      index: 0
    }, {
      name: "删除",
      index: 1
    }],
    comment_open: "1",
    commentlist: [],
    showYzComment: false,
    commentLoading: false,
    commentFinished: false,
    commentTotal: 0,//评论总数
    commentPage: 1, //评论当前页数

    points_plugin:0,
    videoShare:{
      needAnswer:false,
      is_show:false,
      show:false,
      points:0,
      point_name:''
    },
    

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.data.myvideo = wx.createVideoContext("myvideo");
    this.getinformation();
    if (options.vid) {
      this.setData({
        amount_id: options.vid,
      });
    }
    if (options.mid) {
      app._setMid(options.mid);
    }
    if (options.status) {
      this.setData({
        cardFrom: "my",
        sta: options.status,
      });
    }
    if (options.card_id) {
      this.setData({
        card_id: options.card_id,
      });
    }
    if (options.from) {
      this.setData({
        cardFrom: options.from,
      });
    }
    try {
      wx.setStorageSync("vid", this.data.amount_id);
    } catch (e) {
      console.log(e);
    }
    if (options.page) {
      this.setData({
        page: Number(options.page) ? Number(options.page) : 1,
      });
    }
    // 判断是否有page和vid   没有vid就是会员中心进入的样式二   有page的肯定是从列表进入
    if(options.category){
      this.getBasicSet(false);
    } else if (options.page || !options.vid) {
      // this.getData();
      this.getBasicSet(true);
    } else {
      // 有vid就是分享视频详情 任务编号: 42332
      // this.getDetail();
      this.getBasicSet(false);
    }
  },
  gofabu() {
    wx.navigateTo({
      url: "/packageC/video_goods/videoAgreement/videoAgreement",
    });
  },
  gomy(e) {
    if(this.data.cardFrom == "my") return; 
    let uid = e.currentTarget.dataset.uid;
    wx.navigateTo({
      url: "/packageC/video_goods/myVideo/myVideo?uid=" + uid
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    let language = wx.getStorageSync("langIndex");
    this.setData({
      language: language.en,
    });
  },
  goBack(){
    wx.navigateBack({
      delta: 1
    });
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},
  getSubject() {
    if (this.data.is_plugins == 1) {
      if (this.data.AnswerID == this.data.amount_id) {
        //防止重复一直请求答题
        this.includeRedpackID("vid");
        return;
      }
      this.data.AnswerID = this.data.amount_id;
      var urlStr = app.getNetAddresss(
        "plugin.answer-reward.api.index.get-subject"
      );
      app._getNetWork({
        url: urlStr,
        data: {
          vid: this.data.amount_id,
        },
        success: (resdata) => {
          var res = resdata.data;
          if (res.result == 1) {
            if (res.data.status != 1) {
              wx.showToast({
                title: res.msg,
                icon: "none",
                duration: 1500,
              });
              this.data.myvideo.play();
              
            } else {
              if (res.data.subject != null) {
                // wx.navigateTo({
                // 	url: '/packageC/video_goods/videoAnswer/videoAnswer?vid=' + this.data.amount_id,
                // })
                this.data.myvideo.pause();
                let answerfilter = res.data.subject.has_many_answer.filter(
                  function (item) {
                    return item.content != "";
                  }
                );
                this.setData({
                  integral_name: res.data.integral_name,
                  subject: res.data.subject,
                  ["subject.has_many_answer"]: answerfilter,
                  showVideoAnswer: true,
                  'videoShare.needAnswer':true
                });
              } else {
                this.includeRedpackID("vid");
              }
            }
            this.getVideoShareWatch();
          } else {
            this.data.myvideo.play();
            this.includeRedpackID("vid", 0, "fail", res.msg);
          }
        },
        fail: function (res) {
          console.log(res);
        },
      });
    } else {
      this.getVideoShareWatch();
      return;
    }
  },
  getVideoShareWatch() {
    if (this.data.points_plugin == 1) {
      var urlStr = app.getNetAddresss(
        "plugin.video-share.frontend.video.watch-video"
      );
      app._getNetWork({
        url: urlStr,
        data: {
          video_id: this.data.amount_id,
        },
        success: (resdata) => {
          var res = resdata.data;
          if (res.result == 1) {
            if (res.data.is_show == false) {
              this.data.myvideo.play();
              this.setData({
                // show: false,
                ["dataList[" + this.data.activeType + "].list[" + this.data.realIndex + "].show"]: true,
              });
            } else {
              this.data.myvideo.pause();
              this.setData({
                // show: false,
                ["dataList[" + this.data.activeType + "].list[" + this.data.realIndex + "].show"]: false,
              });
              let changeData={};
              changeData['videoShare.points']=res.data.points;
              changeData['videoShare.point_name']=res.data.point_name;
              changeData['videoShare.is_show']=res.data.is_show;
              changeData['videoShare.days']=res.data.days||0;
              if(!this.data.videoShare.needAnswer){
                changeData['videoShare.show']=res.data.is_show;
              }
              this.setData(changeData);
            }
          } else {
            this.data.myvideo.play();
            this.includeRedpackID("vid", 0, "fail", res.msg);
          }
        },
        fail: function (res) {
          console.log(res);
        },
      });
    } else {
      this.includeRedpackID("vid");
      return;
    }
  },
  reward(evt) {
    //短视频红包开启，设置观看完指定的视频后获得，
    //如果该视频开启了短视频答题，则需要先 答对 题目才可以获得红包奖励，
    //并且和原短视频答题设置的积分奖励同时获得，弹窗 只 弹出红包领取弹窗，不在显示获得积分弹窗！！
    let id = evt.currentTarget.dataset.id;
    console.log(evt);
    let urlStr = app.getNetAddresss("plugin.answer-reward.api.index.index");
    app._getNetWork({
      url: urlStr,
      data: {
        vid: this.data.amount_id,
        subject_id: this.data.subject.id,
        answer_id: id,
      },
      success: (resdata) => {
        let res = resdata.data;
        if (res.result != 1) {
          this.setData({ errorShow: true, showVideoAnswer: false });
        } else {
          if (res.data.status == 0) {
            wx.showToast({
              title: res.msg,
              icon: "none",
              duration: 1500,
            });
          } else if (res.data.status == 1) {
            this.setData({
              integral: res.data.integral,
            });
            this.includeRedpackID("vid", 0, "success");
          }
        }
      },
    });
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {},
  gotoVideoAgreement() {
    wx.redirectTo({
      url: "/packageC/video_goods/videoAgreement/videoAgreement",
    });
  },

  /**
   * 用户点击右上角分享
   */
  onShareTimeline: function () {
    var value = wx.getStorageSync("yz_uid");
    var mid = "";
    if (value) {
      mid = value;
    }
    let json = {};
    let shareImg = "";
    if (
      this.data.dataList[this.data.activeType] &&
      this.data.dataList[this.data.activeType].list[this.data.realIndex] &&
      this.data.dataList[this.data.activeType].list[this.data.realIndex].cover
    ) {
      shareImg = this.data.dataList[this.data.activeType].list[this.data.realIndex].cover;
    }
    if (this.data.cardFrom != "card" && this.data.cardFrom != "my") {
      json = {
        title: this.data.showVideo.title ? this.data.showVideo.title : "",
        query: "vid=" + this.data.amount_id + "&mid=" + mid,
      };
    } else {
      json = {
        title: this.data.showVideo.title ? this.data.showVideo.title : "",
        query:
          "vid=" + this.data.amount_id + "&page=" + this.page + "&mid=" + mid,
      };
    }

    if (shareImg) {
      json.imageUrl = shareImg;
    }
    console.log(json);
    return json;
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (res) {
    console.log(res);
    var value = wx.getStorageSync("yz_uid");
    var mid = "";
    if (value) {
      mid = value;
    }
    let json = {};
    let shareImg = "";
    if (
      this.data.dataList[this.data.activeType] &&
      this.data.dataList[this.data.activeType].list[this.data.realIndex] &&
      this.data.dataList[this.data.activeType].list[this.data.realIndex].cover
    ) {
      shareImg = this.data.dataList[this.data.activeType].list[this.data.realIndex].cover;
    }
    // if (res.from == 'button') {  跟下面的一样  先注释
    // 	console.log(this.data.amount_id,this.data.page,mid)
    // 	if(this.data.cardFrom != 'card' && hat.data.cardFrom != 'my'){
    // 		json = {
    // 			title: this.data.showVideo.title ? this.data.showVideo.title : '',
    // 			path: '/packageC/video_goods/VideoDetail/VideoDetail?vid=' + this.data.amount_id + '&mid=' +	mid
    // 		}
    // 	}else {
    // 		json = {
    // 			title: this.data.showVideo.title ? this.data.showVideo.title : '',
    // 			path: '/packageC/video_goods/VideoDetail/VideoDetail?vid=' + this.data.amount_id + '&page=' + this.data.page + '&mid=' + mid
    // 		}
    // 	}

    // 	if(shareImg){
    // 		json.imageUrl = shareImg;
    // 	}
    // 	return json
    // }

    if (this.data.cardFrom != "card" && this.data.cardFrom != "my") {
      json = {
        title: this.data.showVideo.title ? this.data.showVideo.title : "",
        path:
          "/packageC/video_goods/VideoDetail/VideoDetail?vid=" +
          this.data.amount_id +
          "&mid=" +
          mid,
      };
    } else {
      json = {
        title: this.data.showVideo.title ? this.data.showVideo.title : "",
        path:
          "/packageC/video_goods/VideoDetail/VideoDetail?vid=" +
          this.data.amount_id +
          "&page=" +
          this.data.page +
          "&mid=" +
          mid,
      };
    }

    if (shareImg) {
      json.imageUrl = shareImg;
    }
    return json;
  },
  getBasicSet(flag){
    let that = this;
    var urlStr = app.getNetAddresss("plugin.video-share.frontend.video.getBasicSet");
    app._getNetWork({
      url: urlStr,
      data: {
      	vid: this.options.vid
      },
      success: function (resdata) {
        var res = resdata.data;
        if (res.result == 1) {
          let dataList = [];
          if (res.data.set.is_show_own_follow&&res.data.set.is_show_own_follow == '1') {
            // 是否显示我的关注 1-开启
            dataList.push({
              isLoadMore: true,
              page: 1,
              total_page: 0,
              list: [],
              code: "follow",
              activeVideoIndex: 0,
              title: "关注"
            });
          }
          if (res.data.set.is_show_recommend&&res.data.set.is_show_recommend=='1') {
            // 是否显示推荐 1-开启
            dataList.push({
              isLoadMore: true,
              page: 1,
              total_page: 0,
              list: [],
              code: "recommend",
              activeVideoIndex: 0,
              title: "推荐"
            });
          }
          // 最新，默认开启，当其他两个都不显示时，隐藏顶部标签页
          dataList.push({
            isLoadMore: true,
            page: that.data.page,
            total_page: 0,
            list: [],
            code: "default",
            activeVideoIndex: 0,
            title: "最新"
          });
          that.setData({
            BasicSet: res.data.set,
            dataList: dataList,
            activeType: dataList.length-1
          });
          if(flag){
            that.getData(false, true);
          }else{
            that.getDetail();
          }
        } else {
          wx.showToast({
            title: res.msg,
            icon: "none",
            duration: 1500,
          });
        }
      },
      fail: function (res) {
        console.log(res);
      },
    });
  },

  getDetail() {
    let that = this;

    var urlStr = app.getNetAddresss(
      "plugin.video-share.frontend.video.getVideoGoods"
    );
    urlStr += "&video_goods_id=" + this.data.amount_id;

    app._getNetWork({
      url: urlStr,
      // data: {
      // 	json
      // },
      success: function (resdata) {
        var res = resdata.data;
        if (res.result == 1) {
          that.setData({
            showVideo: res.data.video_goods,
          });
          that.getData(true,true);
        } else {
          wx.showToast({
            title: res.msg,
            icon: "none",
            duration: 1500,
          });
        }
      },
      fail: function (res) {
        console.log(res);
      },
    });
  },

  getData(flag,isDefault) {
    let that = this;
    let urlStr = "";
    let _selfJson = {
      detail:{
        current: this.data.dataList[this.data.activeType].activeVideoIndex
      }
    };
    if (this.data.dataList[that.data.activeType].list.length > 0) {
      //切换时，跳转到之前的视频位置记录 activeVideoIndex
      console.log("切换时，跳转到之前的视频位置记录");
      this.data.isLoadMore = this.data.dataList[this.data.activeType].isLoadMore;
      
      this.setData({
        amount_id: null,
        swiperDuration: 0,
        currentVideoIndex: this.data.dataList[this.data.activeType].activeVideoIndex
      });
      console.log("popularVideoChange1");
      this.popularVideoChange(_selfJson);
      return;
    }
    let json = {};

    if(this.data.dataList[this.data.activeType].code == 'default'){
      //默认列表（最新）
      if (this.data.cardFrom == "card") {
        urlStr = app.getNetAddresss("plugin.business-card.frontend.controllers.card.paging.videos");
        json.card_id = this.data.card_id;
      } else if (that.data.cardFrom == "my") {
        urlStr = app.getNetAddresss("plugin.video-share.frontend.video.my-video");
        json.vid = this.data.amount_id;
        json.status = this.data.sta;
        json.v_uid = this.options.uid || '';
        this.setData({
          ['dataList[' + that.data.activeType + '].title']: '我的'
        });
      } else {
        urlStr = app.getNetAddresss(app.globalData.store_alone_temp == 1?storeAlone:'plugin.video-share.frontend.video.getList');
      }
    } else {
      urlStr = app.getNetAddresss(app.globalData.store_alone_temp == 1?storeAlone:'plugin.video-share.frontend.video.getList');
      if (this.data.dataList[this.data.activeType].code == "follow") {
        //关注
        json = {
          search: {
            is_follow: 1
          }
        };
      } else if (this.data.dataList[this.data.activeType].code == "recommend") {
        //推荐
        json = {
          search: {
            is_recommend: 1
          }
        };
      }
    }

    json.page = this.data.dataList[this.data.activeType].page;
    app._postNetWork({
      url: urlStr,
      data: json,
      success: (resdata)=> {
        var res = resdata.data;
        if (res.result == 1) {
          that.data.isLoadMore = true;
          
          try {
            // 判断有没有开启   短视频答题奖励积分   插件
            that.setData({
              is_plugins: res.data.is_plugins,
              points_plugin:res.data.points_plugin
            });
          } catch (e) {
            console.log(e);
          }
          //短视频红包
          try {
            if (
              res.data.video_redpack &&
              res.data.video_redpack.is_open === 1
            ) {
              console.log("短视频红包================");
              that.setData({
                is_openRedpack: true,
                openRedpackData: res.data.video_redpack.data,
              });
              for (let i = 0; i < that.data.openRedpackData.length; i++) {
                if (that.data.openRedpackData[i].view_time_open_state === "1") {
                  that.data.openRedpackTimes.push(
                    that.data.openRedpackData[i].view_time_data
                  );
                }
              }
              that.data.openRedpackTimes = that.data.openRedpackTimes.sort(
                function (a, b) {
                  return a - b;
                }
              );
              console.log(
                "短视频红包累计观看时长数组",
                that.data.openRedpackTimes
              );
            }
          } catch (error) {
            console.log("error", error);
          }
          if (res.data.hasOwnProperty("comment_open")){
            this.setData({
              comment_open:res.data.comment_open
            });
          }
          if (isDefault) {
            if (that.data.cardFrom == "card") {
              that.data.dataList[that.data.activeType].total_page = res.data.last_page;
              that.setData({
                // popularVideo: res.data.data,
                ['dataList[' + that.data.activeType + '].list']: res.data.data
              });
              let popularVideoData = res.data.data;
              if (that.data.amount_id) {
                for (let i = 0; i < res.data.data.length; i++) {
                  if (res.data.data[i].id == that.data.amount_id) {
                    that.setData({
                      showVideo: res.data.data[i],
                    });
                    popularVideoData.splice(0, i);
                    that.setData({
                      ['dataList[' + that.data.activeType + '].list']: popularVideoData,
                    });
                    // wx.setNavigationBarTitle({
                    //   title: that.data.showVideo.title,
                    // });
                    that.setData({
                      firstcontent: true,
                    });
                    that.clickSwiperbtn(0);
                    return;
                  }
                }
                // wx.setNavigationBarTitle({
                //   title: that.data.showVideo.title,
                // });
              } else {
                that.setData({
                  showVideo: that.data.dataList[that.data.activeType].list[0],
                });
                that.clickSwiperbtn(0);
              }
            } else if (that.data.cardFrom == "my") {
              that.data.dataList[that.data.activeType].total_page = res.data.video.last_page;
              that.setData({
                ['dataList[' + that.data.activeType + '].list']: res.data.video.data
              });
              let popularVideoData = res.data.video.data;
              if (that.data.amount_id) {
                for (let i = 0; i < res.data.video.data.length; i++) {
                  if (res.data.video.data[i].id == that.data.amount_id) {
                    that.setData({
                      showVideo: res.data.video.data[i],
                    });
                    popularVideoData.splice(0, i);
                    that.setData({
                      ['dataList[' + that.data.activeType + '].list']: popularVideoData,
                    });
                    // wx.setNavigationBarTitle({
                    //   title: that.data.showVideo.title,
                    // });
                    that.setData({
                      firstcontent: true,
                    });
                    that.clickSwiperbtn(0);
                    return;
                  }
                }
                // wx.setNavigationBarTitle({
                //   title: that.data.showVideo.title,
                // });
              } else {
                that.setData({
                  showVideo: that.data.dataList[that.data.activeType].list[0],
                });
                that.clickSwiperbtn(0);
              }
            } else {
              that.data.dataList[that.data.activeType].total_page = res.data.list.last_page;
              that.setData({
                ['dataList[' + that.data.activeType + '].list']: res.data.list.data
              });
              let popularVideoData = res.data.list.data;
              if (!flag) {
                if (that.data.amount_id) {
                  for (let i = 0; i < res.data.list.data.length; i++) {
                    if (res.data.list.data[i].id == that.data.amount_id) {
                      that.setData({
                        showVideo: res.data.list.data[i],
                      });
                      popularVideoData.splice(0, i);
                      that.setData({
                        ['dataList[' + that.data.activeType + '].list']: popularVideoData,
                      });
                      // wx.setNavigationBarTitle({
                      //   title: that.data.showVideo.title,
                      // });
                      that.setData({
                        firstcontent: true,
                      });
                      console.log("flag2");
                      that.clickSwiperbtn(0);
                      return;
                    }
                  }
                  // wx.setNavigationBarTitle({
                  //   title: that.data.showVideo.title,
                  // });
                } else {
                  that.setData({
                    showVideo: that.data.dataList[that.data.activeType].list[0],
                  });
                  that.clickSwiperbtn(0);
                }
              } else {
                if (that.data.amount_id) {
                  for (let i = 0; i < res.data.list.data.length; i++) {
                    if (res.data.list.data[i].id == that.data.amount_id) {
                      popularVideoData.splice(i, 1);
                      break;
                    }
                  }
                  popularVideoData.unshift(that.data.showVideo);
                  that.setData({
                    ['dataList[' + that.data.activeType + '].list']: popularVideoData,
                  });
                  // wx.setNavigationBarTitle({
                  //   title: that.data.showVideo.title,
                  // });
                  that.clickSwiperbtn(0);
                }
              }
            }
          } else {
            that.setData({
              ['dataList[' + that.data.activeType + '].list']: res.data.list.data,
              ['dataList[' + that.data.activeType + '].total_page']: res.data.list.last_page,
            });
            if (that.data.dataList[that.data.activeType].list.length > 0) {
              that.setData({
                amount_id: that.data.dataList[that.data.activeType].list[0].id,
                showVideo: that.data.dataList[that.data.activeType].list[0],
                currentVideoIndex: 0
              });
              console.log("popularVideoChange2");
              that.popularVideoChange({detail:{current: 0}});
            }              
          }

          that.setData({
            firstcontent: true,
            loading: true,
          });
        } else {
          wx.showToast({
            title: res.msg,
            icon: "none",
            duration: 1500,
          });
        }
      },
      fail: function (res) {
        console.log(res);
      },
    });
  },
  onChangeVideoTab(e){
    this.setData({
      activeType: e.detail.index
    });
    this.getData(false, false);
  },
  getinformation() {
    try {
      const res = wx.getSystemInfoSync();
      let windowHeight = res.windowHeight;
      let windowWidth = res.windowWidth;
      this.setData({
        heightauto: windowHeight + "px",
        widthauto: windowWidth + "px",
      });
      this.data.screeheight = windowHeight;
    } catch (e) {
      // Do something when catch error
    }
  },
  clickSwiperbtn(e) {
    let index = 0;
    if (e.currentTarget) {
      index = e.currentTarget.dataset.index;
    } else {
      index = e;
    }
    this.clickSwiper(index);
  },
  clickSwiper(e) {
    let index = e;
    if (this.data.dataList[this.data.activeType].list.length == 0) return;
    if (this.data.dataList[this.data.activeType].list[index].show &&
      this.data.amount_id === this.data.dataList[this.data.activeType].list[index].id) {
      this.setData({
        // show: false,
        ["dataList[" + this.data.activeType + "].list[" + index + "].show"]: false,
      });
      console.log(">>>>>>>>>>>>>>>111",index,this.data.dataList[this.data.activeType].list[index].show);
      this.data.myvideo.pause();
      return;
    }
    this.judgmentpic(index);
    
    this.setData({
      show: true,
      swiperDuration:500,
      amount_id: this.data.dataList[this.data.activeType].list[index].id,
      ["dataList[" + this.data.activeType + "].list[" + index + "].show"]: true,
    });
    console.log("aaaaaaaaa",index,this.data.dataList[this.data.activeType].list[index].show);
    
    if(!this.data.dataList[this.data.activeType].list[index].hasOwnProperty('member_like')) {
      // 判断没有member_like参数就直接赋值1    1：没点赞  0：点赞
      this.setData({
        ["dataList[" + this.data.activeType + "].list[" + index + "].member_like"]: 1,
      });
    }
    this.data.logID = 0;
    this.data.myvideo.play();
  },
  popularVideoChange(e) {
    clearTimeout(this.data.cleartime);
    let realIndex = e.detail.current;
    let that = this;
    that.data.realIndex = realIndex;
    that.data.AnswerID = 0;
    that.data.cumulativeDuration = parseInt(
      that.data.cumulativeDuration + that.data.currentDuration
    ); //切换视频时计算累计
    that.data.currentDuration = 0;
    this.setData({
      commentlist:[]
    });

    that.data.dataList[that.data.activeType].activeVideoIndex = realIndex;
    that.judgmentpic_2(realIndex);
  },
  judgmentpic_2(index) {
    let realIndex = index;
    let that = this;
    try {
      if (
        that.data.dataList[this.data.activeType].list[realIndex] &&
        that.data.dataList[this.data.activeType].list[realIndex].cover
      ) {
        const query = wx.createSelectorQuery();
        query.select("#pic_" + realIndex).boundingClientRect();
        query.exec(function (res) {
          let screeheight = that.data.screeheight;
          if (res[0] && res[0].height) {
            let imgheight = res[0].height;
            if (imgheight > Math.ceil(screeheight * (7 / 8))) {
              that.setData({
                minStyle: false,
              });
              that.getvideomessage(realIndex);
            } else {
              that.setData({
                minStyle: true,
              });
              that.getvideomessage(realIndex);
            }
          } else {
            that.setData({
              minStyle: true,
            });
            that.getvideomessage(realIndex);
          }
        });
      } else {
        that.setData({
          minStyle: true,
        });
        that.getvideomessage(realIndex);
      }
    } catch (e) {
      that.setData({
        minStyle: true,
      });
      that.getvideomessage(realIndex);
      //TODO handle the exception
    }
  },
  getvideomessage(realIndex) {
    let that = this;
    if (realIndex == that.data.dataList[this.data.activeType].list.length - 2) {
      that.getMoreData();
    }
    this.data.myvideo.pause();
    that.setData({
      show: false,
      showVideo: that.data.dataList[this.data.activeType].list[realIndex],
    });
    if (realIndex === 0) {
      this.setData({
        ["dataList[" + this.data.activeType + "].list[" + realIndex + "].show"]: false,
        ["dataList[" + this.data.activeType + "].list[" + (realIndex + 1) + "].show"]: false,
      });
    } else {
      this.setData({
        ["dataList[" + this.data.activeType + "].list[" + (realIndex - 1) + "].show"]: false,
        ["dataList[" + this.data.activeType + "].list[" + realIndex + "].show"]: false,
      });
      if (that.data.dataList[this.data.activeType].list[realIndex + 1]) {
        this.setData({
          ["dataList[" + this.data.activeType + "].list[" + (realIndex + 1) + "].show"]: false,
        });
      }
    }
    // wx.setNavigationBarTitle({
    //   title: that.data.showVideo.title,
    // });
    try {
      wx.setStorageSync("vid", this.data.showVideo.id);
    } catch (e) {
      console.log(e);
    }
    this.data.cleartime = setTimeout(() => {
      that.clickSwiper(realIndex);
    }, 300);
    //切换结束时
  },
  getMoreData() {
    const that = this;
    let urlStr = '';
    let json = {};
    this.setData({
      ['dataList[' + that.data.activeType + '].isLoadMore']: false
    });
    if (this.data.dataList[this.data.activeType].page >= this.data.dataList[this.data.activeType].total_page) {
      return;
    } else {
      this.data.dataList[this.data.activeType].page = this.data.dataList[this.data.activeType].page + 1;
      if(this.data.dataList[this.data.activeType].code == 'default'){
        //默认列表（最新）
        if (this.data.cardFrom == "card") {
          urlStr = app.getNetAddresss("plugin.business-card.frontend.controllers.card.paging.videos");
          json.card_id = this.data.card_id;
        } else if (that.data.cardFrom == "my") {
          urlStr = app.getNetAddresss("plugin.video-share.frontend.video.my-video");
          json.vid = this.data.amount_id;
          json.status = this.data.sta;
          json.v_uid = this.options.uid || '';
        } else {
          urlStr = app.getNetAddresss(app.globalData.store_alone_temp == 1?storeAlone:'plugin.video-share.frontend.video.getList');
        }
      } else {
        urlStr = app.getNetAddresss(app.globalData.store_alone_temp == 1?storeAlone:'plugin.video-share.frontend.video.getList');
        if (this.data.dataList[this.data.activeType].code == "follow") {
          //关注
          json = {
            search: {
              is_follow: 1
            }
          };
        } else if (this.data.dataList[this.data.activeType].code == "recommend") {
          //推荐
          json = {
            search: {
              is_recommend: 1
            }
          };
        }
      }
      json.page = that.data.dataList[that.data.activeType].page;
      app._postNetWork({
        url: urlStr,
        data: json,
        success: function (resdata) {
          that.data.isLoadMore = true;
          var res = resdata.data;
          if (res.result == 1) {
            let myData = res.data.list.data;
            that.setData({
              ["dataList[" + that.data.activeType + "].list"]: that.data.dataList[that.data.activeType].list.concat(myData),
            });
          } else {
            that.data.page = that.data.page - 1;
            that.data.isLoadMore = false;
          }
        },
        fail: function (res) {
          console.log(res);
        },
      });
    }
  },
  chooseUser(e) {
    if(this.data.cardFrom == "my") return;
    let item = e.currentTarget.dataset.item;
    if (this.data.BasicSet.topSmileLike&&this.data.BasicSet.topSmileLike!='') {
      try {
        wx.navigateTo({
          url: this.data.BasicSet.topSmileLike,
        });
      } catch (e) {
        wx.redirectTo({
          url: this.data.BasicSet.topSmileLike ? this.data.BasicSet.topSmileLike : '/packageG/index/index'
        });
      }
    }else if (item.member && item.member.business_card != 0) {
      wx.navigateTo({
        url:
          "/packageB/member/business_card/BusinessCard/BusinessCard?card_id=" +
          item.member.business_card +
          "&mark=card",
      });
    }
  },
  toggleLike(e) {
    let index = e.currentTarget.dataset.index;
    let item = e.currentTarget.dataset.item;
    if (this.data.dataList[this.data.activeType].list[index].member_like) {
      this.setData({
        ["dataList[" + this.data.activeType + "].list[" + index + "].like_num"]:
          this.data.dataList[this.data.activeType].list[index].like_num + 1,
      });
    } else {
      if (this.data.dataList[this.data.activeType].list[index].like_num > 0) {
        this.setData({
          ["dataList[" + this.data.activeType + "].list[" + index + "].like_num"]:
            this.data.dataList[this.data.activeType].list[index].like_num - 1,
        });
      }
    }
    this.setData({
      ["dataList[" + this.data.activeType + "].list[" + index + "].member_like"]: !this.data.dataList[this.data.activeType].list[
        index
      ].member_like,
    });
    let urlStr = app.getNetAddresss("plugin.video-share.frontend.video.like");
    let json = {
      video_goods_id: item.id,
    };
    app._postNetWork({
      url: urlStr,
      showToastIn: false,
      data: json,
      success: function (resdata) {
        var res = resdata.data;
        if (res.result == 0) {
          wx.showToast({
            icon: "none",
            title: res.msg,
            duration: 1500,
          });
        }
      },
      fail: function (res) {},
    });
  },
  shareVideo() {
    // this.setData({
    // 	showShare: true
    // })
  },
  setVideoShareShow(){
    this.setData({
      'videoShare.show':!this.data.videoShare.show
    });

  },
  close() {
    this.setData({
      showShare: false,
    });
  },
  toGood(e) {
    let item = e.currentTarget.dataset.item;
    wx.navigateTo({
      url:
        "/packageA/detail_v2/detail_v2?id=" + item.goods_id + "&vid=" + item.id,
    });
  },
  judgmentpic(index) {
    let realIndex = index;
    let that = this;
    const query = wx.createSelectorQuery();
    query.select("#pic_" + realIndex).boundingClientRect();
    query.exec(function (res) {
      let screeheight = that.data.screeheight;
      if (res[0] && res[0].height) {
        let imgheight = res[0].height;
        if (imgheight > Math.ceil(screeheight * (7 / 8))) {
          that.setData({
            minStyle: false,
          });
        } else {
          that.setData({
            minStyle: true,
          });
        }
      }
    });
  },
  onLoadedmetadata(event) {
    // console.log("bindloadedmetadata---------------",event)
    if (this.data.maxTime == 0 && this.data.is_openRedpack) {
      this.data.maxTime = parseInt(event.detail.duration);
      this.getViewTimelog();
    } else {
      this.data.maxTime = parseInt(event.detail.duration);
    }
    console.log("视频总时长", this.data.maxTime);
  },
  onTimeupdate(event) {
    //注意：video 使用wx:if="{{show}}"时，在电脑端模拟器（1.03.2101150版本）上每暂停播放后会出现递增video实例，但真机正常
    this.data.currentDuration = event.detail.currentTime;
    let minute = parseInt(
      (this.data.cumulativeDuration + this.data.currentDuration) / 60
    );
    // console.log(event.detail.currentTime,"累计秒", parseInt((this.data.cumulativeDuration + this.data.currentDuration)), "累计分钟", minute);
    if (this.data.openRedpackTimes.indexOf(minute) > -1) {
      //达到累计获奖时长
      this.data.openRedpackTimes.splice(0, 1);
      console.log("删除一个累计时长条件", this.data.openRedpackTimes);
      this.includeRedpackID("time", minute);
    }
    return;
  },
  endedPlay() {
    console.log("播放结束");
    this.data.cumulativeDuration = parseInt(
      this.data.cumulativeDuration + this.data.currentDuration
    ); //结束视频时计算累计
    this.data.currentDuration = 0;
    this.getSubject();
  },
  onPlaying() {
    console.log("onPlaying=================");
    if (this.data.maxTime != 0 && this.data.is_openRedpack) {
      this.getViewTimelog();
    }
    this.addRecord();
  },
  addRecord() {
    let that = this;
    let urlStr = app.getNetAddresss(
      "plugin.video-share.frontend.video.addRecord"
    );
    app._postNetWork({
      url: urlStr,
      showToastIn: false,
      data: {
        video_id: that.data.amount_id,
      },
      success: function (resdata) {},
      fail: function (res) {},
    });
  },
  getViewTimelog() {
    if (this.data.logID == this.data.amount_id) {
      return;
    }
    // console.log("1111111111111=========",this.data.logID,this.data.amount_id,this.data.maxTime)
    this.data.logID = this.data.amount_id;
    let urlStr = app.getNetAddresss(
      "plugin.video-redpack.frontend.activity.logViewTime"
    );
    let json = {
      video_id: this.data.amount_id,
      video_length: this.data.maxTime,
    };
    app._postNetWork({
      url: urlStr,
      showToastIn: false,
      data: json,
      success: function (resdata) {},
      fail: function (res) {},
    });
  },
  includeRedpackID(type, value, status, text) {
    if (this.data.is_openRedpack) {
      if (status === "success") {
        this.setData({
          showVideoAnswer: false,
          logID: 0,
        });
      }
      if (type == "time") {
        //累计时长，获取活动id
        for (let i = 0; i < this.data.openRedpackData.length; i++) {
          if (this.data.openRedpackData[i].view_time_data === value) {
            this.data.activity_reward_id = this.data.openRedpackData[
              i
            ].activity_id;
            console.log(
              "达到红包累计时长",
              this.data.amount_id,
              this.data.activity_reward_id
            );
            this.getRedpackReward(1, 1);
            return;
          }
        }
      } else if (type == "vid") {
        //判断当前视频id是否为短视频红包指定视频
        for (let i = 0; i < this.data.openRedpackData.length; i++) {
          if (
            this.data.openRedpackData[i].view_finish_ids.indexOf(
              this.data.amount_id
            ) > -1
          ) {
            this.data.activity_reward_id = this.data.openRedpackData[
              i
            ].activity_id;
            console.log(
              "短视频红包指定视频",
              this.data.amount_id,
              this.data.activity_reward_id
            );
            this.getRedpackReward(2, 1);
            return;
          }
        }
      }
      if(this.data.videoShare.needAnswer && this.data.points_plugin && this.data.videoShare.is_show){
        this.setData({'videoShare.show':true});
        return;
      }
      if (status === "success") {
        this.setData({
          showVideoAnswer: false,
          successShow: true,
        });
      }
      if (status === "fail") {
        wx.showToast({
          title: text,
          icon: "none",
          duration: 1500,
        });
      }
      this.data.myvideo.play();
      this.getViewTimelog();
    } else {
      if(this.data.videoShare.needAnswer && this.data.points_plugin && this.data.videoShare.is_show){
        this.setData({'videoShare.show':true});
        return;
      }
      if (status === "success") {
        this.setData({
          showVideoAnswer: false,
          successShow: true,
        });
      }
      if (status === "fail") {
        wx.showToast({
          title: text,
          icon: "none",
          duration: 1500,
        });
      }
    }
  },
  getRedpackReward(reward_type, request_type) {
    let that = this;
    this.data.reward_type = reward_type;
    let urlStr = app.getNetAddresss(
      "plugin.video-redpack.frontend.activity.reward"
    );
    let json = {
      video_id: this.data.amount_id,
      activity_id: this.data.activity_reward_id,
      reward_type: reward_type,
      request_type: request_type,
      video_length: this.data.maxTime,
    };
    app._postNetWork({
      url: urlStr,
      showToastIn: false,
      data: json,
      success: function (resdata) {
        var res = resdata.data;
        if (res.result == 1) {
          if (request_type == 1) {
            that.data.myvideo.pause();
            // console.log("红包=================", that.data.myvideo);
            that.setData({
              redpack_info: res.data,
              showRedpack: true,
            });
            if (res.data.bind_mobile == 1 && res.data.member_bind_mobile == 0) {
              //开启绑定，但用户未绑定手机
              that.setData({
                bind_mobile: true,
              });
            }
          } else {
            that.setData({
              ["redpack_info.amount"]: res.data.amount,
              openRedpack: true,
            });
          }
        } else {
          // that.data.myvideo.play();
          // that.getViewTimelog();
          wx.showToast({
            icon: "none",
            title: res.msg,
            duration: 1500,
          });
        }
      },
      fail: function (res) {},
    });
  },
  openRedpackM() {
    if (
      this.data.redpack_info.bind_mobile == 1 &&
      this.data.redpack_info.member_bind_mobile == 0
    ) {
      //开启绑定，但用户未绑定手机
      this.getimgdata();
      this.setData({
        showVerification: true,
      });
      return;
    } else {
      this.getRedpackReward(this.data.reward_type, 2);
    }
  },
  //获取图片验证码
  getimgdata(data) {
    let that = this;
    let urlStr = app.getNetAddresss("home-page.getCaptcha");
    if (data) {
      if (data.captcha) {
        that.setData({
          imgcode: data.captcha.img,
        });
      }
    } else {
      app._getNetWork({
        url: urlStr,
        validateBol: 2,
        success: function (resdata) {
          var res = resdata.data;
          if (res.result == 1) {
            if (res.data.captcha) {
              that.setData({
                imgcode: res.data.captcha.img,
              });
            }
          }
        },
        fail: function (res) {
          console.log(res);
        },
      });
    }
  },
  getPhoneNumber(e) {
    let info = e.detail;
    if (e.detail.errMsg == "getPhoneNumber:ok") {
      this.getPhoneM(info.code);
    } else {
      this.setData({
        showVerification: true,
      });
    }
  },
  getPhoneM(info) {
    let urlStr = app.getNetAddresss('member.member.miniMemberMobile');
    let that = this;
    app._postNetWork({
      url: urlStr,
      data: {
        code: info,
      },
      showToastIn: false,
      success: function (resdata) {
        var res = resdata.data;
        if (res.result == 1) {
          that.setData({
            "form.mobile": res.data.phone_info.purePhoneNumber,
            showVerification: true,
          });
        } else {
          wx.showToast({
            icon: 'none',
            title: res.msg,
            duration: 1500
          });
        }
      },
      fail: function (res) { }
    });
  },
  //绑定手机号的值
  mobileinp(e) {
    let val = e.detail.value;
    this.setData({
      "form.mobile": val.trim(),
    });
  },
  //绑定图形验证码的值
  captchainp(e) {
    let val = e.detail.value;
    this.setData({
      "form.captcha": val.trim(),
    });
  },
  //绑定验证码的值
  codeinp(e) {
    let val = e.detail.value;
    this.setData({
      "form.code": val.trim(),
    });
  },
  sendCode(e) {
    if (this.data.start1) {
      return false;
    }
    let time = 60;
    let that = this;
    that.setData({
      start1: true,
      codetext: "(" + time + ")秒后重新获取",
    });
    let set = setInterval(function () {
      that.setData({
        codetext: "(" + --time + ")秒后重新获取",
      });
    }, 1000);
    setTimeout(function () {
      that.setData({
        codetext: "获取短信验证码",
        start1: false,
      });
      clearInterval(set);
    }, 60000);
    that.verificationCode(set);
  },
  //发送验证码
  verificationCode(set) {
    let that = this;
    if (app._isTextEmpty(this.data.form.mobile)) {
      wx.showToast({
        icon: "none",
        title: "请填写手机号",
        duration: 1500,
      });
      that.setData({
        codetext: "获取短信验证码",
        start1: false,
      });
      clearInterval(set);
      return;
    }

    if (app._isMoblie(this.data.form.mobile)) {
      wx.showToast({
        icon: "none",
        title: "请填写正确的手机号",
        duration: 1500,
      });
      return;
    }

    if (app._isTextEmpty(this.data.form.captcha) && this.data.imgcode) {
      wx.showToast({
        icon: "none",
        title: "请填图形验证码",
        duration: 1500,
      });
      that.setData({
        codetext: "获取短信验证码",
        start1: false,
      });
      clearInterval(set);
      return;
    } else {
      let urlStr = app.getNetAddresss("member.register.sendCodeV2");
      urlStr += "&mobile=" + this.data.form.mobile;
      urlStr += "&captcha=" + this.data.form.captcha;
      urlStr += "&code=" + this.data.form.code;
      // 发送获取验证码的请求
      app._getNetWork({
        url: urlStr,
        validateBol: 2,
        success: function (resdata) {
          var res = resdata.data;
          if (res.result == 1) {
            wx.showToast({
              icon: "none",
              title: "已发送",
              duration: 1500,
            });
          } else {
            wx.showToast({
              icon: "none",
              title: res.msg,
              duration: 1500,
            });
            //刷新图形验证码
            that.setData({
              "form.captcha": "",
              start1: false,
              codetext: "获取短信验证码",
            });
            clearTimeout(set);
            that.getimgdata();
          }
        },
        fail: function (res) {
          console.log(res);
        },
      });
    }
  },
  alterAction() {
    if (app._isTextEmpty(this.data.form.mobile)) {
      wx.showToast({
        icon: "none",
        title: "请填写手机号",
        duration: 1500,
      });
      return;
    }
    if (app._isMoblie(this.data.form.mobile)) {
      wx.showToast({
        icon: "none",
        title: "请填写正确的手机号",
        duration: 1500,
      });
      return;
    }
    if (app._isTextEmpty(this.data.form.code)) {
      wx.showToast({
        icon: "none",
        title: "请填验证码",
        duration: 1500,
      });
      return;
    }

    let urlStr = app.getNetAddresss(
      "plugin.video-redpack.frontend.activity.bindMobile"
    );
    app._postNetWork({
      url: urlStr,
      showToastIn: false,
      data: that.data.form,
      validateBol: 2,
      success: function (resdata) {
        var res = resdata.data;
        if (res.result == 1) {
          console.log(that.data);
          that.getRedpackReward(that.data.reward_type, 2);
          that.setData({
            showVerification: false,
            showRedpack: true,
          });
        } else {
          wx.showToast({
            icon: "none",
            title: res.msg,
            duration: 1500,
          });
        }
      },
      fail: function (res) {},
    });
  },
  cloneVerification() {
    this.setData({
      showVerification: false,
      ["form.captcha"]: "",
      ["form.code"]: "",
    });
  },
  cloneAnswer() {
    this.setData({
      errorShow: false,
      successShow: false,
      logID: 0,
      AnswerID: 0,
    });
    this.data.myvideo.play();
    this.getViewTimelog();
  },
  cloneRedpack() {
    this.setData({
      logID: 0,
      AnswerID: 0,
      showRedpack: false,
      openRedpack: false,
    });
    if (this.data.reward_type == 2) {
      this.getViewTimelog();
    }
    this.data.myvideo.play();
  },
  followMember(e){
    let that = this;
    var urlStr = app.getNetAddresss("plugin.video-share.frontend.video.editFollow");
    app._getNetWork({
      url: urlStr,
      data:{
        member_id: e.currentTarget.dataset.uid,
        follow_type: e.currentTarget.dataset.fllow == 1 ? 2 : 1
      },
      success: function (resdata) {
        var res = resdata.data;
        if (res.result == 1) {
          let follow = e.currentTarget.dataset.fllow == 1 ? 0 : 1;
          let uid = e.currentTarget.dataset.uid;
          for (let index = 0; index < that.data.dataList.length; index++) {
            //遍历查找列表中改会员。设置为已修改的状态
            for (let i = 0; i < that.data.dataList[index].list.length; i++) {
              if (that.data.dataList[index].list[i].member&&that.data.dataList[index].list[i].member.uid == uid) {
                that.setData({
                  ['dataList[' + index + '].list[' + i + '].is_follow']: follow
                });
              }
            }
          }
          let msg = e.currentTarget.dataset.fllow == 1 ? "已取消关注" : "关注成功";
          wx.showToast({
            title: msg,
            icon: "none",
            duration: 1500,
          });
        } else {
          wx.showToast({
            title: res.msg,
            icon: "none",
            duration: 1500,
          });
        }
      },
      fail: function (res) {
        console.log(res);
      },
    });
  },
  onIconLink(){
    if (this.data.BasicSet.iconSmileLink=='') return;
    try {
      wx.navigateTo({
        url: this.data.BasicSet.iconSmileLink,
      });
    } catch (e) {
      wx.redirectTo({
        url: this.data.BasicSet.iconSmileLink ? this.data.BasicSet.iconSmileLink : '/packageG/index/index'
      });
    }
  },
  gotoLiveRoom(e){
    if(!e.currentTarget.dataset.rid){
      wx.showToast({
        title: '直播间id获取失败！',
        icon: "none",
        duration: 1500,
      });
      return;
    }
    wx.navigateTo({
      url:
        "/packageD/directSeeding/livePage/livePage?id=" +
        e.currentTarget.dataset.rid +
        "&playerType=live",
    });
  },
  gotoUrl(e){
    let datas = e.currentTarget.dataset;
    if (datas.name == "advertisingPutAD") {
      //投放广告按钮
      if (!datas.iser) {
        wx.navigateTo({url: '/packageH/Advertising/advertisingApply/advertisingApply' });//还不是广告主，跳转申请页
      } else {
        wx.navigateTo({url: '/packageH/Advertising/advertisingPutAD/advertisingPutAD?tag=video&id='+ datas.id });
      }
      return;
    }
    wx.navigateTo({url: '/packageH/Advertising/advertisingList/advertisingList?tag=video&id='+ datas.id });
  },
  cloneADbtn(e){
    let datas = e.currentTarget.dataset;
    if(datas.tag == '1'){
      this.setData({
        isShowADLook: false
      });
    }
    if(datas.tag == '2'){
      this.setData({
        isShowADPut: false
      });
    }
  },
  gotoHome () {
    wx.reLaunch({
      url: '/packageG/index/index',
    });
  },
  toComment() {
    //显示评论弹窗组件
    if (this.data.commentlist.length > 0) {
      this.setData({
        showYzComment: true
      });
      return;
    }
    this.getCommentData();
  },
  cloneCOMInput(){
    this.setData({
      showYzComment: false
    });
  },
  getCommentData() {
    this.setData({
      commentLoading:true,
      showYzComment:true,
      commentPage: 1
    });
    let urlStr = app.getNetAddresss("plugin.video-share.frontend.comment.comment-list");
    app._getNetWork({
      url: urlStr,
      data: {video_id: this.data.amount_id},
      success: (resdata)=> {
        var res = resdata.data;
        this.setData({
          commentLoading: false
        });
        if (res.result == 1) {
          this.setData({
            commentTotal: res.data.num,
            commentlist: res.data.list.data,
            commentFinished: res.data.list.last_page <= 1?true:false
          });
          
        } else {
          wx.showToast({
            title: res.msg,
            icon: 'none',
            duration: 1500
          });
        }
      },
      fail: function(res) {
        console.log(res);
      }
    });
  },
  onCommentMore(){
    if (this.data.commentFinished || this.data.commentLoading) {
      return;
    }
    console.log("触发加载更多");
    this.setData({
      commentLoading: true
    });
    let urlStr = app.getNetAddresss("plugin.video-share.frontend.comment.comment-list");
    app._getNetWork({
      url: urlStr,
      data: {video_id: this.data.amount_id,page: this.data.commentPage +1},
      success: (resdata)=> {
        var res = resdata.data;
        this.setData({
          commentLoading: false
        });
        if (res.result == 1) {
          this.setData({
            commentlist: this.data.commentlist.concat(res.data.list.data),
            commentFinished: res.data.list.current_page >= res.data.list.last_page?true:false
          });
          
        } else {
          wx.showToast({
            title: res.msg,
            icon: 'none',
            duration: 1500
          });
        }
      },
      fail: function(res) {
        console.log(res);
      }
    });
  },
  sendComment(e) {
    let {text} = e.detail;
    let {type,index,childIndex} = e.detail.options;
    let Json = {
      content: text
    };
    let _URL = "plugin.video-share.frontend.comment.create-comment"; //创建主评论
    if (type == "main") {
      //主评论
      Json.video_id = this.data.amount_id;
    } else if (type == "reply") {
      Json.comment_id = this.data.commentlist[index].id;
      _URL = "plugin.video-share.frontend.comment.reply-comment"; //回复父评论
    } else if (type == "childReply") {
      Json.comment_id = this.data.commentlist[index].append_arr[childIndex].id;
      _URL = "plugin.video-share.frontend.comment.reply-comment"; //回复子评论
    }
    app._getNetWork({
      url: app.getNetAddresss(_URL),
      data: Json,
      success: (resdata)=> {
        var res = resdata.data;
        wx.showToast({
          title: res.msg,
          icon: 'none',
          duration: 1500
        });
        if (res.result == 1) {
          let commentlist = this.data.commentlist;
          if (res.data.type == "1") {
            //主评论
            commentlist.unshift({
              append_arr: [],
              id: res.data.id,
              support_num: 0,
              head_image: res.data.head_img_url,
              nick_name: res.data.nick_name,
              created_at: res.data.created_at,
              content: res.data.content,
              can_del: 1
            });
            this.setData({
              commentTotal: this.data.commentTotal+1
            });
          } else if (res.data.type == "2") {
            commentlist[index].append_arr.unshift({
              id: res.data.reply_comment_id,
              support_num: 0,
              head_image: res.data.head_img_url,
              nick_name: res.data.nick_name,
              created_at: res.data.created_at,
              content: res.data.content,
              can_del: 1,
              reply_name: res.data.reply_name
            });
          }
          this.setData({commentlist});
          this.setData({
            ["dataList[" + this.data.activeType + "].list[" + this.data.realIndex + "].comment_num"]: commentlist.length,
          });
        }
      },
      fail: function(res) {
        console.log(res);
      }
    });

  },
  delComment() {
    let {type,index,childIndex} = this.data.commentInputOptiones;
    let Json = {
      comment_id: type == "reply"?this.data.commentlist[index].id:this.data.commentlist[index].append_arr[childIndex].id
    };
    app._getNetWork({
      url: app.getNetAddresss('plugin.video-share.frontend.comment.del'),
      data: Json,
      success: (resdata)=> {
        var res = resdata.data;
        if (res.result == 1) {
          wx.showToast({
            title: '已删除',
            icon: 'none',
            duration: 1500
          });
          let commentlist = this.data.commentlist;
          if (type == "reply") {
            commentlist.splice(index, 1);
            this.setData({
              commentTotal: this.data.commentTotal-1
            });
          } else if (type == "childReply") {
            commentlist[index].append_arr.splice(childIndex, 1);
          }
          this.setData({commentlist});
          
        } else {
          wx.showToast({
            title: res.msg,
            icon: 'none',
            duration: 1500
          });
        }
      },
      fail: function(res) {
        console.log(res);
      }
    });
  },
  clickLikeItem(e) {
    let {index, itemindex, status} = e.currentTarget.dataset;
    let Json = {
      comment_id: this.data.commentlist[index].id //点赞主评论
    };
    if (itemindex != null && itemindex !== "") {
      //点赞子评论
      Json.comment_id = this.data.commentlist[index].append_arr[itemindex].id;
    }
    let urlStr = app.getNetAddresss("plugin.video-share.frontend.comment.support");
    app._getNetWork({
      url: urlStr,
      data: Json,
      success: (resdata)=> {
        var res = resdata.data;
        if (res.result == 1) {
          
          if (itemindex != null && itemindex !== "") {
            //点赞子评论
            let support_num = this.data.commentlist[index].append_arr[itemindex].support_num;
            this.setData({
              ['commentlist['+ index +'].append_arr['+itemindex+'].is_support']: !status,
              ['commentlist['+ index +'].append_arr['+itemindex+'].support_num']: status ? --support_num : ++support_num
            });
          } else {
            let num = this.data.commentlist[index].support_num;
            this.setData({
              ['commentlist['+ index +'].is_support']: !status,
              ['commentlist['+ index +'].support_num']: status ? --num : ++num
            });
          }
        } else {
          wx.showToast({
            title: res.msg,
            icon: 'none',
            duration: 1500
          });
        }
      },
      fail: function(res) {
        console.log(res);
      }
    });
  },
  showCOMInput(e){
    let authority = e.currentTarget.dataset.authority == 1 ? true : false;
    this.setData({
      commentInputOptiones: e.detail
    });
    if (e.detail.type != "main" && authority) {
      //显示动作面板，可进行删除操作
      this.setData({
        showSheet: true
      });
      return;
    }
    this.setData({
      showCommentInput: true
    });
  },
  onCloseSheet(){
    this.setData({
      showSheet: false
    });
  },
  getRely(e){
    let _commentId = this.data.commentlist[e.detail.index].id;
    let page = Math.floor(this.data.commentlist[e.detail.index].append_arr.length/5)+1;
    let urlStr = app.getNetAddresss("plugin.video-share.frontend.comment.get-replys");
    app._getNetWork({
      url: urlStr,
      data: {comment_id: _commentId,page:page},
      success: (resdata)=> {
        var res = resdata.data;
        if (res.result == 1) {
          this.setData({
            ['commentlist['+ e.detail.index +'].append_arr']: this.data.commentlist[e.detail.index].append_arr.concat(res.data.data)
          });
          
        } else {
          wx.showToast({
            title: res.msg,
            icon: 'none',
            duration: 1500
          });
        }
      },
      fail: function(res) {
        console.log(res);
      }
    });
  },
  onSelectSheet(event){
    let {index} = event.detail;
    if (index == 0) {
      //回复操作
      this.setData({
        showCommentInput: true
      });
    } else if (index == 1) {
      this.delComment();
    }
  }
});
