// component/waterFlowLayout/waterFlowLayout.js
const wxService = require('../../utils/wxService')
const utils = require('../../utils/util')

Component({
  /**
   * 组件的属性列表
   */
  properties: {
    currentHasUserInfo: {
      type: Boolean,
      value: false,
      observer(val){
      }
    },
    imageData: {
      type: Array,
      value: [],
    },
    type: {
      type: Number,
      value: [],
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    // imageheight: 0
    userIsLogin : false
  },

  observers: {
    currentHasUserInfo(val) {
      console.log(val)
      this.setData({
        userIsLogin: val
      })
    }

  },

  /**
   * 组件的方法列表
   */
  methods: {
    onTapLike(e) {
      if (e.currentTarget.dataset.currentType != 2) return;
      const { memberId } = wx.getStorageSync('_baseUserInfo')
      let params = {
        contentId: e.currentTarget.dataset.id,
        type: e.currentTarget.dataset.type,
        userId: memberId
      }
      this.triggerEvent('updataLike', params)
    },
    onTapShare(e) {
      if (e.currentTarget.dataset.currentType != 2) return;
      console.log(e)
      let params = {
        url: e.currentTarget.dataset.url,
        title: e.currentTarget.dataset.title,
        headline: e.currentTarget.dataset.headline,
        describe: e.currentTarget.dataset.describe,
        id: e.currentTarget.dataset.id
      }
      wxService.nextTick(() => {
        this.triggerEvent('_onTapShare', params)
      })
    },

    //详情
    gotoDetail(e) {
      // type 1:内容  2：我的发布
      if (this.data.type == 1) {
        wxService.router(`/pages/wantToBuyDetail/wantToBuyDetail?id=${e.currentTarget.dataset.id}`)
      } else if (this.data.type == 2) {
        if (e.currentTarget.dataset.currentType == 2){
          wxService.router(`/subPackage/page/pages/myReleaseDetail/myReleaseDetail?id=${e.currentTarget.dataset.id}`)
        }
      }
    },

    //授權
    _getUserInfo(res){
      wxService.nextTick(() => {
        this.triggerEvent('getAuth',res);
      })
    }
    //获取图片高度
    // imageLoad(e) {
    //   console.log('height', utils.imageUtil(e))
    //   let imageSize = utils.imageUtil(e)
    //   this.data.imageData.forEach((item)=>{
    //     item.imageheight = imageSize.imageHeight
    //   })
    //   // this.setData({
    //   //   // imagewidth: imageSize.imageWidth,
    //   //   imageheight: imageSize.imageHeight
    //   // })
    //   console.log('imageData',this.data.imageData)
    // }
  }
})
