<template>
  <div>
    <div :title="getAllName(item[areaName])">{{ spliceNameFun(item.partyOrgName, 8) }}</div>
    <div v-if="item.principalName && !item.principalName.includes(',')" @click="gotoPersonnel(item.resiId)" :title="getAllName(item.principalName)">{{ spliceNameFun(item.principalName, 12) }}</div>
    <div class="name_more" v-if="item.principalName && item.principalName.includes(',')">
      <span v-for="(i, k) in item.principalName.split(',')" :key="i" @click="gotoPersonnel(item.resiId[k])" :title="getAllName(i)">{{ spliceNameFun(i, 12) }}{{ k === getItemNameArr(item.principalName).length - 1 ? "" : "," }}</span>
      <popTips :item="item" />
    </div>
  </div>
</template>

<script>
export default {
  name: "NameSplit",
  props: {
    item: {
      type: Object,
      default: () => {},
    },
    areaName: {
      type: String,
      default: "partyOrgName",
    },
    peopleName: {
      type: String,
      default: "principalName",
    },
  },
  data() {
    return {};
  },
  methods: {
    getAllName(item) {
      return item;
    },

    getItemNameArr(str) {
      return str.split(",").slice(0, 2);
    },

    spliceNameFun(row, num) {
      if (row && row.length > num) {
        return row.substring(0, num) + "...";
      }
      return row;
    },
    gotoPersonnel(id) {
      if (id) {
        this.$router.push({ path: "/organizational/orgPersonnel", query: { user_id: id } });
      } else {
        this.$message.error("无法跳转！");
      }
    },
  },
};
</script>
