add.vue 36 KB

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