<template>
  <div class="infoWin">
    <div class="header-new">
      <img
        class="header-img"
        :src="
          info.platform === '2'
            ? require('@/assets/images/mapSearch/内保单位.png')
            : require('@/assets/images/mapSearch/搜地址.png')
        "
        alt=""
      />{{ info.name }}
      <el-button class="follow-btn" v-if="!isFollowed" type="primary" plain size="mini" @click="followCompany(info.id)">
        关注
      </el-button>
      <el-button class="follow-btn" v-if="isFollowed" type="primary" plain size="mini" @click="unFollowCompany(info.id)">
        取消关注
      </el-button>
    </div>
    <div v-if="returnWin?.infoType === 'station'" class="back" @click="onClickStation(returnWin.info)">&lt; 返回驻勤点信息</div>

    <div v-if="returnWin?.infoType === 'employee'" class="back" @click="onClickEmployee(returnWin.info)">&lt; 返回保安员信息</div>

    <div v-if="returnWin?.infoType === 'rail'" class="back" @click="onClickRail(returnWin.info)">&lt; 返回电子围栏信息</div>

    <div class="content-new">
      <div class="content-new-label">{{ info.platform === "1" ? "法定代表人" : "负责人员" }}：</div>
      <div class="content-new-value">{{ info.legal }}</div>
    </div>
    <div class="content-new">
      <div class="content-new-label">联系方式：</div>
      <div class="content-new-value">
        {{ isPhone ? info.legalContact : "***********" }}
        <span class="hide-show" @click.stop="isPhone = !isPhone" v-if="isPhone">隐藏</span>
        <span class="hide-show" @click.stop="isPhone = !isPhone" v-if="!isPhone">显示</span>
      </div>
    </div>
    <div class="content-new">
      <div class="content-new-label">{{ info.platform === "1" ? "注册地址" : "内保单位地址" }}：</div>
      <el-tooltip effect="dark" :content="info.registerAddress" placement="top">
        <div class="content-new-value">
          {{ info.registerAddressSlice }}
        </div>
      </el-tooltip>
    </div>
    <div class="content-new" v-if="info.platform === '2'">
      <div class="content-new-label">内保单位监督机构：</div>
      <div class="content-new-value">{{ info.superviseDepartName }}</div>
    </div>
    <div class="content-new" v-if="info.platform === '2'">
      <div class="content-new-label">驻勤点个数：</div>
      <div class="content-new-value active" @click="clickCompanyStations(info, 'company')">
        {{ info.countOfActivityStation }}
      </div>
    </div>
    <div class="content-new" v-if="info.platform === '1'">
      <div class="content-new-label">保安员数：</div>
      <div class="content-new-value">{{ info.countOfSecurityMan }}</div>
    </div>
    <div class="content-new" v-if="info.platform === '1'">
      <div class="content-new-label">企业类型：</div>
      <div class="content-new-value">{{ info.institutionalName }}</div>
    </div>
    <div class="content-new" v-if="info.platform === '2'">
      <div class="content-new-label">内保单位类型：</div>
      <div class="content-new-value">
        {{ info.institutionalName }}
      </div>
    </div>
    <div class="content-new" v-if="info.platform === '2'">
      <div class="content-new-label">保卫管理员人数：</div>
      <div class="content-new-value">
        {{ info.countOfMan }}
      </div>
    </div>
  </div>
</template>

<script>
import { follow, unFollow } from "@/api/tenant-content-follow-controller";
export default {
  name: "OverlayCompany",
  props: {
    info: {
      type: Object,
    },
    returnWin: {
      type: Object,
    },
  },
  computed: {
    isFollowed() {
      //是否关注
      return this.info.followed;
    },
  },
  data() {
    return {
      isPhone: false,
    };
  },
  methods: {
    /**
     * @关注公司
     */
    followCompany(companyId) {
      follow("Company", companyId).then(() => {
        this.$message({
          type: "success",
          message: "关注成功!",
        });
        this.info.followed = true;
      });
    },
    /**
     * @取消关注保安员
     */
    unFollowCompany(companyId) {
      this.$confirm("是否取消关注状态", "提示", {
        confirmButtonText: "取消关注",
        customClass: "del-model",
        type: "warning",
      })
        .then(() => {
          unFollow("Company", companyId);
          this.info.followed = false;
        })
        .catch(() => {});
    },
    /**
     * @返回保安员
     */
    onClickEmployee(info) {
      this.$bus.$emit("click-employee", { info, infoType: "company" });
    },
    /**
     * @返回驻勤点
     */
    onClickStation(info) {
      this.$bus.$emit("click-station", { info, infoType: "company" });
    },

    /**
     * @返回电子围栏
     */
    onClickRail(info) {
      this.$bus.$emit("click-rail", { info, infoType: "company" });
    },

    /**
     * @点击驻勤点人个数
     */
    clickCompanyStations(info, infoType) {
      this.$bus.$emit("click-companyStations", { info, infoType });
    },
  },
};
</script>

<style scoped></style>
