<template>
  <div id="recruitmentManagement">
    <search-box :formList="formList" @search="search" @init="init" />
    <table-list
      :tableSets="tableSet"
      :tableData="tableData"
      :navText="navText"
      @addClick="addClick"
      :loading="loading"
    >
      <template slot="btn" slot-scope="props">
        <el-button type="text" @click="addClick(props.scope.row, 2)"
          >详情</el-button
        >
        <el-button
          type="text"
          @click="
            props.scope.row.status === 1
              ? fbStatus(props.scope.row)
              : stopStatus(props.scope.row)
          "
          v-if="props.scope.row.status === 1 || props.scope.row.status === 2"
          >{{ props.scope.row.status === 1 ? "发布" : "停止" }}</el-button
        >
        <el-button
          type="text"
          @click="addClick(props.scope.row, 0)"
          v-if="props.scope.row.status === 1"
          >修改</el-button
        >
        <el-button
          type="text"
          @click="del(props.scope.row)"
          v-if="props.scope.row.status === 1"
          >删除</el-button
        >
      </template>
    </table-list>
    <pagination
      :total="total"
      :pageSize="pageSize"
      :currentPage="currentPage"
      @handleSizeChange="handleSizeChange"
      @handleCurrentChange="handleCurrentChange"
    />
    <el-dialog
      :visible.sync="dialogVisible"
      width="600px"
      :show-close="false"
      :before-close="close"
    >
      <div slot="title" class="hearders">
        <div class="leftTitle">
          {{ statusPop === 1 ? "添加" : statusPop === 0 ? "修改" : "详情" }}
        </div>
        <div class="rightBoxs">
          <img src="@/assets/images/Close@2x.png" alt="" @click="close" />
        </div>
      </div>
      <div>
        <el-form
          label-position="right"
          label-width="120px"
          :model="listData"
          :rules="rules"
          ref="listData"
        >
          <el-form-item
            v-for="(items, indexs) in listitem"
            :key="indexs"
            :label="items.label"
            :prop="items.prop"
          >
            <el-radio-group
              v-if="items.scope === 'radio'"
              v-model="listData[items.prop]"
            >
              <el-radio
                v-for="(item, index) in items.options"
                :key="index"
                :label="item.value"
                :disabled="statusPop === 2"
                >{{ item.label }}</el-radio
              >
            </el-radio-group>
            <!-- <el-input
              :disabled="statusPop === 2"
              v-else-if="items.scope === 'textarea'"
              type="textarea"
              v-model="listData[items.prop]"
            ></el-input> -->
            <editor
                v-else-if="items.scope === 'textarea'"
                :disabled="statusPop === 2"
                v-model="listData[items.prop]"
                :min-height="100"
                :max-height="300"
                :uploadStatus="uploadStatus"
              />
            <el-select
              :placeholder="items.placeholder"
              :disabled="statusPop === 2"
              v-else-if="items.scope === 'jobStatus'"
              v-model="listData[items.prop]"
              filterable
              allow-create
              clearable
              @clear="clearForm"
              @change="changeJob"
            >
              <el-option
                v-for="(item, index) in items.options"
                :key="index"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
            <el-select
              :placeholder="items.placeholder"
              :disabled="statusPop === 2"
              v-else-if="items.scope === 'select'"
              v-model="listData[items.prop]"
            >
              <el-option
                v-for="(item, index) in items.options"
                :key="index"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
            <div v-else-if="items.scope === 'zmPeople'">
              <el-radio-group v-model="listData[items.prop]">
                <el-radio
                  v-for="(item, index) in items.options"
                  :key="index"
                  :label="item.value"
                  :disabled="statusPop === 2"
                  >{{ item.label }}</el-radio
                >
              </el-radio-group>
              <el-input-number
                size="mini"
                v-if="listData[items.prop] === 1"
                v-model="listData[items.prop1]"
                :disabled="statusPop === 2"
                controls-position="right"
                :min="1"
                :max="9999"
              ></el-input-number>
            </div>
            <div v-else-if="items.scope === 'checkboxs'">
              <el-checkbox-group v-model="listData[items.prop]">
                <el-checkbox
                  label="全职"
                  :disabled="statusPop === 2"
                ></el-checkbox>
                <el-checkbox
                  label="兼职"
                  :disabled="statusPop === 2"
                ></el-checkbox>
                <el-checkbox
                  label="实习生"
                  :disabled="statusPop === 2"
                ></el-checkbox>
              </el-checkbox-group>
            </div>
            <div v-else-if="items.scope === 'address'">
              <v-distpicker
                :disabled="statusPop === 2"
                @province="changeProvince"
                @city="changeCity"
                @area="changeArea"
                :province="listData[items.prop1]"
                :city="listData[items.prop2]"
                :area="listData[items.prop3]"
              ></v-distpicker>
            </div>
            <div v-else-if="items.scope === 'moreInputs'">
              <el-select
                v-model="listData[items.prop]"
                placeholder="请选择"
                style="margin-right: 10px"
                :disabled="statusPop === 2"
              >
                <el-option
                  v-for="(item, index) in items.options"
                  :key="index"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
              <el-input
                style="width: 90px"
                :disabled="statusPop === 2"
                v-model="listData[items.prop2]"
              ></el-input>
              ~
              <el-input
                style="width: 90px"
                :disabled="statusPop === 2"
                v-model="listData[items.prop3]"
              ></el-input>
              元
            </div>
            <div v-else-if="items.scope === 'selectF'">
              <ul class="ulList">
                <li
                  v-for="(item, index) in listData[items.prop]"
                  :key="index"
                  :class="statusPop !== 2 ? 'mar_r' : ''"
                >
                  {{ item }}
                  <i
                    class="el-icon-error clears"
                    @click="clickf(index)"
                    v-if="statusPop !== 2"
                  ></i>
                </li>
                <el-popover placement="top" width="240" v-model="visibleF">
                  <p style="text-align: center; margin-bottom: 6px">加分证书</p>
                  <el-cascader
                    style="width: 100%"
                    v-model="zsmsg"
                    :options="optionsTion"
                    :size="'medium'"
                    clearable
                    :disabled="statusPop === 2"
                    :props="{
                      label: 'categoryName',
                      value: 'categoryName',
                      checkStrictly: true,
                      emitPath: false,
                    }"
                  ></el-cascader>
                  <!-- <el-input
                    size="mini"
                    style="margin-bottom: 6px"
                    v-model="zsmsg"
                  ></el-input> -->
                  <div style="text-align: center; margin-top: 10px">
                    <el-button size="mini" type="text" @click="zsmsg = ''"
                      >重置</el-button
                    >
                    <el-button type="primary" size="mini" @click="addflLists(1)"
                      >确定</el-button
                    >
                  </div>
                  <el-button slot="reference" size="mini" v-if="statusPop !== 2"
                    >新增</el-button
                  >
                </el-popover>
                <div style="clear: both"></div>
              </ul>
            </div>
            <div v-else-if="items.scope === 'selectS'">
              <ul class="ulList">
                <li
                  v-for="(item, index) in listData[items.prop]"
                  :key="index"
                  :class="statusPop !== 2 ? 'mar_r' : ''"
                >
                  {{ item }}
                  <i
                    class="el-icon-error clears"
                    @click="clicks(index)"
                    v-if="statusPop !== 2"
                  ></i>
                </li>
                <el-popover placement="top" width="160" v-model="visible">
                  <p style="text-align: center; margin-bottom: 6px">福利标签</p>
                  <el-input
                    size="mini"
                    style="margin-bottom: 6px"
                    v-model="flmsg"
                  ></el-input>
                  <div style="text-align: right; margin: 0">
                    <el-button size="mini" type="text" @click="flmsg = ''"
                      >重置</el-button
                    >
                    <el-button type="primary" size="mini" @click="addflLists(2)"
                      >确定</el-button
                    >
                  </div>
                  <el-button slot="reference" size="mini" v-if="statusPop !== 2"
                    >新增</el-button
                  >
                </el-popover>
                <div style="clear: both"></div>
              </ul>
            </div>
            <el-input
              :disabled="statusPop === 2"
              v-else
              v-model="listData[items.prop]"
            ></el-input>
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="close">取 消</el-button>
        <el-button
          type="primary"
          v-if="statusPop !== 2"
          @click="submit('listData')"
          >确 定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>

<script>
import searchBox from "@/components/searchBox";
import VDistpicker from "v-distpicker";
import tableList from "@/components/tableList";
import Editor from "@/components/Editor";
import pagination from "@/components/pagination";
export default {
  components: { searchBox, tableList, pagination, VDistpicker ,Editor},
  data() {
    return {
      uploadStatus: 2, //富文本组件传值
      visible: false,
      visibleF: false,
      flmsg: "",
      zsmsg: "",
      loading: false, //当前表单加载是否加载动画
      navText: {
        title: "招聘管理",
        index: 0,
        ch: "条",
        num: true,
        choice: false,
        addHide: false,
        backFatherBtn: {
          status: false,
          title: "未定义",
        },
      },
      //搜索
      formList: [
        {
          label: "招聘岗位",
          prop: "job",
          placeholder: "请输入招聘岗位",
        },
        {
          label: "状态",
          prop: "status",
          placeholder: "请选择状态",
          scope: "select",
          options: [
            {
              label: "已发布",
              value: 2,
            },
            {
              label: "未发布",
              value: 1,
            },
            {
              label: "停用",
              value: 0,
            },
          ],
        },
        {
          label: "发布时间",
          prop: "finishTime",
          scope: "datePicker",
        },
        {
          label: "公司名称",
          prop: "companyName",
          placeholder: "请输入公司名称",
        },
      ],
      // 表单
      tableSet: [
        {
          label: "公司名称",
          prop: "companyName",
          hidden: true,
        },
        {
          label: "岗位名称",
          prop: "job",
          hidden: true,
        },
        {
          label: "工作性质",
          prop: "jobNature",
          hidden: true,
        },
        {
          label: "薪资",
          prop1: "incomeType",
          prop2: "incomeStart",
          prop3: "incomeEnd",
          hidden: true,
          scope: "Salary",
          width: "200px",
        },
        {
          label: "福利",
          prop: "welfare",
          hidden: true,
        },
        {
          label: "加分证书",
          prop: "bonusCertificate",
          hidden: true,
        },
        {
          label: "工作地址",
          prop1: "province",
          prop2: "city",
          prop3: "district",
          prop4: "address",
          hidden: true,
          width: "280px",
          scope: "address",
        },
        {
          label: "最低学历",
          prop: "minimumEduLabel",
          hidden: true,
        },
        {
          label: "工作年限",
          prop: "workingYearsLabel",
          hidden: true,
        },
        {
          label: "招聘人数",
          prop: "peopleNum",
          hidden: true,
          scope: "peopleNum",
        },
        // {
        //   label: "应聘人数",
        //   prop: "workingYearsLabel",
        //   hidden: true,
        // },
        {
          label: "联系人",
          prop: "linkMan",
          hidden: true,
        },
        {
          label: "联系电话",
          prop: "linkTel",
          hidden: true,
        },
        {
          label: "专业",
          prop: "major",
          hidden: true,
        },
        {
          label: "是否加急",
          prop: "isUrgent",
          hidden: true,
          scope: "isUrgent",
        },
        // {
        //   label: "发布时间",
        //   prop: "createTime",
        //   hidden: true,
        // },
        {
          label: "状态",
          prop: "status",
          hidden: true,
          scope: "statusZpFB",
        },
      ],
      optionsTion: [],
      tableData: [], //表单数据
      total: 0, //一共多少条
      pageSize: 10, //每页多少条数据
      currentPage: 1, //当前页码
      // 弹窗字段
      listitem: [
        {
          label: "公司名称",
          prop: "companyId",
          scope: "select",
          options: [],
          placeholder: "请输入公司名称",
        },
        {
          label: "岗位",
          prop: "job",
          placeholder: "请选择岗位",
          scope: "jobStatus",
        },
        {
          label: "工作城市",
          prop1: "province",
          prop2: "city",
          prop3: "district",
          scope: "address",
        },
        {
          label: "详细地址",
          prop: "address",
          placeholder: "请输入详细地址",
        },
        {
          label: "招聘人数",
          prop: "peopleType",
          prop1: "peopleNum",
          scope: "zmPeople",
          options: [
            {
              label: "不限",
              value: 0,
            },
            {
              label: "有限",
              value: 1,
            },
          ],
        },
        {
          label: "工作性质",
          prop: "jobNature",
          scope: "checkboxs",
        },
        {
          label: "岗位薪资",
          prop: "incomeType",
          prop2: "incomeStart",
          prop3: "incomeEnd",
          scope: "moreInputs",
          options: [
            {
              label: "月薪",
              value: 1,
            },
            {
              label: "年薪",
              value: 2,
            },
          ],
        },
        {
          label: "工作职责",
          prop: "duty",
          scope: "textarea",
        },
        {
          label: "任职要求",
          prop: "requirement",
          scope: "textarea",
        },
        {
          label: "加分证书",
          prop: "bonusCertificate",
          scope: "selectF",
        },
        {
          label: "福利",
          prop: "welfare",
          scope: "selectS",
        },
        {
          label: "岗位关键词",
          prop: "jobKey",
        },
        {
          label: "工作年限",
          prop: "workingYearsDict",
          scope: "select",
          options: [],
        },
        {
          label: "最低学历要求",
          prop: "minimumEduDict",
          scope: "select",
          options: [],
        },
        {
          label: "联系人",
          prop: "linkMan",
        },
        {
          label: "联系人电话",
          prop: "linkTel",
        },
        {
          label: "专业",
          prop: "major",
        },
        {
          label: "是否加急",
          prop: "isUrgent",
          scope: "radio",
          options: [
            {
              label: "是",
              value: 1,
            },
            {
              label: "不是",
              value: 0,
            },
          ],
        },
        {
          label: "状态",
          prop: "status",
          scope: "radio",
          options: [
            {
              label: "启用",
              value: 1,
            },
            {
              label: "停用",
              value: 0,
            },
          ],
        },
      ],
      //   弹窗数据
      listData: {
        jobNature: [],
      },
      psCity: {
        province: "",
        city: "",
        district: "",
      },
      statusPop: -1,
      dialogVisible: false,
      zpmb: [],
      //表单验证
      rules: {
        companyId: [
          { required: true, message: "请选择公司名称", trigger: "change" },
        ],
        linkMan: [{ required: true, message: "请输入联系人", trigger: "blur" }],
        address: [
          { required: true, message: "请输入详细地址", trigger: "blur" },
        ],
        linkTel: [
          { required: true, message: "请输入联系电话", trigger: "blur" },
        ],
        incomeType: [
          { required: true, message: "请选择薪资类型", trigger: "change" },
        ],
        welfare: [
          { required: true, message: "请新增福利标签", trigger: "change" },
        ],
        status: [{ required: true, message: "请选择状态", trigger: "change" }],
        isUrgent: [
          { required: true, message: "请选择是否加急", trigger: "change" },
        ],
        job: [{ required: true, message: "请输入岗位名称", trigger: "change" }],
        major: [{ required: true, message: "请输入专业", trigger: "blur" }],
        duty: [{ required: true, message: "请输入工作职责", trigger: "blur" }],
        requirement: [
          { required: true, message: "请输入任职要求", trigger: "blur" },
        ],
        workingYearsDict: [
          { required: true, message: "请选择工作年限", trigger: "change" },
        ],
        minimumEduDict: [
          { required: true, message: "请选择最低学历", trigger: "change" },
        ],
        peopleType: [
          { required: true, message: "请选择招聘人数类型", trigger: "change" },
        ],
        jobNature: [
          { required: true, message: "请选择工作性质", trigger: "change" },
        ],
      },
    };
  },
  created() {
    this.getDict();
  },
  mounted() {
    this.search();
    this.initCascader();
    // this.stopStatusssss()
  },
  methods: {
    changeJob(v) {
      var self = this;
      this.zpmb.forEach((item, index) => {
        if (item.job == v) {
          self.$set(self.listData, "incomeType", item.incomeType);
          self.$set(self.listData, "incomeStart", item.incomeStart);
          self.$set(self.listData, "incomeEnd", item.incomeEnd);
          self.$set(self.listData, "duty", item.duty);
          self.$set(self.listData, "requirement", item.requirement);
          self.$set(self.listData, "welfare", item.welfare.split(","));
          self.$set(self.listData, "jobKey", item.jobKey);
          self.$set(
            self.listData,
            "workingYearsDict",
            Number(item.workingYearsDict)
          );
          self.$set(
            self.listData,
            "minimumEduDict",
            Number(item.minimumEduDict)
          );
          self.$set(self.listData, "major", item.major);
          self.checkForms("listData");
        }
      });
    },
    clearForm(v) {
      return false;
    },
    clicks(v) {
      this.listData.welfare.splice(v, 1);
    },
    clickf(v) {
      this.listData.bonusCertificate.splice(v, 1);
    },
    fbStatus(v) {
      var self = this;
      var datas = {
        id: v.id,
        status: 2,
      };
      self.$api.editrecruitneeds(datas).then((res) => {
        if (res.code === 200) {
          self.$message.success("发布成功");
          self.search();
        }
      });
    },
    stopStatus(v) {
      var self = this;
      var datas = {
        id: v.id,
        status: 0,
      };
      self.$api.editrecruitneeds(datas).then((res) => {
        if (res.code === 200) {
          self.$message.success("停止成功");
          self.search();
        }
      });
    },
    stopStatusssss() {
      var self = this;
      var datas = {
        id: 1,
        status: 1,
      };
      self.$api.editrecruitneeds(datas).then((res) => {
        if (res.code === 200) {
          self.$message.success("停止成功");
          self.search();
        }
      });
    },
    addflLists(v) {
      var self = this;
      this.flmsg = this.flmsg.replace(/^\s*|\s*$/g, "");
      this.zsmsg = this.zsmsg.replace(/^\s*|\s*$/g, "");
      if (v === 1) {
        console.log(self.zsmsg, 9898);
        if (!self.zsmsg.length) {
          self.$message.error("请输入加分证书");
          return;
        } else {
          if (self.listData.bonusCertificate.indexOf(self.zsmsg) === -1) {
            self.listData.bonusCertificate.push(self.zsmsg);
            self.zsmsg = "";
            self.visibleF = false;
          } else {
            self.$message.error("当前证书已存在列表");
            return;
          }
        }
      }
      if (v === 2) {
        if (!self.flmsg.length) {
          self.$message.error("请输入福利标签");
          return;
        } else {
          self.listData.welfare.push(self.flmsg);
          self.flmsg = "";
          self.visible = false;
        }
      }
    },
    changeProvince(v) {
      this.psCity.province = v.value;
      this.psCity.city = "";
      this.psCity.district = "";
    },
    changeCity(v) {
      this.psCity.city = v.value;
      this.psCity.district = "";
    },
    changeArea(v) {
      this.psCity.district = v.value;
    },
    getDict() {
      var arays = []; //学历
      var newArrays = []; //学历转换

      var workYears = []; //工作年限
      var workYearsArrays = []; //工作年限转换

      var companys = []; //公司名称
      var companysArrays = [
        {
          label: this.$store.state.userInfo[0].tenant.tenantName,
          value: 0,
        },
      ]; //公司名称转换
      this.$api.recruitcompanyConlist().then((res) => {
        res.rows.forEach((item, index) => {
          let arrayList = {
            label: item.companyName,
            value: item.companyId,
          };
          companysArrays.push(arrayList);
        });
      });
      var zpmb = []; //招聘模板
      var zpmbArrays = [];

      this.$store.state.UserDict.forEach((item, index) => {
        if (item.dictType == "edu_level") {
          arays.push(item);
        }
        if (item.dictType == "working_years") {
          workYears.push(item);
        }
      });
      arays.forEach((item, index) => {
        let arrayList = {
          label: item.dictLabel,
          value: item.dictCode,
        };
        newArrays.push(arrayList);
      });
      workYears.forEach((item, index) => {
        let arrayList = {
          label: item.dictLabel,
          value: item.dictCode,
        };
        workYearsArrays.push(arrayList);
      });
      this.$api.recruittemplatelist().then((res) => {
        this.zpmb = res.rows;
        res.rows.forEach((item, index) => {
          let arrayList = {
            label: item.job,
            value: item.job,
          };
          zpmbArrays.push(arrayList);
        });
      });
      for (let i = 0; i < this.listitem.length; i++) {
        if (this.listitem[i].label === "最低学历要求") {
          this.listitem[i].options = newArrays;
        }
        if (this.listitem[i].label === "工作年限") {
          this.listitem[i].options = workYearsArrays;
        }
        if (this.listitem[i].label === "公司名称") {
          this.listitem[i].options = companysArrays;
        }
        if (this.listitem[i].label === "岗位") {
          this.listitem[i].options = zpmbArrays;
        }
      }
    },
    search(v) {
      console.log(v);
      this.loading = true;
      if (v === undefined) {
        v = {
          pageSize: this.pageSize,
          pageNum: this.currentPage,
        };
      }
      var data = {
        pushTimeStart: v.finishTime ? (v.finishTime[0] / 1000).toFixed(0) : "",
        pushTimeEnd: v.finishTime ? (v.finishTime[1] / 1000).toFixed(0) : "",
        companyName: v.companyName,
        job: v.job,
        status: v.status === undefined ? "0,1,2" : v.status,
        pageSize: this.pageSize,
        pageNum: this.currentPage,
      };
      this.$api.recruitneedslist(data).then((res) => {
        this.tableData = res.rows;
        this.total = res.total;
        this.navText.index = res.total;
      });
      this.loading = false;
    },
    init() {
      this.search();
    },
    del(v) {
      var self = this;
      this.$confirm("此操作将删除该招聘信息, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          var datas = {
            id: v.id,
            status: -1,
          };
          self.$api.editrecruitneeds(datas).then((res) => {
            if (res.code === 200) {
              self.$message.success("删除成功");
              self.search();
            }
          });
        })
        .catch(() => {});
    },
    addClick(v, int) {
      var self = this;
      if (v === undefined) {
        this.statusPop = 1;
        this.listData = {
          jobNature: [],
          welfare: [],
          bonusCertificate: [],
        };
      } else {
        this.statusPop = int;
        this.$api.recruitneedsid(v.id).then((res) => {
          res.data.minimumEduDict = Number(res.data.minimumEduDict);
          res.data.workingYearsDict = Number(res.data.workingYearsDict);
          res.data.welfare = res.data.welfare.split(",");
          res.data.bonusCertificate = res.data.bonusCertificate.split(",");
          res.data.jobNature = res.data.jobNature.split(",");
          self.listData = res.data;
          if (res.data.peopleNum === 0) {
            self.$set(self.listData, "peopleType", 0);
          } else {
            self.$set(self.listData, "peopleType", 1);
          }
          self.$set(self.psCity, "province", res.data.province);
          self.$set(self.psCity, "city", res.data.city);
          self.$set(self.psCity, "district", res.data.district);
          console.log(self.psCity);
        });
      }
      this.dialogVisible = true;
    },
    checkForms(formName) {
      var self = this;
      this.$refs[formName].validate((valid) => {
        if (valid) {
          return true;
        } else {
          return false;
        }
      });
    },
    submit(formName) {
      var self = this;
      this.$refs[formName].validate((valid) => {
        if (valid) {
          var tests = /(^[1-9]\d*(\.\d{1,2})?$)|(^0(\.\d{1,2})?$)/;
          if (!tests.test(self.listData.incomeStart)) {
            self.$message.error("请输入正确薪资价格");
            return;
          }
          if (!tests.test(self.listData.incomeEnd)) {
            self.$message.error("请输入正确薪资价格");
            return;
          }
          if (
            Number(self.listData.incomeStart) > Number(self.listData.incomeEnd)
          ) {
            self.$message.error("请输入正确薪资范围格式");
            return;
          }
          if (self.psCity.province === "" || self.psCity.province === "省") {
            self.$message.error("请选择省份");
            return;
          }
          if (self.psCity.city === "" || self.psCity.city === "市") {
            self.$message.error("请选择城市");
            return;
          }
          if (self.psCity.district === "" || self.psCity.district === "区") {
            self.$message.error("请选择区域");
            return;
          }
          this.rulesTableSumbit();
        } else {
          return false;
        }
      });
    },
    rulesTableSumbit() {
      var self = this;
      var dataLists = JSON.parse(JSON.stringify(this.listData));
      if (dataLists.peopleType === 0) {
        dataLists.peopleNum = 0;
      } else {
        if (dataLists.peopleNum >= 1) {
        } else {
          self.$message.error("请输入招聘人数");
          return;
        }
      }

      dataLists.province = self.psCity.province;
      dataLists.city = self.psCity.city;
      dataLists.district = self.psCity.district;
      switch (dataLists.workingYearsDict) {
        case "0":
          dataLists.workingYearsStart = 0;
          dataLists.workingYearsEnd = 0;
          break;
        case "1":
          dataLists.workingYearsStart = 0;
          dataLists.workingYearsEnd = 1;
          break;
        case "2":
          dataLists.workingYearsStart = 1;
          dataLists.workingYearsEnd = 3;
          break;
        case "3":
          dataLists.workingYearsStart = 3;
          dataLists.workingYearsEnd = 5;
          break;
        case "4":
          dataLists.workingYearsStart = 5;
          dataLists.workingYearsEnd = 10;
          break;
        case "5":
          dataLists.workingYearsStart = 10;
          dataLists.workingYearsEnd = 0;
          break;
        default:
          break;
      }
      if (dataLists.welfare.length) {
        dataLists.welfare = dataLists.welfare.toString();
      }
      if (dataLists.bonusCertificate.length) {
        dataLists.bonusCertificate = dataLists.bonusCertificate.toString();
      }
      if (dataLists.jobNature.length) {
        dataLists.jobNature = dataLists.jobNature.toString();
      }

      if (this.statusPop === 1) {
        this.$api.addrecruitneeds(dataLists).then((res) => {
          if (res.code === 200) {
            this.$message.success("新增成功");
            this.dialogVisible = false;
            this.search();
          }
        });
      }
      if (this.statusPop === 0) {
        this.$api.editrecruitneeds(dataLists).then((res) => {
          if (res.code === 200) {
            this.$message.success("修改成功");
            this.dialogVisible = false;
            this.search();
          }
        });
      }
      this.$refs["listData"].resetFields();
    },
    //级联选择器数据
    initCascader() {
      this.$api
        .inquireProfessionClassification()
        .then((res) => {
          this.arrayChangeType(res.rows);
        })
        .catch((err) => {
          console.log(err);
        });
    },
    // 接口数据转换级联类型
    arrayChangeType(options) {
      let result = [];
      if (!Array.isArray(options)) {
        return result;
      }
      options.forEach((item) => {
        delete item.children;
      });
      let map = {};
      options.forEach((item) => {
        map[item.categoryId] = item;
      });
      options.forEach((item) => {
        let parent = map[item.pid];
        if (parent) {
          (parent.children || (parent.children = [])).push(item);
        } else {
          result.push(item);
        }
      });
      result = result.sort(this.sortBy("sort", true));
      result.forEach((item, index) => {
        if (item.children) {
          item.children.sort(this.sortBy("sort", true));
        }
      });
      this.optionsTion = result;
      return result;
    },
    sortBy(attr, rev) {
      //第二个参数没有传递 默认升序排列
      if (rev == undefined) {
        rev = 1;
      } else {
        rev = rev ? 1 : -1;
      }

      return function (a, b) {
        a = a[attr];
        b = b[attr];
        if (a < b) {
          return rev * -1;
        }
        if (a > b) {
          return rev * 1;
        }
        return 0;
      };
    },
    close() {
      if (this.statusPop === 2) {
        this.dialogVisible = false;
        return;
      }
      this.$confirm("是否关闭该窗口", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$refs["listData"].resetFields();
          this.dialogVisible = false;
        })
        .catch(() => {});
    },
    handleSizeChange(v) {
      this.pageSize = v;
      this.currentPage = 1;
      this.search();
    },
    handleCurrentChange(v) {
      this.currentPage = v;
      this.search();
    },
  },
};
</script>

<style lang="less" scoped>
.ulList {
  li {
    float: left;
    border-radius: 6px;
    border: 1px solid #409eff;
    color: #409eff;
    padding: 0px 13px;
    height: 36px;
    line-height: 36px;
    text-align: center;
    margin-bottom: 10px;
    margin-right: 14px;
    position: relative;
    .clears {
      position: absolute;
      top: 4px;
      right: 4px;
      color: red;
      cursor: pointer;
    }
  }
  .mar_r {
    padding-right: 20px !important;
  }
}
/deep/.el-button {
  border-radius: 8px;
}
/deep/.el-dialog {
  border-radius: 8px;
  .el-dialog__header {
    padding: 0;
    .hearders {
      height: 40px;
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 0px 18px 0px 20px;
      border-bottom: 1px solid #e2e2e2;
      .leftTitle {
        font-size: 14px;
        font-weight: bold;
        color: #2f4378;
      }
      .rightBoxs {
        display: flex;
        align-items: center;
        img {
          width: 14px;
          height: 14px;
          margin-left: 13px;
          cursor: pointer;
        }
      }
    }
  }
  .el-dialog__footer {
    padding: 0;
    .dialog-footer {
      padding: 0px 40px;
      height: 70px;
      border-top: 1px solid #e2e2e2;
      display: flex;
      align-items: center;
      justify-content: flex-end;
    }
  }
}
.imgBox {
  width: 100%;
  // height: 210px;
  border: 1px solid #e2e2e2;
  border-radius: 8px;
  padding: 8px 8px 3px;
  display: flex;
  flex-direction: column;
  align-items: center;
  .imgLabel {
    flex: 1;
    width: 100%;
    border: 1px dotted #e2e2e2;
    color: #999;
    font-size: 14px;
    cursor: pointer;
    border-radius: 8px;
    .msPhoto {
      display: flex;
      justify-content: center;
      align-items: center;
      max-width: 100%;
      max-height: 270px;
      img {
        max-width: 100%;
        max-height: 270px;
      }
    }
    .imgbbx {
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      width: 100%;
      height: 100%;
      i {
        font-weight: bold;
        margin: 14px 0;
        font-size: 24px;
      }
    }
  }
  p {
    margin: 5px 0px;
  }
}
</style>

