<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="产品编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="code">
|
<a-input v-model="model.code" placeholder="请输入产品编号" ></a-input>
|
</a-form-model-item>
|
</a-col>
|
<a-col :span="24">
|
<a-form-model-item label="产品名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="name">
|
<a-input v-model="model.name" placeholder="请输入产品名称" ></a-input>
|
</a-form-model-item>
|
</a-col>
|
<!-- <a-col :span="24">
|
<a-form-model-item label="产品类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="type">
|
<a-input v-model="model.type" placeholder="请输入产品类型" ></a-input>
|
</a-form-model-item>
|
</a-col>-->
|
|
<a-col :span='24'>
|
<a-form-model-item
|
label='产品类型'
|
:labelCol='labelCol'
|
required
|
:wrapperCol='wrapperCol'>
|
|
<a-tree-select
|
style='width:80%'
|
:treeData='treeData'
|
v-model='model.type'
|
placeholder='请选择产品类型'
|
>
|
</a-tree-select>
|
|
<a-button style='width: 18%;margin-left: 2%' type="primary">
|
新增
|
</a-button>
|
</a-form-model-item>
|
</a-col>
|
|
<a-col :span='24'>
|
<a-form-model-item label='启用状态' :labelCol='labelCol' :wrapperCol='wrapperCol' prop='enabled'>
|
<j-switch v-model='model.enabled'></j-switch>
|
</a-form-model-item>
|
</a-col>
|
|
<a-col :span="24">
|
<!-- <a-form-model-item label="负责人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="principal">
|
<a-input v-model="model.principal" placeholder="请输入负责人" ></a-input>
|
</a-form-model-item>-->
|
|
<a-form-model-item label="负责人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="principal">
|
<j-select-user-by-dep placeholder="请选择负责人" v-model="model.principal" :multi="false"></j-select-user-by-dep>
|
</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'
|
|
export default {
|
name: 'LimsTestingProductForm',
|
components: {
|
},
|
props: {
|
//表单禁用
|
disabled: {
|
type: Boolean,
|
default: false,
|
required: false
|
}
|
},
|
data () {
|
return {
|
model:{
|
},
|
treeData:[],
|
labelCol: {
|
xs: { span: 24 },
|
sm: { span: 5 },
|
},
|
wrapperCol: {
|
xs: { span: 24 },
|
sm: { span: 16 },
|
},
|
confirmLoading: false,
|
validatorRules: {
|
code: [{ required: true, message: '产品编号不能为空', trigger: 'blur' }],
|
name: [{ required: true, message: '产品名称不能为空', trigger: 'blur' }],
|
enabled: [{ required: true, message: '产品使用状态不能为空', trigger: 'blur' }],
|
},
|
url: {
|
listProdType:"/lims/testing/ptype/list",
|
add: "/lims/testing/product/add",
|
edit: "/lims/testing/product/edit",
|
queryById: "/lims/testing/product/queryById"
|
}
|
}
|
},
|
computed: {
|
formDisabled(){
|
return this.disabled
|
},
|
},
|
created () {
|
//备份model原始值
|
this.modelDefault = JSON.parse(JSON.stringify(this.model));
|
},
|
methods: {
|
add () {
|
this.modelDefault.enabled = 1
|
this.edit(this.modelDefault);
|
},
|
edit (record) {
|
this.queryProdTypeList()
|
this.model = Object.assign({}, record);
|
this.visible = true;
|
},
|
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';
|
}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(() => {
|
that.confirmLoading = false;
|
})
|
}
|
|
})
|
},
|
/**
|
* 查询产品类型
|
*/
|
queryProdTypeList(){
|
getAction(this.url.listProdType).then((res)=>{
|
console.info(res)
|
if(res.success){
|
let list = res.result.records
|
// 递归
|
const toTree = (items, id = null, link = 'pid') =>
|
items
|
.filter(item => item[link] == id)
|
.map(item => ({
|
...item,
|
title:item.name,
|
value:item.id,
|
key:item.id,
|
children: toTree(items, item.id)
|
}))
|
|
|
this.treeData = toTree(list)
|
|
}
|
|
})
|
|
}
|
}
|
}
|
</script>
|