<template>
  <ww-open-data v-if="is_trial" :type="type" :openid="openid" :style="name_style" />
  <span v-else :style="name_style">{{ name }}</span>
</template>

<script>
/**
 * type - 开放数据类型 userName-用户名称 departmentName-部门名称
 * openid - userid / departmentid
 * name - 非试用版下的名称
 * is_trial - 是否是试用版，默认false
 */
export default {
  name: "WlStaffName",
  props: {
    is_trial: {
      type: Boolean,
      default: false,
    },
    type: {
      type: String,
      default: "userName",
    },
    name: {
      type: String,
    },
    openid: {
      type: String,
    },
    fontSize: {
      type: [String, Number],
    },
    color: {
      type: String,
      default: "",
    },
    cursor: {
      type: String,
      default: "",
    },
  },
  computed: {
    name_style() {
      return {
        fontSize: typeof this.fontSize === "string" ? this.fontSize : this.fontSize + "px",
        color: this.color,
        cursor: this.cursor,
      };
    },
  },
  watch: {
    is_trial: {
      handler(val) {
        if (val) {
          setTimeout(() => {
            window.top.WWOpenData.bindAll(document.querySelector("ww-open-data"));
          });
        }
      },
      immediate: true,
    },
  },
  mounted() {
    if (this.is_trial) {
      window.top.WWOpenData.bindAll(document.querySelector("ww-open-data"));
    }
  },
  updated() {
    if (this.is_trial) {
      window.top.WWOpenData.bindAll(document.querySelector("ww-open-data"));
    }
  },
};
</script>
