<template>
|
<el-dialog :title="!dataForm.id ? '新增' : '修改'" :close-on-click-modal="false" :visible.sync="visible">
|
<el-form :model="dataForm" :rules="rules" ref="dataForm" label-width="100px" class="l-mes">
|
<el-row>
|
<el-col :span="12">
|
<el-form-item label="人员编号" prop="staffNo">
|
<el-input v-model="dataForm.staffNo" placeholder="人员编号"></el-input>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="人员名称" prop="staffName">
|
<el-input v-model="dataForm.staffName" placeholder="人员名称"></el-input>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<el-row>
|
<el-col :span="12">
|
<el-form-item label="公司" prop="companyId">
|
<el-select @change="changeCompany" style="width: 100%;" v-model="dataForm.companyId" placeholder="请选择">
|
<el-option v-for="item in options" :key="item.id" :label="item.companyName" :value="item.id">
|
</el-option>
|
</el-select>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="工厂" prop="factoryId">
|
<el-select @change="changeFactory" style="width: 100%;" v-model="dataForm.factoryId" placeholder="请选择">
|
<el-option v-for="item in optionsfactory" :key="item.id" :label="item.factoryName" :value="item.id">
|
</el-option>
|
</el-select>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<el-row>
|
<el-col :span="12">
|
<el-form-item label="部门" prop="divisionId">
|
<el-select @change="changeDivision" v-model="dataForm.divisionId" filterable placeholder="请选择" style="width: 100%;">
|
<el-option v-for="(item, index) in this.divisionOptions" :key="index" :label="item.divisionName"
|
:value="item.id">
|
</el-option>
|
</el-select>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="岗位" prop="postId">
|
<el-select v-model="dataForm.postId" filterable placeholder="请选择" style="width: 100%;">
|
<el-option v-for="item in this.postOptions" :key="item.id" :label="item.postName" :value="item.id">
|
</el-option>
|
</el-select>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<el-row>
|
<el-col :span="12">
|
<el-form-item label="邮箱" prop="email">
|
<el-input v-model="dataForm.email" placeholder="邮箱"></el-input>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="电话" prop="phone">
|
<el-input v-model="dataForm.phone" placeholder="电话"></el-input>
|
</el-form-item>
|
</el-col>
|
<!-- <el-col :span="12">
|
<el-form-item label="岗位" prop="post">
|
<el-input v-model="dataForm.post" placeholder="岗位"></el-input>
|
</el-form-item>
|
</el-col>-->
|
</el-row>
|
<el-row>
|
<el-col :span="12">
|
<el-form-item label="人员系数" prop="personnelFactor">
|
<el-input v-model="dataForm.personnelFactor" placeholder="人员系数"></el-input>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<el-row>
|
<el-col :span="12">
|
<el-form-item label="人员性质" prop="personNature">
|
<el-select v-model="dataForm.personNature" placeholder="请选择" style="width: 100%;">
|
<el-option v-for="item in this.personNatureOptions" :key="item.value" :label="item.label"
|
:value="item.value">
|
</el-option>
|
</el-select>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="试用截止日期" prop="trialDeadline">
|
<el-input v-model="dataForm.trialDeadline" placeholder=""></el-input>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
</el-form>
|
<span slot="footer" class="dialog-footer">
|
<el-button @click="visible = false">取消</el-button>
|
<el-button type="primary" :disabled="isSubmit" v-thinclick="`dataFormSubmit`">确定</el-button>
|
</span>
|
</el-dialog>
|
</template>
|
|
<script>
|
import { getObj, loadDivision, dataFormTransfer } from '@/api/basic/staff'
|
import { getList, getDivisionByFactoryId ,getObjById} from '@/api/basic/post'
|
import { dateFormat, dateFormatYearMonthDate } from '@/util/date'
|
import {
|
loadFactoryListByCompany
|
} from '@/api/basic/division'
|
|
import { loadCompany } from '@/api/basic/factory'
|
|
export default {
|
props: {
|
personNatureOptions: {
|
type: Array,
|
default: () => {
|
return []
|
}
|
}
|
},
|
data() {
|
return {
|
visible: false,
|
options: [],
|
optionsfactory: [],
|
dataForm: {
|
id: 0,
|
staffNo: '',
|
staffName: '',
|
phone: '',
|
email: '',
|
post: '',
|
postId: null,
|
personnelFactor: '',
|
createTime: '',
|
updateTime: '',
|
createUser: '',
|
updateUser: '',
|
divisionId: '',
|
personNature: '',
|
trialDeadline: '',
|
companyId: null,
|
companyName: null,
|
factoryId: null,
|
factoryName: null,
|
},
|
divisionOptions: [],
|
postOptions: [],
|
dataRule: {},
|
isSubmit: false
|
}
|
},
|
computed: {
|
rules: function () {
|
return {
|
divisionId: [
|
{ required: true, message: '部门不能为空', trigger: 'blur' }
|
],
|
postId: [{ required: true, message: '岗位不能为空', trigger: 'blur' }],
|
staffNo: [
|
{ required: true, message: '人员编号不能为空', trigger: 'blur' }
|
],
|
staffName: [
|
{ required: true, message: '人员名称不能为空', trigger: 'blur' }
|
],
|
companyId: [
|
{ required: true, message: '公司名称不能为空', trigger: 'blur' }
|
],
|
factoryId: [
|
{ required: true, message: '工厂名称不能为空', trigger: 'blur' }
|
]
|
}
|
}
|
},
|
methods: {
|
changeDivision(){
|
getObjById(this.dataForm.companyId,this.dataForm.factoryId,this.dataForm.divisionId).then((response) => {
|
this.postOptions = response.data.data
|
})
|
},
|
changeCompany() {
|
loadFactoryListByCompany(this.dataForm.companyId).then((res) => {
|
this.optionsfactory = res.data.data
|
})
|
// this.divisionOptions=[]
|
// this.dataForm.divisionId=''
|
this.dataForm.companyName = this.options.filter(item => {
|
return item.id == this.dataForm.companyId
|
})[0].companyName;
|
},
|
changeFactory() {
|
getDivisionByFactoryId(this.dataForm.companyId, this.dataForm.factoryId).then((res) => {
|
this.divisionOptions=res.data.data
|
})
|
this.dataForm.factoryName = this.optionsfactory.filter(item => {
|
return item.id == this.dataForm.factoryId
|
})[0].factoryName;
|
},
|
initCompanySelect() {
|
loadCompany().then((res) => {
|
this.options = res.data
|
})
|
},
|
init(id) {
|
this.dataForm.id = id || 0
|
this.visible = true
|
this.$nextTick(() => {
|
this.$refs.dataForm.resetFields()
|
if (this.dataForm.id) {
|
getObj(this.dataForm.id).then((response) => {
|
this.dataForm = response.data.data
|
this.changeCompany()
|
this.changeFactory()
|
this.changeDivision()
|
})
|
} else {
|
const trialDeadline = new Date()
|
trialDeadline.setDate(new Date().getDate() + 90)
|
this.dataForm.trialDeadline = dateFormatYearMonthDate(
|
dateFormat(trialDeadline)
|
)
|
this.dataForm.personNature = '试用工'
|
}
|
})
|
},
|
// 表单提交
|
dataFormSubmit() {
|
this.isSubmit = true
|
const transferData = {
|
staffNo: this.dataForm.staffNo,
|
staffName: this.dataForm.staffName,
|
divisionId: this.dataForm.divisionId,
|
phone: this.dataForm.phone,
|
email: this.dataForm.email,
|
post: this.dataForm.post,
|
postId: this.dataForm.postId,
|
id: this.dataForm.id,
|
personnelFactor: this.dataForm.personnelFactor,
|
personNature: this.dataForm.personNature,
|
trialDeadline: this.dataForm.trialDeadline,
|
factoryId: this.dataForm.factoryId,
|
factoryName: this.dataForm.factoryName,
|
companyId: this.dataForm.companyId,
|
companyName: this.dataForm.companyName
|
}
|
this.$refs.dataForm.validate((valid) => {
|
if (valid) {
|
dataFormTransfer(transferData).then((res) => {
|
if (
|
res.data.data === true &&
|
res.data.code === 0 &&
|
this.dataForm.id === 0
|
) {
|
this.$message.success('添加成功!')
|
this.visible = false
|
this.$emit('refreshDataList')
|
} else if (
|
res.data.data === true &&
|
res.data.code === 0 &&
|
this.dataForm.id != 0
|
) {
|
this.$message.success('修改成功!')
|
this.visible = false
|
this.$emit('refreshDataList')
|
}
|
this.isSubmit = false
|
})
|
} else {
|
this.isSubmit = false
|
}
|
})
|
},
|
initDivisionSelect() {
|
loadDivision().then((res) => {
|
this.divisionOptions = res.data
|
})
|
},
|
initPostSelect() {
|
getList().then((res) => {
|
this.postOptions = res.data.data
|
})
|
}
|
},
|
created() {
|
// this.initDivisionSelect()
|
// this.initPostSelect()
|
this.initCompanySelect()
|
if(this.dataForm.staffNo!=''){
|
console.log(121212);
|
this.changeCompany()
|
this.changeDivision()
|
}
|
},
|
watch: {
|
'dataForm.divisionId': {
|
handler(newValue, oldValue) {
|
if (newValue != ''&&oldValue!=''&&oldValue!=undefined&&newValue!=undefined) {
|
if(oldValue!=newValue){
|
this.dataForm.postId=null
|
this.postOptions=[]
|
}
|
}
|
},
|
immediate: true,
|
deep: true
|
},
|
'dataForm.companyId': {
|
handler(newValue, oldValue) {
|
if (newValue != ''&&oldValue!=''&&oldValue!=undefined&&newValue!=undefined) {
|
console.log(newValue);
|
console.log(oldValue);
|
if(oldValue!=newValue){
|
this.dataForm.factoryId=null
|
this.dataForm.divisionId=null
|
this.divisionOptions=[]
|
this.dataForm.postId=null
|
this.postOptions=[]
|
}
|
}
|
},
|
immediate: true,
|
deep: true
|
},
|
'dataForm.factoryId': {
|
handler(newValue, oldValue) {
|
if (newValue != ''&&oldValue!=''&&oldValue!=undefined&&newValue!=undefined) {
|
console.log(newValue);
|
console.log(oldValue);
|
if(oldValue!=newValue){
|
this.dataForm.divisionId=null
|
this.divisionOptions=[]
|
this.dataForm.postId=null
|
this.postOptions=[]
|
}
|
}
|
},
|
immediate: true,
|
deep: true
|
},
|
'dataForm.personNature': {
|
handler(newValue, oldValue) {
|
if (
|
oldValue === '试用工' &&
|
(newValue === '正式工' || newValue === '合同工')
|
) {
|
this.$confirm('是否清空【试用截止日期】字段', '提示', {
|
confirmButtonText: '确定',
|
cancelButtonText: '取消',
|
closeOnClickModal: false,
|
type: 'warning'
|
}).then(() => {
|
this.dataForm.trialDeadline = ''
|
})
|
}
|
},
|
immediate: true,
|
deep: true
|
}
|
}
|
}
|
</script>
|