<template>
|
<a-modal
|
:title="title"
|
:width="600"
|
:visible="visible"
|
:maskClosable="false"
|
:confirmLoading="confirmLoading"
|
:okButtonProps="{ props: {disabled: disableSubmit} }"
|
@ok="handleOk"
|
@cancel="handleCancel"
|
cancelText="关闭"
|
>
|
<a-spin :spinning="confirmLoading">
|
<a-form :form="form">
|
<a-row :gutter="24">
|
<a-col :span="24">
|
<a-form-item
|
label="单据名称"
|
:labelCol="{span:4}"
|
:wrapperCol="{span:18}"
|
>
|
<a-input
|
allow-clear
|
:disabled="false"
|
:placeholder="disableSubmit?'':'请输入单据名称'"
|
v-decorator="[ 'functionName', validatorRules.functionName]"
|
/>
|
</a-form-item>
|
</a-col>
|
</a-row>
|
<a-row :gutter="24">
|
<a-col :span="24">
|
<a-form-item
|
label="固定字符"
|
:labelCol="{span:4}"
|
:wrapperCol="{span:18}"
|
>
|
<a-input
|
allow-clear
|
:disabled="false"
|
:placeholder="disableSubmit?'':'请输入固定字符'"
|
v-decorator="[ 'beginSymbol', validatorRules.beginSymbol]"
|
/>
|
</a-form-item>
|
</a-col>
|
</a-row>
|
<!-- <a-row :gutter="24">
|
<a-col :span="24">
|
<a-form-item
|
label="企业代码"
|
:labelCol="{span:4}"
|
:wrapperCol="{span:18}"
|
>
|
<a-input
|
allow-clear
|
:disabled="codeDisable"
|
:placeholder="disableSubmit?'':'请输入企业代码'"
|
v-decorator="[ 'enterpriseCode', validatorRules.enterpriseCode]"
|
/>
|
</a-form-item>
|
</a-col>
|
</a-row> -->
|
<a-row :gutter="24">
|
<a-col :span="24">
|
<a-form-item
|
label="类型"
|
:labelCol="{span:4}"
|
:wrapperCol="{span:18}"
|
>
|
<a-input
|
allow-clear
|
:disabled="codeDisable"
|
:placeholder="disableSubmit?'':'请输入类型'"
|
v-decorator="[ 'type', validatorRules.type]"
|
/>
|
</a-form-item>
|
</a-col>
|
</a-row>
|
|
</a-form>
|
</a-spin>
|
|
<template slot="footer">
|
<a-button
|
:style="{marginRight: '8px'}"
|
@click="handleCancel"
|
>
|
关闭
|
</a-button>
|
<a-button
|
:disabled="confirmLoading"
|
:loading="confirmLoading"
|
@click="handleOk"
|
type="primary"
|
>确定</a-button>
|
<!-- icon="save" -->
|
</template>
|
|
</a-modal>
|
</template>
|
|
<script>
|
import pick from 'lodash.pick'
|
import { httpAction } from '@/api/manage'
|
import { duplicateCheck } from '@/api/api'
|
|
export default {
|
name: 'SerialNumberModel',
|
data() {
|
return {
|
title: '',
|
visible: false,
|
disableSubmit: false,
|
codeDisable: true,
|
model: {},
|
labelCol: {
|
xs: { span: 24 },
|
sm: { span: 6 },
|
},
|
wrapperCol: {
|
xs: { span: 24 },
|
sm: { span: 18 },
|
},
|
confirmLoading: false,
|
form: this.$form.createForm(this),
|
validatorRules: {
|
functionName: {
|
rules: [
|
{ required: true, message: '请输入单据名称!' },
|
{ min: 0, max: 30, message: '长度不超过 30 个字符', trigger: 'blur' },
|
]
|
},
|
beginSymbol: {
|
rules: [
|
{ required: true, message: '请输入固定字符!' },
|
{ min: 0, max: 30, message: '长度不超过 30 个字符', trigger: 'blur' },
|
{ validator: this.validateName },
|
]
|
},
|
// enterpriseCode: {
|
// rules: [
|
// { required: true, message: '请输入企业代码!' },
|
// { min: 0, max: 30, message: '长度不超过 30 个字符', trigger: 'blur' },
|
// ]
|
// },
|
type: {
|
rules: [
|
{ required: true, message: '请输入类型!' },
|
{ min: 0, max: 90, message: '长度不超过 90 个字符', trigger: 'blur' },
|
{ validator: this.validateType },
|
]
|
},
|
},
|
url: {
|
add: '/eam/serialNumber/add',
|
edit: '/eam/serialNumber/edit',
|
},
|
}
|
},
|
|
methods: {
|
add() {
|
this.edit({})
|
},
|
edit(record) {
|
this.form.resetFields()
|
this.model = Object.assign({}, record)
|
this.visible = true
|
this.$nextTick(() => {
|
this.form.setFieldsValue(pick(this.model, 'functionName', 'beginSymbol', 'enterpriseCode', 'type'))
|
})
|
if (record.id) {
|
this.codeDisable = true;
|
} else {
|
this.codeDisable = false;
|
}
|
},
|
close() {
|
this.$emit('close')
|
this.visible = false
|
},
|
handleOk() {
|
const that = this
|
// 触发表单验证
|
this.form.validateFields((err, values) => {
|
if (!err) {
|
that.confirmLoading = true
|
let httpurl = ''
|
let method = ''
|
if (!this.model.id) {
|
httpurl += this.url.add
|
method = 'post'
|
} else {
|
httpurl += this.url.edit
|
method = 'put'
|
}
|
let formData = Object.assign(this.model, values)
|
httpAction(httpurl, formData, method)
|
.then((res) => {
|
if (res.success) {
|
that.$message.success(res.message)
|
that.$emit('ok')
|
} else {
|
that.$message.warning(res.message)
|
}
|
})
|
.finally(() => {
|
that.confirmLoading = false
|
that.close()
|
})
|
}
|
})
|
},
|
handleCancel() {
|
this.close()
|
},
|
|
//验证 固定字符
|
validateName(rule, value, callback) {
|
var params = {
|
tableName: 'mom_serial_number_map',
|
fieldName: 'begin_symbol',
|
fieldVal: value,
|
dataId: this.model.id,
|
//数据库中存在字段del_flag并使用该字段作为未删除策略,真删除:false 假删除:true
|
delFlag: 'true',
|
};
|
duplicateCheck(params).then((res) => {
|
if (res.success) {
|
callback();
|
} else {
|
callback("固定字符已存在!");
|
}
|
})
|
},
|
//验证 类型
|
validateType(rule, value, callback) {
|
var params = {
|
tableName: 'mom_serial_number_map',
|
fieldName: 'type',
|
fieldVal: value,
|
dataId: this.model.id,
|
//数据库中存在字段del_flag并使用该字段作为未删除策略,真删除:false 假删除:true
|
delFlag: 'true',
|
};
|
duplicateCheck(params).then((res) => {
|
if (res.success) {
|
callback();
|
} else {
|
callback("类型已存在!");
|
}
|
})
|
},
|
},
|
}
|
</script>
|
|
<style lang="less" scoped>
|
</style>
|