add.vue 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998
  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 @change="handCompanyChange">
  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="请输入客户名称"> </el-input>
  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="请输入工商名称" @blur="selectBusinessBtn"> </el-input>
  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="请输入发票抬头" disabled />
  135. </el-form-item>
  136. </el-col>
  137. <el-col :span="8">
  138. <el-form-item label="详细地址" prop="address">
  139. <el-cascader
  140. v-model="codeArr"
  141. :options="regionData as any"
  142. placeholder="请选择"
  143. @change="handleChange"
  144. style="width: 100%"
  145. ></el-cascader>
  146. </el-form-item>
  147. </el-col>
  148. <el-col :span="8">
  149. <el-form-item>
  150. <el-input v-model="form.address" placeholder="请输入详细地址" />
  151. </el-form-item>
  152. </el-col>
  153. </el-row>
  154. </el-form>
  155. </el-card>
  156. <!-- 工商信息 -->
  157. <el-card shadow="never" class="mb-4">
  158. <template #header>
  159. <span class="font-medium">工商信息</span>
  160. </template>
  161. <el-form :model="businessForm" label-width="120px">
  162. <el-row :gutter="20">
  163. <el-col :span="8">
  164. <el-form-item label="企业工商名称" prop="businessCustomerName">
  165. <el-input v-model="businessForm.businessCustomerName" placeholder="请输入企业工商名称" :disabled="true" />
  166. </el-form-item>
  167. </el-col>
  168. <el-col :span="8">
  169. <el-form-item label="社会信用代码" prop="socialCreditCode">
  170. <el-input v-model="businessForm.socialCreditCode" placeholder="请输入社会信用代码" :disabled="true" />
  171. </el-form-item>
  172. </el-col>
  173. <el-col :span="8">
  174. <el-form-item label="法人姓名" prop="legalPersonName">
  175. <el-input v-model="businessForm.legalPersonName" placeholder="请输入法人姓名" :disabled="true" />
  176. </el-form-item>
  177. </el-col>
  178. </el-row>
  179. <el-row :gutter="20">
  180. <el-col :span="8">
  181. <el-form-item label="注册资本" prop="registeredCapital">
  182. <el-input v-model="businessForm.registeredCapital" placeholder="请输入注册资本" :disabled="true" />
  183. </el-form-item>
  184. </el-col>
  185. <el-col :span="8">
  186. <el-form-item label="登记机关" prop="registrationAuthority">
  187. <el-input v-model="businessForm.registrationAuthority" placeholder="请输入登记机关" :disabled="true" />
  188. </el-form-item>
  189. </el-col>
  190. <el-col :span="8">
  191. <el-form-item label="成立日期" prop="establishmentDate">
  192. <el-input v-model="businessForm.establishmentDate" class="w-full" :disabled="true" />
  193. </el-form-item>
  194. </el-col>
  195. </el-row>
  196. <el-row :gutter="20">
  197. <el-col :span="8">
  198. <el-form-item label="吊销日期" prop="revocationDate">
  199. <el-input v-model="businessForm.revocationDate" class="w-full" :disabled="true" />
  200. </el-form-item>
  201. </el-col>
  202. <el-col :span="8">
  203. <el-form-item label="登记状态" prop="registrationStatus">
  204. <el-input v-model="businessForm.registrationStatus" placeholder="请输入登记状态" :disabled="true" />
  205. </el-form-item>
  206. </el-col>
  207. <el-col :span="8">
  208. <el-form-item label="实缴资本" prop="paidInCapital">
  209. <el-input v-model="businessForm.paidInCapital" placeholder="请输入实缴资本" :disabled="true" />
  210. </el-form-item>
  211. </el-col>
  212. </el-row>
  213. <el-row :gutter="20">
  214. <el-col :span="16">
  215. <el-form-item label="详细地址" prop="businessAddress">
  216. <el-input v-model="businessForm.businessAddress" placeholder="请输入详细地址" :disabled="true" />
  217. </el-form-item>
  218. </el-col>
  219. </el-row>
  220. <el-row :gutter="20">
  221. <el-col :span="24">
  222. <el-form-item label="营业执照" prop="businessLicense">
  223. <div
  224. v-if="!businessForm.businessLicense"
  225. class="upload-box"
  226. @click="businessLicenseSelectorVisible = true"
  227. style="
  228. width: 360px;
  229. height: 200px;
  230. border: 2px dashed #d9d9d9;
  231. border-radius: 4px;
  232. display: flex;
  233. align-items: center;
  234. justify-content: center;
  235. cursor: pointer;
  236. transition: all 0.3s;
  237. "
  238. >
  239. <div style="text-align: center; color: #8c939d">
  240. <el-icon :size="40" style="margin-bottom: 8px">
  241. <Plus />
  242. </el-icon>
  243. <div style="font-size: 14px">点击上传</div>
  244. </div>
  245. </div>
  246. <div v-else style="position: relative; display: inline-block">
  247. <el-image
  248. :src="businessForm.businessLicense"
  249. style="width: 360px; height: 200px"
  250. fit="contain"
  251. :preview-src-list="[businessForm.businessLicense]"
  252. />
  253. <el-button
  254. type="danger"
  255. :icon="Delete"
  256. circle
  257. size="small"
  258. style="position: absolute; top: 5px; right: 5px"
  259. @click="businessForm.businessLicense = ''"
  260. />
  261. </div>
  262. </el-form-item>
  263. </el-col>
  264. </el-row>
  265. </el-form>
  266. </el-card>
  267. <!-- 营业执照选择器对话框 -->
  268. <FileSelector
  269. v-model="businessLicenseSelectorVisible"
  270. title="选择营业执照"
  271. :allowed-types="[1]"
  272. :multiple="false"
  273. :allow-upload="true"
  274. @confirm="handleBusinessLicenseSelected"
  275. />
  276. <!-- 联系人信息列表 -->
  277. <el-card shadow="never" class="mb-4">
  278. <template #header>
  279. <div class="flex justify-between items-center">
  280. <span class="font-medium">联系人信息列表</span>
  281. <el-button type="primary" @click="handleAddContact">添加联系人</el-button>
  282. </div>
  283. </template>
  284. <el-table :data="contactList" border>
  285. <el-table-column type="index" label="序号" align="center" width="60" />
  286. <el-table-column label="联系人姓名" align="center" prop="contactName" min-width="120" />
  287. <el-table-column label="职位" align="center" prop="roleName" min-width="120"> </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 { 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 { getBusinessInfoBycustomerName } from '@/api/customer/customerFile/businessInfo';
  382. import type { BusinessInfoForm } from '@/api/customer/customerFile/businessInfo/types';
  383. import AddContactDialog from './components/addContactDialog.vue';
  384. import AddInvoiceDialog from './components/addInvoiceDialog.vue';
  385. import { regionData } from 'element-china-area-data';
  386. import { listEnterpriseScale } from '@/api/customer/customerCategory/enterpriseScale';
  387. import { listIndustryCategory } from '@/api/customer/customerCategory/industryCategory';
  388. import type { EnterpriseScaleVO } from '@/api/customer/customerCategory/enterpriseScale/types';
  389. import type { IndustryCategoryVO } from '@/api/customer/customerCategory/industryCategory/types';
  390. import { listComStaff, getComStaff } from '@/api/company/comStaff';
  391. import { ComStaffVO, ComStaffQuery, ComStaffForm } from '@/api/company/comStaff/types';
  392. import { listDept, getDept, listDeptExcludeChild } from '@/api/system/dept';
  393. import { DeptVO } from '@/api/system/dept/types';
  394. import { listCompany } from '@/api/company/company';
  395. import { CompanyVO } from '@/api/company/company/types';
  396. import { Plus, Delete } from '@element-plus/icons-vue';
  397. import { log } from 'console';
  398. const { proxy } = getCurrentInstance() as ComponentInternalInstance;
  399. const { customer_type, customer_level } = toRefs<any>(proxy?.useDict('customer_type', 'customer_level'));
  400. const route = useRoute();
  401. const router = useRouter();
  402. const formRef = ref<any>(null);
  403. const salesFormRef = ref<any>(null);
  404. const submitLoading = ref(false);
  405. // 生成客户编号
  406. const customerNumber = ref('');
  407. const isEdit = ref(false);
  408. const customerId = ref<string>('');
  409. const codeArr = ref([]);
  410. // 下拉框数据列表
  411. const enterpriseScaleList = ref<EnterpriseScaleVO[]>([]);
  412. const industryCategoryList = ref<IndustryCategoryVO[]>([]);
  413. const invoiceTypeList = ref<InvoiceTypeVO[]>([]);
  414. const companyList = ref<CompanyVO[]>([]);
  415. const settlementMethodList = ref<SettlementMethodVO[]>([]);
  416. const customerLevelList = ref<CustomerLevelVO[]>([]);
  417. const customerTypeList = ref<CustomerTypeVO[]>([]);
  418. const comStaffList = ref<ComStaffVO[]>([]);
  419. const comDeptList = ref<DeptVO[]>([]);
  420. // 企业基本信息表单
  421. const form = reactive<CustomerInfoForm>({
  422. customerNo: '',
  423. belongCompanyId: undefined,
  424. companyName: '',
  425. businessCustomerName: '',
  426. shortName: '',
  427. invoiceTypeId: undefined,
  428. enterpriseScaleId: undefined,
  429. customerTypeId: undefined,
  430. industryCategoryId: undefined,
  431. customerLevelId: undefined,
  432. landline: '',
  433. fax: '',
  434. url: '',
  435. postCode: '',
  436. validityFromDate: undefined,
  437. validityToDate: undefined,
  438. invoiceTop: '',
  439. address: '',
  440. status: '0',
  441. remark: ''
  442. });
  443. // 工商信息
  444. const businessForm = reactive<BusinessInfoForm>({
  445. businessCustomerName: '',
  446. socialCreditCode: '',
  447. legalPersonName: '',
  448. registeredCapital: '',
  449. registrationAuthority: '',
  450. establishmentDate: '',
  451. revocationDate: '',
  452. registrationStatus: '',
  453. paidInCapital: undefined,
  454. businessAddress: '',
  455. businessLicense: '',
  456. status: '0'
  457. });
  458. // 联系人列表
  459. const contactList = ref<CustomerContactForm[]>([]);
  460. const contactDialogVisible = ref(false);
  461. const currentContact = ref<CustomerContactForm | undefined>(undefined);
  462. const currentContactIndex = ref<number>(-1);
  463. // 销售信息
  464. const salesForm = reactive<SalesInfoForm>({
  465. salesPersonId: undefined,
  466. serviceStaffId: undefined,
  467. belongingDepartmentId: undefined,
  468. status: '0'
  469. });
  470. // 开票信息列表
  471. const invoiceList = ref<InvoiceInfoForm[]>([]);
  472. const invoiceDialogVisible = ref(false);
  473. const currentInvoice = ref<InvoiceInfoForm | undefined>(undefined);
  474. const currentInvoiceIndex = ref<number>(-1);
  475. // 表单验证规则
  476. const rules = {
  477. belongCompanyId: [{ required: true, message: '请选择所属公司', trigger: 'change' }],
  478. customerName: [{ required: true, message: '请输入客户名称', trigger: 'blur' }],
  479. businessCustomerName: [
  480. { required: true, message: '请输入工商名称', trigger: 'blur' },
  481. {
  482. // 允许:中文 + 常见标点 (括号、中圆点、横杠)
  483. // 禁止:数字、字母、空格、@#$%等其他符号
  484. pattern: /^[\u4e00-\u9fa5()()·\-]+$/,
  485. message: '名称不能包含数字、字母或特殊符号,仅限中文及常用标点',
  486. trigger: 'blur'
  487. }
  488. ],
  489. shortName: [{ required: true, message: '请输入企业简称', trigger: 'blur' }],
  490. invoiceTypeId: [{ required: true, message: '请选择开票类型', trigger: 'change' }],
  491. enterpriseScaleId: [{ required: true, message: '请选择企业规模', trigger: 'change' }],
  492. customerTypeId: [{ required: true, message: '请选择客户类别', trigger: 'change' }],
  493. industryCategoryId: [{ required: true, message: '请选择行业类别', trigger: 'change' }],
  494. customerLevelId: [{ required: true, message: '请选择客户等级', trigger: 'change' }],
  495. address: [{ required: true, message: '请输入详细地址', trigger: 'blur' }]
  496. };
  497. // 销售信息表单验证规则
  498. const salesRules = {
  499. salesPersonId: [{ required: true, message: '请选择业务人员', trigger: 'change' }],
  500. serviceStaffId: [{ required: true, message: '请选择客服人员', trigger: 'change' }]
  501. };
  502. // 获取角色名称
  503. // const getRoleName = (roleId: string | number | undefined) => {
  504. // return roleMap[String(roleId)] || '-';
  505. // };
  506. // Logo选择器相关
  507. const logoSelectorVisible = ref(false);
  508. const businessLicenseSelectorVisible = ref(false);
  509. // Logo选择处理
  510. const handleLogoSelected = (files: any[]) => {
  511. if (files && files.length > 0) {
  512. const file = files[0]; // 取第一个文件
  513. if (file && (file.url || file.path)) {
  514. // form.value.logo = file.url || file.path;
  515. ElMessage.success('Logo选择成功');
  516. // 选择完成后清理表单验证状态
  517. nextTick(() => {
  518. formRef.value?.clearValidate();
  519. });
  520. } else {
  521. ElMessage.error('请选择有效的图片文件');
  522. }
  523. } else {
  524. ElMessage.error('请选择有效的图片文件');
  525. }
  526. };
  527. const handCompanyChange = async (val) => {
  528. try {
  529. try {
  530. // 1. 处理清空情况
  531. if (!val) {
  532. form.companyName = '';
  533. return;
  534. }
  535. // 2. 在本地列表中查找完整对象
  536. const selectedCompany = companyList.value.find((item) => item.id === val);
  537. if (selectedCompany) {
  538. // 3. 赋值操作
  539. form.companyName = selectedCompany.companyName;
  540. } else {
  541. // 如果本地列表没找到(可能是数据不同步),可以选择清空或调用接口查询
  542. form.companyName = '';
  543. }
  544. } catch (error) {}
  545. } catch (error) {}
  546. };
  547. // 营业执照选择处理
  548. const handleBusinessLicenseSelected = (files: any[]) => {
  549. if (files && files.length > 0) {
  550. const file = files[0]; // 取第一个文件
  551. if (file && (file.url || file.path)) {
  552. businessForm.businessLicense = file.url || file.path;
  553. // ElMessage.success('营业执照选择成功');
  554. // 选择完成后清理表单验证状态
  555. nextTick(() => {
  556. formRef.value?.clearValidate('businessLicense');
  557. });
  558. } else {
  559. ElMessage.error('请选择有效的图片文件');
  560. }
  561. } else {
  562. ElMessage.error('请选择有效的图片文件');
  563. }
  564. };
  565. // 监听对话框关闭,清理表单验证状态
  566. watch(logoSelectorVisible, (newVal) => {
  567. if (!newVal) {
  568. // 对话框关闭后清理可能的表单验证状态
  569. nextTick(() => {
  570. formRef.value?.clearValidate();
  571. });
  572. }
  573. });
  574. // 初始化
  575. onMounted(async () => {
  576. // 加载下拉框数据
  577. await loadEnterpriseScaleList();
  578. await loadIndustryCategoryList();
  579. await loadInvoiceTypeList();
  580. await loadCompanyList();
  581. await loadSettlementMethodList();
  582. await loadCustomerLevelList();
  583. await loadCustomerTypeList();
  584. await loadComStaffList();
  585. await loadComDeptList();
  586. // 判断是新增还是编辑
  587. const id = route.query.id as any;
  588. if (id) {
  589. // 编辑模式
  590. isEdit.value = true;
  591. customerId.value = id as string;
  592. await loadCustomerData(id);
  593. } else {
  594. // 新增模式,生成客户编号
  595. customerNumber.value = generateCustomerNumber();
  596. }
  597. });
  598. const selectBusinessBtn = async () => {
  599. try {
  600. // 验证基本信息表单
  601. await formRef.value.validateField('businessCustomerName');
  602. const res = await getBusinessInfoBycustomerName(form.businessCustomerName);
  603. const data = res.data;
  604. // 填充信息
  605. Object.assign(businessForm, data);
  606. form.invoiceTop = data.businessCustomerName;
  607. form.businessCustomerName = data.businessCustomerName;
  608. } catch (error) {
  609. // ElMessage.error('查询工商信息失败');
  610. }
  611. };
  612. // 加载客户数据(编辑模式)
  613. const loadCustomerData = async (id: string) => {
  614. try {
  615. const res = await getCustomerInfo(id);
  616. const data = res.data;
  617. // 填充基本信息
  618. Object.assign(form, data);
  619. customerNumber.value = data.customerNo || '';
  620. // 填充工商信息
  621. if (data.customerBusinessInfoVo) {
  622. Object.assign(businessForm, data.customerBusinessInfoVo);
  623. }
  624. // 填充销售信息
  625. if (data.customerSalesInfoVo) {
  626. Object.assign(salesForm, data.customerSalesInfoVo);
  627. }
  628. // 填充联系人列表
  629. if (data.customerContactVoList) {
  630. contactList.value = data.customerContactVoList as any;
  631. }
  632. // 填充开票信息列表
  633. if (data.customerInvoiceInfoVoList) {
  634. invoiceList.value = data.customerInvoiceInfoVoList;
  635. }
  636. // 如果有省市区编码,回显到级联选择器
  637. if (data.regProvincialNo && data.regCityNo && data.regCountyNo) {
  638. codeArr.value = [data.regProvincialNo, data.regCityNo, data.regCountyNo] as any;
  639. }
  640. } catch (error) {
  641. console.error('加载客户数据失败:', error);
  642. ElMessage.error('加载客户数据失败');
  643. }
  644. };
  645. // 加载企业规模列表
  646. const loadEnterpriseScaleList = async () => {
  647. try {
  648. const res = await listEnterpriseScale({ dataSource: 'A10' } as any);
  649. enterpriseScaleList.value = res.rows || [];
  650. } catch (error) {
  651. console.error('加载企业规模列表失败:', error);
  652. }
  653. };
  654. // 加载行业类别列表
  655. const loadIndustryCategoryList = async () => {
  656. try {
  657. const res = await listIndustryCategory({ dataSource: 'A10' } as any);
  658. industryCategoryList.value = res.rows || [];
  659. } catch (error) {
  660. console.error('加载行业类别列表失败:', error);
  661. }
  662. };
  663. // 加载开票类型列表
  664. const loadInvoiceTypeList = async () => {
  665. try {
  666. const res = await listInvoiceType({ dataSource: 'A10' } as any);
  667. invoiceTypeList.value = res.rows || [];
  668. } catch (error) {
  669. console.error('加载开票类型列表失败:', error);
  670. }
  671. };
  672. // 加载公司列表
  673. const loadCompanyList = async () => {
  674. try {
  675. const query: any = { isShow: '0', dataSource: 'A10' };
  676. const res = await listCompany(query);
  677. companyList.value = res.rows || [];
  678. } catch (error) {
  679. console.error('加载公司列表失败:', error);
  680. }
  681. };
  682. // 加载结算方式列表
  683. const loadSettlementMethodList = async () => {
  684. try {
  685. const query: any = { isShow: '0' };
  686. const res = await listSettlementMethod(query);
  687. settlementMethodList.value = res.rows || [];
  688. } catch (error) {
  689. console.error('加载结算方式列表失败:', error);
  690. }
  691. };
  692. // 加载客户等级列表
  693. const loadCustomerLevelList = async () => {
  694. try {
  695. const res = await listCustomerLevel({ dataSource: 'A10' } as any);
  696. customerLevelList.value = res.rows || [];
  697. } catch (error) {
  698. console.error('加载客户等级列表失败:', error);
  699. }
  700. };
  701. // 加载客户类别列表
  702. const loadCustomerTypeList = async () => {
  703. try {
  704. const res = await listCustomerType({ dataSource: 'A10' } as any);
  705. customerTypeList.value = res.rows || [];
  706. } catch (error) {
  707. console.error('加载客户类别列表失败:', error);
  708. }
  709. };
  710. // 加载员工列表
  711. const loadComStaffList = async () => {
  712. try {
  713. const query: any = { status: '0' };
  714. const res = await listComStaff(query);
  715. comStaffList.value = res.rows || [];
  716. } catch (error) {
  717. console.error('加载员工列表失败:', error);
  718. }
  719. };
  720. // 加载部门列表
  721. const loadComDeptList = async () => {
  722. try {
  723. const res = await listDept();
  724. // 处理可能的不同返回结构
  725. comDeptList.value = res.rows || res.data || [];
  726. } catch (error) {
  727. console.error('加载部门列表失败:', error);
  728. }
  729. };
  730. // 打开添加联系人对话框
  731. const handleAddContact = () => {
  732. currentContact.value = undefined;
  733. currentContactIndex.value = -1;
  734. contactDialogVisible.value = true;
  735. };
  736. /** 处理区域选择变化 */
  737. const handleChange = (val: string[]) => {
  738. // 保存编码
  739. form.regProvincialNo = val[0];
  740. form.regCityNo = val[1];
  741. form.regCountyNo = val[2];
  742. // 根据编码获取名称
  743. const names: string[] = [];
  744. if (val[0]) {
  745. const province = regionData.find((item: any) => item.value === val[0]);
  746. if (province) {
  747. names.push(province.label);
  748. if (val[1] && province.children) {
  749. const city = province.children.find((item: any) => item.value === val[1]);
  750. if (city) {
  751. names.push(city.label);
  752. if (val[2] && city.children) {
  753. const county = city.children.find((item: any) => item.value === val[2]);
  754. if (county) {
  755. names.push(county.label);
  756. }
  757. }
  758. }
  759. }
  760. }
  761. }
  762. // 将省市区名称用斜杠连接
  763. form.provincialCityCounty = names.join('/');
  764. };
  765. // 处理业务人员选择变化
  766. const handleSalesPersonChange = (staffId: any) => {
  767. // 根据选中的业务人员ID,找到对应的部门ID
  768. const selectedStaff = comStaffList.value.find((staff) => staff.staffId === staffId);
  769. if (selectedStaff && selectedStaff.deptId) {
  770. // 确保 deptId 的类型一致,watch 会自动触发加载部门名称
  771. salesForm.belongingDepartmentId = String(selectedStaff.deptId);
  772. }
  773. };
  774. // 部门名称(响应式)
  775. const deptName = ref('');
  776. // 监听部门ID变化,自动加载部门名称
  777. watch(
  778. () => salesForm.belongingDepartmentId,
  779. async (newDeptId) => {
  780. if (!newDeptId) {
  781. deptName.value = '';
  782. return;
  783. }
  784. // 先从列表中查找
  785. const dept = comDeptList.value.find((d) => String(d.deptId) === String(newDeptId));
  786. if (dept) {
  787. deptName.value = dept.deptName;
  788. return;
  789. }
  790. // 如果列表中没有,从API获取
  791. try {
  792. const res = await getDept(newDeptId);
  793. if (res.data) {
  794. deptName.value = res.data.deptName;
  795. comDeptList.value.push(res.data);
  796. }
  797. } catch (error) {
  798. console.error('获取部门信息失败:', error);
  799. deptName.value = String(newDeptId);
  800. }
  801. },
  802. { immediate: true }
  803. );
  804. // 编辑联系人
  805. const handleEditContact = (row: CustomerContactForm, index: number) => {
  806. currentContact.value = { ...row };
  807. currentContactIndex.value = index;
  808. contactDialogVisible.value = true;
  809. };
  810. // 确认添加/编辑联系人
  811. const handleContactConfirm = (data: CustomerContactForm) => {
  812. // 如果新增/编辑的是主联系人(isPrimary === '0'),将其他所有联系人设置为非主联系人
  813. if (data.isPrimary === '0') {
  814. contactList.value.forEach((item) => {
  815. item.isPrimary = '1';
  816. });
  817. }
  818. if (currentContactIndex.value >= 0) {
  819. // 编辑
  820. contactList.value[currentContactIndex.value] = data;
  821. } else {
  822. // 新增
  823. contactList.value.push(data);
  824. }
  825. };
  826. // 删除联系人
  827. const removeContact = (index: number) => {
  828. ElMessageBox.confirm('确定要删除该联系人吗?', '提示', {
  829. confirmButtonText: '确定',
  830. cancelButtonText: '取消',
  831. type: 'warning'
  832. })
  833. .then(() => {
  834. contactList.value.splice(index, 1);
  835. ElMessage.success('删除成功');
  836. })
  837. .catch(() => {});
  838. };
  839. // 打开添加开票信息对话框
  840. const handleAddInvoice = () => {
  841. currentInvoice.value = {};
  842. currentInvoice.value.taxId = businessForm.socialCreditCode;
  843. currentInvoice.value.address = businessForm.businessAddress;
  844. currentInvoiceIndex.value = -1;
  845. invoiceDialogVisible.value = true;
  846. };
  847. // 编辑开票信息
  848. const handleEditInvoice = (row: InvoiceInfoForm, index: number) => {
  849. currentInvoice.value = { ...row };
  850. currentInvoiceIndex.value = index;
  851. invoiceDialogVisible.value = true;
  852. };
  853. // 确认添加/编辑开票信息
  854. const handleInvoiceConfirm = (data: InvoiceInfoForm) => {
  855. // 如果新增/编辑的是主账号(isPrimaryAccount === '0'),将其他所有账号设置为非主账号
  856. if (data.isPrimaryAccount === '0') {
  857. invoiceList.value.forEach((item) => {
  858. item.isPrimaryAccount = '1';
  859. });
  860. }
  861. if (currentInvoiceIndex.value >= 0) {
  862. // 编辑
  863. invoiceList.value[currentInvoiceIndex.value] = data;
  864. } else {
  865. // 新增
  866. invoiceList.value.push(data);
  867. }
  868. };
  869. // 删除开票信息
  870. const removeInvoice = (index: number) => {
  871. ElMessageBox.confirm('确定要删除该开票信息吗?', '提示', {
  872. confirmButtonText: '确定',
  873. cancelButtonText: '取消',
  874. type: 'warning'
  875. })
  876. .then(() => {
  877. invoiceList.value.splice(index, 1);
  878. ElMessage.success('删除成功');
  879. })
  880. .catch(() => {});
  881. };
  882. // 提交表单
  883. const handleSubmit = async () => {
  884. try {
  885. // 1. 业务前置校验
  886. if (contactList.value.length < 1) {
  887. ElMessage.warning('请至少添加一名联系人!');
  888. return;
  889. }
  890. // 2. 表单字段校验
  891. await formRef.value?.validate();
  892. await salesFormRef.value?.validate();
  893. submitLoading.value = true;
  894. const submitData: CustomerInfoForm = {
  895. ...form,
  896. customerNo: customerNumber.value,
  897. customerBusinessBo: businessForm,
  898. customerSalesInfoBo: salesForm,
  899. customerContactBoList: contactList.value,
  900. customerInvoiceInfoBoList: invoiceList.value
  901. };
  902. await addCustomerInfo(submitData);
  903. ElMessage.success('添加成功');
  904. router.back();
  905. } catch (error) {
  906. console.error('保存失败:', error);
  907. ElMessage.error('保存失败,请重试');
  908. } finally {
  909. submitLoading.value = false;
  910. }
  911. };
  912. </script>
  913. <style scoped>
  914. .upload-box:hover {
  915. border-color: #409eff !important; /* 鼠标悬停时变蓝 */
  916. }
  917. </style>