<template>
    <div>
      <el-breadcrumb separator=">">
        <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>
          <a href="#">基础信息管理</a>
        </el-breadcrumb-item>
        <el-breadcrumb-item>
          <a href="/base/enterpriseInfo-list">招聘信息管理</a>
        </el-breadcrumb-item>
      </el-breadcrumb>
      <el-divider></el-divider>
      <!--
        要resetFields起作用，必须配置:model和prop
      -->
      <el-form ref="queryForm" :model="queryModel" inline class="demo-form-inline">
        <el-form-item label="企业名称" prop="name">
          <el-input type="text" size="mini" v-model="queryModel.name"></el-input>
        </el-form-item>
        <el-form-item label="行业" prop="intendedIndustries">
          <el-select v-model="queryModel.intendedIndustries" size="mini" filterable placeholder="请选择" clearable>
            <el-option
                  v-for="result in intendedIndustriesList"
                  :key="result.id"
                  :label="result.name"
                  :value="result.value"
                ></el-option>
            </el-select>
        </el-form-item>
        <el-form-item label="职位名称" prop="positionName">
          <el-input type="text" size="mini" v-model="queryModel.positionName"></el-input>
        </el-form-item>
        <el-form-item label="结算方式" prop="method">
          <el-select v-model="queryModel.method" size="mini" filterable placeholder="请选择" clearable>
            <el-option
                  v-for="result in methodList"
                  :key="result.id"
                  :label="result.name"
                  :value="result.value"
                ></el-option>
            </el-select>
        </el-form-item>
        <el-form-item label="工作地区" prop="workArea">
          <el-input type="text" size="mini" v-model="queryModel.workArea"></el-input>
        </el-form-item>
        <el-form-item label="审核状态" prop="status">
          <el-select v-model="queryModel.status" size="mini" filterable placeholder="请选择" clearable>
            <el-option
                  v-for="result in statusList"
                  :key="result.id"
                  :label="result.name"
                  :value="result.value"
                ></el-option>
            </el-select>
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            size="mini"
            icon="ios-search"
            @click="changePage(1)"
            :loading="loading"
          >查询</el-button>&nbsp;
          <el-button
            type="info"
            size="mini"
            style="margin-left: 8px"
            @click="handleReset('queryForm')"
          >重置</el-button>&nbsp;
        </el-form-item>
      </el-form>
      <el-divider></el-divider>
      <el-row class="button-group">
        <el-button type="primary" size="small" plain icon="el-icon-circle-plus" @click="handleAdd">新增</el-button>
        <el-button
          type="primary"
          size="small"
          plain
          icon="el-icon-remove"
          :disabled="multipleSelection.length==0"
          @click="handleBatchDelete"
        >删除选中项</el-button>
      </el-row>
      <el-table
        :data="tableData"
        style="min-height:400px;"
        v-loading="loading"
        stripe
        @sort-change="sortChange"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="55"></el-table-column>
        <el-table-column  prop="enterpriseName"  label="企业名称">
            <template slot-scope="{row}">
                <span>{{row.enterpriseName}}</span>
          </template>
        </el-table-column>
        <el-table-column  prop="industryN"  label="行业"></el-table-column>
        <el-table-column  prop="positionName"  label="职位名称"></el-table-column>
        <el-table-column  prop="salary"  label="薪资待遇"></el-table-column>
        <el-table-column  prop="settlementMethodN"  label="结算方式"></el-table-column>
        <el-table-column  prop="recruitingNumbers"  label="招聘人数"></el-table-column>
        <el-table-column  prop="contacts"  label="联系人"></el-table-column>
        <el-table-column  prop="contactsPhone"  label="联系电话" width="120"></el-table-column>
        <el-table-column  prop="workArea"  label="工作地区"></el-table-column>
        <el-table-column  prop="address"  label="详细地址"></el-table-column>
        <el-table-column  prop="browseNumber"  label="浏览次数"></el-table-column>
        <el-table-column  prop="status"  label="审核状态">
          <template slot-scope="{row}">
            <span v-if="row.status=='0'" style="color: #F56C6C;">未审核</span>
            <span v-else-if="row.status=='1'" style="color: #67C23A;">已审核</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="300">
          <template slot-scope="{row}">
            <el-button size="mini" type="warning" @click="handleEdit(row)">编辑</el-button>
            <el-button v-if="row.status=='0'" size="mini" type="primary" @click="handleCheck(row)">审核</el-button>
            <el-button size="mini" type="success" @click="handleRelation(row)">收到报名</el-button>
            <el-button size="mini" type="danger" @click="handleDelete(row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        :current-page.sync="pageIndex"
        :total="totalElements"
        :page-sizes="pageSizeList"
        @current-change="changePage"
        @size-change="pageSizeChange"
        layout="total, sizes, prev, pager, next, jumper"
      ></el-pagination>
      <enterpriseInfo-detail
        v-if="showModal"
        ref="userDetail"
        :businessKey="businessKey"
        :title="modalTitle"
        @close="onDetailModalClose"
      ></enterpriseInfo-detail>
      <recruitPersonRelation-list
        v-if="showModal2"
        :businessKey="businessKey"
        :title="modalTitle2"
        @close="onDetailModalClose2"
      ></recruitPersonRelation-list>
      <recruitInformationInfo-detail
        v-if="showModal3"
        :businessKey="businessKey"
        :title="modalTitle3"
        @close="onDetailModalClose3"
      ></recruitInformationInfo-detail>
    </div>
  </template>
  <script>
  import recruitInformationInfoApi from "@/api/base/recruitInformationInfo";
  import enterpriseInfoDetail from "./enterpriseInfo-detail";
  import recruitPersonRelationList from "./recruitPersonRelation-list";
  import recruitInformationInfoDetail from "./recruitInformationInfo-detail";
  import dataDictionaryApi from "@/api/sys/dataDictionary";
  
  export default {
    name: 'baseRecruitInformationInfoList',
    data() {
      var self = this;
  
      return {
        queryModel: {
          name: "",
          positionName:"",
          intendedIndustries:"",
          method:"",
          status:"",
          workArea:"",
        },
        loading: false,
        tableData: [],
        pageIndex: 1,
        pageSize: 10,
        totalPages: 0,
        totalElements: 0,
        field: "",
        direction: "",
        pageSizeList: [10, 20, 30],
        multipleSelection: [],
        modalTitle: "",
        modalTitle2: "",   
        modalTitle3: "",      
        businessKey: "",
        showModal: false,
        showModal2:false,
        showModal3:false,
        dialogFormVisible:false,
        newPassword:"",
        intendedIndustriesList:[],
        methodList:[],
        statusList:[
          {
            "id":"0",
            "name":"未审核",
            "value":"0"
          },
          {
            "id":"1",
            "name":"已审核",
            "value":"1"
          }
        ],
        props: {
          // 配置项（必选）
          value: "id",
          label: "name",
          children: "children"
        },
      };
    },
    created() {
        dataDictionaryApi.findByCatalogName({catalogName: "意向行业",})
        .then((response) => {
            var jsonData = response.data;
            this.intendedIndustriesList = jsonData.data;
        });

        dataDictionaryApi.findByCatalogName({catalogName: "结算方式",})
        .then((response) => {
            var jsonData = response.data;
            this.methodList = jsonData.data;
        });
    },
    methods: {
      changePage(pageIndex) {
        var self = this;
  
        console.log(pageIndex);
  
        self.pageIndex = pageIndex;
        var formData = new FormData();
  
        formData.append("pageIndex", self.pageIndex);
        formData.append("pageSize", self.pageSize);
  
        formData.append("name", self.queryModel.name);
        formData.append("positionName", self.queryModel.positionName);
        formData.append("intendedIndustries", self.queryModel.intendedIndustries);
        formData.append("method", self.queryModel.method);
        formData.append("status", self.queryModel.status);
        formData.append("workArea", self.queryModel.workArea);
        
  
        self.loading = true;
  
        recruitInformationInfoApi.pageList(formData).then(function(response) {
          self.loading = false;
  
          var jsonData = response.data;
  
          if(jsonData.result){
            var pageInfo = jsonData.data;
  
            self.tableData = pageInfo.data;
            self.totalPages = pageInfo.totalPages;
            self.totalElements = pageInfo.recordsTotal;
          }
          else {
            self.$message({
                message: jsonData.message + "",
                type: "warning"
              });
          }
        }).catch((error)=>{
          self.loading = false;
        });
      },
      pageSizeChange(pageSize) {
        this.pageSize = pageSize;
      },
      sortChange(data) {
        this.field = data.column.field;
        this.direction = data.order == "ascending" ? "asc" : "desc";
  
        this.changePage(this.pageIndex);
      },
      handleSelectionChange(val) {
        this.multipleSelection = val;
      },
      handleReset(name) {
        this.$refs[name].resetFields();
      },
      handleAdd() {
        var self = this;
        
        self.modalTitle3 = "新增招聘信息";
        self.businessKey = "";
        self.showModal3 = true;
      },
      handleEdit(record) {
        var self = this;
        
        self.modalTitle3 = "编辑招聘信息";
        self.businessKey = record.id;
        self.showModal3 = true;
      },
      handleRelation(record) {
        var self = this;
        self.modalTitle2 = "收到报名列表";
        self.businessKey = record.id;
        self.showModal2 = true;
      },
      handleCheck(record){
        var self = this;
  
        this.$confirm("是否确认审核？", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
            recruitInformationInfoApi.check(record.id).then(function(response) {
            var jsonData = response.data;

            if (jsonData.result) {
              // var index = self.tableData.indexOf(record);
              // self.tableData.splice(index, 1);
              self.changePage(self.pageIndex);

              self.$message({
                type: "success",
                message: "审核成功!"
              });
            }
          });
        });
      },
      handleDelete(record) {
        var self = this;
  
        this.$confirm("是否确认删除？", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
            recruitInformationInfoApi.remove(record.id).then(function(response) {
            var jsonData = response.data;
  
            if (jsonData.result) {
              // var index = self.tableData.indexOf(record);
              // self.tableData.splice(index, 1);
              self.changePage(self.pageIndex);
  
              self.$message({
                type: "success",
                message: "删除成功!"
              });
            }
          });
        });
      },
      handleBatchDelete() {
        var self = this;
  
        var idList = this.multipleSelection.map(record => {
          return record.id;
        });
  
        this.$confirm("是否确认删除选中项？", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
            recruitInformationInfoApi.batchRemove(idList).then(function(response) {
            var jsonData = response.data;
  
            if (jsonData.result) {
              self.changePage(self.pageIndex);
  
              self.$message({
                type: "success",
                message: "删除成功!"
              });
            }
          });
        });
      },
      onDetailModalClose(refreshed) {
        this.showModal = false;
  
        if(refreshed) {
          this.changePage(this.pageIndex);
        }
      },
      onDetailModalClose2(refreshed) {
        this.showModal2 = false;
  
        if(refreshed) {
          this.changePage(this.pageIndex);
        }
      },
      onDetailModalClose3(refreshed) {
        this.showModal3 = false;
  
        if(refreshed) {
          this.changePage(this.pageIndex);
        }
      },
    },
    mounted: function() {
      var self = this;
      this.changePage(1);
    },
    components: {
      "enterpriseInfo-detail":enterpriseInfoDetail,
      "recruitPersonRelation-list":recruitPersonRelationList,
      "recruitInformationInfo-detail":recruitInformationInfoDetail
    }
  };
  </script>
  <style lang="scss" scoped>
  .el-breadcrumb {
    margin: 10px;
    line-height: 20px;
  }
  
  .el-divider {
    margin: 5px 0;
  }
  
  .demo-form-inline {
    margin-left: 10px;
    text-align: left;
  }
  
  .button-group {
    padding: 10px;
    text-align: left;
  }
  </style>