<template>
  <div class="cmain">
    <el-form ref="form" :model="form" :disabled="param.detail || param.audit" :rules="rules" label-width="100px">
      <el-row>
        <el-col :span="12">
          <el-form-item label="职位名称" prop="title">
            <el-input v-model="form.title" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="发布企业" prop="enterpriseName">
            <el-input v-model="form.enterpriseName">
              <template slot="append"><span class="pon" @click="op('enterprise', form)">详情</span></template>
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="工作类型" prop="type">
            <el-input :value="form.type == 0 ? '全职' : '兼职'" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="职位分类" prop="positionName">
            <el-input v-model="form.positionName" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="经验要求" prop="experience">
            <el-input v-model="form.experience" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="薪资范围" prop="salary">
            <el-input v-model="form.salary" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="城市名称" prop="cityName">
            <el-input v-model="form.cityName" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="地区名称" prop="regionName">
            <el-input v-model="form.regionName" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="详细地址" prop="address">
            <el-input v-model="form.regionName" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="职位状态" prop="state">
            <el-input :value="form.state == 0 ? '启用' : '关闭'" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-form-item label="职位要求">
        <div v-html="form.contents" style="color: #808080; background-color: #f5f7fa; padding: 15px; border-radius: 7px; border: 1px solid #dfe4ed"></div>
      </el-form-item>
    </el-form>
    <div class="mfooter" v-if="!param.detail">
      <el-button type="primary" @click="submitForm(1)">审核通过</el-button>
      <el-button type="danger" @click="submitForm(2)">不通过</el-button>
      <el-button @click="$layer.close(layerid)">取 消</el-button>
    </div>
  </div>
</template>

<script>
import enterprise from '@/views/work/enterprise/edit.vue';
export default {
  data() {
    return {
      form: {},
      rules: {}
    };
  },
  props: {
    param: {
      type: Object,
      default: () => {
        return {};
      }
    },
    layerid: {
      type: String
    }
  },
  mounted() {
    if (this.param.id) {
      this.ajax({ url: '/work/position/detail/' + this.param.id }).then((response) => {
        this.form = response.data;
      });
    }
  },
  methods: {
    op(tag, row) {
      if (tag == 'enterprise') {
        this.iframe({ obj: enterprise, param: { id: row.userId, detail: true }, title: '企业详情', width: '50%', height: '65%' });
      }
    },
    submitForm(audit) {
      this.$refs['form'].validate((valid) => {
        if (valid) {
          this.$prompt('确认审核通过?', {
            type: 'warning',
            showInput: audit == 1 ? false : true,
            inputType: 'textarea',
            inputPlaceholder: '请输入审核不通过原因',
            inputValidator: (value) => {
              if (!value && audit == 2) {
                return '请输入审核不通过原因';
              }
            }
          }).then(({ value }) => {
            this.post({ url: '/work/position/edit', data: { id: this.form.id, audit: audit, msg: value } }).then((response) => {
              this.$modal.msgSuccess('操作成功');
              this.$layer.close(this.layerid);
              this.$parent.getList();
            });
          });
        }
      });
    }
  }
};
</script>
