index.js 2.33 KB
Newer Older
程智春 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
// static/nativeComponents/LiveBroadcast/index.js
let app = getApp()
const { indexApi } = app
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    datas: {
      type: Object
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    showNum : 0,
    showList : true,
  },
  ready(){
    if (this.data.datas.componentData.liveList.length >= this.data.datas.componentData.showNum) {
      this.setData({
        showNum: this.data.datas.componentData.showNum
      })
    } else {
      this.setData({
        showNum: this.data.datas.componentData.liveList.length
      })
    }



    this.init()
    console.log('datas.componentData.style', this.data.datas.componentData.liveList)
  },

  /**
   * 组件的方法列表
   */
  methods: {
    init(){
      this.setData({
        'datas.componentData.liveList' : []
      })
      console.log(this.data.datas.componentData.liveList, 'this.data.datas.componentData.liveList')

      indexApi.getLiveCon(this.data.datas.componentData.liveIdList).then(res => {
        if(res.data.code == '200'){
          if(res.data.data.length == 0){
            this.setData({
              showList : false,
              'datas.componentData.liveList' : [],
              'datas.componentData.liveIdList':[]
            })
          }else{
            res.data.data.forEach(item => {
              item.coverUrl = app.DFSImg(item.coverUrl);
              item.anchorHeadImages = app.DFSImg(item.anchorHeadImages);
              item.watchNum = item.watchNum ? (Number(item.watchNum) > 10000 ?( Number(item.watchNum)/10000).toFixed(1) + 'w' : item.watchNum ) : 0
            })
            this.setData({
              'datas.componentData.liveList' : res.data.data
            })
          }

          console.log(this.data.datas.componentData.liveList,'this.data.datas.componentData.liveList')
        }else{
          this.setData({
            showList : false
          })
        }
      })

    },
侯体倬 committed
76 77
    toList(e){
      app.trackCpn(e, this.data.datas.componentName, '查看更多')
程智春 committed
78 79 80 81 82 83 84
      app.$themeToLink({
        type: 1,
        link: '/liveBroadcast/list'
      })
    },
    toLiveDetail(e){
      let id = e.currentTarget.dataset.itemid
侯体倬 committed
85
      app.trackCpn(e, this.data.datas.componentName, id)
程智春 committed
86 87 88 89 90 91 92
      app.$themeToLink({
        type: 1,
        link: '/liveBroadcast/lived?liveId=' + id
      })
    }
  }
})