add.vue 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798
  1. <template>
  2. <div class="p-4">
  3. <!-- 企业基本信息 -->
  4. <el-card shadow="never" class="mb-4">
  5. <template #header>
  6. <span class="font-medium"
  7. >企业基本信息/ <span style="color: #ff0033"> 客户编号:{{ customerNumber }} </span></span
  8. >
  9. <el-button style="float: right" type="primary" @click="handleSubmit" :loading="submitLoading">保存</el-button>
  10. </template>
  11. <el-form ref="formRef" :model="form" :rules="rules" label-width="120px">
  12. <el-row :gutter="20">
  13. <el-col :span="8">
  14. <el-form-item label="所属公司" prop="belongCompanyId">
  15. <el-select v-model="form.belongCompanyId" placeholder="请选择所属公司" class="w-full" filterable>
  16. <el-option v-for="item in companyList" :key="item.id" :label="`${item.companyCode} , ${item.companyName}`" :value="item.id" />
  17. </el-select>
  18. </el-form-item>
  19. </el-col>
  20. <el-col :span="8">
  21. <el-form-item label="客户名称" prop="customerName">
  22. <el-input v-model="form.customerName" placeholder="请输入客户名称" />
  23. </el-form-item>
  24. </el-col>
  25. <el-col :span="8">
  26. <el-form-item label="工商名称" prop="businessCustomerName">
  27. <el-input v-model="form.businessCustomerName" placeholder="请输入工商名称" />
  28. </el-form-item>
  29. </el-col>
  30. </el-row>
  31. <el-row :gutter="20">
  32. <el-col :span="8">
  33. <el-form-item label="企业简称" prop="shortName">
  34. <el-input v-model="form.shortName" placeholder="请输入企业简称" />
  35. </el-form-item>
  36. </el-col>
  37. <el-col :span="8">
  38. <el-form-item label="开票类型" prop="invoiceTypeId">
  39. <el-select v-model="form.invoiceTypeId" placeholder="请选择开票类型" class="w-full">
  40. <el-option v-for="item in invoiceTypeList" :key="item.id" :label="item.invoiceTypeName" :value="item.id" />
  41. </el-select>
  42. </el-form-item>
  43. </el-col>
  44. <el-col :span="8">
  45. <el-form-item label="企业规模" prop="enterpriseScaleId">
  46. <el-select v-model="form.enterpriseScaleId" placeholder="请选择企业规模" class="w-full" filterable>
  47. <el-option v-for="item in enterpriseScaleList" :key="item.id" :label="item.enterpriseScaleName" :value="item.id" />
  48. </el-select>
  49. </el-form-item>
  50. </el-col>
  51. </el-row>
  52. <el-row :gutter="20">
  53. <el-col :span="8">
  54. <el-form-item label="客户类别" prop="customerTypeId">
  55. <el-select v-model="form.customerTypeId" placeholder="请选择客户类别" class="w-full">
  56. <el-option v-for="dict in customer_type" :key="dict.value" :label="dict.label" :value="dict.value" />
  57. </el-select>
  58. </el-form-item>
  59. </el-col>
  60. <el-col :span="8">
  61. <el-form-item label="行业类别" prop="industryCategoryId">
  62. <el-select v-model="form.industryCategoryId" placeholder="请选择行业类别" class="w-full" filterable>
  63. <el-option v-for="item in industryCategoryList" :key="item.id" :label="item.industryCategoryName" :value="item.id" />
  64. </el-select>
  65. </el-form-item>
  66. </el-col>
  67. <el-col :span="8">
  68. <el-form-item label="客户等级" prop="customerLevelId">
  69. <el-select v-model="form.customerLevelId" placeholder="请选择客户等级" class="w-full">
  70. <el-option v-for="dict in customer_level" :key="dict.value" :label="dict.label" :value="dict.value" />
  71. </el-select>
  72. </el-form-item>
  73. </el-col>
  74. </el-row>
  75. <el-row :gutter="20">
  76. <el-col :span="8">
  77. <el-form-item label="固定电话" prop="landline">
  78. <el-input v-model="form.landline" placeholder="请输入固定电话" />
  79. </el-form-item>
  80. </el-col>
  81. <el-col :span="8">
  82. <el-form-item label="传真" prop="fax">
  83. <el-input v-model="form.fax" placeholder="请输入传真" />
  84. </el-form-item>
  85. </el-col>
  86. <el-col :span="8">
  87. <el-form-item label="网址" prop="url">
  88. <el-input v-model="form.url" placeholder="请输入网址" />
  89. </el-form-item>
  90. </el-col>
  91. </el-row>
  92. <el-row :gutter="20">
  93. <el-col :span="8">
  94. <el-form-item label="邮政编码" prop="postCode">
  95. <el-input v-model="form.postCode" placeholder="请输入邮政编码" />
  96. </el-form-item>
  97. </el-col>
  98. <el-col :span="8">
  99. <el-form-item label="开始时间" prop="validityFromDate">
  100. <el-date-picker v-model="form.validityFromDate" type="date" placeholder="请选择开始时间" class="w-full" style="width: 100%" />
  101. </el-form-item>
  102. </el-col>
  103. <el-col :span="8">
  104. <el-form-item label="结束时间" prop="validityToDate">
  105. <el-date-picker
  106. v-model="form.validityToDate"
  107. type="date"
  108. placeholder="请选择结束时间"
  109. class="w-full"
  110. style="width: 100%"
  111. :disabled-date="(time) => form.validityFromDate && time.getTime() < new Date(form.validityFromDate).getTime()"
  112. />
  113. </el-form-item>
  114. </el-col>
  115. </el-row>
  116. <el-row :gutter="20">
  117. <el-col :span="8">
  118. <el-form-item label="发票抬头" prop="invoiceTop">
  119. <el-input v-model="form.invoiceTop" placeholder="请输入发票抬头" />
  120. </el-form-item>
  121. </el-col>
  122. <el-col :span="8">
  123. <el-form-item label="详细地址" prop="address">
  124. <el-cascader v-model="codeArr" :options="regionData" placeholder="请选择" @change="handleChange" style="width: 100%"></el-cascader>
  125. </el-form-item>
  126. </el-col>
  127. <el-col :span="8">
  128. <el-form-item>
  129. <el-input v-model="form.address" placeholder="请输入详细地址" />
  130. </el-form-item>
  131. </el-col>
  132. </el-row>
  133. </el-form>
  134. </el-card>
  135. <!-- 工商信息 -->
  136. <el-card shadow="never" class="mb-4">
  137. <template #header>
  138. <span class="font-medium">工商信息</span>
  139. </template>
  140. <el-form :model="businessForm" label-width="120px">
  141. <el-row :gutter="20">
  142. <el-col :span="8">
  143. <el-form-item label="企业工商名称" prop="businessCustomerName">
  144. <el-input v-model="businessForm.businessCustomerName" placeholder="请输入企业工商名称" :disabled="true" />
  145. </el-form-item>
  146. </el-col>
  147. <el-col :span="8">
  148. <el-form-item label="社会信用代码" prop="socialCreditCode">
  149. <el-input v-model="businessForm.socialCreditCode" placeholder="请输入社会信用代码" :disabled="true" />
  150. </el-form-item>
  151. </el-col>
  152. <el-col :span="8">
  153. <el-form-item label="法人姓名" prop="legalPersonName">
  154. <el-input v-model="businessForm.legalPersonName" placeholder="请输入法人姓名" :disabled="true" />
  155. </el-form-item>
  156. </el-col>
  157. </el-row>
  158. <el-row :gutter="20">
  159. <el-col :span="8">
  160. <el-form-item label="注册资本" prop="registeredCapital">
  161. <el-input v-model="businessForm.registeredCapital" placeholder="请输入注册资本" :disabled="true" />
  162. </el-form-item>
  163. </el-col>
  164. <el-col :span="8">
  165. <el-form-item label="登记机关" prop="registrationAuthority">
  166. <el-input v-model="businessForm.registrationAuthority" placeholder="请输入登记机关" :disabled="true" />
  167. </el-form-item>
  168. </el-col>
  169. <el-col :span="8">
  170. <el-form-item label="成立日期" prop="establishmentDate">
  171. <el-input v-model="businessForm.establishmentDate" class="w-full" :disabled="true" />
  172. </el-form-item>
  173. </el-col>
  174. </el-row>
  175. <el-row :gutter="20">
  176. <el-col :span="8">
  177. <el-form-item label="吊销日期" prop="revocationDate">
  178. <el-input v-model="businessForm.revocationDate" class="w-full" :disabled="true" />
  179. </el-form-item>
  180. </el-col>
  181. <el-col :span="8">
  182. <el-form-item label="登记状态" prop="registrationStatus">
  183. <el-input v-model="businessForm.registrationStatus" placeholder="请输入登记状态" :disabled="true" />
  184. </el-form-item>
  185. </el-col>
  186. <el-col :span="8">
  187. <el-form-item label="实缴资本" prop="paidInCapital">
  188. <el-input v-model="businessForm.paidInCapital" placeholder="请输入实缴资本" :disabled="true" />
  189. </el-form-item>
  190. </el-col>
  191. </el-row>
  192. <el-row :gutter="20">
  193. <el-col :span="16">
  194. <el-form-item label="详细地址" prop="businessAddress">
  195. <el-input v-model="businessForm.businessAddress" placeholder="请输入详细地址" :disabled="true" />
  196. </el-form-item>
  197. </el-col>
  198. </el-row>
  199. <el-row :gutter="20">
  200. <el-col :span="24">
  201. <el-form-item label="营业执照" prop="businessLicense">
  202. <div
  203. v-if="!businessForm.businessLicense"
  204. class="upload-box"
  205. @click="businessLicenseSelectorVisible = true"
  206. style="
  207. width: 360px;
  208. height: 200px;
  209. border: 2px dashed #d9d9d9;
  210. border-radius: 4px;
  211. display: flex;
  212. align-items: center;
  213. justify-content: center;
  214. cursor: pointer;
  215. transition: all 0.3s;
  216. "
  217. @mouseenter="(e) => (e.currentTarget.style.borderColor = '#409eff')"
  218. @mouseleave="(e) => (e.currentTarget.style.borderColor = '#d9d9d9')"
  219. >
  220. <div style="text-align: center; color: #8c939d">
  221. <el-icon :size="40" style="margin-bottom: 8px">
  222. <Plus />
  223. </el-icon>
  224. <div style="font-size: 14px">点击上传</div>
  225. </div>
  226. </div>
  227. <div v-else style="position: relative; display: inline-block">
  228. <el-image
  229. :src="businessForm.businessLicense"
  230. style="width: 360px; height: 200px"
  231. fit="contain"
  232. :preview-src-list="[businessForm.businessLicense]"
  233. />
  234. <el-button
  235. type="danger"
  236. :icon="Delete"
  237. circle
  238. size="small"
  239. style="position: absolute; top: 5px; right: 5px"
  240. @click="businessForm.businessLicense = ''"
  241. />
  242. </div>
  243. </el-form-item>
  244. </el-col>
  245. </el-row>
  246. </el-form>
  247. </el-card>
  248. <!-- 营业执照选择器对话框 -->
  249. <FileSelector
  250. v-model="businessLicenseSelectorVisible"
  251. title="选择营业执照"
  252. :allowed-types="[1]"
  253. :multiple="false"
  254. :allow-upload="true"
  255. @confirm="handleBusinessLicenseSelected"
  256. />
  257. <!-- 联系人信息列表 -->
  258. <el-card shadow="never" class="mb-4">
  259. <template #header>
  260. <div class="flex justify-between items-center">
  261. <span class="font-medium">联系人信息列表</span>
  262. <el-button type="primary" @click="handleAddContact">添加联系人</el-button>
  263. </div>
  264. </template>
  265. <el-table :data="contactList" border>
  266. <el-table-column type="index" label="序号" align="center" width="60" />
  267. <el-table-column label="联系人姓名" align="center" prop="contactName" min-width="120" />
  268. <el-table-column label="职位" align="center" prop="roleId" min-width="120">
  269. <template #default="{ row }">
  270. <span>{{ getRoleName(row.roleId) }}</span>
  271. </template>
  272. </el-table-column>
  273. <el-table-column label="手机号" align="center" prop="phone" min-width="150" />
  274. <el-table-column label="固定电话" align="center" prop="officePhone" min-width="150" />
  275. <el-table-column label="邮箱地址" align="center" prop="email" min-width="180" />
  276. <el-table-column label="备注信息" align="center" prop="remark" min-width="180" />
  277. <el-table-column label="操作" align="center" width="150" fixed="right">
  278. <template #default="{ row, $index }">
  279. <el-button link type="primary" @click="handleEditContact(row, $index)">编辑</el-button>
  280. <el-button link type="danger" @click="removeContact($index)">删除</el-button>
  281. </template>
  282. </el-table-column>
  283. </el-table>
  284. </el-card>
  285. <!-- 添加/编辑联系人对话框 -->
  286. <add-contact-dialog v-model="contactDialogVisible" :edit-data="currentContact" @confirm="handleContactConfirm" />
  287. <!-- 销售信息 -->
  288. <el-card shadow="never" class="mb-4">
  289. <template #header>
  290. <div class="flex justify-between items-center">
  291. <span class="font-medium">销售信息</span>
  292. <el-button type="primary" @click="handleSubmit">保存</el-button>
  293. </div>
  294. </template>
  295. <el-form :model="salesForm" label-width="120px">
  296. <el-row :gutter="20">
  297. <el-col :span="8">
  298. <el-form-item label="业务人员" prop="salesPersonId">
  299. <el-select v-model="salesForm.salesPersonId" placeholder="请选择业务人员" class="w-full" filterable>
  300. <el-option label="张三" value="1" />
  301. <el-option label="李四" value="2" />
  302. <el-option label="王五" value="3" />
  303. <el-option label="赵六" value="4" />
  304. </el-select>
  305. </el-form-item>
  306. </el-col>
  307. <el-col :span="8">
  308. <el-form-item label="客服人员" prop="serviceStaffId">
  309. <el-select v-model="salesForm.serviceStaffId" placeholder="请选择客服人员" class="w-full" filterable>
  310. <el-option label="客服A" value="1" />
  311. <el-option label="客服B" value="2" />
  312. <el-option label="客服C" value="3" />
  313. <el-option label="客服D" value="4" />
  314. </el-select>
  315. </el-form-item>
  316. </el-col>
  317. <el-col :span="8">
  318. <el-form-item label="所属部门" prop="belongingDepartmentId">
  319. <el-select v-model="salesForm.belongingDepartmentId" placeholder="请选择所属部门" class="w-full" filterable disabled>
  320. <el-option label="销售部" value="1" />
  321. <el-option label="市场部" value="2" />
  322. <el-option label="客服部" value="3" />
  323. <el-option label="技术部" value="4" />
  324. </el-select>
  325. </el-form-item>
  326. </el-col>
  327. </el-row>
  328. </el-form>
  329. </el-card>
  330. <!-- 企业开票信息 -->
  331. <el-card shadow="never" class="mb-4">
  332. <template #header>
  333. <div class="flex justify-between items-center">
  334. <span class="font-medium">企业开票信息</span>
  335. <el-button type="primary" @click="handleAddInvoice">新增</el-button>
  336. </div>
  337. </template>
  338. <el-table :data="invoiceList" border>
  339. <el-table-column type="index" label="序号" align="center" width="60" />
  340. <el-table-column label="纳税人识别号" align="center" prop="taxId" min-width="180" />
  341. <el-table-column label="开户行名称" align="center" prop="bankName" min-width="180" />
  342. <el-table-column label="银行账户" align="center" prop="bankAccount" min-width="180" />
  343. <el-table-column label="是否主账号" align="center" prop="isPrimaryAccount" min-width="120">
  344. <template #default="{ row }">
  345. <span>{{ row.isPrimaryAccount === '0' ? '是' : '否' }}</span>
  346. </template>
  347. </el-table-column>
  348. <el-table-column label="备注" align="center" prop="remark" min-width="180" />
  349. <el-table-column label="操作" align="center" width="150" fixed="right">
  350. <template #default="{ row, $index }">
  351. <el-button link type="primary" @click="handleEditInvoice(row, $index)">编辑</el-button>
  352. <el-button link type="danger" @click="removeInvoice($index)">删除</el-button>
  353. </template>
  354. </el-table-column>
  355. </el-table>
  356. </el-card>
  357. <!-- 添加/编辑开票信息对话框 -->
  358. <add-invoice-dialog v-model="invoiceDialogVisible" :edit-data="currentInvoice" @confirm="handleInvoiceConfirm" />
  359. </div>
  360. </template>
  361. <script setup lang="ts" name="CustomerInfoAdd">
  362. import { listCustomerInfo, getCustomerInfo, addCustomerInfo } from '@/api/customer/customerFile/customerInfo';
  363. import { CustomerInfoForm } from '@/api/customer/customerFile/customerInfo/types';
  364. import { listInvoiceType } from '@/api/customer/invoiceType';
  365. import { InvoiceTypeVO, InvoiceTypeQuery } from '@/api/customer/invoiceType/types';
  366. import FileSelector from '@/components/FileSelector/index.vue';
  367. import { generateCustomerNumber } from '@/utils/customerNumber';
  368. import type { CustomerContactForm } from '@/api/customer/customerFile/customerContact/types';
  369. import type { InvoiceInfoForm } from '@/api/customer/customerFile/invoiceInfo/types';
  370. import type { SalesInfoForm } from '@/api/customer/customerFile/salesInfo/types';
  371. import type { BusinessInfoForm } from '@/api/customer/customerFile/businessInfo/types';
  372. import AddContactDialog from './components/addContactDialog.vue';
  373. import AddInvoiceDialog from './components/addInvoiceDialog.vue';
  374. import { regionData } from 'element-china-area-data';
  375. import { listEnterpriseScale } from '@/api/customer/customerCategory/enterpriseScale';
  376. import { listIndustryCategory } from '@/api/customer/customerCategory/industryCategory';
  377. import type { EnterpriseScaleVO } from '@/api/customer/customerCategory/enterpriseScale/types';
  378. import type { IndustryCategoryVO } from '@/api/customer/customerCategory/industryCategory/types';
  379. import { listSysCompany } from '@/api/company/sysCompany';
  380. import type { SysCompanyVO } from '@/api/company/sysCompany/types';
  381. import { Plus, Delete } from '@element-plus/icons-vue';
  382. const { proxy } = getCurrentInstance() as ComponentInternalInstance;
  383. const { customer_type, customer_level } = toRefs<any>(proxy?.useDict('customer_type', 'customer_level'));
  384. const route = useRoute();
  385. const router = useRouter();
  386. const formRef = ref<any>(null);
  387. const submitLoading = ref(false);
  388. // 生成客户编号
  389. const customerNumber = ref('');
  390. const isEdit = ref(false);
  391. const customerId = ref<string>('');
  392. const codeArr = ref([]);
  393. // 下拉框数据列表
  394. const enterpriseScaleList = ref<EnterpriseScaleVO[]>([]);
  395. const industryCategoryList = ref<IndustryCategoryVO[]>([]);
  396. const invoiceTypeList = ref<InvoiceTypeVO[]>([]);
  397. const companyList = ref<SysCompanyVO[]>([]);
  398. // Logo选择器相关
  399. const logoSelectorVisible = ref(false);
  400. const businessLicenseSelectorVisible = ref(false);
  401. // Logo选择处理
  402. const handleLogoSelected = (files: any[]) => {
  403. if (files && files.length > 0) {
  404. const file = files[0]; // 取第一个文件
  405. if (file && (file.url || file.path)) {
  406. // form.value.logo = file.url || file.path;
  407. ElMessage.success('Logo选择成功');
  408. // 选择完成后清理表单验证状态
  409. nextTick(() => {
  410. formRef.value?.clearValidate();
  411. });
  412. } else {
  413. ElMessage.error('请选择有效的图片文件');
  414. }
  415. } else {
  416. ElMessage.error('请选择有效的图片文件');
  417. }
  418. };
  419. // 营业执照选择处理
  420. const handleBusinessLicenseSelected = (files: any[]) => {
  421. if (files && files.length > 0) {
  422. const file = files[0]; // 取第一个文件
  423. if (file && (file.url || file.path)) {
  424. businessForm.businessLicense = file.url || file.path;
  425. ElMessage.success('营业执照选择成功');
  426. // 选择完成后清理表单验证状态
  427. nextTick(() => {
  428. formRef.value?.clearValidate('businessLicense');
  429. });
  430. } else {
  431. ElMessage.error('请选择有效的图片文件');
  432. }
  433. } else {
  434. ElMessage.error('请选择有效的图片文件');
  435. }
  436. };
  437. // 监听对话框关闭,清理表单验证状态
  438. watch(logoSelectorVisible, (newVal) => {
  439. if (!newVal) {
  440. // 对话框关闭后清理可能的表单验证状态
  441. nextTick(() => {
  442. formRef.value?.clearValidate();
  443. });
  444. }
  445. });
  446. // 初始化
  447. onMounted(async () => {
  448. // 加载下拉框数据
  449. await loadEnterpriseScaleList();
  450. await loadIndustryCategoryList();
  451. await loadInvoiceTypeList();
  452. await loadCompanyList();
  453. // 判断是新增还是编辑
  454. const id = route.query.id;
  455. if (id) {
  456. // 编辑模式
  457. isEdit.value = true;
  458. customerId.value = id as string;
  459. await loadCustomerData(id);
  460. } else {
  461. // 新增模式,生成客户编号
  462. customerNumber.value = generateCustomerNumber();
  463. }
  464. });
  465. // 加载客户数据(编辑模式)
  466. const loadCustomerData = async (id: string) => {
  467. try {
  468. const res = await getCustomerInfo(id);
  469. const data = res.data;
  470. // 填充基本信息
  471. Object.assign(form, data);
  472. customerNumber.value = data.customerNo || '';
  473. // 填充工商信息
  474. if (data.customerBusinessInfoVo) {
  475. Object.assign(businessForm, data.customerBusinessInfoVo);
  476. }
  477. // 填充销售信息
  478. if (data.customerSalesInfoVo) {
  479. Object.assign(salesForm, data.customerSalesInfoVo);
  480. }
  481. // 填充联系人列表
  482. if (data.customerContactVoList) {
  483. contactList.value = data.customerContactVoList;
  484. }
  485. // 填充开票信息列表
  486. if (data.customerInvoiceInfoVoList) {
  487. invoiceList.value = data.customerInvoiceInfoVoList;
  488. }
  489. // 如果有省市区编码,回显到级联选择器
  490. if (data.regProvincialNo && data.regCityNo && data.regCountyNo) {
  491. codeArr.value = [data.regProvincialNo, data.regCityNo, data.regCountyNo] as any;
  492. }
  493. } catch (error) {
  494. console.error('加载客户数据失败:', error);
  495. ElMessage.error('加载客户数据失败');
  496. }
  497. };
  498. // 加载企业规模列表
  499. const loadEnterpriseScaleList = async () => {
  500. try {
  501. const res = await listEnterpriseScale();
  502. enterpriseScaleList.value = res.rows || [];
  503. } catch (error) {
  504. console.error('加载企业规模列表失败:', error);
  505. }
  506. };
  507. // 加载行业类别列表
  508. const loadIndustryCategoryList = async () => {
  509. try {
  510. const res = await listIndustryCategory();
  511. industryCategoryList.value = res.rows || [];
  512. } catch (error) {
  513. console.error('加载行业类别列表失败:', error);
  514. }
  515. };
  516. // 加载开票类型列表
  517. const loadInvoiceTypeList = async () => {
  518. try {
  519. const res = await listInvoiceType();
  520. invoiceTypeList.value = res.rows || [];
  521. } catch (error) {
  522. console.error('加载开票类型列表失败:', error);
  523. }
  524. };
  525. // 加载公司列表
  526. const loadCompanyList = async () => {
  527. try {
  528. const res = await listSysCompany();
  529. companyList.value = res.rows || [];
  530. } catch (error) {
  531. console.error('加载公司列表失败:', error);
  532. }
  533. };
  534. // 企业基本信息表单
  535. const form = reactive<CustomerInfoForm>({
  536. customerNo: '',
  537. belongCompanyId: undefined,
  538. companyName: '',
  539. businessCustomerName: '',
  540. shortName: '',
  541. invoiceTypeId: undefined,
  542. enterpriseScaleId: undefined,
  543. customerTypeId: undefined,
  544. industryCategoryId: undefined,
  545. customerLevelId: undefined,
  546. landline: '',
  547. fax: '',
  548. url: '',
  549. postCode: '',
  550. validityFromDate: undefined,
  551. validityToDate: undefined,
  552. invoiceTop: '',
  553. address: '',
  554. status: '0',
  555. remark: ''
  556. });
  557. // 工商信息
  558. const businessForm = reactive<BusinessInfoForm>({
  559. businessCustomerName: '',
  560. socialCreditCode: '',
  561. legalPersonName: '',
  562. registeredCapital: '',
  563. registrationAuthority: '',
  564. establishmentDate: '',
  565. revocationDate: '',
  566. registrationStatus: '',
  567. paidInCapital: undefined,
  568. businessAddress: '',
  569. businessLicense: '',
  570. status: '0'
  571. });
  572. // 联系人列表
  573. const contactList = ref<CustomerContactForm[]>([]);
  574. const contactDialogVisible = ref(false);
  575. const currentContact = ref<CustomerContactForm | undefined>(undefined);
  576. const currentContactIndex = ref<number>(-1);
  577. // 销售信息
  578. const salesForm = reactive<SalesInfoForm>({
  579. salesPersonId: undefined,
  580. serviceStaffId: undefined,
  581. belongingDepartmentId: undefined,
  582. status: '0'
  583. });
  584. // 开票信息列表
  585. const invoiceList = ref<InvoiceInfoForm[]>([]);
  586. const invoiceDialogVisible = ref(false);
  587. const currentInvoice = ref<InvoiceInfoForm | undefined>(undefined);
  588. const currentInvoiceIndex = ref<number>(-1);
  589. // 表单验证规则
  590. const rules = {
  591. belongCompanyId: [{ required: true, message: '请选择所属公司', trigger: 'change' }],
  592. customerName: [{ required: true, message: '请输入客户名称', trigger: 'blur' }],
  593. businessCustomerName: [{ required: true, message: '请输入工商名称', trigger: 'blur' }],
  594. shortName: [{ required: true, message: '请输入企业简称', trigger: 'blur' }],
  595. invoiceTypeId: [{ required: true, message: '请选择开票类型', trigger: 'change' }],
  596. enterpriseScaleId: [{ required: true, message: '请选择企业规模', trigger: 'change' }],
  597. customerTypeId: [{ required: true, message: '请选择客户类别', trigger: 'change' }],
  598. industryCategoryId: [{ required: true, message: '请选择行业类别', trigger: 'change' }],
  599. customerLevelId: [{ required: true, message: '请选择客户等级', trigger: 'change' }],
  600. address: [{ required: true, message: '请输入详细地址', trigger: 'blur' }]
  601. };
  602. // 获取角色名称
  603. const getRoleName = (roleId: string | number | undefined) => {
  604. const roleMap: Record<string, string> = {
  605. '1': '采购经理',
  606. '2': '财务',
  607. '3': '其他'
  608. };
  609. return roleMap[String(roleId)] || '-';
  610. };
  611. // 打开添加联系人对话框
  612. const handleAddContact = () => {
  613. currentContact.value = undefined;
  614. currentContactIndex.value = -1;
  615. contactDialogVisible.value = true;
  616. };
  617. /** 处理区域选择变化 */
  618. const handleChange = (val: string[]) => {
  619. // 保存编码
  620. form.regProvincialNo = val[0];
  621. form.regCityNo = val[1];
  622. form.regCountyNo = val[2];
  623. // 根据编码获取名称
  624. const names: string[] = [];
  625. if (val[0]) {
  626. const province = regionData.find((item: any) => item.value === val[0]);
  627. if (province) {
  628. names.push(province.label);
  629. if (val[1] && province.children) {
  630. const city = province.children.find((item: any) => item.value === val[1]);
  631. if (city) {
  632. names.push(city.label);
  633. if (val[2] && city.children) {
  634. const county = city.children.find((item: any) => item.value === val[2]);
  635. if (county) {
  636. names.push(county.label);
  637. }
  638. }
  639. }
  640. }
  641. }
  642. }
  643. // 将省市区名称用斜杠连接
  644. form.provincialCityCounty = names.join('/');
  645. };
  646. // 编辑联系人
  647. const handleEditContact = (row: CustomerContactForm, index: number) => {
  648. currentContact.value = { ...row };
  649. currentContactIndex.value = index;
  650. contactDialogVisible.value = true;
  651. };
  652. // 确认添加/编辑联系人
  653. const handleContactConfirm = (data: CustomerContactForm) => {
  654. if (currentContactIndex.value >= 0) {
  655. // 编辑
  656. contactList.value[currentContactIndex.value] = data;
  657. } else {
  658. // 新增
  659. contactList.value.push(data);
  660. }
  661. };
  662. // 删除联系人
  663. const removeContact = (index: number) => {
  664. ElMessageBox.confirm('确定要删除该联系人吗?', '提示', {
  665. confirmButtonText: '确定',
  666. cancelButtonText: '取消',
  667. type: 'warning'
  668. })
  669. .then(() => {
  670. contactList.value.splice(index, 1);
  671. ElMessage.success('删除成功');
  672. })
  673. .catch(() => {});
  674. };
  675. // 打开添加开票信息对话框
  676. const handleAddInvoice = () => {
  677. currentInvoice.value = undefined;
  678. currentInvoiceIndex.value = -1;
  679. invoiceDialogVisible.value = true;
  680. };
  681. // 编辑开票信息
  682. const handleEditInvoice = (row: InvoiceInfoForm, index: number) => {
  683. currentInvoice.value = { ...row };
  684. currentInvoiceIndex.value = index;
  685. invoiceDialogVisible.value = true;
  686. };
  687. // 确认添加/编辑开票信息
  688. const handleInvoiceConfirm = (data: InvoiceInfoForm) => {
  689. if (currentInvoiceIndex.value >= 0) {
  690. // 编辑
  691. invoiceList.value[currentInvoiceIndex.value] = data;
  692. } else {
  693. // 新增
  694. invoiceList.value.push(data);
  695. }
  696. };
  697. // 删除开票信息
  698. const removeInvoice = (index: number) => {
  699. ElMessageBox.confirm('确定要删除该开票信息吗?', '提示', {
  700. confirmButtonText: '确定',
  701. cancelButtonText: '取消',
  702. type: 'warning'
  703. })
  704. .then(() => {
  705. invoiceList.value.splice(index, 1);
  706. ElMessage.success('删除成功');
  707. })
  708. .catch(() => {});
  709. };
  710. // 提交表单
  711. const handleSubmit = async () => {
  712. try {
  713. await formRef.value?.validate();
  714. submitLoading.value = true;
  715. // 将客户编号赋值到表单
  716. form.customerNo = customerNumber.value;
  717. // 组装提交数据,按照后端要求的结构
  718. const submitData: CustomerInfoForm = {
  719. ...form,
  720. customerBusinessBo: businessForm,
  721. customerSalesInfoBo: salesForm,
  722. customerContactBoList: contactList.value,
  723. customerInvoiceInfoBoList: invoiceList.value
  724. };
  725. await addCustomerInfo(submitData);
  726. ElMessage.success('添加成功');
  727. router.back();
  728. } catch (error) {
  729. console.error('保存失败:', error);
  730. ElMessage.error('保存失败,请重试');
  731. } finally {
  732. submitLoading.value = false;
  733. }
  734. };
  735. </script>