405 lines
12 KiB
Vue
405 lines
12 KiB
Vue
<template>
|
|
<div class="form-container">
|
|
<el-form ref="workStudyPositionFormRef" :model="form" :rules="rules" label-width="120px" v-loading="loading">
|
|
<el-row :gutter="20">
|
|
<el-col :span="12">
|
|
<el-form-item label="岗位名称" prop="positionName">
|
|
<el-input v-model="form.positionName" placeholder="请输入岗位名称" maxlength="50" show-word-limit />
|
|
</el-form-item>
|
|
</el-col>
|
|
<el-col :span="12">
|
|
<el-form-item label="发布范围" prop="positionScope">
|
|
<el-select v-model="form.positionScope" placeholder="请选择发布范围" style="width: 100%">
|
|
<el-option v-for="option in positionScopeOptions" :key="option.value" :label="option.label" :value="option.value" />
|
|
</el-select>
|
|
</el-form-item>
|
|
</el-col>
|
|
</el-row>
|
|
|
|
<el-row :gutter="20">
|
|
<el-col :span="12">
|
|
<el-form-item label="发布学院" prop="collegeId">
|
|
<el-select v-model="form.collegeId" placeholder="请选择发布学院" style="width: 100%" @change="handleCollegeChange">
|
|
<el-option v-for="college in collegeOptions" :key="college.deptId" :label="college.deptName" :value="college.deptId" />
|
|
</el-select>
|
|
</el-form-item>
|
|
</el-col>
|
|
<el-col :span="12">
|
|
<el-form-item label="需求人数" prop="requiredCount">
|
|
<el-input-number v-model="form.requiredCount" :min="1" :max="999" placeholder="请输入需求人数" style="width: 100%" />
|
|
</el-form-item>
|
|
</el-col>
|
|
</el-row>
|
|
|
|
<el-row :gutter="20">
|
|
<el-col :span="12">
|
|
<el-form-item label="工作时间" prop="workTime">
|
|
<el-input v-model="form.workTime" placeholder="例如:周一至周五 9:00-17:00" maxlength="100" show-word-limit />
|
|
</el-form-item>
|
|
</el-col>
|
|
<el-col :span="12">
|
|
<el-form-item label="开始日期" prop="startDate">
|
|
<el-date-picker v-model="form.startDate" type="date" placeholder="选择开始日期" style="width: 100%" value-format="YYYY-MM-DD" />
|
|
</el-form-item>
|
|
</el-col>
|
|
</el-row>
|
|
|
|
<el-row :gutter="20">
|
|
<el-col :span="12">
|
|
<el-form-item label="结束日期" prop="endDate">
|
|
<el-date-picker v-model="form.endDate" type="date" placeholder="选择结束日期" style="width: 100%" value-format="YYYY-MM-DD" />
|
|
</el-form-item>
|
|
</el-col>
|
|
<el-col :span="12">
|
|
<el-form-item label="联系老师" prop="contactTeacher">
|
|
<el-input v-model="form.contactTeacher" placeholder="请输入联系老师姓名" maxlength="20" show-word-limit />
|
|
</el-form-item>
|
|
</el-col>
|
|
</el-row>
|
|
|
|
<el-row :gutter="20">
|
|
<el-col :span="12">
|
|
<el-form-item label="联系电话" prop="contactPhone">
|
|
<el-input v-model="form.contactPhone" placeholder="请输入联系电话" maxlength="20" show-word-limit />
|
|
</el-form-item>
|
|
</el-col>
|
|
<el-col :span="12">
|
|
<el-form-item label="薪资情况" prop="salaryInfo">
|
|
<el-input
|
|
v-model="form.salaryInfo"
|
|
type="textarea"
|
|
:rows="2"
|
|
placeholder="请输入薪资情况,例如:20元/小时,按月发放"
|
|
maxlength="200"
|
|
show-word-limit
|
|
/>
|
|
</el-form-item>
|
|
</el-col>
|
|
</el-row>
|
|
|
|
<el-row :gutter="20">
|
|
<el-col :span="24">
|
|
<el-form-item label="岗位要求" prop="positionRequirements">
|
|
<el-input
|
|
v-model="form.positionRequirements"
|
|
type="textarea"
|
|
:rows="4"
|
|
placeholder="请详细描述岗位要求,包括专业要求、技能要求、工作内容等"
|
|
maxlength="1000"
|
|
show-word-limit
|
|
/>
|
|
</el-form-item>
|
|
</el-col>
|
|
</el-row>
|
|
|
|
<el-row :gutter="20" v-if="form.id">
|
|
<el-col :span="12">
|
|
<el-form-item label="岗位状态" prop="status">
|
|
<el-select v-model="form.status" placeholder="请选择岗位状态" style="width: 100%">
|
|
<el-option v-for="option in statusOptions" :key="option.value" :label="option.label" :value="option.value" />
|
|
</el-select>
|
|
</el-form-item>
|
|
</el-col>
|
|
<el-col :span="12">
|
|
<el-form-item label="当前人数" prop="currentCount">
|
|
<el-input-number
|
|
v-model="form.currentCount"
|
|
:min="0"
|
|
:max="form.requiredCount || 999"
|
|
placeholder="当前申请人数"
|
|
style="width: 100%"
|
|
disabled
|
|
/>
|
|
</el-form-item>
|
|
</el-col>
|
|
</el-row>
|
|
</el-form>
|
|
|
|
<div class="form-footer">
|
|
<el-button @click="cancel">取 消</el-button>
|
|
<el-button type="primary" @click="submitForm">确 定</el-button>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<script setup>
|
|
import { ref, reactive, watch, getCurrentInstance, onMounted } from 'vue';
|
|
import { getWorkStudyPosition, addWorkStudyPosition, updateWorkStudyPosition } from '@/api/jcbt/workStudyPosition';
|
|
import { listColleges } from '@/api/xg/xsjcxx/classMsg/college';
|
|
|
|
const props = defineProps({
|
|
positionId: {
|
|
type: [String, Number],
|
|
default: undefined
|
|
}
|
|
});
|
|
|
|
const emit = defineEmits(['success', 'cancel']);
|
|
|
|
const { proxy } = getCurrentInstance();
|
|
|
|
const loading = ref(false);
|
|
const workStudyPositionFormRef = ref();
|
|
|
|
// 学院选项数据
|
|
const collegeOptions = ref([]);
|
|
|
|
// 表单数据
|
|
const form = ref({
|
|
id: undefined,
|
|
positionName: '',
|
|
positionScope: 'COLLEGE',
|
|
requiredCount: 1,
|
|
workTime: '',
|
|
startDate: '',
|
|
endDate: '',
|
|
positionRequirements: '',
|
|
salaryInfo: '',
|
|
contactTeacher: '',
|
|
contactPhone: '',
|
|
status: 'DRAFT',
|
|
currentCount: 0,
|
|
collegeId: undefined,
|
|
collegeName: ''
|
|
});
|
|
|
|
// 表单验证规则
|
|
const rules = reactive({
|
|
positionName: [
|
|
{ required: true, message: '岗位名称不能为空', trigger: 'blur' },
|
|
{ min: 2, max: 50, message: '岗位名称长度在 2 到 50 个字符', trigger: 'blur' }
|
|
],
|
|
positionScope: [{ required: true, message: '请选择发布范围', trigger: 'change' }],
|
|
collegeId: [{ required: true, message: '发布学院不能为空', trigger: 'change' }],
|
|
requiredCount: [
|
|
{ required: true, message: '需求人数不能为空', trigger: 'blur' },
|
|
{ type: 'number', min: 1, max: 999, message: '需求人数必须在 1 到 999 之间', trigger: 'blur' }
|
|
],
|
|
workTime: [
|
|
{ required: true, message: '工作时间不能为空', trigger: 'blur' },
|
|
{ max: 100, message: '工作时间长度不能超过 100 个字符', trigger: 'blur' }
|
|
],
|
|
startDate: [{ required: true, message: '开始日期不能为空', trigger: 'change' }],
|
|
endDate: [
|
|
{ required: true, message: '结束日期不能为空', trigger: 'change' },
|
|
{
|
|
validator: (rule, value, callback) => {
|
|
if (value && form.value.startDate && value <= form.value.startDate) {
|
|
callback(new Error('结束日期必须大于开始日期'));
|
|
} else {
|
|
callback();
|
|
}
|
|
},
|
|
trigger: 'change'
|
|
}
|
|
],
|
|
contactTeacher: [
|
|
{ required: true, message: '联系老师不能为空', trigger: 'blur' },
|
|
{ max: 20, message: '联系老师长度不能超过 20 个字符', trigger: 'blur' }
|
|
],
|
|
contactPhone: [
|
|
{ required: true, message: '联系电话不能为空', trigger: 'blur' },
|
|
{ pattern: /^1[3-9]\d{9}$/, message: '请输入正确的手机号码', trigger: 'blur' }
|
|
],
|
|
salaryInfo: [
|
|
{ required: true, message: '薪资情况不能为空', trigger: 'blur' },
|
|
{ max: 200, message: '薪资情况长度不能超过 200 个字符', trigger: 'blur' }
|
|
],
|
|
positionRequirements: [
|
|
{ required: true, message: '岗位要求不能为空', trigger: 'blur' },
|
|
{ max: 1000, message: '岗位要求长度不能超过 1000 个字符', trigger: 'blur' }
|
|
]
|
|
});
|
|
|
|
// 选项数据
|
|
const positionScopeOptions = ref([
|
|
{ label: '本学院', value: 'COLLEGE' },
|
|
{ label: '全校', value: 'UNIVERSITY' }
|
|
]);
|
|
|
|
const statusOptions = ref([
|
|
{ label: '草稿', value: 'DRAFT' },
|
|
{ label: '已发布', value: 'PUBLISHED' },
|
|
{ label: '招录中', value: 'RECRUITING' },
|
|
{ label: '已满员', value: 'FULL' },
|
|
{ label: '已过期', value: 'EXPIRED' },
|
|
{ label: '已暂停', value: 'SUSPENDED' },
|
|
{ label: '已取消', value: 'CANCELLED' }
|
|
]);
|
|
|
|
/** 取消按钮 */
|
|
const cancel = () => {
|
|
emit('cancel');
|
|
};
|
|
|
|
/** 表单重置 */
|
|
const reset = () => {
|
|
form.value = {
|
|
id: undefined,
|
|
positionName: '',
|
|
positionScope: 'COLLEGE',
|
|
requiredCount: 1,
|
|
workTime: '',
|
|
startDate: '',
|
|
endDate: '',
|
|
positionRequirements: '',
|
|
salaryInfo: '',
|
|
contactTeacher: '',
|
|
contactPhone: '',
|
|
status: 'DRAFT',
|
|
currentCount: 0,
|
|
collegeId: undefined,
|
|
collegeName: ''
|
|
};
|
|
workStudyPositionFormRef.value?.resetFields();
|
|
};
|
|
|
|
/** 提交表单 */
|
|
const submitForm = async () => {
|
|
const valid = await workStudyPositionFormRef.value?.validate();
|
|
if (!valid) return;
|
|
|
|
loading.value = true;
|
|
try {
|
|
if (form.value.id) {
|
|
await updateWorkStudyPosition(form.value);
|
|
proxy?.$modal.msgSuccess('修改成功');
|
|
} else {
|
|
await addWorkStudyPosition(form.value);
|
|
proxy?.$modal.msgSuccess('新增成功');
|
|
}
|
|
emit('success');
|
|
} catch (error) {
|
|
console.error('提交失败:', error);
|
|
} finally {
|
|
loading.value = false;
|
|
}
|
|
};
|
|
|
|
/** 获取岗位详细信息 */
|
|
const getPosition = async (id) => {
|
|
loading.value = true;
|
|
try {
|
|
const res = await getWorkStudyPosition(id);
|
|
Object.assign(form.value, res.data);
|
|
} catch (error) {
|
|
console.error('获取岗位信息失败:', error);
|
|
} finally {
|
|
loading.value = false;
|
|
}
|
|
};
|
|
|
|
/** 获取学院列表 */
|
|
const getCollegeList = async () => {
|
|
loading.value = true;
|
|
try {
|
|
const res = await listColleges();
|
|
collegeOptions.value = res.data;
|
|
if (form.value.collegeId) {
|
|
const college = collegeOptions.value.find((item) => item.deptId === form.value.collegeId);
|
|
if (college) {
|
|
form.value.collegeName = college.deptName;
|
|
}
|
|
}
|
|
} catch (error) {
|
|
console.error('获取学院列表失败:', error);
|
|
} finally {
|
|
loading.value = false;
|
|
}
|
|
};
|
|
|
|
/** 处理学院选择变化 */
|
|
const handleCollegeChange = (value) => {
|
|
const college = collegeOptions.value.find((item) => item.deptId === value);
|
|
if (college) {
|
|
form.value.collegeName = college.deptName;
|
|
} else {
|
|
form.value.collegeName = '';
|
|
}
|
|
};
|
|
|
|
// 监听props变化
|
|
watch(
|
|
() => props.positionId,
|
|
(newVal) => {
|
|
reset();
|
|
if (newVal) {
|
|
getPosition(newVal);
|
|
}
|
|
},
|
|
{ immediate: true }
|
|
);
|
|
|
|
// 组件挂载时初始化数据
|
|
onMounted(() => {
|
|
getCollegeList();
|
|
});
|
|
|
|
// 暴露方法
|
|
defineExpose({
|
|
reset
|
|
});
|
|
</script>
|
|
|
|
<style scoped lang="scss">
|
|
.form-container {
|
|
padding: 20px;
|
|
|
|
.form-footer {
|
|
display: flex;
|
|
justify-content: flex-end;
|
|
gap: 10px;
|
|
margin-top: 20px;
|
|
padding-top: 20px;
|
|
border-top: 1px solid #ebeef5;
|
|
}
|
|
|
|
/* 表单样式美化 */
|
|
:deep(.el-form-item__label) {
|
|
font-weight: 600;
|
|
color: #333;
|
|
}
|
|
|
|
:deep(.el-input__inner) {
|
|
border-radius: 6px;
|
|
}
|
|
|
|
:deep(.el-textarea__inner) {
|
|
border-radius: 6px;
|
|
}
|
|
|
|
:deep(.el-select) {
|
|
width: 100%;
|
|
}
|
|
|
|
:deep(.el-date-editor) {
|
|
width: 100%;
|
|
}
|
|
|
|
/* 必填项标识 */
|
|
:deep(.el-form-item.is-required .el-form-item__label::before) {
|
|
color: #f56c6c;
|
|
}
|
|
}
|
|
|
|
/* 响应式设计 */
|
|
@media (max-width: 768px) {
|
|
.form-container {
|
|
padding: 15px;
|
|
|
|
:deep(.el-col) {
|
|
margin-bottom: 15px;
|
|
}
|
|
|
|
.form-footer {
|
|
flex-direction: column;
|
|
|
|
.el-button {
|
|
width: 100%;
|
|
margin-bottom: 10px;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
</style>
|