<template>
|
<a-modal
|
:title="title"
|
:width="800"
|
: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
|
:labelCol="{span:3}"
|
:wrapperCol="{span:21}"
|
label="供应商编号"
|
>
|
<a-input
|
:disabled="disableSubmit"
|
allow-clear
|
placeholder="请输入供应商编号"
|
v-decorator="['supplierCode', validatorRules.supplierCode ]"
|
/>
|
</a-form-item>
|
</a-col>
|
</a-row>
|
|
<a-row :gutter="24">
|
<a-col :span="24">
|
<a-form-item
|
:labelCol="{span:3}"
|
:wrapperCol="{span:21}"
|
label="供应商名称"
|
>
|
<a-input
|
:disabled="disableSubmit"
|
allow-clear
|
placeholder="请输入供应商名称"
|
v-decorator="['supplierName', validatorRules.supplierName ]"
|
/>
|
</a-form-item>
|
</a-col>
|
</a-row>
|
<a-row :gutter="24">
|
<a-col :span="12">
|
<a-form-item
|
:labelCol="labelCol"
|
:wrapperCol="wrapperCol"
|
label="国家"
|
>
|
<a-input
|
:disabled="disableSubmit"
|
allow-clear
|
placeholder="请输入国家"
|
v-decorator="['country', validatorRules.country ]"
|
/>
|
<!-- <j-dict-select-tag
|
:disabled="disableSubmit"
|
placeholder="请选择国家"
|
:triggerChange="true"
|
dictCode="country_list"
|
v-decorator="['country', validatorRules.country]"
|
/> -->
|
</a-form-item>
|
</a-col>
|
<a-col :span="12">
|
<a-form-item
|
:labelCol="labelCol"
|
:wrapperCol="wrapperCol"
|
label="省份"
|
>
|
<a-input
|
:disabled="disableSubmit"
|
allow-clear
|
placeholder="请输入省份"
|
v-decorator="['province', validatorRules.province ]"
|
/>
|
</a-form-item>
|
</a-col>
|
</a-row>
|
|
<a-row :gutter="24">
|
<a-col :span="12">
|
<a-form-item
|
:labelCol="labelCol"
|
:wrapperCol="wrapperCol"
|
label="城市"
|
>
|
<a-input
|
:disabled="disableSubmit"
|
allow-clear
|
placeholder="请输入城市"
|
v-decorator="['city', validatorRules.city ]"
|
/>
|
</a-form-item>
|
</a-col>
|
<a-col :span="12">
|
<a-form-item
|
:labelCol="labelCol"
|
:wrapperCol="wrapperCol"
|
label="联系人"
|
>
|
<a-input
|
:disabled="disableSubmit"
|
allow-clear
|
placeholder="请输入联系人"
|
v-decorator="['contact', validatorRules.contact]"
|
/>
|
</a-form-item>
|
</a-col>
|
</a-row>
|
|
<a-row :gutter="24">
|
<a-col :span="24">
|
<a-form-item
|
:labelCol="{span:3}"
|
:wrapperCol="{span:21}"
|
label="详细地址"
|
>
|
<a-input
|
:disabled="disableSubmit"
|
allow-clear
|
placeholder="请输入详细地址"
|
v-decorator="['address', validatorRules.address]"
|
/>
|
</a-form-item>
|
</a-col>
|
</a-row>
|
|
<a-row :gutter="24">
|
<a-col :span="12">
|
<a-form-item
|
:labelCol="labelCol"
|
:wrapperCol="wrapperCol"
|
label="邮箱"
|
>
|
<a-input
|
:disabled="disableSubmit"
|
allow-clear
|
placeholder="请输入邮箱"
|
v-decorator="['email', validatorRules.email]"
|
/>
|
</a-form-item>
|
</a-col>
|
<a-col :span="12">
|
<a-form-item
|
:labelCol="labelCol"
|
:wrapperCol="wrapperCol"
|
label="邮编"
|
>
|
<a-input
|
:disabled="disableSubmit"
|
allow-clear
|
placeholder="请输入邮编"
|
v-decorator="['postcode', validatorRules.postcode]"
|
/>
|
</a-form-item>
|
</a-col>
|
</a-row>
|
|
<a-row :gutter="24">
|
<a-col :span="12">
|
<a-form-item
|
:labelCol="labelCol"
|
:wrapperCol="wrapperCol"
|
label="传真"
|
>
|
<a-input
|
:disabled="disableSubmit"
|
allow-clear
|
placeholder="请输入传真"
|
v-decorator="['fax', validatorRules.fax]"
|
/>
|
</a-form-item>
|
</a-col>
|
<a-col :span="12">
|
<a-form-item
|
:labelCol="labelCol"
|
:wrapperCol="wrapperCol"
|
label="手机号码"
|
>
|
<a-input
|
:disabled="disableSubmit"
|
allow-clear
|
placeholder="请输入手机号码"
|
v-decorator="['phone', validatorRules.phone]"
|
/>
|
</a-form-item>
|
</a-col>
|
</a-row>
|
|
<a-row :gutter="24">
|
<a-col :span="12">
|
<a-form-item
|
:labelCol="labelCol"
|
:wrapperCol="wrapperCol"
|
label="公司电话"
|
>
|
<a-input
|
:disabled="disableSubmit"
|
allow-clear
|
placeholder="请输入公司电话"
|
v-decorator="['companyTelephone', validatorRules.companyTelephone]"
|
/>
|
</a-form-item>
|
</a-col>
|
<a-col :span="12">
|
<a-form-item
|
:labelCol="labelCol"
|
:wrapperCol="wrapperCol"
|
label="官方网站"
|
>
|
<a-input
|
:disabled="disableSubmit"
|
allow-clear
|
placeholder="请输入官方网站"
|
v-decorator="['officialWebsite', validatorRules.officialWebsite]"
|
/>
|
</a-form-item>
|
</a-col>
|
</a-row>
|
|
<a-row :gutter="24">
|
<a-col :span="24">
|
<a-form-item
|
:labelCol="{span:3}"
|
:wrapperCol="{span:21}"
|
label="备注"
|
>
|
<a-textarea
|
:disabled="disableSubmit"
|
placeholder="请输入备注"
|
allow-clear
|
v-decorator="['remark', validatorRules.remark]"
|
/>
|
</a-form-item>
|
</a-col>
|
</a-row>
|
|
</a-form>
|
</a-spin>
|
</a-modal>
|
</template>
|
|
<script>
|
import { httpAction, getAction } from '@/api/manage'
|
import JDate from '@/components/jeecg/JDate'
|
import pick from 'lodash.pick'
|
import moment from 'moment'
|
import { duplicateCheck } from '@/api/api'//重复校验
|
import JTreeDict from '@/components/jeecg/JTreeDict'//分类字典树形下拉组件
|
|
export default {
|
name: "SpplierModal",
|
components: {
|
JDate,
|
JTreeDict,
|
},
|
data() {
|
return {
|
editorValue: '',
|
title: "操作",
|
visible: false,
|
disableSubmit: false,
|
model: {},
|
treeData: [],
|
supplierId: "", //保存供应商id
|
labelCol: {
|
xs: { span: 24 },
|
sm: { span: 6 },
|
},
|
wrapperCol: {
|
xs: { span: 24 },
|
sm: { span: 18 },
|
},
|
|
confirmLoading: false,
|
form: this.$form.createForm(this),
|
validatorRules: {
|
supplierCode: {
|
rules: [
|
{ required: true, message: '请输入编号' },
|
{ min: 2, max: 30, message: '长度在 2 到 30 个字符', trigger: 'blur' },
|
{ validator: this.validateNum },
|
]
|
},
|
supplierName: {
|
rules: [
|
{ required: true, message: '请输入名称' },
|
{ min: 0, max: 64, message: '长度不超过 64 个字符', trigger: 'blur' },
|
{ validator: this.validateName },
|
]
|
},
|
country: {
|
rules: [
|
{ required: true, message: '请选择国家' },
|
]
|
},
|
address: {
|
rules: [
|
{ min: 0, max: 100, message: '最长 100 个字符', trigger: 'blur' },
|
]
|
},
|
postcode: {
|
rules: [
|
{ pattern: /^[0-9]{6}$/, message: '请输入正确邮编' },
|
]
|
},
|
email: {
|
rules: [
|
{ validator: this.validateEmail },
|
]
|
},
|
contact: {
|
rules: [
|
{ min: 0, max: 30, message: '最长 30 个字符', trigger: 'blur' },
|
]
|
},
|
fax: {
|
rules: [
|
{ min: 0, max: 30, message: '最长 30 个字符', trigger: 'blur' },
|
// { pattern: /^0\d{2,3}-[1-9]\d{6,7}$/, message: '请输入正确传真' },
|
]
|
},
|
phone: {
|
rules: [
|
{ validator: this.validatePhone },
|
]
|
},
|
companyTelephone: {
|
rules: [
|
{ min: 0, max: 30, message: '最长 30 个字符', trigger: 'blur' },
|
// { pattern: /^0\d{2,3}-[1-9]\d{6,7}$/, message: '请输入正确座机号码' },
|
]
|
},
|
officialWebsite: {
|
rules: [
|
{ pattern: /^([hH][tT]{2}[pP]:\/\/|[hH][tT]{2}[pP][sS]:\/\/|www\.)(([A-Za-z0-9-~]+)\.)+([A-Za-z0-9-~\/])+$/, message: '请输入正确网络地址' },
|
]
|
},
|
remark: {
|
rules: [
|
{ min: 0, max: 100, message: '最长 100 个字符', trigger: 'blur' },
|
]
|
},
|
},
|
url: {
|
add: "/base/supplier/add",
|
edit: "/base/supplier/edit",
|
},
|
}
|
},
|
created() {
|
},
|
methods: {
|
add() {
|
this.edit({});
|
},
|
edit(record) {
|
this.form.resetFields();
|
this.model = Object.assign({}, record);
|
this.supplierId = record.id;
|
this.visible = true;
|
this.$nextTick(() => {
|
this.form.setFieldsValue(
|
pick(this.model, 'supplierCode', 'supplierName', 'country','province','city', 'address', 'contact', 'postcode', 'fax', 'email', 'phone', 'companyTelephone', 'officialWebsite', 'remark')
|
)
|
//时间格式化
|
});
|
},
|
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()
|
},
|
//验证 编号
|
validateNum(rule, value, callback) {
|
var params = {
|
tableName: 'base_supplier',
|
fieldName: 'supplier_code',
|
fieldVal: value,
|
dataId: this.supplierId,
|
//数据库中存在字段del_flag并使用该字段作为未删除策略,真删除:false 假删除:true
|
delFlag: 'true',
|
};
|
duplicateCheck(params).then((res) => {
|
if (res.success) {
|
callback();
|
} else {
|
callback("供应商编号已存在!");
|
}
|
})
|
},
|
//验证 名称
|
validateName(rule, value, callback) {
|
var params = {
|
tableName: 'base_supplier',
|
fieldName: 'supplier_name',
|
fieldVal: value,
|
dataId: this.supplierId,
|
//数据库中存在字段del_flag并使用该字段作为未删除策略,真删除:false 假删除:true
|
delFlag: 'true',
|
};
|
duplicateCheck(params).then((res) => {
|
if (res.success) {
|
callback();
|
} else {
|
callback("供应商名称已存在!");
|
}
|
})
|
},
|
//验证 手机号
|
validatePhone(rule, value, callback) {
|
if (!value) {
|
callback()
|
} else {
|
//[05] 手机号不支持199号码段--------------------
|
if (new RegExp(/^1[3|4|5|7|8|9][0-9]\d{8}$/).test(value)) {
|
var params = {
|
tableName: 'base_supplier',
|
fieldName: 'phone',
|
fieldVal: value,
|
dataId: this.supplierId
|
};
|
duplicateCheck(params).then((res) => {
|
if (res.success) {
|
callback()
|
} else {
|
callback("手机号已存在!")
|
}
|
})
|
} else {
|
callback("请输入正确格式的手机号码!");
|
}
|
}
|
},
|
//验证 Email
|
validateEmail(rule, value, callback) {
|
if (!value) {
|
callback()
|
} else {
|
if (new RegExp(/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/).test(value)) {
|
var params = {
|
tableName: 'base_supplier',
|
fieldName: 'email',
|
fieldVal: value,
|
dataId: this.supplierId
|
};
|
duplicateCheck(params).then((res) => {
|
console.log(res)
|
if (res.success) {
|
callback()
|
} else {
|
callback("邮箱已存在!")
|
}
|
})
|
} else {
|
callback("请输入正确格式的邮箱!")
|
}
|
}
|
},
|
// 关闭弹窗时清除表单校验
|
removeValidate() {
|
if (this.$refs.form) this.$refs.form.clearValidate()
|
}
|
}
|
}
|
</script>
|
|
<style scoped>
|
.ant-btn {
|
padding: 0 10px;
|
margin-left: 3px;
|
}
|
|
.ant-form-item-control {
|
line-height: 0px;
|
}
|
|
/** 主表单行间距 */
|
.ant-form .ant-form-item {
|
margin-bottom: 10px;
|
}
|
|
/** Tab页面行间距 */
|
.ant-tabs-content .ant-form-item {
|
margin-bottom: 0px;
|
}
|
</style>
|