<template>
  <basic-container>
    <!--搜索栏-->
<!--    <el-form-->
<!--      size="small"-->
<!--      label-position="right"-->
<!--      style="padding-left: 10px; padding-right: 10px"-->
<!--      :inline="true"-->
<!--    >-->
<!--      <el-row :span="24">-->
<!--        <el-form-item label="社区街道名称:">-->
<!--          <el-input-->
<!--            v-model="query.companyName"-->
<!--            placeholder="社区街道名称"-->
<!--            clearable-->
<!--          ></el-input>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="岗位编码:">-->
<!--          <el-input-->
<!--            v-model="query.missionNo"-->
<!--            placeholder="岗位编码"-->
<!--            clearable-->
<!--          ></el-input>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="岗位标题:">-->
<!--          <el-input-->
<!--            v-model="query.jobName"-->
<!--            placeholder="岗位标题"-->
<!--            clearable-->
<!--          ></el-input>-->
<!--        </el-form-item>-->
<!--&lt;!&ndash;        <el-form-item>&ndash;&gt;-->
<!--&lt;!&ndash;          <el-select v-model="query.type" placeholder="请选择搜索时间类型">&ndash;&gt;-->
<!--&lt;!&ndash;            <el-option label="岗位开始日期" :value="0"></el-option>&ndash;&gt;-->
<!--&lt;!&ndash;            <el-option label="岗位结束日期" :value="2"></el-option>&ndash;&gt;-->
<!--&lt;!&ndash;            &lt;!&ndash; <el-option label="报名截止日期" :value="3"></el-option> &ndash;&gt;&ndash;&gt;-->
<!--&lt;!&ndash;          </el-select>&ndash;&gt;-->
<!--&lt;!&ndash;        </el-form-item>&ndash;&gt;-->
<!--        <el-form-item label="日期范围:">-->
<!--          <el-date-picker-->
<!--            v-model="query.time"-->
<!--            type="daterange"-->
<!--            range-separator="至"-->
<!--            start-placeholder="开始日期"-->
<!--            end-placeholder="结束日期"-->
<!--            value-format="yyyy-MM-dd"-->
<!--          >-->
<!--          </el-date-picker>-->
<!--        </el-form-item>-->
<!--&lt;!&ndash;        <tool-tip></tool-tip>&ndash;&gt;-->
<!--        <br>-->
<!--        <el-form-item label="岗位状态：">-->
<!--          <el-select v-model="query.reviewState">-->
<!--            <el-option-->
<!--              v-for="(item, index) in recruitStatus"-->
<!--              :key="index"-->
<!--              :label="item.label"-->
<!--              :value="item.value"-->
<!--            ></el-option>-->
<!--          </el-select>-->
<!--        </el-form-item>-->
<!--        <div class="searchBtn">-->
<!--          <el-button-->
<!--            type="primary"-->
<!--            size="small"-->
<!--            icon="el-icon-search"-->
<!--            @click="searchChange1"-->
<!--            >搜 索</el-button-->
<!--          >-->
<!--          <el-button size="small" icon="el-icon-delete" @click="searchReset1"-->
<!--            >清 空</el-button-->
<!--          >-->
<!--        </div>-->
<!--      </el-row>-->
<!--    </el-form>-->
    <!--搜索-->
    <avue-crud
      :option="option"
      :table-loading="loading"
      :data="data"
      ref="crud"
      v-model="form"
      :permission="permissionList"
      :before-open="beforeOpen"
      :before-close="beforeClose"
      :page.sync="page"
      @row-update="rowUpdate"
      @row-save="rowSave"
      @search-change="searchChange"
      @search-reset="searchReset"
      @selection-change="selectionChange"
      @current-change="currentChange"
      @size-change="sizeChange"
      @refresh-change="refreshChange"
      @on-load="onLoad"
    >
      <template slot-scope="{ row }" slot="menu">
        <el-button
          type="text"
          size="small"
          @click.stop="rowView(row)"
          v-if="vaildData(permission.manage_mission_view, false)"
          >详情</el-button
        >
        <el-button
          v-if="vaildData(permission.manage_mission_check, false) && row.reviewState === 1"
          type="text"
          size="small"
          @click.stop="handleCheck(row)"
          >审核</el-button
        >
      </template>
    </avue-crud>
    <el-drawer title="详情" :visible.sync="viewDrawer" size="60%">
      <post-view :model="view"></post-view>
    </el-drawer>
    <el-dialog
      title="审核"
      :visible.sync="centerDialogVisible"
      width="30%"
      append-to-body
      center>
      <span>请核对招聘信息后再进行审核通过</span>
      <span slot="footer" class="dialog-footer">
         <el-button @click="centerDialogVisible = false">取 消</el-button>
        <el-button type="warning" @click="handelAuditing(0)">不通过</el-button>
        <el-button type="primary" @click="handelAuditing(9)">通 过</el-button>
      </span>
    </el-dialog>
  </basic-container>
</template>

<script>
import {
  // getList,
  // review,
  complet,
  // getDetail,
  download,
} from "@/api/workstation/post";
import  {
  getList,
  getDetail,
  review
} from '@/api/manage/recruit'
import { mapGetters } from "vuex";
import postView from "@/views/util/post-view.vue";
import zpView from "./zpView.vue";
import { recruitStatus, wageUnitCategoryState} from "@/common/dic";
import { calcDate } from "@/util/date";
import { Message } from "element-ui";
import lodash from "lodash";

const message = lodash.throttle(
  function (options) {
    Message(options);
  },
  3000,
  { trailing: false }
);

export default {
  components: {postView, zpView},
  name: "manage_mission",
  data() {
    return {
      recruitStatus,
      view: {},
      form: {},
      selectionList: [],
      query: { type: '' },
      loading: false,
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0,
      },
      checkDialog: false,
      finishDialog: false,
      viewDrawer: false,
      mStatusList: [
        { value: 1, label: "招聘中" },
        { value: 2, label: "任务中" },
        { value: 3, label: "已完成" },
        { value: 4, label: "已失效" },
        {
          label: "审核未通过",
          value: 9,
        },
      ],
      option: {
        height: "auto",
        tip: false,
        columnBtn: false,
        searchShow: true,
        searchMenuSpan: 5,
        menuWidth: 270,
        border: true,
        selection: false,
        viewBtn: false,
        addBtn: false,
        editBtn: false,
        delBtn: false,
        dialogClickModal: false,
        dialogType: "drawer",
        dialogFullscreen: true,
        mStatusList: recruitStatus,
        column: [
          {
            label: "社区街道名称",
            prop: "companyName",
            display: false,
          },
          {
            label: "岗位编码",
            prop: "missionNo",
            display: false,
          },
          {
            label: "岗位标题",
            prop: "jobName",
            display: false,
          },
          {
            label: "招聘人数",
            prop: "peopleNum",
            search: false,
            searchSpan: 1,
            display: false,
            minWidth: 70,
          },
          {
            label: "岗位时长",
            prop: "missionDuration",
            search: false,
            searchSpan: 5,
            display: false,
            minWidth: 70,
            hide: true,
          },
          {
            label: "",
            prop: "time",
            type: "date",
            hide: true,
            valueFormat: "yyyy-MM-dd",
          },
          {
            label: "岗位开始日期",
            prop: "stime",
            type: "date",
            display: false,
            minWidth: 100,
            format: "yyyy-MM-dd",
          },
          {
            label: "岗位结束日期",
            prop: "etime",
            type: "date",
            display: false,
            minWidth: 100,
            hide: true,
            format: "yyyy-MM-dd",
          },
          {
            label: "报名截止日期",
            prop: "etimePub",
            type: "date",
            search: false,
            searchSpan: 5,
            display: false,
            minWidth: 100,
            hide: true,
            format: "yyyy-MM-dd",
          },
          {
            label: "工资",
            prop: "wage",
            search: false,
            searchSpan: 5,
            display: false,
            width: 80,
          },
          {
            label: "工资单位",
            prop: "wageUnitCategory",
            search: false,
            dicData: wageUnitCategoryState,
            searchSpan: 5,
            display: false,
            hide: true,
          },
          {
            label: "审核状态",
            type: "reviewState",
            prop: "reviewState",
            dicData: recruitStatus,
            display: false,
            span: 24,
            width: 80,
          },
        ],
      },
      data: [],
      centerDialogVisible: false,
      AuditingData: null,
    };
  },
  computed: {
    ...mapGetters(["userInfo", "permission"]),
    permissionList() {
      return {
        viewBtn: this.vaildData(
          this.permission.manage_station_mainList_view,
          false
        ),
      };
    },
    ids() {
      let ids = [];
      this.selectionList.forEach((ele) => {
        ids.push(ele.id);
      });
      return ids;
    },
  },
  methods: {
    initData() {
      this.onLoad(this.page, this.query);
    },
    rowView(row) {
      getDetail({id: row.id, jobType: row.jobType}).then((resp) => {
        this.viewDrawer = true;
        this.view = resp.data.data;
      });
    },
    searchReset() {
      this.query = {};
      this.onLoad(this.page);
    },
    searchChange(params, done) {
      if (params.time) {
        params.stime = params.time[0];
        params.etime = params.time[1];
        delete params.time;
      }
      this.query = params;
      this.page.currentPage = 1;
      this.onLoad(this.page, params);
      done();
    },
    searchChange1() {
      if (this.query.time) {
        this.query.stime = this.query.time[0];
        this.query.etime = this.query.time[1];
       // delete this.query.time;
      }
      this.page.currentPage = 1;
      this.onLoad(this.page, this.query);
    },
    searchReset1() {
      this.query = {};
      this.onLoad(this.page);
    },
    selectionChange(list) {
      this.selectionList = list;
    },
    selectionClear() {
      this.selectionList = [];
      this.$refs.crud.toggleSelection();
    },
    beforeOpen(done, type) {
      if (["add", "edit"].includes(type)) {
        this.initData();
        done();
      }
      if (["edit", "view"].includes(type)) {
        this.loading = true;
      }
    },
    beforeClose(done) {
      done();
    },
    currentChange(currentPage) {
      this.page.currentPage = currentPage;
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
    },
    refreshChange() {
      this.onLoad(this.page, this.query);
    },
    onLoad(page, params = {}) {
      params = Object.assign(this.query, params);
      this.loading = true;
      getList(
        page.currentPage,
        page.pageSize,
        Object.assign(this.query, params)
      ).then((res) => {
        const data = res.data.data;
        this.page.total = data.total;
        this.data = data.records;
        this.loading = false;
        this.data.map((val) => {
          val.missionDuration =
            calcDate(
              new Date(val.stime).getTime(),
              new Date(val.etime).getTime()
            ).days + "天";
          val.payStatus =
            (val.payPersonTotal && val.payPersonTotal) > 0
              ? "已支付"
              : "未支付";
        });
      });
    },
    handleDelay(row) {
      this.$refs.delay.open(row.missionNo);
    },
    async handelAuditing(type) {
      const {id, reviewState, jobType} = this.AuditingData
      let resData = await review({id, reviewState: type, jobType})
      this.AuditingData = null
      this.centerDialogVisible = false
      if(resData.data.code === 200) {
        this.$message({
          type: "success",
          message: "审核成功!",
        });
      } else {
          message({
            type: "warning",
            message: "审核失败",
          });
      }
    },
    handleCheck(row) {
      this.centerDialogVisible = true
      this.AuditingData = row
    },
  },
};
</script>

<style>
  .el-form-item {
    margin-right: 18px !important;
  }
.searchBtn{
  display: inline-block;
}
</style>
