<template>
  <div class="page-body">
    <div class="page-search row items-center">
      <div class="col row wrap q-mr-lg q-col-gutter-md">
        <div class="col-3">
          <q-input @change="resetSearch" clearable standout="bg-primary text-white" class="col-6 q-pr-lg q-pr-lg"
            v-model="msg.PositionName" label="岗位名称" maxlength="20" @clear="resetSearch" />
        </div>
        <div class="col-3">
          <q-select filled stack-label option-value="Id" option-label="TypeName" v-model="msg.TypeId"
            :options="typeList" label="招聘类型" :dense="false" class="col-6 q-pr-lg q-pb-lg" emit-value map-options
            @input="resetSearch()" />
        </div>
      </div>
    </div>
    <div class="page-content">
      <q-table :pagination="msg" :loading="loading" no-data-label="暂无相关数据" flat class="sticky-column-table"
        separator="none" :data="data" :columns="columns" row-key="name">
        <template v-slot:top="props">
          <div class="col-2 q-table__title">招聘信息</div>
          <q-space />
          <div class="page-option">
            <q-btn color="accent" class="q-mr-md" size="sm" icon="add" label="新增招聘" @click="EditComic(null)" />
          </div>
        </template>
        <template v-slot:body-cell-TypeId="props">
          <q-td>
            <span>{{getTypeName(props.row.TypeId)}}</span>
          </q-td>
        </template>
        <template v-slot:body-cell-SalaryType="props">
          <q-td>
            <span>{{props.row.SalaryType==1?'固定薪资':'面议'}}</span>
          </q-td>
        </template>
        <template v-slot:bottom>
          <q-pagination class="full-width justify-end" v-model="msg.pageIndex" color="primary" :max="pageCount"
            :input="true" @input="changePage" />
        </template>
        <template v-slot:body-cell-optioned="props">
          <q-td :props="props">
            <q-btn flat size="xs" icon="edit" color="accent" style="font-weight:400" label="编辑"
              @click="EditComic(props.row)" />
            <q-btn flat size="xs" icon="delete" color="negative" style="font-weight:400" label="删除"
              @click="delMonthly(props.row)" />
          </q-td>
        </template>
      </q-table>
      <recruit-form v-if="isShowRecruitForm" :save-obj="recruitObjOption" @close="closeRecruit" @success="refreshPage">
      </recruit-form>
    </div>
  </div>
</template>
<script>
  import {
    GetWebRecruitmentPage,
    GetWebRecruitmentTypeList,
    RemoveWebRecruitmentStatus
  } from '../../api/system/webkit'
  import recruitForm from '../../components/system/recruit-form'
  export default {
    meta: {
      title: "招聘信息管理"
    },
    components: {
      recruitForm
    },
    data() {
      return {
        columns: [{
          name: 'PositionName',
          label: '岗位名称',
          field: 'PositionName',
          align: 'left'
        }, {
          name: 'TypeId',
          label: '招聘类型',
          field: 'TypeId',
          align: 'left'
        },{
          name: 'SalaryStr',
          label: '薪资',
          field: 'SalaryStr',
          align: 'left'
        },{
          name: 'Experience',
          label: '工作经验',
          field: 'Experience',
          align: 'left'
        }, {
          name: 'Education',
          label: '学历',
          field: 'Education',
          align: 'left'
        }, {
          name: 'WorkPlace',
          label: '工作地点',
          field: 'WorkPlace',
          align: 'left'
        }, {
          name: 'PublishTimeStr',
          label: '更新时间',
          field: 'PublishTimeStr',
          align: 'left'
        },{
          name: 'optioned',
          label: '操作',
          field: 'MenuId'
        }],
        data: [],
        loading: true,
        msg: {
          pageIndex: 1,
          pageSize: 12,
          rowsPerPage: 12,
          PositionName: '', //岗位名称
          TypeId: 0 //招聘类型
        },
        pageCount: 0,
        isShowRecruitForm: false,
        recruitObjOption: null,
        typeList: [] //类型下拉
      }
    },
    mounted() {
      this.getTypeList();
      this.getList()
    },
    methods: {
      //重新查询
      resetSearch() {
        this.msg.pageIndex = 1;
        this.getList();
      },
      //翻页
      changePage(val) {
        this.msg.pageIndex = val;
        this.getList()
      },
      //获取招聘类型下拉数据
      getTypeList() {
        let msg = {
          TypeName: ''
        }
        GetWebRecruitmentTypeList(msg).then(res => {
          if (res.Code == 1) {
            this.typeList = res.Data;
            let obj = {
              Id: 0,
              TypeName: '不限'
            }
            this.typeList.unshift(obj);
          }
        }).catch(() => {})
      },
      getTypeName(Id) {
        let str = '';
        this.typeList.forEach(x => {
          if (x.Id == Id) {
            str = x.TypeName;
          }
        })
        return str;
      },
      //获取菜单分页列表
      getList() {
        this.loading = true;
        GetWebRecruitmentPage(this.msg).then(res => {
          this.loading = false
          this.data = res.Data.PageData;
          this.pageCount = res.Data.PageCount;
        }).catch(() => {
          this.loading = false
        })
      },
      //刷新页面
      refreshPage() {
        if (!this.recruitObjOption) {
          this.msg.pageIndex = 1;
          this.msg.TypeName = "";
        }
        this.getList()
      },
      //新增修改菜单
      EditComic(obj) {
        if (obj) {
          this.recruitObjOption = obj
        } else {
          this.recruitObjOption = null
        }
        this.isShowRecruitForm = true
      },
      //关闭弹窗
      closeRecruit() {
        this.isShowRecruitForm = false
      },
      //删除
      delMonthly(obj) {
        this.$q.dialog({
          title: '提示信息',
          message: '是否确定删除？',
          cancel: true,
          persistent: true,
          ok: "确定",
          cancel: "取消",
        }).onOk(() => {
          let delMsg = {
            Id: obj.Id,
            Status: 1
          }
          RemoveWebRecruitmentStatus(delMsg).then(res => {
            if (res.Code == 1) {
              this.$q.notify({
                icon: 'iconfont icon-chenggong',
                color: 'accent',
                timeout: 2000,
                message: '操作成功',
                position: 'top'
              })
              this.getList();
            }
          })
        })
      }
    }
  }

</script>
<style lang="sass">
  @import url('~assets/css/table.sass')

</style>
