detail.js 5.55 KB
import {
  getBindtapData,
  pxToRpx,
  getLastScreenHeight
} from '../../utils/util';

let app = getApp();
Page({
  data: {
    isOverShare: true,
    authorizeVisible: false,
    total: 0,
    page: 1,
    size: 10,
    dataList: [],
    productList: [], // 产品列表
    indexInfo: {},
    userInfo: {},
    options: {},
    detailData: {},
    vidHeight: 0, // 视频高度
    isVideoEnded: false,
  },
  onShareAppMessage(res) {
    if (res.from === 'button') {
      // 来自页面内转发按钮
    } else {
      // 打点
      app.stat({
        classify: "share",
        action: this.data.detailData.type == 1 ? "hide_detail_page_share" : "detail_page_share",
        primaryCode: this.data.detailData.videoCode,
      });
    }


    let detailData = this.data.detailData;
    let title = detailData && detailData.videoName || "";
    let path = `pages/detail/detail?c=${detailData.videoCode}`;
    let imageUrl = detailData && detailData.thumbnail || "";
    return {
      title,
      path,
      imageUrl
    }

  },
  showAuth() {
    this.setData({
      authorizeVisible: true
    })
  },
  onLoad(options) {
    this.setData({
      options
    });
    this.queryVideoDetail();
    this.initData();



  },

  /**
   * 基础方法
   * 授权完毕重拉数据用
   */
  initData() {
    this.queryVideoMore();
  },

  /**
   * 到达底部
   * 做加载更多操作
   */
  onReachBottom() {
    if (this.data.dataList.length < this.data.total) {
      this.setData({
        page: this.data.page + 1
      });
      this.queryVideoMore();
    }
  },

  // 重置页面列表 点击搜索条件时需要
  resetPage() {
    this.setData({
      page: 1,
      dataList: []
    })
  },

  /**
   * 到个人列表页面
   */
  toPersonalList() {
    let detailData = this.data.detailData;
    if (detailData && detailData.accountCode) {
      detailData.c = detailData.accountCode;
      app.router.push({
        path: "personalList",
        query: detailData
      })
    }
  },

  /**
   * 跳转详情页面
   */
  onDetailHandler(evt) {
    let curItem = getBindtapData(evt);
    app.router.push({
      path: "detail",
      query: {
        c: curItem.videoCode || ""
      }
    })
  },

  /**
   * 播放完毕
   */
  onVideoEndedHandler(evt) {
    this.setData({
      isVideoEnded: true
    })
    // 打点
    app.stat({
      classify: "video",
      action: this.data.detailData.type == 1 ? "hide_play_end" : "play_end",
      primaryCode: this.data.detailData.videoCode,
    });
  },

  /**
   * 播放开始
   */
  onVideoPlayHandler(evt) {
    // 打点
    app.stat({
      classify: "video",
      action: this.data.detailData.type == 1 ? "hide_play" : "play",
      primaryCode: this.data.detailData.videoCode,
    });
  },

  /**
   * 重播
   */
  onReplayHandler() {
    let video = wx.createVideoContext("vid", this);
    console.log("video:", video);
    video.seek(0);
    video.play();
    this.setData({
      isVideoEnded: false
    })
    // // 打点
    // app.stat({
    //   classify: "video",
    //   action: this.data.detailData.type == 1 ? "hide_play" : "play",
    //   primaryCode: this.data.detailData.videoCode,
    // });
  },

  onShareFriend() {
    app.stat({
      classify: "share",
      action: "detail_page_button_friend_share",
      primaryCode: this.data.detailData.videoCode,
    });
  },

  onShareGroup() {
    app.stat({
      classify: "share",
      action: "detail_page_button_group_share",
      primaryCode: this.data.detailData.videoCode,
    });
  },

  /**
   * 返回首页
   */
  toIndex() {
    app.router.push({
      openType: "reLaunch",
      path: "index"
    })
  },

  /**
   * 请求DataList
   */
  queryVideoMore() {
    return new Promise((resolve, reject) => {
      app.post({
        sid: false,
        url: app.api.videoMore,
        data: {
          page: this.data.page,
          size: this.data.size,
        },
      }).then((result) => {
        let dataList = result.list;
        dataList = this.data.dataList.concat(dataList);
        console.log("dataList:", dataList);
        this.setData({
          dataList: dataList,
          total: result.total
        })
        resolve();
      })
    });
  },

  /**
   * 视频详情
   */
  queryVideoDetail() {

    return new Promise((resolve, reject) => {
      app.post({
        url: app.api.videoDetail,
        data: {
          videoCode: this.data.options.c
        }
      }).then((result) => {
        this.setData({
          detailData: result
        })
        let {
          width,
          height
        } = result;
        let vidHeight = (height / width) * 750;
        if (vidHeight < 800) {
          vidHeight = 800;
        } else {
          vidHeight = getLastScreenHeight(132);
        }
        console.log("vidHeight:", vidHeight);
        // vidHeight = pxToRpx(vidHeight);
        // let vidHeight = getLastScreenHeight(132);

        this.setData({
          vidHeight: vidHeight,
        });

        resolve(result);
      }).catch((err) => {
        reject(err);
      });
    });
  },

  /**
   * 隐藏蒙层
   */
  hideMask() {
    this.setData({
      productDetailVisible: false,
      authorizeVisible: false,
    })
  },
  /**
   * 子组件事件
   * @param {*} evt
   */
  evtcomp(evt) {
    let {
      name,
      data
    } = evt.detail;
    switch (name) {

      // 隐藏蒙层
      case "_evt_hide_mask":
        this.hideMask();
        break;

        /**
         * 重拉数据已在
         */
      case "_evt_auth_complete":
        // this.initData();
        this.hideMask();
        break;

      default:
        break;
    }
  },
})