index.js 2.54 KB
Newer Older
程智春 committed
1
// static/nativeComponents/Notice/index.js
侯体倬 committed
2 3
const app = getApp();
const { DFSImg, $themeToLink } = app;
程智春 committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    datas : {
      type : Object
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
侯体倬 committed
18 19 20 21
    singleImg: '',
    CommonHeight: 0,
    NoticeMargin: 0,
    NoticePadding: 0
程智春 committed
22 23
  },

侯体倬 committed
24 25 26 27 28 29 30 31 32 33 34 35 36 37
  ready() {
    let { noticeList, singleImage } = this.data.datas.componentData
    singleImage = DFSImg(singleImage)
    for (let i = 0; i < noticeList.length; i++) {
      let imageUrl = DFSImg(noticeList[i].imageUrl)
      noticeList[i].imageUrl = imageUrl
    }
    this.setData({
      singleImg: singleImage,
      "data.datas.componentData.noticeList": noticeList
    })
    this.getNoticeHeight()
    this.getNoticeMargin()
    this.getNoticePadding()
程智春 committed
38 39 40 41 42 43
  },

  /**
   * 组件的方法列表
   */
  methods: {
侯体倬 committed
44
    onclickHandle(e) {
侯体倬 committed
45 46 47
      let item = this.data.datas.componentData.noticeList[e.currentTarget.dataset.index]
      app.trackCpn(e, this.data.datas.componentName, item)
      app.$themeToLink(item.link)
侯体倬 committed
48 49 50 51 52 53 54 55 56 57 58 59 60 61
    },
    getNoticeMargin() {
      this.setData({
        NoticeMargin: this.data.datas.componentData.verticalMargin+'px '+this.data.datas.componentData.horizontalMargin+'px'
      })
    },
    getNoticePadding() {
      this.setData({
        NoticePadding: this.data.datas.componentData.verticalPadding+'px '+this.data.datas.componentData.horizontalPadding+'px'
      })
    },
    getNoticeHeight() {
      if (this.data.datas.componentData.isChange) {
        if (this.data.datas.componentData.imageWidth > this.data.datas.componentData.noticeWidth) {
程智春 committed
62
          this.setData({
侯体倬 committed
63
            CommonHeight: this.data.datas.componentData.imageWidth < 53 ? '53px' : this.data.datas.componentData.imageWidth + 'px'
程智春 committed
64
          })
侯体倬 committed
65 66 67 68 69 70
          return
        } else if (this.data.datas.componentData.noticeWidth >= this.data.datas.componentData.imageWidth) {
          this.setData({
            CommonHeight: this.data.datas.componentData.noticeWidth < 53 ? '53px' : this.data.datas.componentData.noticeWidth + 'px'
          })
          return
程智春 committed
71
        }
侯体倬 committed
72 73 74 75 76 77 78 79 80 81
        this.setData({
          CommonHeight: this.data.datas.componentData.noticeWidth > this.data.datas.componentData.imageWidth ? this.data.datas.componentData.noticeWidth + 'px' : this.data.datas.componentData.imageWidth + 'px'
        })
        return
      } else {
        this.setData({
          CommonHeight: this.data.datas.componentData.noticeWidth < 53 ? '53px' : this.data.datas.componentData.noticeWidth + 'px'
        })
        return
      }
程智春 committed
82 83 84
    }
  }
})