wupengfei
2025-03-21 ca8fc597599e8a85288b5d771957bb1bd712e8c7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
<template>
  <LoadingLayout :loading="isEdit && isLoading">
    <AppScrollContainer>
      <ChunkCell title="企业基本信息">
        <ProForm :model="form" :rules="rules" ref="formRef" label-width="120px" :is-read="isDetail">
          <ProFormCol>
            <ProFormColItem :span="12">
              <ProFormItemV2 label="企业名称:" prop="enterpriseName">
                <ProFormText
                  v-model.trim="form.enterpriseName"
                  :maxlength="30"
                  placeholder="请输入供应商名称"
                />
              </ProFormItemV2>
            </ProFormColItem>
          </ProFormCol>
          <ProFormCol>
            <ProFormColItem :span="12">
              <ProFormItemV2 label="法人姓名:" prop="legalPersonName">
                <ProFormText
                  v-model.trim="form.legalPersonName"
                  :maxlength="30"
                  placeholder="请输入法人姓名"
                />
              </ProFormItemV2>
            </ProFormColItem>
          </ProFormCol>
          <ProFormCol>
            <ProFormColItem :span="12">
              <ProFormItemV2 label="法人身份证号:" prop="legalPersonIdNumber">
                <ProFormText
                  v-model.trim="form.legalPersonIdNumber"
                  :maxlength="30"
                  placeholder="请输入法人身份证号"
                />
              </ProFormItemV2>
            </ProFormColItem>
          </ProFormCol>
          <ProFormCol>
            <ProFormColItem :span="12">
              <ProFormItemV2 label="统一社会信用代码:" prop="societyCreditCode">
                <ProFormText
                  v-model.trim="form.societyCreditCode"
                  placeholder="请输入统一社会信用代码"
                />
              </ProFormItemV2>
            </ProFormColItem>
          </ProFormCol>
          <ProFormCol>
            <ProFormColItem :span="12">
              <ProFormItemV2 label="所在省份:" prop="proviceName">
                <ProFormText
                  v-model.trim="form.proviceName"
                  :maxlength="30"
                  placeholder="请输入所在省份"
                />
              </ProFormItemV2>
            </ProFormColItem>
          </ProFormCol>
          <ProFormCol>
            <ProFormColItem :span="12">
              <ProFormItemV2 label="所属行业:" prop="belongIndustryType">
                <ProFormSelect
                  placeholder="请选择所属行业"
                  :value-enum="typeList"
                  enum-value-key="id"
                  enum-label-key="name"
                  clearable
                  v-model="form.belongIndustryType"
                ></ProFormSelect>
              </ProFormItemV2>
            </ProFormColItem>
          </ProFormCol>
          <ProFormCol>
            <ProFormColItem :span="12">
              <ProFormItemV2 label="所在城市:" prop="cityName">
                <ProFormText
                  v-model.trim="form.cityName"
                  :maxlength="30"
                  placeholder="请输入所在城市"
                />
              </ProFormItemV2>
            </ProFormColItem>
          </ProFormCol>
          <ProFormCol>
            <ProFormColItem :span="24">
              <ProFormItemV2 label="主营业务:" prop="cityName">
                <ProFormTextArea
                  v-model="form.cityName"
                  maxlength="200"
                  :rows="6"
                  show-word-limit
                  placeholder="请输入主营业务"
                />
              </ProFormItemV2>
            </ProFormColItem>
          </ProFormCol>
        </ProForm>
      </ChunkCell>
      <ChunkCell title="联系信息">
        <ProForm
          :model="form"
          :rules="rules"
          ref="settingFormRef"
          label-width="140px"
          :scroll-to-error="false"
          :is-read="isDetail"
        >
          <ProFormCol>
            <ProFormColItem :span="12">
              <ProFormItemV2 label="联系人:" prop="contact">
                <ProFormText
                  v-model.trim="form.contact"
                  :maxlength="30"
                  placeholder="请输入联系人"
                />
              </ProFormItemV2>
            </ProFormColItem>
          </ProFormCol>
          <ProFormCol>
            <ProFormColItem :span="12">
              <ProFormItemV2 label="联系电话:" prop="contactPhone">
                <ProFormText v-model.trim="form.contactPhone" placeholder="请输入联系电话" />
              </ProFormItemV2>
            </ProFormColItem>
          </ProFormCol>
          <ProFormCol>
            <ProFormColItem :span="12">
              <ProFormItemV2 label="邮箱:" prop="email">
                <ProFormText
                  v-model.trim="form.email"
                  :maxlength="30"
                  placeholder="请输入邮箱"
                  :formatter="filterCN"
                />
              </ProFormItemV2>
            </ProFormColItem>
          </ProFormCol>
        </ProForm>
      </ChunkCell>
      <ChunkCell title="账号信息">
        <ProForm
          :model="form"
          :rules="rules"
          ref="accountFormRef"
          label-width="140px"
          :scroll-to-error="false"
          :is-read="isDetail"
        >
          <ProFormCol>
            <ProFormColItem :span="12">
              <ProFormItemV2 label="账号:" prop="contact">
                <ProFormText v-model.trim="form.contact" :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 {
  LoadingLayout,
  AppScrollContainer,
  ProForm,
  ProFormItemV2,
  ChunkCell,
  ProFormText,
  ProFormSelect,
  ProFormTextArea,
  ProFormCol,
  ProFormColItem,
} from '@bole-core/components';
import { FormRules, FormInstance } from 'element-plus';
import { SearchType } from '@/constants';
import * as flexEnterpriseServices from '@/services/api/FlexEnterprise';
import { useRouteView, useGlobalEventContext, GlobalEvent, useSearchSettingType } from '@/hooks';
import _ from 'lodash';
import { validateFormList, filterCN } from '@/utils';
import { Message, BoleRegExp } from '@bole-core/core';
import { useQuery } from '@tanstack/vue-query';
 
defineOptions({ name: 'AddOrEditEnterpriseView' });
 
type Props = {
  isDetail: boolean;
  id?: string;
  emitAddEvent?: keyof GlobalEvent;
  emitEditEvent?: keyof GlobalEvent;
  backRouteName?: string;
};
 
const props = withDefaults(defineProps<Props>(), {
  id: '',
  emitAddEvent: 'enterprise:add',
  emitEditEvent: 'enterprise:edit',
  backRouteName: 'EnterpriseManageList',
});
 
const route = useRoute();
const isEdit = computed(() => !!props.id);
const { closeViewPush } = useRouteView();
const eventContext = useGlobalEventContext();
 
const { searchSettingTypeList: typeList } = useSearchSettingType({
  searchType: SearchType.IndustryCategory,
});
 
const form = reactive({
  id: '',
  enterpriseName: '',
  legalPersonName: '',
  legalPersonIdNumber: '',
  societyCreditCode: '',
  proviceName: '',
  cityName: '',
  belongIndustryType: '',
  contact: '',
  contactPhone: '',
  email: '',
});
 
onMounted(async () => {});
 
const { isLoading } = useQuery({
  //   queryKey: ['insureSupplierService/getInsureSupplierInfoById', props.id],
  //   queryFn: async () => {
  //     return await insureSupplierService.getInsureSupplierInfoById(
  //       { id: props.id },
  //       {
  //         showLoading: false,
  //       }
  //     );
  //   },
  onSuccess(data) {},
  enabled: computed(() => !!props.id),
});
 
const formRef = ref<FormInstance>();
const settingFormRef = ref<FormInstance>();
const accountFormRef = ref<FormInstance>();
 
const rules = reactive<FormRules>({
  enterpriseName: [{ required: true, message: '请输入企业名称', trigger: 'blur' }],
  contact: [{ required: true, message: '请输入联系人', trigger: 'blur' }],
  contactPhone: [
    { required: true, message: '请输入联系电话', trigger: 'blur' },
    { message: '请输入正确的联系电话', trigger: 'blur', pattern: BoleRegExp.RegPhoneNumber },
  ],
});
 
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.CreateOrEditFlexEnterpriseInput = {
      enterpriseName: form.enterpriseName,
      legalPersonName: form.legalPersonName,
      legalPersonIdNumber: form.legalPersonIdNumber,
      societyCreditCode: form.societyCreditCode,
      proviceName: form.proviceName,
      cityName: form.cityName,
      belongIndustryType: form.belongIndustryType,
      contact: form.contact,
      contactPhone: form.contactPhone,
      // email: form.email,
    };
    if (isEdit.value) {
      params.id = props.id;
    }
    let res = await flexEnterpriseServices.createOrEditFlexEnterprise(params);
    if (res) {
      Message.successMessage(isEdit ? '编辑成功' : '发布成功');
      eventContext.emit(isEdit ? 'enterprise:edit' : 'enterprise:add');
      handleBack();
    }
  } catch (error) {}
}
 
function handleBack() {
  closeViewPush(route, {
    name: 'EnterpriseManageList',
  });
}
</script>
 
<style lang="scss" scoped>
@use '@/style/common.scss' as *;
</style>