<template>
  <div v-if="recruitData">
    <div class="header">
      <div class="header-left">
        <div class="title-wrapper">
          <div class="title">{{recruitData.title}}</div>
          <div class="status" :style="{color: recruitData.statusColor}">{{recruitData.statusName}}</div>
        </div>
        <div class="salary">薪酬范围：{{recruitData.salaryName}}</div>
        <div class="skill">
          技能：
          <span v-for="(item,index) in recruitData.skills" :key="index">
            <span v-if="index>0">,</span>
            <span>{{item.name}}</span>
          </span>
        </div>
        <div class="experience">经验：{{recruitData.experienceName}}</div>
      </div>
      <div class="owner-wrapper" @click="handleOwnerClick()">
        <img
          class="owner-img"
          :src="recruitData.ownerInfo && recruitData.ownerInfo.iconUrl || ''"
          alt
        />
        <div class="owner-name">{{recruitData.ownerInfo && recruitData.ownerInfo.nickname || ''}}</div>
      </div>
      <div class="company-info" @click="handleCompanyClick()">
        <div style="padding-left:60px;">
          <img
            class="owner-img"
            :src="recruitData.companyInfo && recruitData.companyInfo.logo || ''"
            alt
          />
        </div>
        <div style="padding-left:20px;">
          <div>{{recruitData.companyInfo && recruitData.companyInfo.shortName ? recruitData.companyInfo.shortName : (recruitData.companyInfo && recruitData.companyInfo.name ? recruitData.companyInfo.name : '')}}</div>
          <div
            class="description"
          >{{recruitData.companyInfo && recruitData.companyInfo.description || ''}}</div>
        </div>
      </div>
      <div class="actions">
        <template v-if="recruitData.status==='2'">
          <el-button type="primary" class="btn" @click.stop="handleApproveClick(recruitData.id)">通过</el-button>
          <el-button type="danger" class="btn" @click.stop="handleRejectClick(recruitData.id)">不通过</el-button>
        </template>
        <template v-if="recruitData.status==='3'">
          <el-button type="danger" class="btn" @click.stop="handleRejectClick(recruitData.id)">不通过</el-button>
        </template>
      </div>
    </div>
    <div class="description-wrapper">
      <div class="description-title">工作描述</div>
      <div class="description-content">{{recruitData.description}}</div>
    </div>

    <div class="description-wrapper">
      <div class="description-title">招聘评价</div>
      <div class="description-content">
        <el-row>
          <el-col :span="4">
            <div class="owner-wrapper" @click="handleOwnerClick()" style="margin-left:0;">
              <img
                class="owner-img"
                :src="recruitData.ownerInfo && recruitData.ownerInfo.iconUrl || ''"
                alt
              />
              <div
                class="owner-name"
              >{{recruitData.ownerInfo && recruitData.ownerInfo.nickname || ''}}</div>
            </div>
          </el-col>
          <el-col :span="18">
            <div v-if="recruitData.recruitResult != 0">
              <div>{{recruitData.companyCommentAtFormat}}</div>
              <div>
                <span v-if="recruitData.status==4">停止招聘</span>
                <span v-else>删除岗位</span>
                ；招聘结果：
                {{recruitData.recruitResultName}}
                <span
                  v-if="recruitData.problemsName"
                >；存在问题：{{recruitData.problemsName}}</span>
                <span v-if="recruitData.advice">；意见反馈：{{recruitData.advice}}</span>
              </div>
            </div>
          </el-col>
        </el-row>
      </div>
    </div>

    <div class="description-wrapper">
      <div class="description-title">
        招聘数据（已投递
        <span>{{recruitData.countApplied|| 0}}</span>人，沟通中
        <span>{{recruitData.countTalk || 0}}</span>人）
      </div>
      <div class="description-content">
        <el-table :data="recruitData.developers" style="width: 540px">
          <el-table-column label="UID" width="180">
            <template slot-scope="scope">
              <el-link type="primary" target="_blank" @click="openUser(scope.row.uid)">
                {{scope.row
                .uid}}
              </el-link>
            </template>
          </el-table-column>
          <el-table-column label="已投递" width="180">
            <template
              slot-scope="scope"
            >{{Number(scope.row.applicationState) === 0 ? '否' : scope.row.applicationTime}}</template>
          </el-table-column>
          <el-table-column label="沟通中" width="180">
            <template
              slot-scope="scope"
            >{{Number(scope.row.talkState) === 0 ? '否' : scope.row.lastTalkTime}}</template>
          </el-table-column>
        </el-table>
      </div>
    </div>
    <el-dialog title="请输入审核不通过的原因" :visible.sync="isDialogShow">
      <el-form :model="form">
        <el-form-item label>
          <el-input v-model="form.reason"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="handleCancleClick()">取 消</el-button>
        <el-button type="primary" @click="handleComfirmClick()">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      isDialogShow: false,
      recruitId: "",
      recruitData: {
        developers: []
      },
      form: {
        reason: ""
      }
    };
  },
  mounted() {
    this.recruitId = this.$route.query.id;
    this.getRecruit();
  },
  methods: {
    async getRecruit() {
      const recruitId = this.recruitId;
      const data = {
        recruitId
      };
      let res = await this.$post("/api/admin/recruit/getRecruit", data);
      if (res && res.status === 1) {
        this.recruitData = res.data;
        console.log(this.recruitData);
      }
    },
    handleOwnerClick() {
      const recruitData = this.recruitData;
      // 前往老的后台
      window.open(
        this.$store.state.domainConfig.siteUrl +
          `/rooter/user/${recruitData.uid}`
      );
    },
    handleCompanyClick() {
      const recruitData = this.recruitData;
      window.open(
        this.$store.state.domainConfig.siteUrl + `/company/${recruitData.uid}`
      );
    },
    openUser(uid) {
      let url = window.location.href;
      let jumpUrl = "";
      jumpUrl = this.$store.state.domainConfig.siteUrl + `/wo/${uid}`;
      window.open(jumpUrl, "_black");
    },
    async handleApproveClick(recruitId) {
      const action = "approve";
      const data = {
        recruitId,
        action
      };
      let res = await this.$post("/api/admin/recruit/audit", data);
      if (res && res.status === 1) {
        console.log(res);
        this.$message({
          message: res.info,
          type: "success"
        });
        await this.getRecruit();
      }
    },
    async handleRejectClick(recruitId) {
      this.recruitId = recruitId;
      this.isDialogShow = true;
    },
    handleCancleClick() {
      this.form = {
        reason: ""
      };
      this.isDialogShow = false;
    },
    async handleComfirmClick() {
      const recruitId = this.recruitId;
      const action = "reject";
      const reason = this.form.reason;
      const data = {
        recruitId,
        action,
        reason
      };
      let res = await this.$post("/api/admin/recruit/audit", data);
      if (res && res.status === 1) {
        console.log(res);
        this.$message({
          message: res.info,
          type: "success"
        });
        await this.getRecruit();
      }
      this.form = {
        reason: ""
      };
      this.isDialogShow = false;
    }
  }
};
</script>

<style lang="scss" scoped>
.header {
  display: flex;
}
.title-wrapper {
  display: flex;
  align-items: center;
}
.title {
  line-height: 27px;
  font-weight: bold;
  font-size: 18px;
  color: #101010;
}
.status {
  margin-left: 6px;
  line-height: 20px;
  font-size: 14px;
}
.salary {
  margin-top: 13px;
  line-height: 24px;
  font-size: 16px;
  color: #101010;
}
.skill {
  margin-top: 8px;
  line-height: 24px;
  font-size: 16px;
  color: #101010;
}
.experience {
  margin-top: 8px;
  line-height: 24px;
  font-size: 16px;
  color: #101010;
}
.owner-wrapper {
  margin-left: 100px;
  text-align: center;
}
.owner-img {
  width: 53px;
  height: 53px;
  border-radius: 50%;
}
.owner-name {
  margin-top: 8px;
  line-height: 20px;
  font-size: 14px;
  color: #3f51b5;
}
.description-wrapper {
  margin-top: 50px;
}
.description-title {
  line-height: 27px;
  font-weight: bold;
  font-size: 18px;
  color: #101010;
}
.description-content {
  margin-top: 16px;
  line-height: 24px;
  font-size: 16px;
  color: #101010;
}
.company-info {
  display: flex;
  flex: 2;
  line-height: 2;
}
.company-info .description {
  overflow: hidden;
  height: 30px;
  max-width: 300px;
  word-wrap: normal;
  text-overflow: ellipsis;
  white-space: nowrap;
  word-break: keep-all;
}
.actions {
  display: flex;
  width: 180px;
  align-items: center;
  text-align: center;
}
</style>
