<style>
    .visiHidden{
        visibility: hidden;
    }
</style>
<template>
  <q-dialog v-model="persistent" content-class="bg-grey-1" persistent transition-show="scale" transition-hide="scale">
    <q-card style="width: 800px;max-width:900px;">
      <q-card-section>
        <div class="text-h6">{{optionTitle}}</div>
      </q-card-section>
      <q-card-section class="q-pt-none scroll" style="max-height: 70vh">
        <div class="text-caption q-mb-lg q-px-md text-grey-6">招聘类型信息</div>
        <div class="row wrap">
          <q-select filled stack-label option-value="Id" option-label="TypeName" v-model="objOption.TypeId" ref="TypeId"
            :options="typeList" label="招聘类型" :dense="false" class="col-6 q-pr-lg q-pb-lg"
            :rules="[val => !!val || '请选择招聘类型']" emit-value map-options />
          <q-input filled stack-label maxlength="50" :dense="false" v-model="objOption.PositionName" ref="PositionName"
            :rules="[val => !!val || '请填写岗位名称']" class="col-6 q-pb-lg" label="岗位名称" />
          <q-select filled stack-label option-value="Id" option-label="Name" v-model="objOption.SalaryType"
            :options="SalaryTypeList" label="薪资类型" :dense="false" class="col-6 q-pr-lg q-pb-lg" emit-value
            map-options />
          <q-input filled stack-label maxlength="50" :class="{'visiHidden':objOption.SalaryType==2}" :dense="false" v-model="objOption.SalaryNum" class="col-6 q-pb-lg"
            @keyup.native="checkPrice(objOption,'SalaryNum')" label="多少薪" />
          <template v-if="objOption.SalaryType==1">
            <q-input filled stack-label maxlength="50" :dense="false" v-model="objOption.SalaryStart"
                class="col-6 q-pr-lg q-pb-lg" @keyup.native="checkPrice(objOption,'SalaryStart')" label="开始薪资" />
            <q-input filled stack-label maxlength="50" :dense="false" v-model="objOption.SalaryEnd" class="col-6 q-pb-lg"
                label="结束薪资" @keyup.native="checkPrice(objOption,'SalaryEnd')" />
          </template>
          <q-input filled stack-label maxlength="50" :dense="false" v-model="objOption.Experience"
            class="col-6 q-pr-lg q-pb-lg" label="工作经验" />
          <q-input filled stack-label maxlength="50" :dense="false" v-model="objOption.Education" class="col-6 q-pb-lg"
            label="学历" />
          <q-input filled stack-label maxlength="100" :dense="false" v-model="objOption.WorkPlace"
            class="col-6 q-pr-lg q-pb-lg" label="工作地点" />
          <q-input filled v-model="objOption.PublishTime" class="col-6 q-pb-lg" mask="date" label="更新时间">
            <template v-slot:append>
              <q-icon name="event" class="cursor-pointer">
                <q-popup-proxy ref="qDateProxy" transition-show="scale" transition-hide="scale">
                  <q-date v-model="objOption.PublishTime" @input="() => $refs.qDateProxy.hide()" />
                </q-popup-proxy>
              </q-icon>
            </template>
          </q-input>
          <q-input filled stack-label :dense="false" v-model="objOption.PositionDesc" style="margin-top: 20px"
            type="textarea" class="col-12" label="岗位描述" />
        </div>
      </q-card-section>
      <q-separator />
      <q-card-actions align="right" class="bg-white">
        <q-btn label="取消" flat color="grey-10" style="font-weight:400 !important" @click="closeSaveForm" />
        <q-btn label="立即提交" color="accent q-px-md" style="font-weight:400 !important" :loading="saveLoading"
          @click="saveComic" />
      </q-card-actions>
    </q-card>
  </q-dialog>
</template>

<script>
  import {
    SetWebRecruitment,
    GetWebRecruitmentTypeList,
    GetWebRecruitment
  } from '../../api/system/webkit'
  export default {
    props: {
      saveObj: {
        type: Object,
        default: null
      }
    },
    data() {
      return {
        persistent: true,
        objOption: {
          Id: 0,
          TypeId: 0,
          PositionName: '',
          SalaryType: 1,
          SalaryStart: '',
          SalaryEnd: '',
          SalaryNum: '',
          Experience: '',
          Education: '',
          WorkPlace: '',
          PublishTime: '',
          PositionDesc: ''
        },
        SalaryTypeList: [{
          Id: 1,
          Name: '固定薪资'
        }, {
          Id: 2,
          Name: '面议'
        }],
        optionTitle: "新增招聘信息",
        saveLoading: false,
        typeList: [] //类型下拉
      }
    },
    mounted() {
      this.initObj()
      this.getTypeList();
    },
    methods: {
      //初始化表单
      initObj() {
        if (this.saveObj && this.saveObj.Id > 0) {
          GetWebRecruitment({
            Id: this.saveObj.Id
          }).then(res => {
            if (res.Code == 1) {
              this.objOption.Id = res.Data.Id;
              this.objOption.TypeId = res.Data.TypeId;
              this.objOption.PositionName = res.Data.PositionName;
              this.objOption.SalaryType = res.Data.SalaryType;
              this.objOption.SalaryStart = res.Data.SalaryStart;
              this.objOption.SalaryEnd = res.Data.SalaryEnd;
              this.objOption.SalaryNum = res.Data.SalaryNum;
              this.objOption.Experience = res.Data.Experience;
              this.objOption.Education = res.Data.Education;
              this.objOption.WorkPlace = res.Data.WorkPlace;
              this.objOption.PublishTime = res.Data.PublishTime;
              this.objOption.PositionDesc = res.Data.PositionDesc;
              this.optionTitle = '修改招聘信息'
            }
          })
        }
      },
      //获取招聘类型下拉数据
      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(() => {})
      },
      //关闭弹窗
      closeSaveForm() {
        this.$emit('close')
        this.persistent = false
      },
      //保存菜单
      saveComic() {
        this.$refs.TypeId.validate();
        this.$refs.PositionName.validate();
        if (!this.$refs.TypeId.hasError && !this.$refs.PositionName.hasError) {
          this.saveLoading = true
          SetWebRecruitment(this.objOption).then(res => {
            this.saveLoading = false
            this.$q.notify({
              icon: 'iconfont icon-chenggong',
              color: 'accent',
              timeout: 2000,
              message: '数据保存成功！',
              position: 'top'
            })
            this.$emit("success")
            this.closeSaveForm()
          }).catch(() => {
            this.saveLoading = false
          })
        }
      }
    },
  }

</script>
