<template>
|
<div class="baseCustomer-container">
|
<el-dialog v-model="isShowDialog" :width="800" draggable="" :close-on-click-modal="false">
|
<template #header>
|
<div style="color: #fff">
|
<!--<el-icon size="16" style="margin-right: 3px; display: inline; vertical-align: middle"> <ele-Edit /> </el-icon>-->
|
<span>{{ props.title }}</span>
|
</div>
|
</template>
|
<el-form :model="ruleForm" ref="ruleFormRef" label-width="auto" :rules="rules">
|
<el-row :gutter="35">
|
<el-form-item v-show="false">
|
<el-input v-model="ruleForm.id" />
|
</el-form-item>
|
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
|
<el-form-item label="编号" prop="custCode">
|
<el-input v-model="ruleForm.custCode" placeholder="请输入编号" maxlength="255" show-word-limit clearable />
|
</el-form-item>
|
</el-col>
|
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
|
<el-form-item label="中文名称" prop="custChinaName">
|
<el-input v-model="ruleForm.custChinaName" placeholder="请输入中文名称" @input="custChinaNameChange" maxlength="255" show-word-limit clearable />
|
|
</el-form-item>
|
|
</el-col>
|
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
|
<el-form-item label="英文名称" prop="custEnglishName">
|
<el-input v-model="ruleForm.custEnglishName" placeholder="请输入英文名称" maxlength="255" show-word-limit clearable />
|
|
</el-form-item>
|
|
</el-col>
|
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
|
<el-form-item label="助记码" prop="mnemonicCode">
|
<el-input v-model="ruleForm.mnemonicCode" placeholder="请输入助记码" maxlength="255" show-word-limit clearable />
|
|
</el-form-item>
|
|
</el-col>
|
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
|
<el-form-item label="类型" prop="custType">
|
<el-select clearable v-model="ruleForm.custType" placeholder="请选择类型">
|
<el-option v-for="(item,index) in dl('BaseCustomerTypeEnum')" :key="index" :value="Number(item.value)" :label="`${item.code}`"></el-option>
|
|
</el-select>
|
|
</el-form-item>
|
|
</el-col>
|
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
|
<el-form-item label="联系人" prop="linkMan">
|
<el-input v-model="ruleForm.linkMan" placeholder="请输入联系人" maxlength="50" show-word-limit clearable />
|
|
</el-form-item>
|
|
</el-col>
|
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
|
<el-form-item label="电话" prop="phone">
|
<el-input v-model="ruleForm.phone" placeholder="请输入电话" maxlength="50" show-word-limit clearable />
|
|
</el-form-item>
|
|
</el-col>
|
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
|
<el-form-item label="电子邮件" prop="email">
|
<el-input v-model="ruleForm.email" placeholder="请输入电子邮件" maxlength="50" show-word-limit clearable />
|
|
</el-form-item>
|
|
</el-col>
|
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
|
<el-form-item label="邮编" prop="zipCode">
|
<el-input v-model="ruleForm.zipCode" placeholder="请输入邮编" maxlength="50" show-word-limit clearable />
|
|
</el-form-item>
|
|
</el-col>
|
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
|
<el-form-item label="省份" prop="province">
|
<!-- <el-input v-model="ruleForm.province" placeholder="请输入省份" maxlength="50" show-word-limit clearable /> -->
|
|
|
<el-select
|
v-model="ruleForm.province"
|
filterable
|
clearable
|
placeholder="请选择所在省"
|
style="width: 100%"
|
@change="changeShi(ruleForm.province)"
|
>
|
<el-option
|
v-for="item in provinceAllEnum"
|
:key="item"
|
:label="item"
|
:value="item"
|
/>
|
</el-select>
|
</el-form-item>
|
|
</el-col>
|
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
|
<el-form-item label="城市" prop="city">
|
<!-- <el-input v-model="ruleForm.city" placeholder="请输入城市" maxlength="50" show-word-limit clearable /> -->
|
|
|
<el-select
|
v-model="ruleForm.city"
|
filterable
|
clearable
|
placeholder="请选择所在市"
|
style="width: 100%"
|
>
|
<el-option
|
v-for="item in cityEnums"
|
:key="item.name"
|
:label="item.name"
|
:value="item.name"
|
/>
|
</el-select>
|
|
</el-form-item>
|
|
</el-col>
|
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
|
<el-form-item label="地址" prop="address">
|
<el-input v-model="ruleForm.address" placeholder="请输入地址" maxlength="255" show-word-limit clearable />
|
|
</el-form-item>
|
|
</el-col>
|
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
|
<el-form-item label="是否禁用" prop="isDisabled">
|
<el-switch v-model="ruleForm.isDisabled" active-text="是" inactive-text="否" />
|
|
</el-form-item>
|
|
</el-col>
|
</el-row>
|
</el-form>
|
<template #footer>
|
<span class="dialog-footer">
|
<el-button @click="cancel">取 消</el-button>
|
<el-button type="primary" @click="submit">确 定</el-button>
|
</span>
|
</template>
|
</el-dialog>
|
</div>
|
</template>
|
<style scoped>
|
:deep(.el-select),
|
:deep(.el-input-number) {
|
width: 100%;
|
}
|
</style>
|
<script lang="ts" setup>
|
import { ref,onMounted } from "vue";
|
import { getDictDataItem as di, getDictDataList as dl } from '/@/utils/dict-utils';
|
import { ElMessage } from "element-plus";
|
import type { FormRules } from "element-plus";
|
|
import {cityEnumsAll,provinceAllEnum} from '/@/utils/enum'
|
|
import { addBaseCustomer, updateBaseCustomer, detailBaseCustomer, getMnemonicCode} from "/@/api/main/WmsBase/baseCustomer";
|
|
//父级传递来的参数
|
var props = defineProps({
|
title: {
|
type: String,
|
default: "",
|
},
|
});
|
//父级传递来的函数,用于回调
|
const emit = defineEmits(["reloadTable"]);
|
const ruleFormRef = ref();
|
const isShowDialog = ref(false);
|
const ruleForm = ref<any>({});
|
|
|
// 校验邮箱格式---不能为空
|
const validatorEmailEmpty = (rule: any, value: any, callback: any) => {
|
const mailReg = /^([a-zA-Z\d][\w-]{2,})@(\w{2,})\.([a-z]{2,})(\.[a-z]{2,})?$/;
|
if (!value) {
|
callback()
|
}
|
setTimeout(() => {
|
if (mailReg.test(value)) {
|
callback();
|
} else {
|
callback(new Error("请输入正确的邮箱格式"));
|
}
|
}, 100);
|
};
|
|
// 校验电话号码---可以为空
|
const validatorTelEmpty = (rule:any, value: any, callback: any) => {
|
if (!value) {
|
callback();
|
} else {
|
const reg = /^1[3|4|5|7|8][0-9]\d{8}$/;
|
if (reg.test(value)) {
|
callback();
|
} else {
|
return callback(new Error("请输入正确的手机号格式"));
|
}
|
}
|
};
|
|
//自行添加其他规则
|
const rules = ref<FormRules>({
|
custCode: [{required: true, message: '请输入编号!', trigger: 'blur',},],
|
custChinaName: [{required: true, message: '请输入中文名称!', trigger: 'blur',},],
|
custType: [{required: true, message: '请选择类型!', trigger: 'change',},],
|
|
email: [{validator: validatorEmailEmpty,trigger: 'blur'}],
|
phone: [{validator: validatorTelEmpty,trigger: 'blur'}]
|
|
});
|
|
// 打开弹窗
|
const openDialog = async (row: any) => {
|
// ruleForm.value = JSON.parse(JSON.stringify(row));
|
// 改用detail获取最新数据来编辑
|
let rowData = JSON.parse(JSON.stringify(row));
|
if (rowData.id)
|
ruleForm.value = (await detailBaseCustomer(rowData.id)).data.result;
|
else
|
ruleForm.value = rowData;
|
isShowDialog.value = true;
|
};
|
|
// 关闭弹窗
|
const closeDialog = () => {
|
emit("reloadTable");
|
isShowDialog.value = false;
|
};
|
|
// 取消
|
const cancel = () => {
|
isShowDialog.value = false;
|
};
|
|
// 提交
|
const submit = async () => {
|
ruleFormRef.value.validate(async (isValid: boolean, fields?: any) => {
|
if (isValid) {
|
let values = ruleForm.value;
|
if (ruleForm.value.id == undefined || ruleForm.value.id == null || ruleForm.value.id == "" || ruleForm.value.id == 0) {
|
await addBaseCustomer(values);
|
} else {
|
await updateBaseCustomer(values);
|
}
|
closeDialog();
|
} else {
|
ElMessage({
|
message: `表单有${Object.keys(fields).length}处验证失败,请修改后再提交`,
|
type: "error",
|
});
|
}
|
});
|
};
|
|
|
|
|
|
|
|
// 页面加载时
|
onMounted(async () => {
|
});
|
|
|
|
|
|
|
const provinceEnum = ref([]);
|
//获取客户列表
|
const getProvinceCurrentList = () => {
|
getProvinceList()
|
.then((res) => {
|
if (res.code == 200) {
|
provinceEnum.value = res.data.reduce((curr: any, item: any) => {
|
curr.push({
|
label: item,
|
value: item
|
});
|
return curr;
|
}, []);
|
} else {
|
;
|
}
|
})
|
.catch((err) => {
|
ElMessage.error(err);
|
});
|
};
|
// getProvinceCurrentList()
|
|
|
// 省市联动
|
const cityEnums = ref([])
|
const changeShi = (itemOut?:any) => {
|
if(itemOut){
|
ruleForm.value.city =""
|
cityEnumsAll.forEach((item:any)=>{
|
if(item.name == itemOut){
|
if(item.children[0].name == '市辖区'){
|
cityEnums.value = [
|
{
|
"name": itemOut
|
}
|
];
|
}else{
|
cityEnums.value = item.children;
|
}
|
}
|
})
|
}
|
}
|
|
/*中文名称值改变调用的方法*/
|
const custChinaNameChange = (chinaName?: any) => {
|
|
if(!chinaName){
|
ruleForm.value.mnemonicCode = '';
|
return;
|
}
|
if(chinaName!=undefined&&!chinaName.trim().length){
|
ruleForm.value.mnemonicCode = '';
|
return;
|
}
|
getMnemonicCode(chinaName)
|
.then((res) => {
|
if (res.data.code == 200) {
|
console.log(res);
|
ruleForm.value.mnemonicCode = res.data.result
|
}
|
// else {
|
// ;
|
// }
|
})
|
.catch((err) => {
|
ElMessage.error(err);
|
});
|
};
|
|
//将属性或者函数暴露给父组件
|
defineExpose({ openDialog });
|
</script>
|