<template>
  <Node
    :title="config.nodeName"
    :show-error="showError"
    :content="content"
    :error-info="errorInfo"
    placeholder="请设置抄送人"
    header-bgc="#3296fa"
    header-icon="x-icon-promotion"
    @insertNode="handleInsertNode"
    @selected="onSelectedNode"
    @delNode="handleDelNode"
  />
</template>

<script>
import Node from './Node.vue';
//抄送节点
export default {
  name: 'CcNode',
  components: {
    Node
  },
  props: {
    config: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      showError: false,
      errorInfo: ''
    };
  },
  computed: {
    // 抄送人展示内容
    content() {
      if (this.config.nodeAssigneeList && this.config.nodeAssigneeList.length > 0) {
        const texts = this.config.nodeAssigneeList.map(org => org.name);
        return texts.join('、');
      }
      return '';
    }
  },
  methods: {
    // 校验数据配置的合法性
    validate(errList) {
      this.showError = false;
      if (!this.config.nodeAssigneeList || this.config.nodeAssigneeList.length === 0) {
        this.showError = true;
        this.errorInfo = '请选择需要抄送的人员';
        errList.push(`抄送节点 ${this.config.name} 未设置抄送人`);
      }
      return !this.showError;
    },
    onSelectedNode() {
      this.$emit('selected');
    },
    handleInsertNode(type) {
      this.$emit('insertNode', type)
    },
    handleDelNode() {
      this.$emit('delNode')
    }
  }
};
</script>

<style scoped>
</style>
