<template>
  <div>
    <div class="count-list" v-if="auditData">
      <div class="count-item">全部：{{auditData.countAllStatus}}</div>
      <div class="count-item">审核中：{{auditData.countWaitAudit}}</div>
      <div class="count-item">开放中：{{auditData.countOpen}}</div>
      <div class="count-item">停止招聘：{{auditData.countOffline}}</div>
      <div class="count-item">发布企业：{{auditData.countCompanies}}</div>
      <div class="count-item">当前统计数量：{{auditData.total}}</div>
    </div>
    <el-form :inline="true">
      <el-form-item label="岗位状态">
        <el-select v-model="searchParams.status" placeholder="全部">
          <el-option label="全部" value="0"></el-option>
          <el-option label="审核中" value="2"></el-option>
          <el-option label="开放中" value="3"></el-option>
          <el-option label="停止招聘" value="4"></el-option>
          <el-option label="审核失败" value="6"></el-option>
          <el-option label="已删除" value="5"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="申请审核日期">
        <el-date-picker
          v-model="searchParams.dateTime"
          type="datetimerange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          value-format="yyyy-MM-dd HH:mm:ss"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="发布者">
        <el-input v-model="searchParams.uid" placeholder="全部"></el-input>
      </el-form-item>
      <el-form-item label="招聘结果">
        <el-select v-model="searchParams.recruitResult" placeholder="全部">
          <el-option label="-" value="0"></el-option>
          <el-option label="是" value="1"></el-option>
          <el-option label="否" value="2"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="getAuditList">查询</el-button>
      </el-form-item>
    </el-form>
    <div class="content" v-if="auditData && auditData.list">
      <el-table :data="auditData.list" @row-click="clickRow" border style="width: 100%">
        <el-table-column prop="id" label="岗位ID" width="70"></el-table-column>
        <el-table-column prop="occupationName" label="职位类型"></el-table-column>
        <el-table-column prop="workTypeName" label="工作方式"></el-table-column>
        <el-table-column label="工作周期">
          <template slot-scope="scope">
            <span>{{scope.row.month}}个月</span>
          </template>
        </el-table-column>
        <el-table-column label="驻场地区">
          <template slot-scope="scope">
            <span>{{scope.row.cityName || '-'}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="salaryName" label="薪酬范围"></el-table-column>
        <el-table-column label="公司">
          <template slot-scope="scope">
            <span>{{scope.row.companyInfo && scope.row.companyInfo.shortName ? scope.row.companyInfo.shortName : (scope.row.companyInfo && scope.row.companyInfo.name ? scope.row.companyInfo.name : '')}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="auditAtFormat" label="发布（刷新）日期"></el-table-column>
        <el-table-column prop="createdAtFormat" label="创建日期"></el-table-column>
        <el-table-column prop="submitAuditAtFormat" label="申请审核日期"></el-table-column>
        <el-table-column prop="countApplied" label="已投递" width="70"></el-table-column>
        <el-table-column prop="countTalk" label="沟通中" width="70"></el-table-column>
        <el-table-column prop="statusName" label="岗位状态" width="90"></el-table-column>
        <el-table-column prop="recuitResult" label="招聘结果" width="90">
          <template slot-scope="scope">
            <span v-if="scope.row.recruitResult == 1">是</span>
            <span v-if="scope.row.recruitResult == 2">否</span>
            <span v-if="scope.row.recruitResult == '' || scope.row.recruitResult == 0">-</span>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <el-pagination
      class="order-footer"
      background
      layout="prev, pager, next"
      :page-size="20"
      :total="Number(auditData.total)"
      @current-change="handleCurrentChange"
    />
    <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 {
      page: 1,
      auditData: "",
      form: {
        reason: ""
      },
      searchParams: {
        status: "0",
        uid: null,
        dateTime: [],
        startTime: null,
        endTime: null,
        recruitResult: "0"
      },
      isDialogShow: false
    };
  },
  mounted() {
    this.getAuditList();
  },
  methods: {
    async getAuditList() {
      this.searchParams.startTime = this.searchParams.dateTime[0];
      this.searchParams.endTime = this.searchParams.dateTime[1];
      const page = this.page;
      const data = {
        page,
        ...this.searchParams
      };
      let res = await this.$post("/api/admin/recruit/getAuditList", data);
      if (res && res.status === 1) {
        this.auditData = res.data;
        console.log(this.auditData);
      }
    },
    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"
        });
        this.getAuditList();
      }
    },
    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"
        });
        this.getAuditList();
      }
      this.form = {
        reason: ""
      };
      this.isDialogShow = false;
    },
    handleCurrentChange(val) {
      this.page = val;
      this.getAuditList();
    },
    clickRow(row) {
      const id = row.id;
      this.$router.push({
        path: "/main/job",
        query: {
          id
        }
      });
    }
  }
};
</script>

<style lang="scss" scoped>
.count-list {
  padding-bottom: 10px;
  display: flex;
  align-items: center;
}

.count-item {
  margin-right: 20px;
  font-size: 16px;
}

.content {
  white-space: nowrap;
  overflow-x: scroll;
  height: calc(100% - 150px);
}

.btn {
  width: 80px;
}

.order-footer {
  margin-top: 10px;
}
</style>
