<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" @submit.native.prevent v-show="showSearch">
      <el-form-item label="关键字搜索" prop="title">
        <el-input v-model="queryParams.title" placeholder="请输入职位名称或发布企业" @keyup.enter.native="handleQuery" clearable />
      </el-form-item>
      <el-form-item label="工作类型" prop="type">
        <el-select v-model="queryParams.type" placeholder="请选择" class="se" clearable>
          <el-option value="0" label="全职"></el-option>
          <el-option value="1" label="兼职"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="审核状态" prop="audit">
        <el-select v-model="queryParams.audit" placeholder="状态" class="se" clearable>
          <el-option value="0" label="待审核"></el-option>
          <el-option value="1" label="审核通过"></el-option>
          <el-option value="2" label="审核不通过"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="发布日期">
        <el-date-picker v-model="dateRange" value-format="yyyy-MM-dd" type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-button type="danger" icon="el-icon-delete" :disabled="ids.length == 0" @click="del" v-hasPermi="['work:position:remove']">删除{{ ids.length > 0 ? '(' + ids.length + ')' : '' }}</el-button>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table :data="response.rows" border @selection-change="selects" height="calc(100vh - 270px)">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="职位名称" align="center" prop="title" width="150" />
      <el-table-column label="发布企业" align="center" prop="enterpriseName" width="270">
        <template slot-scope="scope">
          <div class="pon" @click="op('enterprise', scope.row)">{{ scope.row.enterpriseName }}</div>
        </template>
      </el-table-column>
      <el-table-column label="工作类型" align="center" prop="type">
        <template slot-scope="scope">
          <el-tag type="success" v-if="scope.row.type == 0">全职</el-tag>
          <el-tag type="warning" v-if="scope.row.type == 1">兼职</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="职位分类" align="center" prop="positionName" width="120" />
      <el-table-column label="经验要求" align="center" prop="experience" />
      <el-table-column label="薪资范围" align="center" prop="salary" />
      <el-table-column label="城市名称" align="center" prop="cityName" />
      <el-table-column label="地区名称" align="center" prop="regionName" />
      <el-table-column label="详细地址" align="center" prop="address" width="150">
        <template slot-scope="scope">
          <el-popover placement="top-start" title="详细地址" width="300" trigger="hover" :content="scope.row.address + '-' + scope.row.mph">
            <div slot="reference">
              <div class="omit">{{ scope.row.address }}-{{ scope.row.mph }}</div>
            </div>
          </el-popover>
        </template>
      </el-table-column>
      <el-table-column label="是否推荐" align="center" prop="recommend" width="80">
        <template slot-scope="scope">
          <el-tag type="info" v-if="scope.row.recommend == 0">否</el-tag>
          <el-tag type="success" v-if="scope.row.recommend == 1">是</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="职位状态" align="center" prop="state" width="80">
        <template slot-scope="scope">
          <el-tag type="success" v-if="scope.row.state == 0">启用</el-tag>
          <el-tag type="danger" v-if="scope.row.state == 1">关闭</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="职位审核" align="center" width="120">
        <template slot-scope="scope">
          <el-tag type="info" v-if="scope.row.audit == 0">待审核</el-tag>
          <el-tag type="success" v-if="scope.row.audit == 1">审核通过</el-tag>
          <el-popover placement="top-start" v-if="scope.row.audit == 2" title="拒绝原因" width="300" trigger="hover" :content="scope.row.msg">
            <div slot="reference">
              <el-tag type="info">审核不通过</el-tag>
              <i class="el-icon-warning"></i>
            </div>
          </el-popover>
        </template>
      </el-table-column>
      <el-table-column label="发布时间" align="center" prop="createTime" width="160" />
      <el-table-column label="操作" align="center" fixed="right" width="180">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-view" @click="op('detail', scope.row)">详情</el-button>
          <el-button size="mini" type="text" icon="el-icon-edit" @click="op('audit', scope.row)" v-hasPermi="['work:position:edit']" v-if="scope.row.audit == 0">审核</el-button>
          <el-button size="mini" type="text" icon="el-icon-sell" @click="op('recommend', scope.row)" v-hasPermi="['work:position:recommend']" v-if="scope.row.audit == 1">推荐</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="del(scope.row)" v-hasPermi="['work:position:remove']">删除</el-button>
        </template>
      </el-table-column>
      <template slot="empty">
        <el-empty></el-empty>
      </template>
    </el-table>
    <pagination v-if="response.total > 0" :total="response.total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
  </div>
</template>

<script>
import edit from './edit';
import recommend from './recommend';
import enterprise from '@/views/work/enterprise/edit.vue';
export default {
  name: 'Position',
  data() {
    return {
      ids: [],
      showSearch: true,
      response: {},
      dateRange: [],
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        type: null,
        title: null,
        audit: null,
        orderByColumn: 'id',
        isAsc: 'desc'
      }
    };
  },
  created() {
    if (this.$route.query.audit) {
      this.queryParams.audit = this.$route.query.audit;
    }
    this.getList();
  },
  methods: {
    getList() {
      if (this.dateRange) {
        this.queryParams.dateBegin = this.dateRange[0];
        this.queryParams.dateEnd = this.dateRange[1];
      }
      this.ajax({ url: '/work/position/list', data: this.queryParams }).then((response) => {
        this.response = response;
      });
    },
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    resetQuery() {
      this.resetForm('queryForm');
      this.queryParams.audit = null;
      this.dateRange = [];
      this.handleQuery();
    },
    selects(rows) {
      this.ids = rows.map((item) => item.id);
    },
    op(tag, row) {
      if (tag == 'enterprise') {
        this.iframe({ obj: enterprise, param: { id: row.userId, detail: true }, title: '企业详情', width: '50%', height: '65%' });
      }
      if (tag == 'recommend') {
        this.iframe({ obj: recommend, param: { id: row.id }, title: '设为推荐', width: '25%', height: '35%' });
      }
      if (tag == 'detail') {
        this.iframe({ obj: edit, param: { id: row.id, detail: true }, title: '职位详情', width: '45%', height: '70%' });
      }
      if (tag == 'audit') {
        const id = row.id || this.ids[0];
        this.iframe({ obj: edit, param: { id: id, audit: true }, title: '职位审核', width: '45%', height: '70%' });
      }
    },
    del(row) {
      this.$confirm('是否确认删除选中数据?', '警告', { type: 'warning' }).then(() => {
        this.get({ url: '/work/position/remove/' + (row.id || this.ids) }).then((response) => {
          this.$modal.msgSuccess('删除成功');
          this.getList();
        });
      });
    }
  }
};
</script>
