<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="companyId">
|
<el-select @change="changeCompany" 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-col :span="12">
|
<el-form-item label="工厂" prop="factotyId">
|
<el-select style="width: 100%;" v-model="dataForm.factotyId" @change="changeFactory" placeholder="请选择">
|
<el-option v-for="item in factotyOption" :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="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,
|
loadFactoryListByCompany
|
} from '@/api/basic/division'
|
import { loadCompany } from '@/api/basic/factory'
|
|
export default {
|
data() {
|
return {
|
visible: false,
|
factotyOption: [],
|
dataForm: {
|
id: 0,
|
divisionNo: '',
|
divisionName: '',
|
supervisorId: '',
|
remark: '',
|
factotyId: null,
|
factotyName: null,
|
companyId: '',
|
createTime: '',
|
updateTime: '',
|
createUser: '',
|
updateUser: '',
|
staffId: ''
|
},
|
companyOptions: [],
|
staffOptions: [],
|
dataRule: {
|
divisionNo: [
|
{ required: true, message: '部门编号不能为空', trigger: 'blur' }
|
],
|
divisionName: [
|
{ required: true, message: '部门名称不能为空', trigger: 'blur' }
|
],
|
companyId: [
|
{ required: true, message: '公司不能为空', trigger: 'blur' }
|
],
|
factotyId: [
|
{ 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) {
|
console.log(111);
|
getObj(this.dataForm.id).then((response) => {
|
this.dataForm = response.data.data
|
this.dataForm.factotyId = response.data.data.factoryId
|
this.changeCompany()
|
})
|
}
|
})
|
},
|
changeCompany() {
|
loadFactoryListByCompany(this.dataForm.companyId).then((res) => {
|
this.factotyOption = res.data.data
|
})
|
// if (this.dataForm.factotyId != '') {
|
// let datas = this.factotyOption.filter(item => {
|
// return item.id == this.dataForm.factotyId
|
// });
|
// console.log(datas);
|
// }
|
},
|
changeFactory() {
|
this.dataForm.factotyName = this.factotyOption.filter(item => {
|
return item.id == this.dataForm.factotyId
|
})[0].factoryName;
|
console.log(this.dataForm);
|
},
|
// 表单提交
|
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,
|
factoryId: this.dataForm.factotyId,
|
factoryName: this.dataForm.factotyName,
|
}
|
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()
|
},
|
watch: {
|
'dataForm.companyId': {
|
handler(newValue, oldValue) {
|
if (newValue != ''&&oldValue!='') {
|
if(oldValue!=newValue){
|
this.dataForm.factotyId=null
|
}
|
}
|
},
|
immediate: true,
|
deep: true
|
}
|
}
|
}
|
</script>
|