<template>
|
<el-dialog
|
:title="!dataForm.id ? '新增' : '修改'"
|
:close-on-click-modal="false"
|
:visible.sync="visible"
|
>
|
<el-form
|
:model="dataForm"
|
:rules="dataRule"
|
ref="dataForm"
|
label-width="80px"
|
class="l-mes"
|
>
|
<el-row>
|
<el-col :span="12">
|
<el-form-item label="部门编号" prop="divisionNo">
|
<el-input
|
v-model="dataForm.divisionNo"
|
placeholder="部门编号"
|
></el-input>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="部门名称" prop="divisionName">
|
<el-input
|
v-model="dataForm.divisionName"
|
placeholder="部门名称"
|
></el-input>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<el-row>
|
<el-col :span="12">
|
<el-form-item label="管理人员" prop="staffId">
|
<el-select
|
v-model="dataForm.staffId"
|
filterable
|
placeholder="请选择"
|
style="width: 100%;"
|
>
|
<el-option
|
v-for="(item, index) in this.staffOptions"
|
:key="index"
|
:label="item.staffName"
|
:value="item.id"
|
>
|
</el-option>
|
</el-select>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="公司" prop="companyId">
|
<el-select
|
v-model="dataForm.companyId"
|
filterable
|
placeholder="请选择"
|
style="width: 100%;"
|
>
|
<el-option
|
v-for="(item, index) in this.companyOptions"
|
:key="index"
|
:label="item.companyName"
|
: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="remark">
|
<el-input v-model="dataForm.remark" 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,
|
addObj,
|
putObj,
|
loadStaff,
|
dataFormTransfer
|
} from '@/api/basic/division'
|
import { loadCompany } from '@/api/basic/factory'
|
|
export default {
|
data() {
|
return {
|
visible: false,
|
dataForm: {
|
id: 0,
|
divisionNo: '',
|
divisionName: '',
|
supervisorId: '',
|
remark: '',
|
companyId: '',
|
createTime: '',
|
updateTime: '',
|
createUser: '',
|
updateUser: '',
|
companyId: '',
|
staffId: ''
|
},
|
companyOptions: [],
|
staffOptions: [],
|
dataRule: {
|
divisionNo: [
|
{ required: true, message: '部门编号不能为空', trigger: 'blur' }
|
],
|
divisionName: [
|
{ required: true, message: '部门名称不能为空', trigger: 'blur' }
|
],
|
companyId: [
|
{ required: true, message: '公司不能为空', trigger: 'blur' }
|
]
|
},
|
isSubmit: false
|
}
|
},
|
methods: {
|
init(id) {
|
this.dataForm.id = id || 0
|
this.visible = true
|
this.$nextTick(() => {
|
this.$refs.dataForm.resetFields()
|
/* this.initCompanySelect();
|
this.initStaffSelect(); */
|
if (this.dataForm.id) {
|
getObj(this.dataForm.id).then((response) => {
|
this.dataForm = response.data.data
|
})
|
}
|
})
|
},
|
// 表单提交
|
dataFormSubmit() {
|
this.isSubmit = true
|
const transferData = {
|
divisionName: this.dataForm.divisionName,
|
divisionNo: this.dataForm.divisionNo,
|
remark: this.dataForm.remark,
|
staffId: this.dataForm.staffId,
|
companyId: this.dataForm.companyId,
|
id: this.dataForm.id
|
}
|
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
|
}
|
})
|
},
|
initCompanySelect() {
|
loadCompany().then((res) => {
|
this.companyOptions = res.data
|
})
|
},
|
initStaffSelect() {
|
loadStaff().then((res) => {
|
this.staffOptions = res.data
|
})
|
}
|
},
|
created() {
|
this.initCompanySelect()
|
this.initStaffSelect()
|
}
|
}
|
</script>
|