From ab8d587bef7462378e8c4a93d7088fe17cb13845 Mon Sep 17 00:00:00 2001
From: zhengyiming <540361168@qq.com>
Date: 星期二, 28 十月 2025 17:29:51 +0800
Subject: [PATCH] feat: init
---
src/views/CustomerManage/components/AddOrEditCustomerView.vue | 363 +++++++++++++++++++++++++++++++++++++++++++++++++--
src/components/Form/ProFromAddressSelectV2.vue | 4
src/router/index.ts | 8
src/utils/common/common.ts | 31 ++++
4 files changed, 385 insertions(+), 21 deletions(-)
diff --git a/src/components/Form/ProFromAddressSelectV2.vue b/src/components/Form/ProFromAddressSelectV2.vue
index 73a24c3..a324328 100644
--- a/src/components/Form/ProFromAddressSelectV2.vue
+++ b/src/components/Form/ProFromAddressSelectV2.vue
@@ -24,7 +24,7 @@
});
type Props = {
- areaList: number[];
+ areaList: string[];
areaListPlaceholder?: string;
disabled?: boolean;
layer?: AreaType;
@@ -36,7 +36,7 @@
});
const emit = defineEmits<{
- (e: 'update:areaList', val: number[]): void;
+ (e: 'update:areaList', val: string[]): void;
}>();
const { areaList: innerAreaList } = useVModels(props, emit);
diff --git a/src/router/index.ts b/src/router/index.ts
index ca65353..5625665 100644
--- a/src/router/index.ts
+++ b/src/router/index.ts
@@ -124,8 +124,8 @@
{
path: '/AddOrEditCustomer/:id?',
name: 'AddOrEditCustomer',
- hidden: false,
- alwaysShow: true,
+ hidden: true,
+ alwaysShow: false,
component: () => import('@/views/CustomerManage/AddOrEditCustomer.vue'),
meta: {
rank: 10011,
@@ -135,8 +135,8 @@
{
path: '/CustomerDetail/:id',
name: 'CustomerDetail',
- hidden: false,
- alwaysShow: true,
+ hidden: true,
+ alwaysShow: false,
component: () => import('@/views/CustomerManage/CustomerDetail.vue'),
meta: {
rank: 10011,
diff --git a/src/utils/common/common.ts b/src/utils/common/common.ts
index 9965df0..621cf9e 100644
--- a/src/utils/common/common.ts
+++ b/src/utils/common/common.ts
@@ -130,3 +130,34 @@
}
return null;
}
+
+/**
+ * 鍓旈櫎瀵硅薄涓�间负 ''銆乽ndefined銆乶ull 鐨勯敭锛屾敮鎸佸祵濂楀璞�
+ * @param {Object} obj - 闇�瑕佸鐞嗙殑瀵硅薄
+ * @returns {Object} 澶勭悊鍚庣殑鏂板璞�
+ */
+export function removeEmptyKeys<T extends object>(obj: T) {
+ // 濡傛灉涓嶆槸瀵硅薄鎴栦负null锛岀洿鎺ヨ繑鍥炲師鍊�
+ if (obj === null || typeof obj !== 'object') {
+ return obj;
+ }
+
+ // 澶勭悊鏁扮粍锛堥�掑綊澶勭悊姣忎釜鍏冪礌锛�
+ if (Array.isArray(obj)) {
+ return obj.map((item) => removeEmptyKeys(item));
+ }
+
+ // 澶勭悊瀵硅薄
+ const result = {} as T;
+ for (const key in obj) {
+ if (obj.hasOwnProperty(key)) {
+ //@ts-ignore
+ const value = removeEmptyKeys(obj[key]); // 閫掑綊澶勭悊宓屽瀵硅薄
+ // 鍙繚鐣欓潪绌哄�硷紙鎺掗櫎''銆乽ndefined銆乶ull锛�
+ if (value !== '' && value !== undefined && value !== null) {
+ result[key] = value;
+ }
+ }
+ }
+ return result;
+}
diff --git a/src/views/CustomerManage/components/AddOrEditCustomerView.vue b/src/views/CustomerManage/components/AddOrEditCustomerView.vue
index 76fbab5..8377969 100644
--- a/src/views/CustomerManage/components/AddOrEditCustomerView.vue
+++ b/src/views/CustomerManage/components/AddOrEditCustomerView.vue
@@ -1,10 +1,248 @@
<template>
- <div></div>
+ <LoadingLayout :loading="isEdit && isLoading">
+ <AppScrollContainer>
+ <ChunkCell title="浼佷笟鍩烘湰淇℃伅">
+ <ProForm :model="form" ref="formRef" label-width="140px" :is-read="isDetail">
+ <ProFormCol>
+ <ProFormColItem :span="8">
+ <ProFormItemV2
+ label="浼佷笟鍚嶇О:"
+ prop="enterpriseName"
+ :check-rules="[{ message: '璇疯緭鍏ヤ紒涓氬悕绉�' }]"
+ >
+ <ProFormText
+ v-model.trim="form.enterpriseName"
+ :maxlength="30"
+ placeholder="璇疯緭鍏ヤ紒涓氬悕绉�"
+ />
+ </ProFormItemV2>
+ </ProFormColItem>
+ <ProFormColItem :span="8">
+ <ProFormItemV2 label="娉曚汉濮撳悕:" prop="legalPerson">
+ <ProFormText
+ v-model.trim="form.legalPerson"
+ :maxlength="30"
+ placeholder="璇疯緭鍏ユ硶浜哄鍚�"
+ />
+ </ProFormItemV2>
+ </ProFormColItem>
+ <ProFormColItem :span="8">
+ <ProFormItemV2 label="娉曚汉韬唤璇佸彿:" prop="legalIdentity">
+ <ProFormText
+ v-model.trim="form.legalIdentity"
+ :maxlength="30"
+ placeholder="璇疯緭鍏ユ硶浜鸿韩浠借瘉鍙�"
+ />
+ </ProFormItemV2>
+ </ProFormColItem>
+ </ProFormCol>
+ <ProFormCol>
+ <ProFormColItem :span="8">
+ <ProFormItemV2
+ label="缁熶竴绀句細淇$敤浠g爜:"
+ prop="societyCreditCode"
+ :check-rules="[{ message: '璇疯緭鍏ョ粺涓�绀句細淇$敤浠g爜', type: 'societyCreditCode' }]"
+ >
+ <ProFormText
+ v-model.trim="form.societyCreditCode"
+ placeholder="璇疯緭鍏ョ粺涓�绀句細淇$敤浠g爜"
+ />
+ </ProFormItemV2>
+ </ProFormColItem>
+ <ProFormColItem :span="8">
+ <ProFormItemV2
+ label="娉ㄥ唽璧勬湰:"
+ prop="societyCreditCode"
+ :check-rules="[{ message: '璇疯緭鍏ユ敞鍐岃祫鏈�', type: 'societyCreditCode' }]"
+ >
+ <ProFormText v-model.trim="form.societyCreditCode" placeholder="璇疯緭鍏ユ敞鍐岃祫鏈�" />
+ </ProFormItemV2>
+ </ProFormColItem>
+ <ProFormColItem :span="8">
+ <ProFormItemV2
+ label="浼佷笟绫诲瀷:"
+ prop="societyCreditCode"
+ :check-rules="[{ message: '璇疯緭鍏ヤ紒涓氱被鍨�', type: 'societyCreditCode' }]"
+ >
+ <ProFormText v-model.trim="form.societyCreditCode" placeholder="璇疯緭鍏ヤ紒涓氱被鍨�" />
+ </ProFormItemV2>
+ </ProFormColItem>
+ </ProFormCol>
+ <ProFormCol>
+ <ProFormColItem :span="8">
+ <ProFormItemV2
+ label="鎴愮珛鏃ユ湡:"
+ prop="date"
+ :check-rules="[{ message: '璇烽�夋嫨鎴愮珛鏃ユ湡' }]"
+ >
+ <ProFormDatePicker v-model="form.date" type="date" placeholder="璇烽�夋嫨鎴愮珛鏃ユ湡" />
+ </ProFormItemV2>
+ </ProFormColItem>
+ <ProFormColItem :span="8">
+ <ProFormItemV2
+ label="鎵�鍦ㄧ渷浠�:"
+ prop="areaList"
+ :check-rules="[
+ {
+ type: 'array',
+ message: '璇烽�夋嫨',
+ },
+ ]"
+ >
+ <ProFromAddressSelectV2
+ v-model:areaList="form.areaList"
+ areaListPlaceholder="璇烽�夋嫨"
+ :layer="AreaType.City"
+ />
+ </ProFormItemV2>
+ </ProFormColItem>
+ <ProFormColItem :span="8">
+ <ProFormItemV2
+ label="鎵�鍦ㄥ煄甯�:"
+ prop="areaList"
+ :check-rules="[
+ {
+ type: 'array',
+ message: '璇烽�夋嫨',
+ },
+ ]"
+ >
+ <ProFromAddressSelectV2
+ v-model:areaList="form.areaList"
+ areaListPlaceholder="璇烽�夋嫨"
+ :layer="AreaType.City"
+ />
+ </ProFormItemV2>
+ </ProFormColItem>
+ </ProFormCol>
+ <ProFormCol>
+ <ProFormColItem :span="8">
+ <ProFormItemV2
+ label="璇︾粏鍦板潃:"
+ prop="societyCreditCode"
+ :check-rules="[{ message: '璇疯緭鍏ヨ缁嗗湴鍧�' }]"
+ >
+ <ProFormText v-model.trim="form.societyCreditCode" placeholder="璇疯緭鍏ヨ缁嗗湴鍧�" />
+ </ProFormItemV2>
+ </ProFormColItem>
+ </ProFormCol>
+ <ProFormItemV2
+ label="缁忚惀鑼冨洿:"
+ prop="mainBusiness"
+ :check-rules="[{ message: '璇疯緭鍏ョ粡钀ヨ寖鍥�' }]"
+ >
+ <ProFormTextArea
+ v-model="form.mainBusiness"
+ maxlength="200"
+ :rows="6"
+ show-word-limit
+ placeholder="璇疯緭鍏ョ粡钀ヨ寖鍥�"
+ />
+ </ProFormItemV2>
+ </ProForm>
+ </ChunkCell>
+ <ChunkCell title="鍚堜綔淇℃伅">
+ <ProForm
+ :model="form"
+ ref="settingFormRef"
+ label-width="140px"
+ :scroll-to-error="false"
+ :is-read="isDetail"
+ >
+ <ProFormCol>
+ <ProFormColItem :span="8">
+ <ProFormItemV2
+ label="鑱旂郴浜�:"
+ prop="contacts"
+ :check-rules="[{ message: '璇疯緭鍏ヨ仈绯讳汉' }]"
+ >
+ <ProFormText
+ v-model.trim="form.contacts"
+ :maxlength="30"
+ placeholder="璇疯緭鍏ヨ仈绯讳汉"
+ />
+ </ProFormItemV2>
+ </ProFormColItem>
+ <ProFormColItem :span="8">
+ <ProFormItemV2
+ label="鑱旂郴鐢佃瘽:"
+ prop="contactPhoneNumber"
+ :check-rules="[{ message: '璇疯緭鍏ヨ仈绯荤數璇�', type: 'phone' }]"
+ >
+ <ProFormText v-model.trim="form.contactPhoneNumber" placeholder="璇疯緭鍏ヨ仈绯荤數璇�" />
+ </ProFormItemV2>
+ </ProFormColItem>
+ <ProFormColItem :span="8">
+ <ProFormItemV2 label="鑱旂郴閭:" prop="contactEmail">
+ <ProFormText
+ v-model.trim="form.contactEmail"
+ :maxlength="30"
+ placeholder="璇疯緭鍏ヨ仈绯婚偖绠�"
+ :formatter="filterCN"
+ />
+ </ProFormItemV2>
+ </ProFormColItem>
+ </ProFormCol>
+ <ProFormCol>
+ <ProFormColItem :span="8">
+ <ProFormItemV2 label="鍚堜綔鐘舵��:" prop="contacts"> </ProFormItemV2>
+ </ProFormColItem>
+ <ProFormColItem :span="8">
+ <ProFormItemV2 label="绛剧害鐘舵��:" prop="contacts"> </ProFormItemV2>
+ </ProFormColItem>
+ <ProFormColItem :span="8">
+ <ProFormItemV2 label="鍚堜綔鍗忚:" prop="contacts"> </ProFormItemV2>
+ </ProFormColItem>
+ </ProFormCol>
+ </ProForm>
+ </ChunkCell>
+ <ChunkCell title="璐﹀彿淇℃伅">
+ <ProForm
+ :model="form"
+ ref="accountFormRef"
+ label-width="140px"
+ :scroll-to-error="false"
+ :is-read="isDetail"
+ >
+ <ProFormCol>
+ <ProFormColItem :span="8">
+ <ProFormItemV2
+ label="璐﹀彿:"
+ prop="userName"
+ :check-rules="[{ message: '璇疯緭鍏ヨ处鍙�' }]"
+ >
+ <ProFormText
+ v-model.trim="form.userName"
+ :maxlength="30"
+ placeholder="璇疯緭鍏ヨ处鍙�"
+ />
+ </ProFormItemV2>
+ </ProFormColItem>
+ <ProFormColItem :span="8" v-if="!isEdit">
+ <ProFormItemV2
+ label="瀵嗙爜:"
+ prop="password"
+ :check-rules="[{ message: '璇疯緭鍏ュ瘑鐮�' }]"
+ >
+ <ProFormText
+ v-model.trim="form.password"
+ :maxlength="30"
+ placeholder="璇疯緭鍏ュ瘑鐮�"
+ />
+ </ProFormItemV2>
+ </ProFormColItem>
+ </ProFormCol>
+ <div class="chuck-add-or-edit-actions">
+ <el-button @click="handleBack">杩斿洖</el-button>
+ <el-button v-if="!isDetail" type="primary" @click="handleSubmit">纭</el-button>
+ </div>
+ </ProForm>
+ </ChunkCell>
+ </AppScrollContainer>
+ </LoadingLayout>
</template>
<script setup lang="ts">
-import { Message, BoleRegExp } from '@bole-core/core';
-import { useQuery } from '@tanstack/vue-query';
import {
LoadingLayout,
AppScrollContainer,
@@ -16,32 +254,127 @@
ProFormTextArea,
ProFormCol,
ProFormColItem,
+ ProFormDatePicker,
} from '@bole-core/components';
import { FormRules, FormInstance } from 'element-plus';
+import * as enterpriseServices from '@/services/api/enterprise';
+import { useRouteView, useGlobalEventContext, GlobalEvent } from '@/hooks';
+import _ from 'lodash';
+import { validateFormList, filterCN, removeEmptyKeys } from '@/utils';
+import { Message, BoleRegExp } from '@bole-core/core';
+import { useQuery } from '@tanstack/vue-query';
+import { AreaType } from '@/constants';
defineOptions({
name: 'AddOrEditCustomerView',
-})
+});
type Props = {
isDetail: boolean;
-}
+};
-const props = withDefaults(defineProps<Props>(), {
-
-})
+const props = withDefaults(defineProps<Props>(), {});
const route = useRoute();
const id = route.params.id as string;
-const isEdit = !!id;
+const isEdit = !!id;
const { closeViewPush } = useRouteView();
const eventContext = useGlobalEventContext();
+const form = reactive({
+ id: '',
+ enterpriseName: '',
+ legalPerson: '',
+ legalIdentity: '',
+ societyCreditCode: '',
+ industryTypeCode: '',
+ mainBusiness: '',
+ areaList: [] as string[],
+ contacts: '',
+ contactPhoneNumber: '',
+ contactEmail: '',
+ userName: '',
+ password: '',
+ date: '',
+});
+
+const { isLoading } = useQuery({
+ queryKey: ['enterpriseServices/getEnterprise', id],
+ queryFn: async () => {
+ return await enterpriseServices.getEnterprise(
+ { id: id },
+ {
+ showLoading: false,
+ }
+ );
+ },
+ onSuccess(data) {
+ form.id = data.id;
+ form.enterpriseName = data.enterpriseName;
+ form.legalPerson = data.legalPerson;
+ form.legalIdentity = data.legalIdentity;
+ form.societyCreditCode = data.societyCreditCode;
+ form.industryTypeCode = data.industryTypeCode ?? '';
+ form.mainBusiness = data.mainBusiness;
+ form.contacts = data.contacts;
+ form.contactPhoneNumber = data.contactPhoneNumber;
+ form.contactEmail = data.contactEmail;
+ form.userName = data.userName;
+ form.areaList = [data.provinceCode, data.cityCode].filter(Boolean);
+ },
+ enabled: computed(() => !!id),
+});
+
+const formRef = ref<FormInstance>();
+const settingFormRef = ref<FormInstance>();
+const accountFormRef = ref<FormInstance>();
+
+async function handleSubmit() {
+ try {
+ const valid = await validateFormList([
+ formRef.value,
+ settingFormRef.value,
+ accountFormRef.value,
+ ]);
+ if (valid) {
+ handleCreateOrEditFlexEnterprise();
+ }
+ } catch (error) {}
+}
+
+async function handleCreateOrEditFlexEnterprise() {
+ try {
+ let params: API.SaveEnterpriseCommand = {
+ enterpriseName: form.enterpriseName,
+ legalPerson: form.legalPerson,
+ legalIdentity: form.legalIdentity,
+ societyCreditCode: form.societyCreditCode,
+ provinceCode: form.areaList[0],
+ cityCode: form.areaList[1],
+ industryTypeCode: form.industryTypeCode,
+ mainBusiness: form.mainBusiness,
+ contacts: form.contacts,
+ contactPhoneNumber: form.contactPhoneNumber,
+ contactEmail: form.contactEmail,
+ userName: form.userName,
+ password: form.password,
+ };
+ if (isEdit) {
+ params.id = id;
+ }
+ let res = await enterpriseServices.saveEnterprise(removeEmptyKeys(params));
+ if (res) {
+ Message.successMessage(isEdit ? '缂栬緫鎴愬姛' : '鍙戝竷鎴愬姛');
+ eventContext.emit(isEdit ? 'customerManage:edit' : 'customerManage:add');
+ handleBack();
+ }
+ } catch (error) {}
+}
+
+function handleBack() {
+ closeViewPush(route, {
+ name: 'EnterpriseManageList',
+ });
+}
</script>
-
-<style lang="scss" scoped>
-@use '@/style/common.scss' as *;
-
-</style>
-
--
Gitblit v1.9.1