// components/spacecard/spacecard.js
import utils from "../../utils/util";
import icons from "../../utils/icon"
const app = getApp();
Component({
  /**
   * 组件的属性列表
   */
  properties: {
      isCheckbox:{
        type:Boolean,
        value:false
      },
      cardDate:{
        type:Object,
        value:{}
      },
      canvashidden:{
        type:Boolean,
        value:true
      }
  },

  /**
   * 组件的初始数据
   */
  data: {
    imgbaseUrl:app.globalData.imgbaseUrl,
    picInitUrl:app.globalData.picInitUrl,
    unit:"°C",
    imgShow:false,
    statusList: icons.cardstatusList,
  },
  attached: function(){
    if(!this.data.cardDate.picInit){
      let list = JSON.parse(JSON.stringify(this.data.cardDate));
      list.picInit=utils.picInit(list.roomFuncType);
      this.setData({cardDate:list})
    }
  },
  observers: {
    // 'cardDate.roomFuncType': function(rate) {
    //   // 在 rate被设置时，执行这个函数
    //   let list = JSON.parse(JSON.stringify(this.data.cardDate));
    //   list.picInit=utils.picInit(list.roomFuncType);
    //   this.setData({cardDate:list})
    // }
  },
  ready:function(){
  },
  /**
   * 组件的方法列表
   */
  methods: {
    changeStar(e){
      console.log(e);
      let checked=!e.currentTarget.dataset.checked;
      this.setData({"cardDate.subscribe":checked});
      this.triggerEvent("starClick",{checked:checked,spaceId:this.data.cardDate.id});
    },
    goHome(){
      let cardDate=this.data.cardDate;
      this.triggerEvent('listClick', {cardDate});
    },
    imageLoad(ev){
      this.setData({imgShow:true});
      let src = ev.currentTarget.dataset.src,
      width = ev.detail.width,
      height = ev.detail.height;
    }
  }
})
