<template>
|
<a-modal
|
:title="title"
|
:width="800"
|
:visible="visible"
|
:confirmLoading="confirmLoading"
|
@ok="handleOk"
|
@cancel="handleCancel"
|
cancelText="关闭">
|
<a-form-model ref="form" :model="model" :rules="validatorRules" :labelCol="labelCol" :wrapperCol="wrapperCol">
|
<a-form-model-item label="机构编码">
|
<a-input placeholder="请输入机构编码" v-model="model.factoryCode"/>
|
</a-form-model-item>
|
<a-form-model-item label="机构名称" hasFeedback prop="factoryName">
|
<a-input placeholder="请输入机构名称" v-model="model.factoryName"/>
|
</a-form-model-item>
|
<a-form-model-item :hidden="seen" label="上级机构">
|
<a-tree-select style="width:100%" :dropdownStyle="{maxHeight:'200px',overflow:'auto'}" :treeData="departTree"
|
v-model="model.parentId" placeholder="请选择上级机构" disabled>
|
</a-tree-select>
|
</a-form-model-item>
|
<a-form-model-item v-if="!seen&&(model.parentFactoryCategory==1||model.parentFactoryCategory==2)" label="机构类型"
|
hasFeedback
|
prop="factoryCategory">
|
<a-select v-model="model.factoryCategory" placeholder="请选择机构类型">
|
<a-select-option :value="2" v-if="model.parentFactoryCategory!=2">工区</a-select-option>
|
<a-select-option :value="3">工段</a-select-option>
|
</a-select>
|
</a-form-model-item>
|
<a-form-model-item label="排序">
|
<a-input-number v-model="model.sorter"/>
|
</a-form-model-item>
|
<a-form-model-item label="备注">
|
<a-textarea placeholder="请输入备注" v-model="model.remark"/>
|
</a-form-model-item>
|
</a-form-model>
|
</a-modal>
|
</template>
|
|
<script>
|
import { getAction, postAction } from '@/api/manage'
|
import { queryById } from '@/api/api'
|
|
export default {
|
name: 'EamProductionModal',
|
data() {
|
return {
|
departTree: [],
|
title: '操作',
|
seen: false,
|
visible: false,
|
model: {},
|
labelCol: {
|
xs: { span: 24 },
|
sm: { span: 5 }
|
},
|
wrapperCol: {
|
xs: { span: 24 },
|
sm: { span: 16 }
|
},
|
confirmLoading: false,
|
validatorRules: {
|
factoryName: [{ required: true, message: '请输入机构名称!', trigger: 'change' }],
|
factoryCategory: [{ required: true, message: '请选择机构类型!', trigger: 'change' }]
|
},
|
url: {
|
queryById: '/eam/BaseFactory/queryIdTree',
|
add: '/eam/BaseFactory/add'
|
}
|
}
|
},
|
methods: {
|
loadTreeData() {
|
const that = this
|
getAction(that.url.queryById)
|
.then((res) => {
|
if (res.success) {
|
that.departTree = []
|
for (let i = 0; i < res.result.length; i++) {
|
let temp = res.result[i]
|
that.departTree.push(temp)
|
}
|
}
|
})
|
},
|
|
add(record) {
|
if (this.$refs.form) this.$refs.form.clearValidate()
|
const parentFactoryCategory = record ? record.factoryCategory : ''
|
const parentId = record ? record.id : ''
|
if (parentId) this.seen = false
|
else this.seen = true
|
this.visible = true
|
this.model = Object.assign({}, { parentId, parentFactoryCategory })
|
if (parentFactoryCategory == 2) this.model.factoryCategory = +parentFactoryCategory + 1
|
this.loadTreeData()
|
},
|
|
handleOk() {
|
const that = this
|
// 触发表单验证
|
this.$refs.form.validate(valid => {
|
if (valid) {
|
that.confirmLoading = true
|
postAction(this.url.add, this.model)
|
.then((res) => {
|
if (res.success) {
|
that.$notification.success({
|
message: '消息',
|
description: res.message
|
})
|
that.loadTreeData()
|
that.$emit('ok')
|
} else {
|
that.$notification.warning({
|
message: '消息',
|
description: res.message
|
})
|
}
|
})
|
.finally(() => {
|
that.confirmLoading = false
|
that.close()
|
})
|
} else {
|
return false
|
}
|
})
|
},
|
|
close() {
|
this.$emit('close')
|
this.visible = false
|
},
|
|
handleCancel() {
|
this.close()
|
}
|
}
|
}
|
</script>
|