add.vue 34 KB

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