let component = {
  props: {
    value: {
      type: String,
      default: null
    },
    type: {
      type: String,
      default: null
    }
  },
  data() {
    return {
      text: ""
    };
  },
  computed: {},
  render(h) {
    // 不然可能无法正常更新.
    let value = this.value;
    this.$store.dispatch("base/loadSysCode", this.type).then(codes => {
      let c = codes.find(c => c.value === value);
      if (c) {
        this.text = c.label;
      }
    });
    return <span class={{'font-red-error': !this.text}}>{this.text ? this.text : this.$t("ui.sysCode.noCode")}</span>;
  }
};

let directive = {
  bind(el, binding, vnode, oldnode) {
    let codeType = binding.value;
    vnode.context.$store.dispatch("base/loadSysCode", codeType);
  }
};

export default {directive, component};
