ContractFormDialog.vue 88 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675
  1. <template>
  2. <el-dialog
  3. v-model="dialogVisible"
  4. :title="formTitle"
  5. width="100%"
  6. top="20px"
  7. class="dialog-form-layout contract-form-dialog"
  8. destroy-on-close
  9. append-to-body
  10. modal-class="order-module-dialog-mask"
  11. :close-on-click-modal="false"
  12. @opened="handleOpened"
  13. >
  14. <div
  15. class="contract-form-body"
  16. v-loading="formLoading"
  17. element-loading-text="正在加载合同数据..."
  18. >
  19. <el-form
  20. ref="formRef"
  21. :model="form"
  22. :rules="rules"
  23. label-position="right"
  24. label-width="120px"
  25. class="crm-dialog-form"
  26. :disabled="formLoading"
  27. >
  28. <!-- 合同基础信息(一行 4 列) -->
  29. <div class="contract-basic-info">
  30. <el-form-item label="合同编号" prop="contractNo">
  31. <el-input v-model="form.contractNo" placeholder="系统自动生成,格式:SX/X-JT20250926002" maxlength="50" />
  32. </el-form-item>
  33. <el-form-item label="合同名称" prop="contractName">
  34. <el-input
  35. v-model="form.contractName"
  36. placeholder="可不填,自动生成:供方简称-需方简称(合同编号)"
  37. maxlength="100"
  38. show-word-limit
  39. />
  40. </el-form-item>
  41. <el-form-item label="合同类型" prop="contractType" required>
  42. <el-select v-model="form.contractType" placeholder="请选择合同类型" style="width: 100%" @change="handleContractTypeChange">
  43. <el-option v-for="dict in dictStore.getOptions('crm_contract_type')" :key="dict.value" :label="dict.label" :value="dict.value" />
  44. </el-select>
  45. </el-form-item>
  46. <el-form-item label="合同模版" prop="contractTemplate" required>
  47. <el-select v-model="form.contractTemplate" placeholder="请选择合同模版" style="width: 100%" @change="handleContractTemplateChange">
  48. <el-option v-for="dict in dictStore.getOptions('crm_contract_template')" :key="dict.value" :label="dict.label" :value="dict.value" />
  49. </el-select>
  50. </el-form-item>
  51. <el-form-item label="客户名称" prop="customerId" required>
  52. <el-input v-model="form.customerName" placeholder="请选择客户" readonly>
  53. <template #append>
  54. <el-button text @click="handleSelectCustomer">
  55. <el-icon><Search /></el-icon>
  56. </el-button>
  57. </template>
  58. </el-input>
  59. </el-form-item>
  60. <el-form-item label="关联报价单" prop="quoteId">
  61. <el-input v-model="form.quoteNo" placeholder="请选择报价单(可选)" readonly clearable>
  62. <template #append>
  63. <el-button text @click="handleSelectQuote">
  64. <el-icon><Search /></el-icon>
  65. </el-button>
  66. </template>
  67. </el-input>
  68. </el-form-item>
  69. <el-form-item label="联系人" prop="contactId" required>
  70. <el-input v-model="form.contactsName" placeholder="请选择联系人" maxlength="50">
  71. <template #append>
  72. <el-button text @click="handleSelectContact" :disabled="!form.customerId">
  73. <el-icon><Search /></el-icon>
  74. </el-button>
  75. </template>
  76. </el-input>
  77. </el-form-item>
  78. <el-form-item label="联系电话" prop="contactsPhone">
  79. <el-input v-model="form.contactsPhone" placeholder="从客户/联系人带出" maxlength="20" />
  80. </el-form-item>
  81. <el-form-item label="签订日期" prop="signDate">
  82. <el-date-picker
  83. v-model="form.signDate"
  84. type="date"
  85. placeholder="选择签订日期"
  86. value-format="YYYY-MM-DD"
  87. style="width: 100%"
  88. @change="handleSignDateChange"
  89. />
  90. </el-form-item>
  91. <el-form-item label="负责人" prop="ownerUserId" required>
  92. <el-select
  93. v-model="form.ownerUserId"
  94. placeholder="请选择负责人"
  95. filterable
  96. clearable
  97. style="width: 100%"
  98. @change="handleOwnerChange"
  99. >
  100. <el-option v-for="user in userList" :key="user.userId" :label="user.nickName" :value="user.userId" />
  101. </el-select>
  102. </el-form-item>
  103. <el-form-item label="合同金额(元)" prop="amount">
  104. <el-input-number
  105. v-model="form.amount"
  106. :precision="2"
  107. :min="0"
  108. placeholder="可选填,留空则从产品明细自动计算"
  109. style="width: 100%"
  110. class="money-field-input"
  111. />
  112. </el-form-item>
  113. <el-form-item label="合同期限" prop="startDate" required>
  114. <el-date-picker
  115. v-model="contractDateRange"
  116. type="daterange"
  117. range-separator="-"
  118. start-placeholder="开始日期"
  119. end-placeholder="结束日期"
  120. value-format="YYYY-MM-DD"
  121. style="width: 100%"
  122. @change="handleDateRangeChange"
  123. />
  124. </el-form-item>
  125. <el-form-item label="交易主体" prop="supplierId" required>
  126. <el-select v-model="form.supplierId" placeholder="请选择交易主体" clearable style="width: 100%" @change="handleSupplierChange">
  127. <el-option v-for="supplier in supplierList" :key="supplier.id" :label="supplier.supplierName" :value="supplier.id" />
  128. </el-select>
  129. </el-form-item>
  130. <el-form-item label="结算方式" prop="settlementMethod">
  131. <el-select v-model="form.settlementMethod" placeholder="请选择结算方式" clearable style="width: 100%">
  132. <el-option v-for="dict in dictStore.getOptions('crm_settlement_method')" :key="dict.value" :label="dict.label" :value="dict.value" />
  133. </el-select>
  134. </el-form-item>
  135. </div>
  136. <!-- 供方 / 需方信息(左右布局,默认缩略、各自独立展开) -->
  137. <div class="parties-section">
  138. <div class="parties-section-toolbar">
  139. <el-button text type="primary" size="small" @click="partiesExpanded = !partiesExpanded">
  140. <el-icon>
  141. <ArrowUp v-if="partiesExpanded" />
  142. <ArrowDown v-else />
  143. </el-icon>
  144. {{ partiesExpanded ? '收起供需方' : '展开供需方' }}
  145. </el-button>
  146. <el-button type="primary" size="small" @click="handleSwapParties">
  147. <el-icon><Sort /></el-icon>
  148. 供需方调换
  149. </el-button>
  150. </div>
  151. <div class="parties-row">
  152. <div class="party-panel" :class="{ 'is-collapsed': !partiesExpanded }">
  153. <div class="party-panel__header">
  154. <div class="party-panel__title">供方信息</div>
  155. </div>
  156. <div v-if="!partiesExpanded" class="party-panel__summary">
  157. <span class="party-panel__summary-label">单位名称</span>
  158. <span class="party-panel__summary-value" :class="{ 'is-empty': !form.partyA }">
  159. {{ form.partyA || '未填写' }}
  160. </span>
  161. </div>
  162. <div v-show="partiesExpanded" class="form-grid-2">
  163. <el-form-item label="单位名称(章)" prop="partyA">
  164. <el-input v-model="form.partyA" placeholder="请输入单位名称" maxlength="100" />
  165. </el-form-item>
  166. <el-form-item label="单位地址" prop="partyAAddress">
  167. <el-input v-model="form.partyAAddress" placeholder="请输入单位地址" maxlength="200" />
  168. </el-form-item>
  169. <el-form-item label="法定代表人" prop="partyALegalPerson">
  170. <el-input v-model="form.partyALegalPerson" placeholder="请输入法定代表人" maxlength="100" />
  171. </el-form-item>
  172. <el-form-item label="代理人" prop="partyAAgent">
  173. <el-input v-model="form.partyAAgent" placeholder="请输入代理人(可选)" maxlength="100" />
  174. </el-form-item>
  175. <el-form-item label="电话/传真" prop="partyAPhoneFax">
  176. <el-input v-model="form.partyAPhoneFax" placeholder="请输入电话/传真" maxlength="100" />
  177. </el-form-item>
  178. <el-form-item label="开户银行" prop="partyABank">
  179. <el-input v-model="form.partyABank" placeholder="请输入开户银行" maxlength="200" />
  180. </el-form-item>
  181. <el-form-item label="账号" prop="partyAAccount">
  182. <el-input v-model="form.partyAAccount" placeholder="请输入账号" maxlength="100" />
  183. </el-form-item>
  184. </div>
  185. </div>
  186. <div class="party-flow-bridge" aria-hidden="true">
  187. <span class="party-flow-bridge__label">供货</span>
  188. <span class="party-flow-bridge__arrow">
  189. <svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
  190. <path
  191. d="M5 12h11.5"
  192. stroke="currentColor"
  193. stroke-width="2.75"
  194. stroke-linecap="round"
  195. />
  196. <path
  197. d="M13.5 8.5 18.5 12l-5 3.5"
  198. stroke="currentColor"
  199. stroke-width="2.75"
  200. stroke-linecap="round"
  201. stroke-linejoin="round"
  202. />
  203. </svg>
  204. </span>
  205. </div>
  206. <div class="party-panel" :class="{ 'is-collapsed': !partiesExpanded }">
  207. <div class="party-panel__header">
  208. <div class="party-panel__title">需方信息</div>
  209. </div>
  210. <div v-if="!partiesExpanded" class="party-panel__summary">
  211. <span class="party-panel__summary-label">单位名称</span>
  212. <span class="party-panel__summary-value" :class="{ 'is-empty': !form.partyB }">
  213. {{ form.partyB || '未填写' }}
  214. </span>
  215. </div>
  216. <div v-show="partiesExpanded" class="form-grid-2">
  217. <el-form-item label="单位名称(章)" prop="partyB">
  218. <el-input v-model="form.partyB" placeholder="从客户开票信息带出" maxlength="200" />
  219. </el-form-item>
  220. <el-form-item label="单位地址" prop="partyBAddress">
  221. <el-input v-model="form.partyBAddress" placeholder="从客户开票信息带出" maxlength="500" />
  222. </el-form-item>
  223. <el-form-item label="法定代表人" prop="partyBLegalPerson">
  224. <el-input v-model="form.partyBLegalPerson" placeholder="从客户开票信息带出" maxlength="100" />
  225. </el-form-item>
  226. <el-form-item label="代理人" prop="partyBAgent">
  227. <el-input v-model="form.partyBAgent" placeholder="从客户开票信息带出(可选)" maxlength="100" />
  228. </el-form-item>
  229. <el-form-item label="电话/传真" prop="partyBPhoneFax">
  230. <el-input v-model="form.partyBPhoneFax" placeholder="从客户开票信息带出" maxlength="100" />
  231. </el-form-item>
  232. <el-form-item label="开户银行" prop="partyBBank">
  233. <el-input v-model="form.partyBBank" placeholder="从客户开票信息带出" maxlength="200" />
  234. </el-form-item>
  235. <el-form-item label="账号" prop="partyBAccount">
  236. <el-input v-model="form.partyBAccount" placeholder="从客户开票信息带出" maxlength="100" />
  237. </el-form-item>
  238. </div>
  239. </div>
  240. </div>
  241. </div>
  242. <!-- 产品明细部分 -->
  243. <el-divider content-position="left">产品明细</el-divider>
  244. <div class="panel dialog-list-panel mb-4">
  245. <div class="list-toolbar">
  246. <div class="list-toolbar-row">
  247. <div class="list-toolbar-selected">
  248. <el-button class="btn-main" type="primary" @click="handleAddProduct">
  249. <el-icon><Plus /></el-icon>添加产品
  250. </el-button>
  251. <el-button class="btn-ghost" @click="handleRemoveSelectedProducts" :disabled="selectedProducts.length === 0">
  252. <el-icon><Delete /></el-icon>删除选中
  253. </el-button>
  254. </div>
  255. </div>
  256. </div>
  257. <div class="list-body list-wrap">
  258. <ListTable table-key="crm-contract-components-contract-form-dialog" :data="form.products" class="list-table" stripe @selection-change="handleProductSelectionChange">
  259. <el-table-column type="selection" min-width="55" align="center" header-align="center" />
  260. <el-table-column label="序号" type="index" min-width="60" align="center" header-align="center" />
  261. <el-table-column label="产品名称" min-width="160" :show-overflow-tooltip="true">
  262. <template #default="scope">
  263. <el-input
  264. :model-value="scope.row.standardProductName || scope.row.productName"
  265. placeholder="产品名称"
  266. clearable
  267. size="small"
  268. readonly
  269. />
  270. </template>
  271. </el-table-column>
  272. <el-table-column label="别名" min-width="140">
  273. <template #default="scope">
  274. <div class="line-meta-cell">
  275. <el-select
  276. v-if="(scope.row.aliasOptions || []).length"
  277. v-model="scope.row.aliasName"
  278. placeholder="不选则用产品名称"
  279. clearable
  280. filterable
  281. size="small"
  282. class="line-meta-cell__control"
  283. >
  284. <el-option
  285. v-for="name in scope.row.aliasOptions"
  286. :key="name"
  287. :label="name"
  288. :value="name"
  289. />
  290. </el-select>
  291. <span v-else class="text-muted line-meta-cell__empty">—</span>
  292. <el-button
  293. v-if="scope.row.productId"
  294. link
  295. type="primary"
  296. class="line-meta-cell__btn"
  297. @click="openAliasBrandManage(scope.row, 'alias')"
  298. >
  299. <el-icon><Setting /></el-icon>
  300. </el-button>
  301. </div>
  302. </template>
  303. </el-table-column>
  304. <el-table-column label="品牌" min-width="140">
  305. <template #default="scope">
  306. <div class="line-meta-cell">
  307. <el-select
  308. v-if="(scope.row.brandOptions || []).length"
  309. v-model="scope.row.brandId"
  310. placeholder="不限品牌"
  311. clearable
  312. filterable
  313. size="small"
  314. class="line-meta-cell__control"
  315. @change="(val) => handleBrandIdChange(scope.row, val)"
  316. >
  317. <el-option
  318. v-for="b in scope.row.brandOptions"
  319. :key="b.id"
  320. :label="b.brandName"
  321. :value="b.id"
  322. />
  323. </el-select>
  324. <span v-else class="text-muted line-meta-cell__empty">—</span>
  325. <el-button
  326. v-if="scope.row.productId"
  327. link
  328. type="primary"
  329. class="line-meta-cell__btn"
  330. @click="openAliasBrandManage(scope.row, 'brand')"
  331. >
  332. <el-icon><Setting /></el-icon>
  333. </el-button>
  334. </div>
  335. </template>
  336. </el-table-column>
  337. <el-table-column label="型号/规格" prop="productModel" min-width="100" :show-overflow-tooltip="true">
  338. <template #default="scope">
  339. <el-input v-model="scope.row.productModel" placeholder="请输入型号/规格" clearable size="small" readonly />
  340. </template>
  341. </el-table-column>
  342. <el-table-column label="税率(%)" prop="taxRate" min-width="80">
  343. <template #default="scope">
  344. <el-input v-model="scope.row.taxRate" placeholder="税率" @input="handleTaxRateChange(scope.row)" clearable size="small" />
  345. </template>
  346. </el-table-column>
  347. <el-table-column label="单位" prop="unit" width="100" align="center">
  348. <template #default="scope">
  349. <el-select
  350. v-model="scope.row.unit"
  351. placeholder="请选择单位"
  352. clearable
  353. size="small"
  354. style="width: 100%"
  355. @change="handleUnitChange(scope.row)"
  356. >
  357. <el-option v-for="dict in dictStore.getOptions('crm_product_unit')" :key="dict.value" :label="dict.label" :value="dict.value" />
  358. </el-select>
  359. </template>
  360. </el-table-column>
  361. <el-table-column prop="quantity" width="110">
  362. <template #header> <span style="color: #f56c6c">*</span> 数量</template>
  363. <template #default="scope">
  364. <el-input v-model="scope.row.quantity" placeholder="数量" @input="handleQuantityChange(scope.row)" clearable size="small" />
  365. </template>
  366. </el-table-column>
  367. <el-table-column prop="price" width="130">
  368. <template #header>
  369. <span v-if="isFrameworkContract">含税单价(元)</span>
  370. <span v-else><span style="color: #f56c6c">*</span> 含税单价(元)</span>
  371. </template>
  372. <template #default="scope">
  373. <span v-if="isFrameworkContract" class="text-muted">随行就市</span>
  374. <el-input
  375. v-else
  376. v-model="scope.row.price"
  377. placeholder="含税单价"
  378. @input="handlePriceChange(scope.row)"
  379. clearable
  380. size="small"
  381. class="money-field-input"
  382. />
  383. </template>
  384. </el-table-column>
  385. <el-table-column prop="subtotal" width="130" align="right">
  386. <template #header>
  387. <span v-if="isFrameworkContract">含税总价(元)</span>
  388. <span v-else><span style="color: #f56c6c">*</span> 含税总价(元)</span>
  389. </template>
  390. <template #default="scope">
  391. <span v-if="isFrameworkContract" class="text-muted">随行就市</span>
  392. <span v-else class="money-display">¥{{ parseFloat(scope.row.subtotal || 0).toFixed(2) }}</span>
  393. </template>
  394. </el-table-column>
  395. <el-table-column label="税费(元)" prop="taxAmount" min-width="90" align="right">
  396. <template #default="scope">
  397. <span v-if="isFrameworkContract" class="text-muted">随行就市</span>
  398. <span v-else class="money-display">¥{{ parseFloat(scope.row.taxAmount || 0).toFixed(2) }}</span>
  399. </template>
  400. </el-table-column>
  401. <el-table-column prop="packageSpec" min-width="150">
  402. <template #header> <span style="color: #f56c6c">*</span> 包装规格</template>
  403. <template #default="scope">
  404. <el-select
  405. v-model="scope.row.packageSpec"
  406. placeholder="请选择包装规格"
  407. filterable
  408. allow-create
  409. default-first-option
  410. clearable
  411. size="small"
  412. style="width: 100%"
  413. @change="handlePackageSpecChange(scope.row, $event)"
  414. >
  415. <el-option v-for="dict in dictStore.getOptions('crm_product_gg')" :key="dict.value" :label="dict.label" :value="dict.value" />
  416. </el-select>
  417. </template>
  418. </el-table-column>
  419. <el-table-column prop="deliveryMethod" min-width="150">
  420. <template #header> <span style="color: #f56c6c">*</span> 送货方式</template>
  421. <template #default="scope">
  422. <el-select v-model="scope.row.deliveryMethod" placeholder="请选择送货方式" clearable size="small" style="width: 100%">
  423. <el-option v-for="dict in dictStore.getOptions('crm_shfs')" :key="dict.value" :label="dict.label" :value="dict.value" />
  424. </el-select>
  425. </template>
  426. </el-table-column>
  427. <el-table-column prop="remark" label="备注" min-width="160">
  428. <template #default="scope">
  429. <el-input
  430. v-model="scope.row.remark"
  431. type="textarea"
  432. :rows="2"
  433. placeholder="请输入备注"
  434. maxlength="500"
  435. show-word-limit
  436. clearable
  437. size="small"
  438. />
  439. </template>
  440. </el-table-column>
  441. <el-table-column label="操作" min-width="80" align="center" header-align="center" fixed="right" class-name="col-actions">
  442. <template #default="scope">
  443. <el-button link type="danger" @click="handleRemoveProduct(scope.$index)">
  444. <el-icon><Delete /></el-icon>
  445. </el-button>
  446. </template>
  447. </el-table-column>
  448. </ListTable>
  449. </div>
  450. </div>
  451. <!-- 框架合同调价区间 -->
  452. <template v-if="isFrameworkContractType(form.contractType)">
  453. <el-divider content-position="left">框架合同调价区间</el-divider>
  454. <p class="text-muted mb-3" style="font-size: 13px">
  455. 按产品维护生效日期区间与含税单价(可选);若填写区间则须完整(日期、单价、调价函)。合同总金额不与此联动,仍为 0。
  456. </p>
  457. <div v-for="(prod, pIdx) in form.products" :key="'fw-tier-' + pIdx" class="framework-tier-block mb-4">
  458. <div class="fw-tier-title mb-2">{{ prod.productName || '产品' + (pIdx + 1) }}</div>
  459. <el-button type="primary" link class="mb-2 fw-tier-letter-add-btn" @click="addPriceTierRow(pIdx)">
  460. <el-icon><Plus /></el-icon>调价函
  461. </el-button>
  462. <div class="panel dialog-list-panel mb-3">
  463. <div class="list-body list-wrap dialog-list-body-only">
  464. <ListTable table-key="crm-contract-components-contract-form-dialog-2" :data="prod.priceTiers || []" class="list-table" stripe empty-text="暂无调价区间">
  465. <el-table-column type="index" label="#" min-width="50" align="center" header-align="center" />
  466. <el-table-column label="开始日期" min-width="150">
  467. <template #default="scope">
  468. <el-date-picker v-model="scope.row.startDate" type="date" value-format="YYYY-MM-DD" placeholder="开始日期" style="width: 100%" />
  469. </template>
  470. </el-table-column>
  471. <el-table-column label="结束日期" min-width="150">
  472. <template #default="scope">
  473. <el-date-picker v-model="scope.row.endDate" type="date" value-format="YYYY-MM-DD" placeholder="结束日期" style="width: 100%" />
  474. </template>
  475. </el-table-column>
  476. <el-table-column label="含税单价(元)" width="140">
  477. <template #default="scope">
  478. <el-input v-model="scope.row.price" placeholder="含税单价" clearable size="small" class="money-field-input" />
  479. </template>
  480. </el-table-column>
  481. <el-table-column label="调价函" min-width="300">
  482. <template #default="scope">
  483. <el-upload
  484. :http-request="(opt) => handleTierLetterUploadRequest(opt, pIdx, scope.$index)"
  485. list-type="picture-card"
  486. :limit="20"
  487. multiple
  488. accept="image/*"
  489. :file-list="scope.row._letterFiles || []"
  490. :on-remove="(file) => handleTierLetterRemove(file, pIdx, scope.$index)"
  491. class="tier-letter-upload"
  492. >
  493. <el-icon><Plus /></el-icon>
  494. </el-upload>
  495. <div class="text-muted" style="font-size: 11px; margin-top: 4px">支持多张图片</div>
  496. </template>
  497. </el-table-column>
  498. <el-table-column label="操作" min-width="70" align="center" header-align="center" fixed="right" class-name="col-actions">
  499. <template #default="scope">
  500. <el-button link type="danger" @click="removePriceTierRow(pIdx, scope.$index)">
  501. <el-icon><Delete /></el-icon>
  502. </el-button>
  503. </template>
  504. </el-table-column>
  505. </ListTable>
  506. </div>
  507. </div>
  508. </div>
  509. </template>
  510. <el-divider />
  511. <div class="total-section">
  512. <el-row :gutter="20">
  513. <el-col :span="16"></el-col>
  514. <el-col :span="8">
  515. <div class="total-item">
  516. <span class="total-label">合计金额(元):</span>
  517. <span class="total-value money-display">¥{{ parseFloat(form.amount || 0).toLocaleString('zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 }) }}</span>
  518. </div>
  519. </el-col>
  520. </el-row>
  521. </div>
  522. <!-- 附件上传部分 - OpenSpec 标准卡片化布局 -->
  523. <el-divider content-position="left">附件上传</el-divider>
  524. <el-form-item label="附件" prop="attachmentFiles" :required="form.contractTemplate === 'customer_template'">
  525. <ContractAttachmentPanel
  526. v-model="attachmentList"
  527. :biz-type="CRM_UPLOAD_BIZ_TYPE.CONTRACT_ATTACHMENT"
  528. />
  529. </el-form-item>
  530. </el-form>
  531. </div>
  532. <template #footer>
  533. <div class="dialog-footer">
  534. <el-button class="btn-ghost" @click="handleClose">
  535. <el-icon><Close /></el-icon>取消
  536. </el-button>
  537. <el-button
  538. class="btn-ghost"
  539. :loading="saveDraftLoading"
  540. :disabled="formLoading"
  541. @click="handleSaveDraft"
  542. >
  543. <el-icon><FolderChecked /></el-icon>保存草稿
  544. </el-button>
  545. <el-button
  546. class="btn-main"
  547. type="primary"
  548. :loading="submitLoading"
  549. :disabled="formLoading"
  550. @click="handleSubmit"
  551. >
  552. <el-icon><Promotion /></el-icon>提交审批
  553. </el-button>
  554. </div>
  555. </template>
  556. <!-- 产品选择器 -->
  557. <ProductSelector
  558. :visible="productSelectorVisible"
  559. :supplier-id="form.supplierId"
  560. @update:visible="productSelectorVisible = $event"
  561. @confirm="handleProductSelected"
  562. />
  563. <ProductAliasBrandDialog
  564. v-model="aliasBrandManageVisible"
  565. :product-id="aliasBrandManageProductId"
  566. :product-name="aliasBrandManageProductName"
  567. :mode="aliasBrandManageMode"
  568. @saved="handleAliasBrandManaged"
  569. />
  570. <!-- 客户选择器 -->
  571. <CustomerSelector :visible="customerSelectorVisible" @update:visible="customerSelectorVisible = $event" @confirm="handleCustomerConfirm" />
  572. <!-- 联系人选择器 -->
  573. <ContactSelector
  574. :visible="contactSelectorVisible"
  575. @update:visible="contactSelectorVisible = $event"
  576. :customerId="form.customerId"
  577. @confirm="handleContactConfirm"
  578. />
  579. <!-- 报价单选择器 -->
  580. <QuoteSelector
  581. :visible="quoteSelectorVisible"
  582. @update:visible="quoteSelectorVisible = $event"
  583. :customerId="form.customerId"
  584. @confirm="handleQuoteConfirm"
  585. />
  586. <!-- 用户选择器 -->
  587. <!-- 审批弹窗 -->
  588. <ApprovalDialog ref="approvalDialogRef" @success="handleApprovalSuccess" />
  589. </el-dialog>
  590. </template>
  591. <script setup lang="ts">
  592. import { ref, reactive, computed, nextTick, watch } from 'vue'
  593. import type { FormInstance, UploadRequestOptions } from 'element-plus'
  594. import { ElMessage } from 'element-plus'
  595. import {
  596. getContract,
  597. addContract,
  598. updateContract,
  599. type ContractForm,
  600. type ContractProductForm,
  601. type ContractProductPriceTierForm
  602. } from '@/api/crm/contract/index'
  603. import { isFrameworkContractType } from '../contractType'
  604. import { useDictStore } from '@/store/modules/dict'
  605. import { useUserStore } from '@/store/modules/user'
  606. import { $modal } from '@/utils/modal'
  607. import {
  608. Document,
  609. Delete,
  610. Sort,
  611. Plus,
  612. Search,
  613. Close,
  614. FolderChecked,
  615. Promotion,
  616. Loading,
  617. ArrowDown,
  618. ArrowUp,
  619. Setting
  620. } from '@element-plus/icons-vue'
  621. import {
  622. buildUploadFileListFromField,
  623. fillAttachmentInfoCache,
  624. serializeContractAttachments,
  625. type ContractAttachmentItem
  626. } from '@/utils/crm-attachment'
  627. import { buildAttachmentUploadFormData, CRM_UPLOAD_BIZ_TYPE } from '@/utils/crm-upload'
  628. import ContractAttachmentPanel from './ContractAttachmentPanel.vue'
  629. import { getOpportunity } from '@/api/crm/opportunity'
  630. import { getQuote } from '@/api/crm/quote'
  631. import ProductSelector from './ProductSelector.vue'
  632. import ProductAliasBrandDialog from '@/components/business/product-alias-brand-dialog/index.vue'
  633. import CustomerSelector from '@/components/CustomerSelector.vue'
  634. import ContactSelector from '@/components/ContactSelector.vue'
  635. import QuoteSelector from '@/components/QuoteSelector.vue'
  636. import { removeProductsNotAllowedByHazard } from '@/utils/crm-supplier-hazard'
  637. import {
  638. applyBrandSelectChange,
  639. applyManagedProductMetaToLines,
  640. initLineBrandMetaFromProduct,
  641. prepareLineAliasAndBrandForSubmit,
  642. resolveAliasFromSavedName
  643. } from '@/utils/crm-product-brand'
  644. import { fetchProductDetail } from '@/api/crm/product'
  645. import ApprovalDialog from './ApprovalDialog.vue'
  646. import { omitEmptyExceptPartyFields } from '../partyFields'
  647. import { getContactByCustomerId, fetchCustomerDetail } from '@/api/crm/customer'
  648. import type { CustomerVO, ContactVO } from '@/api/crm/customer/types'
  649. import { getDefaultInvoiceInfoByCustomerId } from '@/api/crm/invoiceInfo'
  650. import { listAllSupplierInfo, type SupplierInfoVO } from '@/api/crm/supplierInfo'
  651. import { fetchUploadAttachment, fetchUserOptions } from '@/api/admin'
  652. interface UserVO {
  653. userId: string | number
  654. nickName: string
  655. userName?: string
  656. }
  657. // 扩展表单类型,添加显示用字段
  658. type ExtendedContractForm = ContractForm & {
  659. customerName?: string
  660. opportunityName?: string
  661. quoteNo?: string
  662. contactsName?: string
  663. contactsPhone?: string
  664. ownerUserName?: string
  665. supplierId?: number
  666. settlementMethod?: string
  667. templateContent?: string
  668. }
  669. // 扩展产品类型,添加显示字段
  670. type PriceTierRow = ContractProductPriceTierForm & { _letterFiles?: any[] }
  671. type ExtendedContractProductForm = ContractProductForm & {
  672. productName?: string
  673. productModel?: string
  674. unit?: string
  675. unitPrice?: number
  676. subtotal?: number
  677. priceTiers?: PriceTierRow[]
  678. }
  679. const props = defineProps<{
  680. visible: boolean
  681. editId: string | null
  682. }>()
  683. const emit = defineEmits<{
  684. 'update:visible': [value: boolean]
  685. success: []
  686. }>()
  687. const dialogVisible = computed({
  688. get: () => props.visible,
  689. set: (val) => emit('update:visible', val)
  690. })
  691. const dictStore = useDictStore()
  692. const userStore = useUserStore()
  693. // 表单标题
  694. const formTitle = computed(() => {
  695. return form.value.id ? '编辑合同' : '新增合同'
  696. })
  697. // 合同期限日期范围
  698. const contractDateRange = ref<[string, string]>([])
  699. // 表单数据
  700. const form = ref<ExtendedContractForm>({
  701. id: undefined,
  702. contractNo: undefined,
  703. contractName: '',
  704. contractType: 'sale',
  705. contractTemplate: 'shanxia',
  706. customerId: 0,
  707. customerName: '',
  708. contactId: undefined,
  709. opportunityId: undefined,
  710. opportunityName: '',
  711. quoteId: undefined,
  712. quoteNo: '',
  713. contactsName: '',
  714. contactsPhone: '',
  715. signDate: '',
  716. startDate: '',
  717. endDate: '',
  718. ownerUserId: undefined,
  719. ownerUserName: '',
  720. amount: 0,
  721. supplierId: undefined,
  722. settlementMethod: undefined,
  723. partyA: '',
  724. partyAAddress: '',
  725. partyAContact: '',
  726. partyAMobile: '',
  727. partyALegalPerson: '',
  728. partyAAgent: '',
  729. partyAPhoneFax: '',
  730. partyABank: '',
  731. partyAAccount: '',
  732. partyB: '',
  733. partyBAddress: '',
  734. partyBContact: '',
  735. partyBMobile: '',
  736. partyBLegalPerson: '',
  737. partyBAgent: '',
  738. partyBPhoneFax: '',
  739. partyBBank: '',
  740. partyBAccount: '',
  741. paymentTerms: '',
  742. deliveryTerms: '',
  743. contractTerms: '',
  744. products: [] as ExtendedContractProductForm[],
  745. remark: ''
  746. })
  747. // 供需方是否已调换的标志
  748. const isPartiesSwapped = ref(false)
  749. /** 供方 / 需方信息展开状态(默认缩略,两侧共用) */
  750. const partiesExpanded = ref(false)
  751. const resetPartyExpand = () => {
  752. partiesExpanded.value = false
  753. }
  754. /** 校验失败时,自动展开供需方面板 */
  755. const expandPartiesForInvalidFields = (invalidFields?: Record<string, unknown>) => {
  756. if (!invalidFields) return
  757. const keys = Object.keys(invalidFields)
  758. if (keys.some((k) => k.startsWith('partyA') || k.startsWith('partyB'))) {
  759. partiesExpanded.value = true
  760. }
  761. }
  762. // 记录原始的模板内容(用于检测是否被意外删除)
  763. const originalTemplateContent = ref<string>('')
  764. // 供方信息列表
  765. const supplierList = ref<SupplierInfoVO[]>([])
  766. // 客户简称 / 开票公司名(用于按供需方面板匹配简称)
  767. const customerShortName = ref('')
  768. const customerInvoiceName = ref('')
  769. // 表单校验规则
  770. const rules = ref({
  771. contractType: [{ required: true, message: '合同类型不能为空', trigger: 'change' }],
  772. customerId: [{ required: true, message: '客户不能为空', trigger: 'change' }],
  773. contactId: [{ required: true, message: '联系人不能为空', trigger: 'change' }],
  774. signDate: [{ required: true, message: '签订日期不能为空', trigger: 'change' }],
  775. ownerUserId: [{ required: true, message: '负责人不能为空', trigger: 'change' }],
  776. supplierId: [{ required: true, message: '交易主体不能为空', trigger: 'change' }],
  777. startDate: [
  778. {
  779. validator: (_rule: any, _value: any, callback: any) => {
  780. if (!contractDateRange.value || contractDateRange.value.length !== 2 || !contractDateRange.value[0] || !contractDateRange.value[1]) {
  781. callback(new Error('合同期限不能为空'))
  782. } else {
  783. callback()
  784. }
  785. },
  786. trigger: ['change', 'blur']
  787. }
  788. ],
  789. attachmentFiles: []
  790. })
  791. // 附件列表
  792. const attachmentList = ref<ContractAttachmentItem[]>([])
  793. const isFrameworkContract = computed(() => isFrameworkContractType(form.value.contractType))
  794. // 加载状态
  795. const formLoading = ref(false)
  796. const saveDraftLoading = ref(false)
  797. const submitLoading = ref(false)
  798. /** 编辑打开时立即进入加载态,避免空白表单可被误改 */
  799. watch(
  800. () => props.visible,
  801. (visible) => {
  802. if (visible && props.editId) {
  803. formLoading.value = true
  804. } else if (!visible) {
  805. formLoading.value = false
  806. }
  807. }
  808. )
  809. // 组件引用
  810. const formRef = ref<FormInstance>()
  811. const approvalDialogRef = ref()
  812. // 选择器状态
  813. const customerSelectorVisible = ref(false)
  814. const contactSelectorVisible = ref(false)
  815. const opportunitySelectorVisible = ref(false)
  816. const quoteSelectorVisible = ref(false)
  817. const userSelectorVisible = ref(false)
  818. const productSelectorVisible = ref(false)
  819. // 用户列表(负责人下拉)
  820. const userList = ref<any[]>([])
  821. // 选中的产品列表
  822. const selectedProducts = ref<ExtendedContractProductForm[]>([])
  823. // 临时接口定义
  824. interface OpportunityVO {
  825. id: number
  826. opportunityName: string
  827. customerId?: number
  828. customerName?: string
  829. }
  830. interface QuoteVO {
  831. id: number
  832. quoteNo: string
  833. quoteTitle: string
  834. customerId?: number
  835. customerName?: string
  836. contactId?: number
  837. contactName?: string
  838. productList?: any[]
  839. quoteDate?: string
  840. }
  841. /** 对话框打开后的初始化 */
  842. const handleOpened = async () => {
  843. resetPartyExpand()
  844. const isEdit = !!props.editId
  845. if (isEdit) {
  846. formLoading.value = true
  847. }
  848. try {
  849. await Promise.all([loadSupplierList(), loadUserList()])
  850. if (props.editId) {
  851. await loadContractDetail(props.editId)
  852. } else {
  853. resetForm()
  854. form.value.signDate = new Date().toISOString().split('T')[0]
  855. handleSignDateChange(form.value.signDate)
  856. // 设置默认供方主体为"SX"
  857. const defaultSupplier = supplierList.value.find((supplier) => supplier.supplierCode === 'SX')
  858. if (defaultSupplier) {
  859. form.value.supplierId = defaultSupplier.id
  860. await handleSupplierChange(defaultSupplier.id)
  861. }
  862. }
  863. } catch (error: any) {
  864. console.error('合同表单初始化失败:', error)
  865. $modal.msgError(error?.message || '加载合同数据失败')
  866. if (isEdit) {
  867. dialogVisible.value = false
  868. }
  869. } finally {
  870. formLoading.value = false
  871. }
  872. }
  873. /** 重置表单 */
  874. const resetForm = () => {
  875. form.value = {
  876. id: undefined,
  877. contractNo: undefined,
  878. contractName: '',
  879. contractType: 'sale',
  880. contractTemplate: 'shanxia',
  881. customerId: 0,
  882. customerName: '',
  883. contactId: undefined,
  884. opportunityId: undefined,
  885. opportunityName: '',
  886. quoteId: undefined,
  887. quoteNo: '',
  888. contactsName: '',
  889. contactsPhone: '',
  890. signDate: '',
  891. startDate: '',
  892. endDate: '',
  893. ownerUserId: undefined,
  894. ownerUserName: '',
  895. amount: 0,
  896. supplierId: undefined,
  897. settlementMethod: undefined,
  898. partyA: '',
  899. partyAAddress: '',
  900. partyAContact: '',
  901. partyAMobile: '',
  902. partyALegalPerson: '',
  903. partyAAgent: '',
  904. partyAPhoneFax: '',
  905. partyABank: '',
  906. partyAAccount: '',
  907. partyB: '',
  908. partyBAddress: '',
  909. partyBContact: '',
  910. partyBMobile: '',
  911. partyBLegalPerson: '',
  912. partyBAgent: '',
  913. partyBPhoneFax: '',
  914. partyBBank: '',
  915. partyBAccount: '',
  916. paymentTerms: '',
  917. deliveryTerms: '',
  918. contractTerms: '',
  919. products: [] as ExtendedContractProductForm[],
  920. remark: ''
  921. }
  922. isPartiesSwapped.value = false
  923. resetPartyExpand()
  924. originalTemplateContent.value = ''
  925. customerShortName.value = ''
  926. customerInvoiceName.value = ''
  927. contractDateRange.value = [] as any
  928. attachmentList.value = []
  929. selectedProducts.value = []
  930. }
  931. /** 加载合同详情 */
  932. const loadContractDetail = async (id: number | string) => {
  933. const res = await getContract(id)
  934. const contractData = res.data
  935. Object.assign(form.value, contractData)
  936. originalTemplateContent.value = contractData.templateContent || ''
  937. if (contractData.contactName) {
  938. form.value.contactsName = contractData.contactName
  939. }
  940. if (contractData.contactMobile) {
  941. form.value.contactsPhone = contractData.contactMobile
  942. }
  943. if (contractData.ownerUserName) {
  944. form.value.ownerUserName = contractData.ownerUserName
  945. }
  946. if (contractData.ownerUserId) {
  947. form.value.ownerUserId = contractData.ownerUserId
  948. }
  949. if (contractData.opportunityId) {
  950. try {
  951. const oppRes = await getOpportunity(contractData.opportunityId)
  952. if (oppRes.data) {
  953. form.value.opportunityName = oppRes.data.opportunityName
  954. }
  955. } catch (error) {
  956. console.warn('加载商机信息失败:', error)
  957. }
  958. }
  959. if (contractData.quoteId) {
  960. try {
  961. const quoteRes = await getQuote(contractData.quoteId)
  962. if (quoteRes.data) {
  963. form.value.quoteNo = quoteRes.data.quoteNo
  964. }
  965. } catch (error) {
  966. console.warn('加载报价单信息失败:', error)
  967. }
  968. }
  969. if (contractData.products && Array.isArray(contractData.products)) {
  970. form.value.products = contractData.products.map((product: any) => ({
  971. ...product,
  972. productModel: product.model || '',
  973. isToxic: Number(product.isToxic || 0),
  974. isExplosive: Number(product.isExplosive || 0),
  975. brandMode: product.brandMode || undefined,
  976. brandId: product.brandId || undefined,
  977. brandName: product.brandName || undefined,
  978. brandOptions: [],
  979. priceTiers: (product.priceTiers || []).map((t: any) => {
  980. let ids: string[] = []
  981. if (Array.isArray(t.letterOssIds) && t.letterOssIds.length) {
  982. ids = t.letterOssIds.map((id: any) => String(id))
  983. } else if (t.letterOssId != null && t.letterOssId !== '') {
  984. ids = [String(t.letterOssId)]
  985. }
  986. return {
  987. ...t,
  988. letterOssIds: ids,
  989. _letterFiles: [] as any[]
  990. }
  991. }),
  992. taxRate: product.taxRate || 6,
  993. taxAmount: 0,
  994. packageSpec: product.packageSpec || '',
  995. deliveryMethod: product.deliveryMethod || ''
  996. }))
  997. await enrichContractProductBrandMeta(form.value.products)
  998. if (isFrameworkContractType(contractData.contractType)) {
  999. form.value.products.forEach((product: any) => {
  1000. product.price = 0
  1001. product.subtotal = 0
  1002. product.taxAmount = 0
  1003. })
  1004. form.value.amount = 0
  1005. await enrichFrameworkTierLetterFiles()
  1006. } else {
  1007. form.value.products.forEach((product: any) => {
  1008. calculateProductAmount(product)
  1009. })
  1010. }
  1011. }
  1012. if (form.value.startDate && form.value.endDate) {
  1013. contractDateRange.value = [form.value.startDate, form.value.endDate]
  1014. }
  1015. if (form.value.attachmentFiles) {
  1016. await handleAttachmentData()
  1017. }
  1018. customerShortName.value = ''
  1019. customerInvoiceName.value = ''
  1020. if (form.value.customerId) {
  1021. try {
  1022. const [invoiceRes, customerRes] = await Promise.all([
  1023. getDefaultInvoiceInfoByCustomerId(form.value.customerId),
  1024. fetchCustomerDetail({ id: String(form.value.customerId) })
  1025. ])
  1026. customerInvoiceName.value = invoiceRes?.data?.companyName || ''
  1027. customerShortName.value = customerRes?.data?.shortName || ''
  1028. if (!form.value.customerName && customerRes?.data?.customerName) {
  1029. form.value.customerName = customerRes.data.customerName
  1030. }
  1031. } catch {
  1032. customerInvoiceName.value = ''
  1033. }
  1034. }
  1035. syncPartiesSwappedFlagFromPanels()
  1036. rebuildContractName()
  1037. }
  1038. /** 选择客户 */
  1039. const handleSelectCustomer = () => {
  1040. customerSelectorVisible.value = true
  1041. }
  1042. /** 客户选择确认 */
  1043. const handleCustomerConfirm = async (customer: CustomerVO) => {
  1044. if (customer) {
  1045. form.value.customerId = customer.id
  1046. form.value.customerName = customer.customerName
  1047. const addressParts: string[] = []
  1048. if (customer.province) addressParts.push(customer.province)
  1049. if (customer.city) addressParts.push(customer.city)
  1050. if (customer.district) addressParts.push(customer.district)
  1051. if (customer.address) addressParts.push(customer.address)
  1052. const fullAddress = addressParts.join('')
  1053. form.value.contactId = undefined
  1054. form.value.opportunityId = undefined
  1055. form.value.opportunityName = ''
  1056. form.value.quoteId = undefined
  1057. form.value.quoteNo = ''
  1058. try {
  1059. const [invoiceRes, customerRes] = await Promise.all([
  1060. getDefaultInvoiceInfoByCustomerId(customer.id),
  1061. fetchCustomerDetail({ id: String(customer.id) })
  1062. ])
  1063. const invoiceData = invoiceRes?.data
  1064. // 简称以客户主数据为准(列表/选择器可能缺字段)
  1065. customerShortName.value =
  1066. (customerRes?.data?.shortName || customer.shortName || '').trim()
  1067. if (customerRes?.data?.customerName) {
  1068. form.value.customerName = customerRes.data.customerName
  1069. }
  1070. customerInvoiceName.value = invoiceData?.companyName || ''
  1071. if (invoiceData && invoiceData.companyName) {
  1072. if (isPartiesSwapped.value) {
  1073. form.value.partyA = invoiceData.companyName || ''
  1074. form.value.partyAAddress = invoiceData.companyAddress || fullAddress || ''
  1075. form.value.partyALegalPerson = invoiceData.legalRepresentative || ''
  1076. form.value.partyAAgent = invoiceData.agent || ''
  1077. form.value.partyAPhoneFax = invoiceData.phoneFax || ''
  1078. form.value.partyABank = invoiceData.bankName || ''
  1079. form.value.partyAAccount = invoiceData.bankAccount || ''
  1080. } else {
  1081. form.value.partyB = invoiceData.companyName || ''
  1082. form.value.partyBAddress = invoiceData.companyAddress || fullAddress || ''
  1083. form.value.partyBLegalPerson = invoiceData.legalRepresentative || ''
  1084. form.value.partyBAgent = invoiceData.agent || ''
  1085. form.value.partyBPhoneFax = invoiceData.phoneFax || ''
  1086. form.value.partyBBank = invoiceData.bankName || ''
  1087. form.value.partyBAccount = invoiceData.bankAccount || ''
  1088. }
  1089. } else {
  1090. if (isPartiesSwapped.value) {
  1091. form.value.partyA = customer.customerName
  1092. form.value.partyAAddress = fullAddress
  1093. form.value.partyALegalPerson = ''
  1094. form.value.partyAAgent = ''
  1095. form.value.partyAPhoneFax = customer.telephone || ''
  1096. form.value.partyABank = ''
  1097. form.value.partyAAccount = ''
  1098. } else {
  1099. form.value.partyB = customer.customerName
  1100. form.value.partyBAddress = fullAddress
  1101. form.value.partyBLegalPerson = ''
  1102. form.value.partyBAgent = ''
  1103. form.value.partyBPhoneFax = customer.telephone || ''
  1104. form.value.partyBBank = ''
  1105. form.value.partyBAccount = ''
  1106. }
  1107. }
  1108. } catch (error) {
  1109. console.error('获取客户开票信息失败:', error)
  1110. customerInvoiceName.value = ''
  1111. if (isPartiesSwapped.value) {
  1112. form.value.partyA = customer.customerName
  1113. form.value.partyAAddress = fullAddress
  1114. form.value.partyALegalPerson = ''
  1115. form.value.partyAAgent = ''
  1116. form.value.partyAPhoneFax = customer.telephone || ''
  1117. form.value.partyABank = ''
  1118. form.value.partyAAccount = ''
  1119. } else {
  1120. form.value.partyB = customer.customerName
  1121. form.value.partyBAddress = fullAddress
  1122. form.value.partyBLegalPerson = ''
  1123. form.value.partyBAgent = ''
  1124. form.value.partyBPhoneFax = customer.telephone || ''
  1125. form.value.partyBBank = ''
  1126. form.value.partyBAccount = ''
  1127. }
  1128. }
  1129. if (isPartiesSwapped.value) {
  1130. form.value.partyAContact = ''
  1131. form.value.partyAMobile = customer.mobile || customer.telephone || ''
  1132. } else {
  1133. form.value.partyBContact = ''
  1134. form.value.partyBMobile = customer.mobile || customer.telephone || ''
  1135. }
  1136. form.value.contactsName = ''
  1137. form.value.contactsPhone = customer.mobile || customer.telephone || ''
  1138. try {
  1139. const res = await getContactByCustomerId(customer.id)
  1140. if (res.data && res.data.length > 0) {
  1141. const primaryContact = res.data.find((contact: any) => contact.isPrimary === 1)
  1142. const contact = primaryContact || res.data[0]
  1143. form.value.contactId = contact.id
  1144. form.value.contactsName = contact.contactName
  1145. form.value.contactsPhone = contact.mobile || contact.telephone || ''
  1146. if (isPartiesSwapped.value) {
  1147. form.value.partyAContact = contact.contactName
  1148. form.value.partyAMobile = contact.mobile || contact.telephone || ''
  1149. } else {
  1150. form.value.partyBContact = contact.contactName
  1151. form.value.partyBMobile = contact.mobile || contact.telephone || ''
  1152. }
  1153. }
  1154. } catch (error) {
  1155. console.error('获取客户联系人失败:', error)
  1156. }
  1157. if (!customerShortName.value) {
  1158. customerShortName.value = (customer.shortName || '').trim()
  1159. }
  1160. rebuildContractName()
  1161. }
  1162. }
  1163. /** 选择联系人 */
  1164. const handleSelectContact = () => {
  1165. if (!form.value.customerId) {
  1166. $modal.msgWarning('请先选择客户')
  1167. return
  1168. }
  1169. contactSelectorVisible.value = true
  1170. }
  1171. /** 联系人选择确认 */
  1172. const handleContactConfirm = (contact: ContactVO) => {
  1173. if (contact) {
  1174. form.value.contactId = contact.id
  1175. form.value.contactsName = contact.contactName
  1176. form.value.contactsPhone = contact.mobile || contact.telephone || ''
  1177. if (isPartiesSwapped.value) {
  1178. form.value.partyAContact = contact.contactName
  1179. form.value.partyAMobile = contact.mobile || contact.telephone || ''
  1180. } else {
  1181. form.value.partyBContact = contact.contactName
  1182. form.value.partyBMobile = contact.mobile || contact.telephone || ''
  1183. }
  1184. formRef.value?.validateField('contactId')
  1185. }
  1186. }
  1187. /** 选择商机 */
  1188. const handleSelectOpportunity = () => {
  1189. opportunitySelectorVisible.value = true
  1190. }
  1191. /** 商机选择确认 */
  1192. const handleOpportunityConfirm = (opportunity: OpportunityVO) => {
  1193. if (opportunity) {
  1194. form.value.opportunityId = opportunity.id
  1195. form.value.opportunityName = opportunity.opportunityName
  1196. if (opportunity.customerId && !form.value.customerId) {
  1197. form.value.customerId = opportunity.customerId
  1198. form.value.customerName = opportunity.customerName || ''
  1199. }
  1200. }
  1201. }
  1202. /** 选择报价单 */
  1203. const handleSelectQuote = () => {
  1204. quoteSelectorVisible.value = true
  1205. }
  1206. /** 报价单选择确认 */
  1207. const handleQuoteConfirm = (quote: QuoteVO) => {
  1208. if (quote) {
  1209. form.value.quoteId = quote.id
  1210. form.value.quoteNo = quote.quoteNo
  1211. if (quote.customerId && !form.value.customerId) {
  1212. form.value.customerId = quote.customerId
  1213. form.value.customerName = quote.customerName || ''
  1214. }
  1215. if (quote.contactId) {
  1216. form.value.contactId = quote.contactId
  1217. form.value.contactsName = quote.contactName || ''
  1218. if (isPartiesSwapped.value) {
  1219. form.value.partyAContact = quote.contactName || ''
  1220. } else {
  1221. form.value.partyBContact = quote.contactName || ''
  1222. }
  1223. }
  1224. if (quote.productList && quote.productList.length > 0) {
  1225. $modal
  1226. .confirm('是否要从报价单中带入产品明细?')
  1227. .then(async () => {
  1228. const isFw = isFrameworkContractType(form.value.contractType)
  1229. form.value.products = quote.productList!.map((item: any) => ({
  1230. productId: item.productId,
  1231. productName: item.productName,
  1232. productModel: item.model,
  1233. categoryId: item.categoryId,
  1234. categoryName: item.categoryName || '',
  1235. unit: item.unit || '个',
  1236. quantity: item.quantity || 1,
  1237. price: isFw ? 0 : item.price || 0,
  1238. unitPrice: isFw ? 0 : item.price || 0,
  1239. taxRate: item.taxRate || 13,
  1240. taxAmount: isFw ? 0 : item.taxAmount || 0,
  1241. discount: item.discount || 0,
  1242. subtotal: isFw ? 0 : item.subtotal || (item.quantity || 1) * (item.price || 0) * (1 - (item.discount || 0) / 100),
  1243. packageSpec: item.packageSpec || '',
  1244. deliveryMethod: item.deliveryMethod || '',
  1245. deliveryDate: '',
  1246. description: item.description || '',
  1247. remark: item.remark || '',
  1248. sort: item.sort,
  1249. brandMode: item.brandMode || undefined,
  1250. brandId: item.brandId || undefined,
  1251. brandName: item.brandName || undefined,
  1252. brandOptions: [],
  1253. priceTiers: isFw ? [] : undefined
  1254. }))
  1255. await enrichContractProductBrandMeta(form.value.products)
  1256. calculateTotalAmount()
  1257. })
  1258. .catch(() => {})
  1259. }
  1260. }
  1261. }
  1262. /** 加载用户列表(负责人下拉) */
  1263. const loadUserList = async () => {
  1264. try {
  1265. const res = await fetchUserOptions()
  1266. const options = (res as any)?.data ?? res ?? []
  1267. userList.value = (Array.isArray(options) ? options : []).map((item: any) => ({
  1268. userId: item.value ?? item.userId ?? item.id,
  1269. nickName: item.label ?? item.nickName ?? item.userName ?? ''
  1270. }))
  1271. } catch (error) {
  1272. console.error('加载用户列表失败:', error)
  1273. userList.value = []
  1274. }
  1275. }
  1276. /** 负责人变化 */
  1277. const handleOwnerChange = (userId: string | number) => {
  1278. const user = userList.value.find((item: any) => String(item.userId) === String(userId))
  1279. form.value.ownerUserName = user?.nickName || ''
  1280. }
  1281. /** 选择负责人 */
  1282. const handleSelectUser = () => {
  1283. userSelectorVisible.value = true
  1284. }
  1285. /** 用户选择确认 */
  1286. const handleUserConfirm = (user: UserVO) => {
  1287. if (user) {
  1288. form.value.ownerUserId = user.userId
  1289. form.value.ownerUserName = user.nickName
  1290. }
  1291. }
  1292. /** 供方主体变化处理 */
  1293. const handleSupplierChange = async (supplierId: number | undefined) => {
  1294. if (!supplierId) {
  1295. if (isPartiesSwapped.value) {
  1296. form.value.partyB = ''
  1297. form.value.partyBAddress = ''
  1298. form.value.partyBLegalPerson = ''
  1299. form.value.partyBAgent = ''
  1300. form.value.partyBPhoneFax = ''
  1301. form.value.partyBBank = ''
  1302. form.value.partyBAccount = ''
  1303. } else {
  1304. form.value.partyA = ''
  1305. form.value.partyAAddress = ''
  1306. form.value.partyALegalPerson = ''
  1307. form.value.partyAAgent = ''
  1308. form.value.partyAPhoneFax = ''
  1309. form.value.partyABank = ''
  1310. form.value.partyAAccount = ''
  1311. }
  1312. return
  1313. }
  1314. const supplier = supplierList.value.find((s) => s.id === supplierId)
  1315. if (supplier) {
  1316. if (isPartiesSwapped.value) {
  1317. form.value.partyB = supplier.supplierName || ''
  1318. form.value.partyBAddress = supplier.supplierAddress || ''
  1319. form.value.partyBLegalPerson = supplier.legalPerson || ''
  1320. form.value.partyBAgent = supplier.agent || ''
  1321. form.value.partyBPhoneFax = supplier.phoneFax || ''
  1322. form.value.partyBBank = supplier.bankName || ''
  1323. form.value.partyBAccount = supplier.bankAccount || ''
  1324. } else {
  1325. form.value.partyA = supplier.supplierName || ''
  1326. form.value.partyAAddress = supplier.supplierAddress || ''
  1327. form.value.partyALegalPerson = supplier.legalPerson || ''
  1328. form.value.partyAAgent = supplier.agent || ''
  1329. form.value.partyAPhoneFax = supplier.phoneFax || ''
  1330. form.value.partyABank = supplier.bankName || ''
  1331. form.value.partyAAccount = supplier.bankAccount || ''
  1332. }
  1333. updateContractNoBySupplier(supplier.supplierCode)
  1334. rebuildContractName()
  1335. const allowToxic = Number((supplier as any).allowToxic || 0)
  1336. const allowExplosive = Number((supplier as any).allowExplosive || 0)
  1337. const { kept, removedNames } = removeProductsNotAllowedByHazard(
  1338. form.value.products || [],
  1339. allowToxic,
  1340. allowExplosive
  1341. )
  1342. form.value.products = kept
  1343. if (removedNames.length) {
  1344. $modal.msgWarning(`当前主体不支持以下产品,已自动移除:${removedNames.join('、')}`)
  1345. form.value.products.forEach((p) => calculateProductAmount(p))
  1346. calculateTotalAmount()
  1347. }
  1348. }
  1349. }
  1350. /** 更新合同编号中的供方编码 */
  1351. const updateContractNoBySupplier = (newSupplierCode: string | undefined) => {
  1352. if (!form.value.contractNo || !newSupplierCode) return
  1353. const contractNoPattern = /^([A-Z]+)\/X-JT(\d{8})(\d{3})$/
  1354. const match = form.value.contractNo.match(contractNoPattern)
  1355. if (match) {
  1356. const date = match[2]
  1357. const serialNum = match[3]
  1358. form.value.contractNo = `${newSupplierCode}/X-JT${date}${serialNum}`
  1359. } else {
  1360. const index = form.value.contractNo.indexOf('/X-JT')
  1361. if (index > 0) {
  1362. const oldSupplierCode = form.value.contractNo.substring(0, index)
  1363. form.value.contractNo = form.value.contractNo.replace(oldSupplierCode, newSupplierCode)
  1364. }
  1365. }
  1366. }
  1367. const CONTRACT_NO_STD_RE = /^([A-Z]+)\/X-JT(\d{8})(\d{3})$/
  1368. /** 签订日变更时:标准编号只换日期段,保留序号;并同步名称括号内编号 */
  1369. const syncContractNoDateFromSignDate = (signDateVal: string | null) => {
  1370. if (!signDateVal || !form.value.contractNo) return
  1371. const m = String(form.value.contractNo).match(CONTRACT_NO_STD_RE)
  1372. if (!m) return
  1373. const dateStr = signDateVal.replace(/-/g, '')
  1374. if (dateStr.length !== 8) return
  1375. if (m[2] === dateStr) return
  1376. const nextNo = `${m[1]}/X-JT${dateStr}${m[3]}`
  1377. form.value.contractNo = nextNo
  1378. rebuildContractName()
  1379. }
  1380. /** 面板单位全称 → 匹配交易主体/客户主数据取简称;对不上用全称 */
  1381. const resolvePartyShortName = (partyName?: string): string => {
  1382. const party = (partyName || '').trim()
  1383. if (!party) return ''
  1384. const supplier = form.value.supplierId ? supplierList.value.find((s) => s.id === form.value.supplierId) : undefined
  1385. const supplierName = (supplier?.supplierName || '').trim()
  1386. const supplierShort = (supplier?.shortName || supplierName || '').trim()
  1387. if (supplierName && party === supplierName) return supplierShort || party
  1388. if (supplierShort && party === supplierShort) return supplierShort
  1389. const customerName = (form.value.customerName || '').trim()
  1390. const customerShort = (customerShortName.value || '').trim()
  1391. const invoiceName = (customerInvoiceName.value || '').trim()
  1392. if (customerName && party === customerName) return customerShort || customerName
  1393. if (customerShort && party === customerShort) return customerShort
  1394. if (invoiceName && party === invoiceName) return customerShort || invoiceName
  1395. return party
  1396. }
  1397. /** 重建合同名称:始终 {供方简称}-{需方简称}({合同编号}),随面板调换 */
  1398. const rebuildContractName = () => {
  1399. const partyAShort = resolvePartyShortName(form.value.partyA)
  1400. const partyBShort = resolvePartyShortName(form.value.partyB)
  1401. const nameBody = [partyAShort, partyBShort].filter(Boolean).join('-')
  1402. if (!nameBody) return
  1403. const contractNo = (form.value.contractNo || '').trim()
  1404. form.value.contractName = contractNo ? `${nameBody}(${contractNo})` : nameBody
  1405. }
  1406. /** 根据面板与交易主体/客户推断是否已调换(编辑回显用) */
  1407. const syncPartiesSwappedFlagFromPanels = () => {
  1408. const partyA = (form.value.partyA || '').trim()
  1409. const partyB = (form.value.partyB || '').trim()
  1410. if (!partyA && !partyB) {
  1411. isPartiesSwapped.value = false
  1412. return
  1413. }
  1414. const supplier = form.value.supplierId
  1415. ? supplierList.value.find((s) => s.id === form.value.supplierId)
  1416. : undefined
  1417. const supplierName = (supplier?.supplierName || '').trim()
  1418. if (supplierName) {
  1419. if (partyB === supplierName && partyA !== supplierName) {
  1420. isPartiesSwapped.value = true
  1421. return
  1422. }
  1423. if (partyA === supplierName) {
  1424. isPartiesSwapped.value = false
  1425. return
  1426. }
  1427. }
  1428. const customerName = (form.value.customerName || '').trim()
  1429. const invoiceName = (customerInvoiceName.value || '').trim()
  1430. if ((customerName && partyA === customerName) || (invoiceName && partyA === invoiceName)) {
  1431. isPartiesSwapped.value = true
  1432. return
  1433. }
  1434. if ((customerName && partyB === customerName) || (invoiceName && partyB === invoiceName)) {
  1435. isPartiesSwapped.value = false
  1436. }
  1437. }
  1438. /** 供需方调换:仅交换面板字段,勿再调 handleSupplierChange(会按交易主体覆盖一侧,导致两边都变成交易主体) */
  1439. const handleSwapParties = async () => {
  1440. const temp = {
  1441. partyA: form.value.partyA,
  1442. partyAAddress: form.value.partyAAddress,
  1443. partyAContact: form.value.partyAContact,
  1444. partyAMobile: form.value.partyAMobile,
  1445. partyALegalPerson: form.value.partyALegalPerson,
  1446. partyAAgent: form.value.partyAAgent,
  1447. partyAPhoneFax: form.value.partyAPhoneFax,
  1448. partyABank: form.value.partyABank,
  1449. partyAAccount: form.value.partyAAccount
  1450. }
  1451. form.value.partyA = form.value.partyB
  1452. form.value.partyAAddress = form.value.partyBAddress
  1453. form.value.partyAContact = form.value.partyBContact
  1454. form.value.partyAMobile = form.value.partyBMobile
  1455. form.value.partyALegalPerson = form.value.partyBLegalPerson
  1456. form.value.partyAAgent = form.value.partyBAgent
  1457. form.value.partyAPhoneFax = form.value.partyBPhoneFax
  1458. form.value.partyABank = form.value.partyBBank
  1459. form.value.partyAAccount = form.value.partyBAccount
  1460. form.value.partyB = temp.partyA
  1461. form.value.partyBAddress = temp.partyAAddress
  1462. form.value.partyBContact = temp.partyAContact
  1463. form.value.partyBMobile = temp.partyAMobile
  1464. form.value.partyBLegalPerson = temp.partyALegalPerson
  1465. form.value.partyBAgent = temp.partyAAgent
  1466. form.value.partyBPhoneFax = temp.partyAPhoneFax
  1467. form.value.partyBBank = temp.partyABank
  1468. form.value.partyBAccount = temp.partyAAccount
  1469. isPartiesSwapped.value = !isPartiesSwapped.value
  1470. rebuildContractName()
  1471. $modal.msgSuccess('供需方信息已调换')
  1472. }
  1473. /** 合同类型变化处理 */
  1474. const handleContractTypeChange = (value: string) => {
  1475. if (isFrameworkContractType(value)) {
  1476. form.value.amount = 0
  1477. form.value.products?.forEach((p) => {
  1478. p.price = 0
  1479. p.subtotal = 0
  1480. p.taxAmount = 0
  1481. if (!p.priceTiers) {
  1482. p.priceTiers = []
  1483. }
  1484. })
  1485. }
  1486. if (value === 'purchase' && !isPartiesSwapped.value) {
  1487. $modal
  1488. .confirm('检测到您选择了采购合同,系统将自动调换供需方信息,是否继续?')
  1489. .then(async () => {
  1490. await handleSwapParties()
  1491. })
  1492. .catch(() => {
  1493. rebuildContractName()
  1494. })
  1495. } else {
  1496. rebuildContractName()
  1497. }
  1498. }
  1499. /** 合同模版变化处理 */
  1500. const handleContractTemplateChange = (value: string) => {
  1501. if (value === 'customer_template') {
  1502. ElMessage({
  1503. message: '使用客户模版时,必须上传合同附件!',
  1504. type: 'warning',
  1505. duration: 3000
  1506. })
  1507. }
  1508. }
  1509. /** 合同期限日期范围变化 */
  1510. const handleDateRangeChange = (val: [string, string] | null) => {
  1511. if (val && val.length === 2) {
  1512. form.value.startDate = val[0]
  1513. form.value.endDate = val[1]
  1514. } else {
  1515. form.value.startDate = ''
  1516. form.value.endDate = ''
  1517. contractDateRange.value = [] as any
  1518. }
  1519. nextTick(() => {
  1520. formRef.value?.validateField('startDate')
  1521. })
  1522. }
  1523. /** 签订日期变化处理 */
  1524. const handleSignDateChange = (val: string | null) => {
  1525. if (val) {
  1526. const signDate = new Date(val)
  1527. const endDate = new Date(signDate)
  1528. endDate.setDate(endDate.getDate() + 30)
  1529. const formatDate = (date: Date): string => {
  1530. const year = date.getFullYear()
  1531. const month = String(date.getMonth() + 1).padStart(2, '0')
  1532. const day = String(date.getDate()).padStart(2, '0')
  1533. return `${year}-${month}-${day}`
  1534. }
  1535. const startDateStr = formatDate(signDate)
  1536. const endDateStr = formatDate(endDate)
  1537. contractDateRange.value = [startDateStr, endDateStr]
  1538. form.value.startDate = startDateStr
  1539. form.value.endDate = endDateStr
  1540. } else {
  1541. contractDateRange.value = [] as any
  1542. form.value.startDate = ''
  1543. form.value.endDate = ''
  1544. }
  1545. syncContractNoDateFromSignDate(val)
  1546. nextTick(() => {
  1547. formRef.value?.validateField('startDate')
  1548. })
  1549. }
  1550. /** 添加产品 */
  1551. const handleAddProduct = () => {
  1552. if (!form.value.supplierId) {
  1553. $modal.msgWarning('请先选择交易主体')
  1554. return
  1555. }
  1556. productSelectorVisible.value = true
  1557. }
  1558. /** 产品选择确认 */
  1559. const handleProductSelected = (products: any[]) => {
  1560. const isFw = isFrameworkContractType(form.value.contractType)
  1561. products.forEach((product) => {
  1562. const brandMeta = initLineBrandMetaFromProduct(product)
  1563. form.value.products.push({
  1564. productId: product.id,
  1565. productName: product.productName,
  1566. productModel: product.model || '',
  1567. categoryId: product.categoryId,
  1568. categoryName: product.categoryName || '',
  1569. unit: product.unit || '个',
  1570. quantity: 1,
  1571. price: isFw ? 0 : product.price || 0,
  1572. taxRate: normalizeTaxRateDisplay(product.taxRate, 13),
  1573. taxAmount: 0,
  1574. subtotal: isFw ? 0 : product.price || 0,
  1575. packageSpec: '',
  1576. deliveryMethod: '',
  1577. description: product.description || '',
  1578. remark: '',
  1579. isToxic: Number(product.isToxic || 0),
  1580. isExplosive: Number(product.isExplosive || 0),
  1581. ...brandMeta,
  1582. priceTiers: isFw ? [] : undefined
  1583. })
  1584. })
  1585. form.value.products.forEach((p) => {
  1586. calculateProductAmount(p)
  1587. })
  1588. calculateTotalAmount()
  1589. }
  1590. const handleBrandIdChange = (row: ExtendedContractProductForm, val: string | undefined | null) => {
  1591. applyBrandSelectChange(row, val, row.brandOptions || [])
  1592. }
  1593. const aliasBrandManageVisible = ref(false)
  1594. const aliasBrandManageProductId = ref('')
  1595. const aliasBrandManageProductName = ref('')
  1596. const aliasBrandManageMode = ref<'alias' | 'brand'>('alias')
  1597. function openAliasBrandManage(row: ExtendedContractProductForm, mode: 'alias' | 'brand') {
  1598. if (!row.productId) return
  1599. aliasBrandManageProductId.value = String(row.productId)
  1600. aliasBrandManageProductName.value = String(
  1601. row.standardProductName || row.productName || ''
  1602. )
  1603. aliasBrandManageMode.value = mode
  1604. aliasBrandManageVisible.value = true
  1605. }
  1606. function handleAliasBrandManaged(product: Record<string, any>) {
  1607. applyManagedProductMetaToLines(
  1608. form.value.products || [],
  1609. aliasBrandManageProductId.value,
  1610. product
  1611. )
  1612. }
  1613. async function enrichContractProductBrandMeta(lines: ExtendedContractProductForm[]) {
  1614. await Promise.all(
  1615. (lines || []).map(async (line) => {
  1616. if (!line.productId) return
  1617. try {
  1618. const res: any = await fetchProductDetail({ id: String(line.productId) })
  1619. const data = res?.data ?? res
  1620. if (!data) return
  1621. const meta = initLineBrandMetaFromProduct(data)
  1622. line.standardProductName = meta.standardProductName
  1623. line.aliasOptions = meta.aliasOptions
  1624. line.aliasName = resolveAliasFromSavedName(
  1625. line.productName,
  1626. meta.standardProductName,
  1627. meta.aliasOptions
  1628. )
  1629. line.brandOptions = meta.brandOptions
  1630. if (meta.brandOptions.length) {
  1631. if (line.brandMode === 'required' && line.brandId) {
  1632. applyBrandSelectChange(line, line.brandId, meta.brandOptions)
  1633. } else {
  1634. line.brandMode = 'any'
  1635. line.brandId = undefined
  1636. line.brandName = undefined
  1637. }
  1638. } else {
  1639. line.brandMode = undefined
  1640. line.brandId = undefined
  1641. line.brandName = undefined
  1642. }
  1643. } catch (e) {
  1644. console.warn('enrich contract brand meta failed', line.productId, e)
  1645. }
  1646. })
  1647. )
  1648. }
  1649. /** 规范化税率展示 */
  1650. const normalizeTaxRateDisplay = (value: any, defaultValue = 0): number => {
  1651. if (value === null || value === undefined || value === '') {
  1652. return defaultValue
  1653. }
  1654. const num = Number(value)
  1655. if (Number.isNaN(num)) {
  1656. return defaultValue
  1657. }
  1658. return Number.isInteger(num) ? num : parseFloat(num.toString())
  1659. }
  1660. /** 产品选择变化 */
  1661. const handleProductSelectionChange = (selection: ExtendedContractProductForm[]) => {
  1662. selectedProducts.value = selection
  1663. }
  1664. /** 删除选中的产品 */
  1665. const handleRemoveSelectedProducts = () => {
  1666. if (selectedProducts.value.length === 0) return
  1667. $modal
  1668. .confirm(`确认删除选中的 ${selectedProducts.value.length} 个产品吗?`)
  1669. .then(() => {
  1670. selectedProducts.value.forEach((selectedProduct) => {
  1671. const index = form.value.products.findIndex((p) => p === selectedProduct)
  1672. if (index > -1) {
  1673. form.value.products.splice(index, 1)
  1674. }
  1675. })
  1676. selectedProducts.value = []
  1677. calculateTotalAmount()
  1678. $modal.msgSuccess('删除成功')
  1679. })
  1680. .catch(() => {})
  1681. }
  1682. /** 删除产品 */
  1683. const handleRemoveProduct = (index: number) => {
  1684. form.value.products.splice(index, 1)
  1685. calculateTotalAmount()
  1686. }
  1687. /** 单价变化 */
  1688. const handlePriceChange = (row: ExtendedContractProductForm) => {
  1689. calculateProductAmount(row)
  1690. calculateTotalAmount()
  1691. }
  1692. /** 数量变化 */
  1693. const handleQuantityChange = (row: ExtendedContractProductForm) => {
  1694. calculateProductAmount(row)
  1695. calculateTotalAmount()
  1696. }
  1697. /** 税率变化 */
  1698. const handleTaxRateChange = (row: ExtendedContractProductForm) => {
  1699. calculateProductAmount(row)
  1700. calculateTotalAmount()
  1701. }
  1702. /** 单位变化 */
  1703. const handleUnitChange = (_row: ExtendedContractProductForm) => {
  1704. // 单位变化通常不需要重新计算金额
  1705. }
  1706. /** 包装规格变更处理 */
  1707. const handlePackageSpecChange = (product: ExtendedContractProductForm, value: string) => {
  1708. product.packageSpec = value
  1709. }
  1710. /** 计算产品金额 */
  1711. const calculateProductAmount = (product: ExtendedContractProductForm) => {
  1712. if (isFrameworkContractType(form.value.contractType)) {
  1713. product.price = 0
  1714. product.subtotal = 0
  1715. product.taxAmount = 0
  1716. return
  1717. }
  1718. const price = parseFloat(product.price?.toString() || '0')
  1719. const quantity = parseFloat(product.quantity?.toString() || '0')
  1720. const taxRate = parseFloat(product.taxRate?.toString() || '0')
  1721. const subtotal = Math.round(price * quantity * 100) / 100
  1722. product.subtotal = subtotal
  1723. const taxRateDecimal = taxRate / 100
  1724. let taxAmount = 0
  1725. if (taxRate > 0 && subtotal > 0) {
  1726. const taxBase = subtotal / (1 + taxRateDecimal)
  1727. taxAmount = Math.round(taxBase * taxRateDecimal * 100) / 100
  1728. }
  1729. product.taxAmount = taxAmount
  1730. }
  1731. /** 计算合计金额 */
  1732. const calculateTotalAmount = () => {
  1733. if (isFrameworkContractType(form.value.contractType)) {
  1734. form.value.amount = 0
  1735. return
  1736. }
  1737. let total = 0
  1738. form.value.products.forEach((item) => {
  1739. const quantity = item.quantity || 0
  1740. const price = item.price || 0
  1741. const discount = item.discount || 0
  1742. const subtotal = quantity * price * (1 - discount / 100)
  1743. ;(item as ExtendedContractProductForm).subtotal = subtotal
  1744. total += subtotal
  1745. })
  1746. form.value.amount = total
  1747. }
  1748. /** 框架合同:批量解析调价函 URL */
  1749. const enrichFrameworkTierLetterFiles = async () => {
  1750. const products = form.value.products || []
  1751. const idSet = new Set<string>()
  1752. products.forEach((p: any) => {
  1753. ;(p.priceTiers || []).forEach((t: any) => {
  1754. ;(t.letterOssIds || []).forEach((id: string) => idSet.add(String(id)))
  1755. })
  1756. })
  1757. if (idSet.size === 0) return
  1758. const cache = new Map<string, { name: string; url: string }>()
  1759. fillAttachmentInfoCache([...idSet], cache)
  1760. products.forEach((p: any) => {
  1761. ;(p.priceTiers || []).forEach((t: any) => {
  1762. const ids = t.letterOssIds || []
  1763. t._letterFiles = ids.map((ossId: string, i: number) => {
  1764. const info = cache.get(String(ossId))
  1765. return {
  1766. name: info?.name || `调价函${i + 1}`,
  1767. ossId: String(ossId),
  1768. url: info?.url || ossId,
  1769. uid: `tier-prev-${t.id ?? 'n'}-${i}-${ossId}`,
  1770. status: 'success'
  1771. }
  1772. })
  1773. })
  1774. })
  1775. }
  1776. /** 组装提交/保存的产品明细 */
  1777. const buildProductsPayload = () => {
  1778. const list = form.value.products || []
  1779. list.forEach((product) => prepareLineAliasAndBrandForSubmit(product))
  1780. return list.map((product: any, idx: number) => {
  1781. const base: any = {
  1782. contractId: product.contractId || form.value.id,
  1783. productId: product.productId,
  1784. productName: product.productName,
  1785. productNo: product.productNo,
  1786. categoryId: product.categoryId,
  1787. categoryName: product.categoryName,
  1788. model: product.productModel || product.model,
  1789. unit: product.unit,
  1790. quantity: product.quantity,
  1791. price: product.price,
  1792. discount: product.discount,
  1793. taxRate: product.taxRate,
  1794. taxAmount: product.taxAmount,
  1795. subtotal: product.subtotal,
  1796. deliveryDate: product.deliveryDate,
  1797. description: product.description,
  1798. packageSpec: product.packageSpec,
  1799. deliveryMethod: product.deliveryMethod,
  1800. sort: product.sort ?? idx + 1,
  1801. remark: product.remark,
  1802. brandMode: product.brandMode || null,
  1803. brandId: product.brandMode === 'required' ? product.brandId || null : null,
  1804. brandName: product.brandMode === 'required' ? product.brandName || null : null
  1805. }
  1806. if (product.id) {
  1807. base.id = product.id
  1808. }
  1809. if (isFrameworkContractType(form.value.contractType)) {
  1810. base.price = 0
  1811. base.subtotal = 0
  1812. base.taxAmount = 0
  1813. base.priceTiers = (product.priceTiers || [])
  1814. .filter(
  1815. (t: any) => t.startDate && t.endDate && t.price != null && t.price !== '' && Array.isArray(t.letterOssIds) && t.letterOssIds.length > 0
  1816. )
  1817. .map((t: any, i: number) => ({
  1818. id: t.id,
  1819. startDate: t.startDate,
  1820. endDate: t.endDate,
  1821. price: Number(t.price),
  1822. letterOssIds: (t.letterOssIds || []).map((id: string) => String(id).trim()).filter(Boolean),
  1823. sort: t.sort ?? i + 1
  1824. }))
  1825. }
  1826. return base
  1827. })
  1828. }
  1829. const addPriceTierRow = (pIdx: number) => {
  1830. const p = form.value.products[pIdx]
  1831. if (!p) return
  1832. if (!p.priceTiers) {
  1833. p.priceTiers = []
  1834. }
  1835. p.priceTiers.push({ startDate: '', endDate: '', price: undefined, letterOssIds: [], _letterFiles: [] })
  1836. }
  1837. const removePriceTierRow = (pIdx: number, tIdx: number) => {
  1838. const p = form.value.products[pIdx]
  1839. if (!p?.priceTiers) return
  1840. p.priceTiers.splice(tIdx, 1)
  1841. }
  1842. const handleTierLetterUploadRequest = async (
  1843. options: UploadRequestOptions,
  1844. pIdx: number,
  1845. tIdx: number
  1846. ) => {
  1847. const p = form.value.products[pIdx]
  1848. const tiers = p?.priceTiers
  1849. if (!tiers || !tiers[tIdx]) {
  1850. options.onError?.(new Error('调价区间不存在'))
  1851. return
  1852. }
  1853. const row = tiers[tIdx]
  1854. const formData = buildAttachmentUploadFormData(options.file, {
  1855. bizType: CRM_UPLOAD_BIZ_TYPE.CONTRACT_PRICE_LETTER
  1856. })
  1857. try {
  1858. const res = await fetchUploadAttachment(formData)
  1859. const fileUrl = res?.fileUrl
  1860. if (!fileUrl) {
  1861. throw new Error('上传失败')
  1862. }
  1863. const oid = String(fileUrl)
  1864. row.letterOssIds = row.letterOssIds || []
  1865. row.letterOssIds.push(oid)
  1866. row._letterFiles = row._letterFiles || []
  1867. row._letterFiles.push({
  1868. name: options.file.name || `调价函${row._letterFiles.length + 1}`,
  1869. ossId: oid,
  1870. url: oid,
  1871. uid: options.file.uid,
  1872. status: 'success'
  1873. })
  1874. options.onSuccess?.(res)
  1875. } catch (error: any) {
  1876. ElMessage.error(error?.message || '上传失败')
  1877. options.onError?.(error)
  1878. }
  1879. }
  1880. const handleTierLetterRemove = (file: any, pIdx: number, tIdx: number) => {
  1881. const p = form.value.products[pIdx]
  1882. const tiers = p?.priceTiers
  1883. if (!tiers || !tiers[tIdx]) return
  1884. const row = tiers[tIdx]
  1885. const uid = file.uid
  1886. const idx = (row._letterFiles || []).findIndex((f: any) => f.uid === uid)
  1887. if (idx >= 0) {
  1888. const removed = row._letterFiles[idx]
  1889. row._letterFiles.splice(idx, 1)
  1890. if (removed?.ossId) {
  1891. row.letterOssIds = (row.letterOssIds || []).filter((id: string) => String(id) !== String(removed.ossId))
  1892. }
  1893. }
  1894. }
  1895. /** 处理附件数据 */
  1896. const handleAttachmentData = async () => {
  1897. attachmentList.value = buildUploadFileListFromField(
  1898. form.value.attachmentFiles
  1899. ) as ContractAttachmentItem[]
  1900. }
  1901. /** 保存草稿 */
  1902. const handleSaveDraft = async () => {
  1903. if (!form.value.customerId || form.value.customerId === 0) {
  1904. $modal.msgWarning('客户名称不能为空')
  1905. return
  1906. }
  1907. if (!form.value.supplierId) {
  1908. $modal.msgWarning('交易主体不能为空')
  1909. return
  1910. }
  1911. rebuildContractName()
  1912. saveDraftLoading.value = true
  1913. try {
  1914. const attachmentJson = serializeContractAttachments(attachmentList.value)
  1915. const data: any = { ...form.value }
  1916. data.status = 'draft'
  1917. data.approvalStatus = null
  1918. if (attachmentJson) {
  1919. data.attachmentFiles = attachmentJson
  1920. }
  1921. omitEmptyExceptPartyFields(data)
  1922. if (data.contactsName) {
  1923. data.contactName = data.contactsName
  1924. }
  1925. if (data.contactsPhone) {
  1926. data.contactMobile = data.contactsPhone
  1927. }
  1928. delete data.customerName
  1929. delete data.opportunityName
  1930. delete data.quoteNo
  1931. delete data.contactsName
  1932. delete data.contactsPhone
  1933. delete data.ownerUserName
  1934. delete data.templateContent
  1935. if (data.products && Array.isArray(data.products) && data.products.length > 0) {
  1936. ;(form.value.products || []).forEach((p) => prepareLineAliasAndBrandForSubmit(p))
  1937. for (let i = 0; i < form.value.products.length; i++) {
  1938. const product = form.value.products[i]
  1939. const rowNum = i + 1
  1940. if (!product.productName || product.productName.trim() === '') {
  1941. $modal.msgWarning(`第${rowNum}行产品的产品名称不能为空`)
  1942. return
  1943. }
  1944. }
  1945. data.products = buildProductsPayload()
  1946. } else {
  1947. delete data.products
  1948. }
  1949. if (form.value.id) {
  1950. await updateContract(data)
  1951. $modal.msgSuccess('保存成功')
  1952. } else {
  1953. await addContract(data)
  1954. $modal.msgSuccess('保存成功')
  1955. }
  1956. handleClose()
  1957. emit('success')
  1958. } finally {
  1959. saveDraftLoading.value = false
  1960. }
  1961. }
  1962. /** 提交审批 */
  1963. const handleSubmit = async () => {
  1964. try {
  1965. await formRef.value?.validate()
  1966. } catch (error) {
  1967. expandPartiesForInvalidFields(error as Record<string, unknown>)
  1968. ElMessage.warning({
  1969. message: '请填写完整的必填信息',
  1970. duration: 3000
  1971. })
  1972. return
  1973. }
  1974. if (form.value.contractTemplate === 'customer') {
  1975. const hasAttachments = attachmentList.value.some((file) => file.status === 'success' && file.ossId)
  1976. if (!hasAttachments) {
  1977. ElMessage.warning({
  1978. message: '使用客户模版时,必须上传合同附件',
  1979. duration: 3000
  1980. })
  1981. return
  1982. }
  1983. }
  1984. const requiresProducts = form.value.contractType === 'sale' || form.value.contractType === 'purchase' || isFrameworkContractType(form.value.contractType)
  1985. const validateProductRowCommon = (product: any, rowNum: number): boolean => {
  1986. if (!product.productName || String(product.productName).trim() === '') {
  1987. $modal.msgWarning(`第${rowNum}行产品的产品名称不能为空`)
  1988. return false
  1989. }
  1990. if (!product.quantity || Number(product.quantity) <= 0) {
  1991. $modal.msgWarning(`第${rowNum}行产品的数量不能为空且必须大于0`)
  1992. return false
  1993. }
  1994. if (!product.packageSpec || String(product.packageSpec).trim() === '') {
  1995. $modal.msgWarning(`第${rowNum}行产品的包装规格不能为空`)
  1996. return false
  1997. }
  1998. if (!product.deliveryMethod || String(product.deliveryMethod).trim() === '') {
  1999. $modal.msgWarning(`第${rowNum}行产品的送货方式不能为空`)
  2000. return false
  2001. }
  2002. return true
  2003. }
  2004. if (requiresProducts) {
  2005. if (!form.value.products || form.value.products.length === 0) {
  2006. $modal.msgWarning('销售合同、采购合同或框架合同必须至少添加一个产品')
  2007. return
  2008. }
  2009. ;(form.value.products || []).forEach((p) => prepareLineAliasAndBrandForSubmit(p))
  2010. for (let i = 0; i < form.value.products.length; i++) {
  2011. const product = form.value.products[i]
  2012. const rowNum = i + 1
  2013. if (!validateProductRowCommon(product, rowNum)) return
  2014. const isFw = isFrameworkContractType(form.value.contractType)
  2015. if (!isFw) {
  2016. if (!product.price || Number(product.price) <= 0) {
  2017. $modal.msgWarning(`第${rowNum}行产品的含税单价不能为空且必须大于0`)
  2018. return
  2019. }
  2020. if (!product.subtotal || Number(product.subtotal) <= 0) {
  2021. $modal.msgWarning(`第${rowNum}行产品的含税总价不能为空且必须大于0`)
  2022. return
  2023. }
  2024. } else {
  2025. const tiers = product.priceTiers || []
  2026. for (let j = 0; j < tiers.length; j++) {
  2027. const t = tiers[j]
  2028. const tRow = j + 1
  2029. if (!t.startDate || !t.endDate) {
  2030. $modal.msgWarning(`产品「${product.productName}」调价区间第${tRow}行:请选择开始与结束日期`)
  2031. return
  2032. }
  2033. if (String(t.startDate) > String(t.endDate)) {
  2034. $modal.msgWarning(`产品「${product.productName}」调价区间第${tRow}行:开始日期不能晚于结束日期`)
  2035. return
  2036. }
  2037. const pVal = t.price === null || t.price === '' ? NaN : Number(t.price)
  2038. if (Number.isNaN(pVal) || pVal <= 0) {
  2039. $modal.msgWarning(`产品「${product.productName}」调价区间第${tRow}行:含税单价必须大于0`)
  2040. return
  2041. }
  2042. if (!(t.letterOssIds?.length > 0)) {
  2043. $modal.msgWarning(`产品「${product.productName}」调价区间第${tRow}行:请上传调价函`)
  2044. return
  2045. }
  2046. }
  2047. }
  2048. }
  2049. } else if (form.value.products && form.value.products.length > 0) {
  2050. ;(form.value.products || []).forEach((p) => prepareLineAliasAndBrandForSubmit(p))
  2051. for (let i = 0; i < form.value.products.length; i++) {
  2052. const product = form.value.products[i]
  2053. const rowNum = i + 1
  2054. if (!validateProductRowCommon(product, rowNum)) return
  2055. if (!product.price || Number(product.price) <= 0) {
  2056. $modal.msgWarning(`第${rowNum}行产品的含税单价不能为空且必须大于0`)
  2057. return
  2058. }
  2059. if (!product.subtotal || Number(product.subtotal) <= 0) {
  2060. $modal.msgWarning(`第${rowNum}行产品的含税总价不能为空且必须大于0`)
  2061. return
  2062. }
  2063. }
  2064. }
  2065. submitLoading.value = true
  2066. try {
  2067. rebuildContractName()
  2068. const attachmentJson = serializeContractAttachments(attachmentList.value)
  2069. const data: any = { ...form.value }
  2070. if (attachmentJson) {
  2071. data.attachmentFiles = attachmentJson
  2072. }
  2073. omitEmptyExceptPartyFields(data)
  2074. if (data.contactsName) {
  2075. data.contactName = data.contactsName
  2076. }
  2077. if (data.contactsPhone) {
  2078. data.contactMobile = data.contactsPhone
  2079. }
  2080. delete data.customerName
  2081. delete data.opportunityName
  2082. delete data.quoteNo
  2083. delete data.contactsName
  2084. delete data.contactsPhone
  2085. delete data.ownerUserName
  2086. delete data.templateContent
  2087. if (data.products && Array.isArray(data.products) && data.products.length > 0) {
  2088. data.products = buildProductsPayload()
  2089. } else {
  2090. delete data.products
  2091. }
  2092. let contractId: string | number
  2093. if (form.value.id) {
  2094. await updateContract(data)
  2095. contractId = form.value.id
  2096. $modal.msgSuccess('保存成功')
  2097. } else {
  2098. const res = await addContract(data)
  2099. contractId = res.data
  2100. if (contractId == null || contractId === '') {
  2101. $modal.msgError('保存成功但未返回合同 ID,请从列表重新提交审批')
  2102. emit('success')
  2103. return
  2104. }
  2105. form.value.id = contractId as any
  2106. $modal.msgSuccess('保存成功')
  2107. }
  2108. approvalDialogRef.value?.open(contractId, 'submit')
  2109. } finally {
  2110. submitLoading.value = false
  2111. }
  2112. }
  2113. /** 审批成功回调 */
  2114. const handleApprovalSuccess = () => {
  2115. handleClose()
  2116. emit('success')
  2117. }
  2118. /** 关闭对话框 */
  2119. const handleClose = () => {
  2120. dialogVisible.value = false
  2121. }
  2122. /** 加载供方信息列表 */
  2123. const loadSupplierList = async () => {
  2124. try {
  2125. const res = await listAllSupplierInfo({ status: '0' })
  2126. supplierList.value = res.data || []
  2127. return res.data || []
  2128. } catch (error) {
  2129. console.error('加载供方信息列表失败:', error)
  2130. return []
  2131. }
  2132. }
  2133. </script>
  2134. <style scoped lang="scss">
  2135. .contract-form-dialog {
  2136. :deep(.el-dialog__wrapper) {
  2137. padding: 0 !important;
  2138. top: 20px !important;
  2139. height: calc(100vh - 40px) !important;
  2140. }
  2141. :deep(.el-dialog) {
  2142. backdrop-filter: none;
  2143. height: 100% !important;
  2144. max-height: calc(100vh - 40px);
  2145. display: flex;
  2146. flex-direction: column;
  2147. }
  2148. :deep(.dialog-footer) {
  2149. display: flex;
  2150. justify-content: center;
  2151. align-items: center;
  2152. gap: 16px;
  2153. width: 100%;
  2154. }
  2155. :deep(.el-dialog__header),
  2156. :deep(.el-dialog__footer) {
  2157. flex: 0 0 auto;
  2158. }
  2159. :deep(.el-dialog__body) {
  2160. padding-top: 8px;
  2161. flex: 1 1 auto;
  2162. min-height: 0;
  2163. max-height: none;
  2164. overflow-y: auto;
  2165. overflow-x: hidden;
  2166. }
  2167. }
  2168. .contract-form-body {
  2169. position: relative;
  2170. min-height: 280px;
  2171. padding: 0 4px;
  2172. }
  2173. .contract-basic-info {
  2174. display: grid;
  2175. grid-template-columns: repeat(4, minmax(0, 1fr));
  2176. gap: 12px 14px;
  2177. margin-bottom: 20px;
  2178. :deep(.el-form-item) {
  2179. margin-bottom: 0;
  2180. }
  2181. :deep(.el-input-number) {
  2182. width: 100%;
  2183. }
  2184. }
  2185. @media (max-width: 1100px) {
  2186. .contract-basic-info {
  2187. grid-template-columns: repeat(2, minmax(0, 1fr));
  2188. }
  2189. }
  2190. @media (max-width: 560px) {
  2191. .contract-basic-info {
  2192. grid-template-columns: 1fr;
  2193. }
  2194. }
  2195. .parties-section {
  2196. margin: 8px 0 20px;
  2197. }
  2198. .parties-section-toolbar {
  2199. display: flex;
  2200. justify-content: flex-end;
  2201. align-items: center;
  2202. gap: 8px;
  2203. margin-bottom: 12px;
  2204. }
  2205. .parties-row {
  2206. display: flex;
  2207. align-items: stretch;
  2208. gap: 0;
  2209. min-height: 0;
  2210. }
  2211. .party-panel {
  2212. flex: 1 1 0;
  2213. min-width: 0;
  2214. padding: 16px;
  2215. border: 1px solid var(--border, #d9e8e2);
  2216. border-radius: 10px;
  2217. background: #fff;
  2218. &.is-collapsed {
  2219. padding: 12px 16px;
  2220. }
  2221. :deep(.el-form-item) {
  2222. margin-bottom: 0;
  2223. }
  2224. }
  2225. .party-panel__header {
  2226. display: flex;
  2227. align-items: center;
  2228. margin-bottom: 12px;
  2229. .party-panel.is-collapsed & {
  2230. margin-bottom: 8px;
  2231. }
  2232. }
  2233. .party-panel__title {
  2234. margin-bottom: 0;
  2235. padding-left: 10px;
  2236. font-size: 14px;
  2237. font-weight: 600;
  2238. color: var(--section-bar-title-color, var(--primary-dark, #059669));
  2239. line-height: 1.5;
  2240. border-left: 3px solid var(--section-bar-border-color, var(--primary, #10b981));
  2241. }
  2242. .party-panel__summary {
  2243. display: flex;
  2244. align-items: baseline;
  2245. gap: 8px;
  2246. min-width: 0;
  2247. padding: 2px 0 2px 10px;
  2248. }
  2249. .party-panel__summary-label {
  2250. flex-shrink: 0;
  2251. font-size: 12px;
  2252. color: var(--mint-text-muted, #64748b);
  2253. line-height: 1.5;
  2254. }
  2255. .party-panel__summary-value {
  2256. min-width: 0;
  2257. font-size: 14px;
  2258. font-weight: 500;
  2259. color: var(--mint-text, #0f172a);
  2260. line-height: 1.5;
  2261. overflow: hidden;
  2262. text-overflow: ellipsis;
  2263. white-space: nowrap;
  2264. &.is-empty {
  2265. font-weight: 400;
  2266. color: var(--mint-text-muted, #94a3b8);
  2267. }
  2268. }
  2269. .party-flow-bridge {
  2270. flex: 0 0 88px;
  2271. display: flex;
  2272. flex-direction: column;
  2273. align-items: center;
  2274. justify-content: center;
  2275. gap: 10px;
  2276. padding: 0 8px;
  2277. }
  2278. .party-flow-bridge__label {
  2279. font-size: 12px;
  2280. font-weight: 600;
  2281. color: var(--primary-dark, #168f45);
  2282. letter-spacing: 0.06em;
  2283. padding: 4px 10px;
  2284. border-radius: 999px;
  2285. background: #e6f8ed;
  2286. border: 1px solid #a8e0b8;
  2287. line-height: 1.2;
  2288. }
  2289. .party-flow-bridge__arrow {
  2290. display: flex;
  2291. align-items: center;
  2292. justify-content: center;
  2293. width: 44px;
  2294. height: 44px;
  2295. border-radius: 50%;
  2296. color: var(--primary-dark, #168f45);
  2297. background: linear-gradient(145deg, #e6f8ed 0%, #d4f0de 100%);
  2298. border: 1px solid #a8e0b8;
  2299. box-shadow: 0 2px 8px rgba(28, 168, 81, 0.14);
  2300. svg {
  2301. width: 22px;
  2302. height: 22px;
  2303. display: block;
  2304. }
  2305. }
  2306. @media (max-width: 1100px) {
  2307. .parties-row {
  2308. flex-direction: column;
  2309. min-height: 0;
  2310. }
  2311. .party-flow-bridge {
  2312. flex: 0 0 auto;
  2313. flex-direction: row;
  2314. gap: 12px;
  2315. padding: 12px 0;
  2316. }
  2317. .party-flow-bridge__arrow {
  2318. transform: rotate(90deg);
  2319. }
  2320. }
  2321. .total-section {
  2322. margin-top: 20px;
  2323. padding: 15px;
  2324. background-color: #f5f7fa;
  2325. border-radius: 4px;
  2326. }
  2327. .total-item {
  2328. display: flex;
  2329. justify-content: flex-end;
  2330. align-items: center;
  2331. margin-bottom: 10px;
  2332. font-size: 16px;
  2333. &:last-child {
  2334. margin-bottom: 0;
  2335. }
  2336. }
  2337. .total-label {
  2338. font-weight: bold;
  2339. margin-right: 10px;
  2340. }
  2341. .total-value {
  2342. font-size: 18px;
  2343. font-weight: bold;
  2344. }
  2345. .text-muted {
  2346. color: #1e293b;
  2347. }
  2348. :deep(.money-field-input.el-input-number .el-input__inner),
  2349. :deep(.money-field-input.el-input-number .el-input__wrapper input) {
  2350. color: #dc2626 !important;
  2351. -webkit-text-fill-color: #dc2626 !important;
  2352. font-weight: 600;
  2353. }
  2354. /* 统一表格内输入框和下拉框高度 */
  2355. :deep(.el-table .el-input__wrapper) {
  2356. height: 32px !important;
  2357. min-height: 32px !important;
  2358. }
  2359. :deep(.el-table .el-select__wrapper) {
  2360. height: 32px !important;
  2361. min-height: 32px !important;
  2362. }
  2363. :deep(.el-table .el-input--small .el-input__wrapper) {
  2364. height: 32px !important;
  2365. min-height: 32px !important;
  2366. }
  2367. :deep(.el-table .el-select--small .el-select__wrapper) {
  2368. height: 32px !important;
  2369. min-height: 32px !important;
  2370. }
  2371. /* 价格输入框红色文字 */
  2372. .price-input :deep(.el-input__inner) {
  2373. color: #e34d59;
  2374. }
  2375. /* 去除输入框后置按钮的边框和背景 */
  2376. :deep(.el-input-group__append) {
  2377. background: transparent !important;
  2378. border: none !important;
  2379. box-shadow: none !important;
  2380. }
  2381. :deep(.el-input-group__append .el-button) {
  2382. border: none !important;
  2383. background: transparent !important;
  2384. box-shadow: none !important;
  2385. padding: 0 15px !important;
  2386. }
  2387. :deep(.el-input-group__append .el-button:hover) {
  2388. background: transparent !important;
  2389. border: none !important;
  2390. }
  2391. :deep(.el-input-group__append .el-button:focus) {
  2392. background: transparent !important;
  2393. border: none !important;
  2394. }
  2395. /* 框架合同调价函:表格内多图卡片上传 */
  2396. .tier-letter-upload :deep(.el-upload-list--picture-card) {
  2397. display: flex;
  2398. flex-wrap: wrap;
  2399. gap: 8px;
  2400. }
  2401. .tier-letter-upload :deep(.el-upload--picture-card) {
  2402. width: 72px;
  2403. height: 72px;
  2404. line-height: 72px;
  2405. }
  2406. .tier-letter-upload :deep(.el-upload-list--picture-card .el-upload-list__item) {
  2407. width: 72px;
  2408. height: 72px;
  2409. margin: 0;
  2410. }
  2411. /* 框架合同:增加「调价函」行内按钮可点区域宽度 */
  2412. .fw-tier-letter-add-btn.el-button--primary.is-link {
  2413. min-width: 108px;
  2414. padding-left: 12px;
  2415. padding-right: 12px;
  2416. justify-content: center;
  2417. }
  2418. .mb-3 {
  2419. margin-bottom: 12px;
  2420. }
  2421. .mb-4 {
  2422. margin-bottom: 16px;
  2423. }
  2424. .ml-2 {
  2425. margin-left: 8px;
  2426. }
  2427. .line-meta-cell {
  2428. display: flex;
  2429. align-items: center;
  2430. gap: 4px;
  2431. min-width: 0;
  2432. }
  2433. .line-meta-cell__control {
  2434. flex: 1;
  2435. min-width: 0;
  2436. }
  2437. .line-meta-cell__empty {
  2438. flex: 1;
  2439. min-width: 0;
  2440. }
  2441. .line-meta-cell__btn {
  2442. flex-shrink: 0;
  2443. padding: 4px;
  2444. }
  2445. </style>