// packageG/independent_store/mycomponent/storeInfo/storeInfo.js
const app = getApp();
Component({
  options: {
    styleIsolation: 'apply-shared',
    multipleSlots: true
  },
  properties: {
    datas: {
      type: Object,
      value: {},
      observer (newVal, oldVal) {
        if (newVal.store_introduce) {
          this.setData({
            contentNode: newVal.information.replace(/\<img/gi, '<img style="max-width:100%;height:auto;display:block"')
          });
          this.getTextRect();
        }
      }
    }
  },
  lifetimes: {
    ready () {
      this.getTextRect();
    },
  },
  data: {
    showMore: false,
    readmore: false,
    contentNode: '',
  },

  methods: {
    getTextRect () {
      const query = wx.createSelectorQuery().in(this);
      query.select(".introduce-text").boundingClientRect().exec((res) => {
        const lineHeight = 20;
        const height = res[0].height;
        if (height / lineHeight <= 4) {
          this.setData({
            showMore: false,
          });
        } else {
          this.setData({
            showMore: true,
            readmore: true,
          });
        }
      });
    },
    phoneCall (e) {
      let mobile = e.currentTarget.dataset.mobile;
      let name = e.currentTarget.dataset.realname;
      if (mobile) {
        this.triggerEvent('contactPopup', {
          mobile,
          name
        });
      } else {
        app.tips("该员工未备注手机号");
      }
    },
    copyWx (e) {
      let wechat = e.currentTarget.dataset.wechat;
      if (wechat) {
        wx.setClipboardData({
          data: wechat,
          success: (res) => {
            app.tips("复制成功");
          },
          fail (err) {
            app.tips("复制失败");
          }
        });
      } else {
        app.tips("该员工暂无微信号");
      }

    },
    toggle () {
      this.setData({
        readmore: !this.data.readmore
      });
    },
    goBusinessCard (e) {
      let item = e.currentTarget.dataset.item;
      if (item.card_id) {
        wx.navigateTo({
          url: '/packageB/member/business_card/BusinessCard/BusinessCard?mark=card&card_id=' + item.card_id
        });
      }
    },
  }
});
