<template>
|
<a-spin :spinning="confirmLoading">
|
<j-form-container :disabled="formDisabled">
|
<a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
|
<a-row>
|
<a-col :span="24">
|
<a-form-model-item :label="preLabel+'编码'" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="code">
|
<a-input v-model="model.code" :placeholder="'系统自动生成'+preLabel+'编码'" :disabled="true" ></a-input>
|
</a-form-model-item>
|
</a-col>
|
<a-col :span="24">
|
<a-form-model-item :label="preLabel+'名称'" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="name">
|
<a-input v-model="model.name" :placeholder="'请输入'+preLabel+'名称'" ></a-input>
|
</a-form-model-item>
|
</a-col>
|
<a-col :span="24">
|
<a-form-model-item label="责任组织" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="departId">
|
<a-select v-model="model.departId" placeholder="请选择责任组织">
|
<a-select-option :key="item.id" :value="item.id" v-for="item of departList">
|
{{item.orgCode+"/"+item.departName}}
|
</a-select-option>
|
</a-select>
|
</a-form-model-item>
|
</a-col>
|
<a-col :span="24">
|
<a-form-model-item label="是否虚拟" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="virtualFlag">
|
<a-radio-group button-style="solid" v-model="model.virtualFlag">
|
<a-radio-button :value="0" style="width:100px;text-align: center;">
|
真 实
|
</a-radio-button>
|
<a-radio-button :value="1" style="width:100px;text-align: center;">
|
虚 拟
|
</a-radio-button>
|
</a-radio-group>
|
</a-form-model-item>
|
</a-col>
|
<a-col :span="24">
|
<a-form-model-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="remark">
|
<a-input v-model="model.remark" placeholder="请输入备注"></a-input>
|
</a-form-model-item>
|
</a-col>
|
</a-row>
|
</a-form-model>
|
</j-form-container>
|
</a-spin>
|
</template>
|
|
<script>
|
|
import { httpAction, getAction } from '@/api/manage'
|
import { validateDuplicateValue } from '@/utils/util'
|
import { putAction } from '../../../../api/manage'
|
|
export default {
|
name: 'FactoryModelForm',
|
components: {
|
},
|
props: {
|
//表单禁用
|
disabled: {
|
type: Boolean,
|
default: false,
|
required: false
|
},
|
factoryElementCategoryId:{
|
type: String,
|
default: '',
|
required: false
|
},
|
preLabel:{
|
type: String,
|
default: '',
|
required: false
|
},
|
parentId:{
|
type:String,
|
default:'',
|
required:false
|
},
|
enterpriseId:{
|
type:String,
|
default:'',
|
required:false
|
},
|
version:{
|
type:Number,
|
required:false
|
}
|
},
|
data () {
|
return {
|
departList:[],
|
codeRule:'mom_base_factory_model_code_rule',
|
tempName:'',
|
isUsable:false,
|
model:{
|
},
|
labelCol: {
|
xs: { span: 24 },
|
sm: { span: 5 },
|
},
|
wrapperCol: {
|
xs: { span: 24 },
|
sm: { span: 16 },
|
},
|
confirmLoading: false,
|
validatorRules: {
|
code: [
|
{ required: true, message: '请输入'+this.preLabel+'编码!'},
|
],
|
name: [
|
{ required: true, message: '请输入'+this.preLabel+'名称!'},
|
{ validator:this.validateName},
|
{min:0,max:32,message:'长度超出最大限制,请缩减长度'}
|
],
|
departId: [
|
{ required: true, message: '请选择责任组织'},
|
],
|
virtualFlag:[
|
{ required: true, message: '请选择虚拟状态'},
|
],
|
remark:[
|
{min:0,max:100,message:'长度超出最大限制,请缩减长度'}
|
],
|
},
|
url: {
|
add: "/base/factoryModel/add",
|
edit: "/base/factoryModel/edit",
|
queryById: "/base/factoryModel/queryById",
|
getDepartList:"/base/depart/usableList",
|
ruleBaseURL:"/sys/fillRule/executeRuleByCode",
|
check:"/base/factoryModel/check",
|
getVersion: "/base/factoryModel/getVersionList"
|
}
|
}
|
},
|
computed: {
|
formDisabled(){
|
return this.disabled
|
},
|
},
|
created () {
|
//备份model原始值
|
this.modelDefault = JSON.parse(JSON.stringify(this.model));
|
this.getDepartList();
|
|
},
|
methods: {
|
add () {
|
this.edit(this.modelDefault);
|
},
|
edit (record) {
|
this.model = Object.assign({}, record);
|
if(this.model.id){
|
this.tempName=this.model.name;
|
}
|
this.visible = true;
|
console.log(this.parentId+"=="+this.version+"=="+this.enterpriseId)
|
if(!this.model.id){
|
var ruleCodeParam={
|
parentId:this.parentId,
|
version:this.version?this.version:1,
|
enterpriseId:this.enterpriseId
|
}
|
putAction(this.url.ruleBaseURL+"/"+this.codeRule,ruleCodeParam).then(res=>{
|
this.model.code=res.result;
|
});
|
if(this.version){
|
this.model.version = this.version;
|
}
|
else{
|
this.model.version = 1;
|
}
|
}
|
},
|
submitForm () {
|
const that = this;
|
// 触发表单验证
|
this.$refs.form.validate(valid => {
|
if (valid) {
|
that.confirmLoading = true;
|
let httpurl = '';
|
let method = '';
|
if(!this.model.id){
|
httpurl+=this.url.add;
|
method = 'post';
|
this.model.versionStatus='0';
|
this.model.enterpriseId = this.enterpriseId;
|
this.model.parentId = this.parentId;
|
this.model.factoryElementCategoryId = this.factoryElementCategoryId;
|
}else{
|
httpurl+=this.url.edit;
|
method = 'put';
|
}
|
httpAction(httpurl,this.model,method).then((res)=>{
|
if(res.success){
|
that.$message.success(res.message);
|
that.$emit('ok');
|
}else{
|
that.$message.warning(res.message);
|
}
|
}).finally(() => {
|
this.$emit('reloadUi')
|
that.confirmLoading = false;
|
})
|
}else{
|
this.$emit("changeAddLoading")
|
}
|
|
})
|
},
|
validateName(rule, value, callback){
|
var params = {
|
name:value,
|
version:this.version,
|
parentId:this.parentId
|
};
|
getAction(this.url.check,params).then(res=>{
|
if(res.result.length==0){
|
callback();
|
}
|
else if(this.tempName==value){
|
callback();
|
}
|
else{
|
callback('名称重复,请重新输入');
|
}
|
})
|
},
|
clearInfo(){
|
this.model.orgCode=''
|
var ruleCodeParam={
|
version:this.version,
|
parentId:this.parentId,
|
enterpriseId:this.enterpriseId
|
}
|
putAction(this.url.ruleBaseURL+"/"+this.codeRule,ruleCodeParam).then(res=>{
|
this.model.code=res.result;
|
this.model.name='';
|
this.model.departId='';
|
this.model.remark=''
|
this.model.virtualFlag=''
|
});
|
},
|
getDepartList(){
|
this.confirmLoading=true;
|
getAction(this.url.getDepartList,{enterpriseId:this.enterpriseId}).then(res=>{
|
if(res.success){
|
this.departList = res.result
|
for(var i=0;i<this.departList.length;i++){
|
if(this.departList[i].id==this.model.departId){
|
this.isUsable=true;
|
break;
|
}
|
}
|
if(!this.isUsable&&this.model.id){
|
this.model.departId='';
|
this.$message.warning("当前所属的责任组织已经失效,请重新选择生效版本")
|
}
|
}else{
|
that.$message.warning(res.message);
|
}
|
}).finally(res=>{
|
this.confirmLoading=false
|
})
|
},
|
},
|
}
|
</script>
|