add.vue 71 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961
  1. <template>
  2. <div class="app-container">
  3. <el-card shadow="never" class="mb-3">
  4. <div class="flex items-center justify-between">
  5. <div class="flex items-center">
  6. <el-button icon="ArrowLeft" @click="handleBack">返回</el-button>
  7. <span class="ml-4 text-xl font-bold">{{ pageTitle }}</span>
  8. </div>
  9. </div>
  10. </el-card>
  11. <div class="product-wizard-page">
  12. <!-- 步骤条 -->
  13. <el-card shadow="never" class="mb-3">
  14. <el-steps :active="currentStep" finish-status="success" align-center>
  15. <el-step title="选择分类" description="选择商品分类" />
  16. <el-step title="填写商品信息" description="填写商品基本信息" />
  17. <el-step title="完成" description="确认提交" />
  18. </el-steps>
  19. </el-card>
  20. <!-- 步骤内容 -->
  21. <div class="step-content" v-loading="loading">
  22. <!-- 步骤1: 选择分类 -->
  23. <el-card v-show="currentStep === 0" shadow="never" class="step-card">
  24. <template #header>
  25. <div class="flex items-center justify-between">
  26. <span class="text-lg font-bold">选择分类</span>
  27. <span v-if="selectedLevel3Name" class="text-sm ml-4" style="color: #409eff"> 已选:{{ getCategoryPath() }} </span>
  28. </div>
  29. </template>
  30. <div class="category-selection">
  31. <el-row :gutter="20">
  32. <!-- 一级分类 -->
  33. <el-col :span="8">
  34. <div class="category-box">
  35. <div class="category-header">选择一级分类</div>
  36. <div class="category-search">
  37. <el-input v-model="searchLevel1" placeholder="搜索一级分类" clearable prefix-icon="Search" size="small" />
  38. </div>
  39. <div class="category-list">
  40. <div
  41. v-for="item in filteredLevel1Categories"
  42. :key="item.id"
  43. :class="[
  44. 'category-item',
  45. { 'active': categoryForm.topCategoryId === item.id, 'disabled': !item.children || item.children.length === 0 }
  46. ]"
  47. @click="selectLevel1(item)"
  48. >
  49. <span>{{ item.label }}</span>
  50. <el-icon v-if="categoryForm.topCategoryId === item.id"><ArrowRight /></el-icon>
  51. </div>
  52. <el-empty v-if="filteredLevel1Categories.length === 0" description="暂无数据" :image-size="60" />
  53. </div>
  54. </div>
  55. </el-col>
  56. <!-- 二级分类 -->
  57. <el-col :span="8">
  58. <div class="category-box">
  59. <div class="category-header">选择二级分类</div>
  60. <div class="category-search">
  61. <el-input v-model="searchLevel2" placeholder="搜索二级分类" clearable prefix-icon="Search" size="small" />
  62. </div>
  63. <div class="category-list">
  64. <div
  65. v-for="item in filteredLevel2Categories"
  66. :key="item.id"
  67. :class="[
  68. 'category-item',
  69. { 'active': categoryForm.mediumCategoryId === item.id, 'disabled': !item.children || item.children.length === 0 }
  70. ]"
  71. @click="selectLevel2(item)"
  72. >
  73. <span>{{ item.label }}</span>
  74. <el-icon v-if="categoryForm.mediumCategoryId === item.id"><ArrowRight /></el-icon>
  75. </div>
  76. <el-empty
  77. v-if="filteredLevel2Categories.length === 0"
  78. :description="categoryForm.topCategoryId ? '当前分类无子分类,请选择其他一级分类' : '请先选择一级分类'"
  79. :image-size="60"
  80. />
  81. </div>
  82. </div>
  83. </el-col>
  84. <!-- 三级分类 -->
  85. <el-col :span="8">
  86. <div class="category-box">
  87. <div class="category-header">选择三级分类</div>
  88. <div class="category-search">
  89. <el-select
  90. v-model="level3SearchValue"
  91. placeholder="搜索全部三级分类"
  92. filterable
  93. remote
  94. clearable
  95. :remote-method="handleLevel3Search"
  96. :loading="level3SearchLoading"
  97. size="small"
  98. class="w-full"
  99. @change="handleLevel3SearchSelect"
  100. >
  101. <el-option v-for="item in level3SearchOptions" :key="item.id" :label="item.categoryName" :value="item.id" />
  102. </el-select>
  103. </div>
  104. <div class="category-list">
  105. <div
  106. v-for="item in filteredLevel3Categories"
  107. :key="item.id"
  108. :class="['category-item', { 'active': categoryForm.bottomCategoryId === item.id }]"
  109. @click="selectLevel3(item)"
  110. >
  111. <span>{{ item.label }}</span>
  112. <el-icon v-if="categoryForm.bottomCategoryId === item.id"><Check /></el-icon>
  113. </div>
  114. <el-empty
  115. v-if="filteredLevel3Categories.length === 0"
  116. :description="categoryForm.mediumCategoryId ? '当前分类无子分类,请选择其他二级分类' : '请先选择二级分类'"
  117. :image-size="60"
  118. />
  119. </div>
  120. </div>
  121. </el-col>
  122. </el-row>
  123. </div>
  124. <!-- 已选分类提示 -->
  125. <!-- <div class="mt-4">
  126. <el-checkbox v-model="autoCreateCategory" label="如果选择的分类不存在,自动创建分类" />
  127. </div>
  128. <div class="mt-2">
  129. <el-input
  130. v-model="manualCategoryInput"
  131. placeholder="请输入入口类名称"
  132. clearable
  133. style="width: 400px;"
  134. />
  135. </div> -->
  136. </el-card>
  137. <!-- 步骤2: 填写商品信息 -->
  138. <el-card v-show="currentStep === 1" shadow="never" class="step-card">
  139. <template #header>
  140. <span class="text-lg font-bold">基本信息</span>
  141. </template>
  142. <el-form ref="productFormRef" :model="productForm" :rules="productRules" label-width="120px" class="product-info-form">
  143. <!-- 商品分类显示 -->
  144. <el-form-item label="商品分类:">
  145. <div class="category-display">
  146. <span class="category-text">{{ getCategoryPath() }}</span>
  147. <el-link type="primary" :underline="false" @click="currentStep = 0" class="ml-2">修改</el-link>
  148. <el-link type="danger" :underline="false" @click="clearCategory" class="ml-2">删除</el-link>
  149. </div>
  150. </el-form-item>
  151. <!-- 商品名称 -->
  152. <el-form-item label="商品名称:" prop="itemName" required>
  153. <el-input v-model="productForm.itemName" type="textarea" :rows="2" placeholder="请输入商品名称" maxlength="200" show-word-limit />
  154. </el-form-item>
  155. <!-- A10产品名称 -->
  156. <el-form-item label="A10产品名称:">
  157. <el-input
  158. :value="a10ProductNameComputed"
  159. type="textarea"
  160. :rows="2"
  161. disabled
  162. placeholder="自动拼接:品牌名 + 规格型号 + 产品分类 + 发票规格"
  163. />
  164. <div class="form-item-tip">A10产品名称由系统自动拼接:品牌名 + 规格型号 + 产品分类(三级分类)+ 发票规格,无需手动填写</div>
  165. </el-form-item>
  166. <!-- 规格型号 和 UPC(69)条码 -->
  167. <el-row :gutter="20">
  168. <el-col :span="12">
  169. <el-form-item label="规格型号:">
  170. <el-input v-model="productForm.specificationsCode" placeholder="请输入规格型号" maxlength="20" show-word-limit />
  171. </el-form-item>
  172. </el-col>
  173. <el-col :span="12">
  174. <el-form-item label="UPC(69)条码:">
  175. <el-input v-model="productForm.barCoding" placeholder="请输入UPC(69)条码" maxlength="20" show-word-limit @input="handleUpcInput" />
  176. </el-form-item>
  177. </el-col>
  178. </el-row>
  179. <!-- 发票名称 和 发票规格 -->
  180. <el-row :gutter="20">
  181. <el-col :span="12">
  182. <el-form-item label="发票名称:">
  183. <el-input v-model="productForm.invoiceName" placeholder="请输入发票名称" maxlength="20" show-word-limit />
  184. </el-form-item>
  185. </el-col>
  186. <el-col :span="12">
  187. <el-form-item label="发票规格:">
  188. <el-input v-model="productForm.invoiceSpecs" placeholder="请输入发票规格" maxlength="20" show-word-limit />
  189. </el-form-item>
  190. </el-col>
  191. </el-row>
  192. <el-row :gutter="20">
  193. <!-- 商品品牌 -->
  194. <el-col :span="12">
  195. <el-form-item label="商品品牌:" prop="brandId" required>
  196. <el-select
  197. v-model="productForm.brandId"
  198. placeholder="请输入品牌名称搜索"
  199. filterable
  200. remote
  201. clearable
  202. :remote-method="handleBrandSearch"
  203. :loading="brandLoading"
  204. class="w-full"
  205. >
  206. <el-option v-for="item in brandOptions" :key="item.id" :label="`${item.brandNo},${item.brandName}`" :value="item.id" />
  207. </el-select>
  208. </el-form-item>
  209. </el-col>
  210. <el-col :span="12">
  211. <el-form-item label="单位:">
  212. <el-select
  213. v-model="productForm.unitId"
  214. placeholder="请选择"
  215. clearable
  216. class="w-full"
  217. :disabled="productForm.productReviewStatus === 1"
  218. >
  219. <el-option v-for="option in unitOptions" :key="option.id" :label="`${option.unitNo},${option.unitName}`" :value="option.id" />
  220. </el-select>
  221. </el-form-item>
  222. </el-col>
  223. </el-row>
  224. <!-- 税率编码 、税率 和 币种 -->
  225. <el-row :gutter="20">
  226. <el-col :span="12">
  227. <el-form-item label="税率编码:">
  228. <el-input
  229. v-model="taxCodeNo"
  230. placeholder="点击选择税率编码"
  231. readonly
  232. class="w-full"
  233. style="cursor: pointer"
  234. @click="taxCodeSelectRef?.open()"
  235. >
  236. <template #suffix>
  237. <el-icon style="cursor: pointer" @click.stop="taxCodeSelectRef?.open()"><Search /></el-icon>
  238. </template>
  239. </el-input>
  240. </el-form-item>
  241. </el-col>
  242. <el-col :span="12">
  243. <el-form-item label="税率:" required>
  244. <el-select v-model="productForm.taxRate" placeholder="请选择税率" clearable class="w-full">
  245. <el-option v-for="option in taxRateOptions" :key="option.id" :label="`${option.taxrateNo},${option.taxrateName}`" :value="option.taxrate" />
  246. </el-select>
  247. </el-form-item>
  248. </el-col>
  249. </el-row>
  250. <el-row :gutter="20">
  251. <el-col :span="12">
  252. <el-form-item label="币种:">
  253. <el-select v-model="productForm.currency" placeholder="请选择" class="w-full">
  254. <el-option label="人民币(RMB)" value="RMB" />
  255. <el-option label="美元(USD)" value="USD" />
  256. <el-option label="欧元(EUR)" value="EUR" />
  257. </el-select>
  258. </el-form-item>
  259. </el-col>
  260. </el-row>
  261. <!-- TaxCodeSelect 弹窗 -->
  262. <TaxCodeSelect ref="taxCodeSelectRef" @select="handleTaxCodeSelect" />
  263. <!-- 销量人气 -->
  264. <el-row :gutter="20">
  265. <el-col :span="12">
  266. <el-form-item label="销量人气:">
  267. <el-input
  268. v-model="productForm.salesVolume"
  269. type="number"
  270. placeholder="请输入销量人气"
  271. :min="0"
  272. step="1"
  273. @input="handleSalesVolumeInput"
  274. />
  275. </el-form-item>
  276. </el-col>
  277. </el-row>
  278. <!-- 促销标题 -->
  279. <el-form-item label="促销标题:">
  280. <el-input v-model="productForm.promotionTitle" type="textarea" :rows="3" placeholder="请输入促销标题" maxlength="300" show-word-limit />
  281. </el-form-item>
  282. <!-- 商品简介 -->
  283. <el-form-item label="商品简介:">
  284. <el-input v-model="productForm.productDescription" type="textarea" :rows="3" placeholder="请输入商品简介" maxlength="500" show-word-limit />
  285. </el-form-item>
  286. <!-- 重量 和 体积 -->
  287. <el-row :gutter="20">
  288. <el-col :span="12">
  289. <el-form-item label="商品重量:">
  290. <el-input v-model="productForm.productWeight" placeholder="0" maxlength="10" show-word-limit>
  291. <template #append>
  292. <el-select v-model="productForm.weightUnit" placeholder="请选择" style="width: 100px">
  293. <el-option label="kg" value="kg" />
  294. <el-option label="g" value="g" />
  295. <el-option label="t" value="t" />
  296. </el-select>
  297. </template>
  298. </el-input>
  299. </el-form-item>
  300. </el-col>
  301. <el-col :span="12">
  302. <el-form-item label="商品体积:">
  303. <el-input v-model="productForm.productVolume" placeholder="0" maxlength="10" show-word-limit>
  304. <template #append>
  305. <el-select v-model="productForm.volumeUnit" placeholder="请选择" style="width: 80px">
  306. <el-option label="m³" value="m3" />
  307. <el-option label="cm³" value="cm3" />
  308. <el-option label="L" value="L" />
  309. </el-select>
  310. </template>
  311. </el-input>
  312. </el-form-item>
  313. </el-col>
  314. </el-row>
  315. <!-- 参考链接 -->
  316. <el-form-item label="参考链接">
  317. <el-input v-model="productForm.referenceLink" type="textarea" :rows="3" placeholder="请输入参考链接" />
  318. </el-form-item>
  319. <!-- 售后服务 -->
  320. <el-form-item label="售后服务:">
  321. <el-select v-model="productForm.afterSalesService" placeholder="请选择" clearable class="w-full">
  322. <el-option v-for="option in afterSalesOptions" :key="option.id" :label="option.afterSalesItems" :value="option.id" />
  323. </el-select>
  324. </el-form-item>
  325. <!-- 服务保障 -->
  326. <el-form-item label="服务保障:">
  327. <el-checkbox-group v-model="serviceGuarantees">
  328. <el-checkbox v-for="option in serviceGuaranteeOptions" :key="option.id" :label="option.ensureName" :value="option.id" />
  329. </el-checkbox-group>
  330. </el-form-item>
  331. <!-- 安装服务 -->
  332. <el-form-item label="安装服务:">
  333. <el-checkbox-group v-model="installationServices">
  334. <el-checkbox label="免费安装" value="freeInstallation" />
  335. </el-checkbox-group>
  336. </el-form-item>
  337. </el-form>
  338. </el-card>
  339. <!-- 销售价格 -->
  340. <el-card v-show="currentStep === 1" shadow="never" class="step-card mt-3">
  341. <template #header>
  342. <span class="text-lg font-bold">销售价格</span>
  343. </template>
  344. <el-form ref="priceFormRef" :model="productForm" :rules="productRules" label-width="120px" class="product-info-form">
  345. <el-row :gutter="20">
  346. <el-col :span="8">
  347. <el-form-item label="市场价:" prop="marketPrice" required>
  348. <el-input v-model="productForm.marketPrice" type="number" placeholder="请输入市场价" :min="0" @blur="formatPrice('marketPrice')" />
  349. </el-form-item>
  350. </el-col>
  351. <el-col :span="8">
  352. <el-form-item label="官网价:" prop="memberPrice" required>
  353. <el-input
  354. v-model="productForm.memberPrice"
  355. type="number"
  356. placeholder="请输入平台售价"
  357. :min="0"
  358. @blur="formatPrice('memberPrice')"
  359. />
  360. </el-form-item>
  361. </el-col>
  362. </el-row>
  363. <el-row :gutter="20">
  364. <el-col :span="8">
  365. <el-form-item label="最低起订量:" prop="minOrderQuantity" required>
  366. <el-input v-model="productForm.minOrderQuantity" min="1" type="number" placeholder="请输入最低起订量" />
  367. </el-form-item>
  368. </el-col>
  369. <el-col :span="8">
  370. <el-form-item label="备注:">
  371. <span class="currency-text">市场价>官网价</span>
  372. </el-form-item>
  373. </el-col>
  374. </el-row>
  375. </el-form>
  376. </el-card>
  377. <!-- 供应价格 -->
  378. <el-card v-show="currentStep === 1" shadow="never" class="step-card mt-3">
  379. <template #header>
  380. <span class="text-lg font-bold">供应价格</span>
  381. </template>
  382. <el-form label-width="120px" class="product-info-form">
  383. <el-row :gutter="20">
  384. <el-col :span="8">
  385. <el-form-item label="供应价:">
  386. <el-input
  387. v-model="productForm.supplyPrice"
  388. type="number"
  389. placeholder="请输入供应价"
  390. :min="0"
  391. @blur="formatPrice('supplyPrice')"
  392. />
  393. </el-form-item>
  394. </el-col>
  395. <el-col :span="8">
  396. <el-form-item label="供应有效时间:">
  397. <el-date-picker
  398. v-model="productForm.supplyValidityPeriod"
  399. type="date"
  400. placeholder="请选择供应有效时间"
  401. value-format="YYYY-MM-DD"
  402. class="w-full"
  403. />
  404. </el-form-item>
  405. </el-col>
  406. <el-col :span="8">
  407. <el-form-item label="是否包邮:">
  408. <el-radio-group v-model="productForm.supplyPostStatus">
  409. <el-radio :value="0">不包邮</el-radio>
  410. <el-radio :value="1">包邮</el-radio>
  411. </el-radio-group>
  412. </el-form-item>
  413. </el-col>
  414. </el-row>
  415. </el-form>
  416. </el-card>
  417. <!-- 自定义属性 -->
  418. <el-card v-show="currentStep === 1" shadow="never" class="step-card mt-3">
  419. <template #header>
  420. <div class="flex items-center justify-between">
  421. <span class="text-lg font-bold">自定义属性</span>
  422. <el-button type="primary" icon="Plus" size="small" @click="addDiyAttribute">添加属性</el-button>
  423. </div>
  424. </template>
  425. <el-form label-width="0px" class="product-info-form">
  426. <div v-if="diyAttributesList.length === 0" class="text-center text-gray-400 py-4 text-sm">
  427. 暂无自定义属性,点击右上角"添加属性"按钮添加
  428. </div>
  429. <el-row v-for="(item, index) in diyAttributesList" :key="index" :gutter="20" class="mb-2">
  430. <el-col :span="11">
  431. <el-input v-model="item.attributeKey" placeholder="请输入属性名称" clearable />
  432. </el-col>
  433. <el-col :span="11">
  434. <el-input v-model="item.attributeValue" placeholder="请输入属性值" clearable />
  435. </el-col>
  436. <el-col :span="2" class="flex items-center">
  437. <el-button type="danger" icon="Delete" circle size="small" @click="removeDiyAttribute(index)" />
  438. </el-col>
  439. </el-row>
  440. </el-form>
  441. </el-card>
  442. <!-- 商品属性 -->
  443. <el-card v-show="currentStep === 1" shadow="never" class="step-card mt-3">
  444. <template #header>
  445. <span class="text-lg font-bold">商品属性</span>
  446. </template>
  447. <el-form ref="attributeFormRef" :model="productForm" label-width="120px" class="product-info-form">
  448. <div v-if="attributesList.length === 0" class="text-center text-gray-500 py-8">该分类暂无属性配置</div>
  449. <template v-else>
  450. <el-row :gutter="20" v-for="(row, rowIndex) in Math.ceil(attributesList.length / 2)" :key="rowIndex">
  451. <el-col :span="12" v-for="colIndex in 2" :key="colIndex">
  452. <template v-if="attributesList[rowIndex * 2 + colIndex - 1]">
  453. <el-form-item
  454. :label="attributesList[rowIndex * 2 + colIndex - 1].productAttributesName + ':'"
  455. :required="attributesList[rowIndex * 2 + colIndex - 1].required === '1'"
  456. >
  457. <!-- 下拉选择 -->
  458. <el-select
  459. v-if="attributesList[rowIndex * 2 + colIndex - 1].isOptional === '0'"
  460. v-model="productAttributesValues[attributesList[rowIndex * 2 + colIndex - 1].productAttributesName]"
  461. placeholder="请选择"
  462. clearable
  463. class="w-full"
  464. >
  465. <el-option
  466. v-for="option in parseAttributesList(attributesList[rowIndex * 2 + colIndex - 1].attributesList)"
  467. :key="option"
  468. :label="option"
  469. :value="option"
  470. />
  471. </el-select>
  472. <!-- 多选 -->
  473. <el-select
  474. v-else-if="attributesList[rowIndex * 2 + colIndex - 1].isOptional === '2'"
  475. v-model="productAttributesValues[attributesList[rowIndex * 2 + colIndex - 1].productAttributesName]"
  476. placeholder="请选择"
  477. multiple
  478. clearable
  479. class="w-full"
  480. >
  481. <el-option
  482. v-for="option in parseAttributesList(attributesList[rowIndex * 2 + colIndex - 1].attributesList)"
  483. :key="option"
  484. :label="option"
  485. :value="option"
  486. />
  487. </el-select>
  488. <!-- 文本输入 -->
  489. <el-input
  490. v-else
  491. v-model="productAttributesValues[attributesList[rowIndex * 2 + colIndex - 1].productAttributesName]"
  492. placeholder="请输入"
  493. clearable
  494. />
  495. </el-form-item>
  496. </template>
  497. </el-col>
  498. </el-row>
  499. </template>
  500. </el-form>
  501. </el-card>
  502. <!-- 商品详情 -->
  503. <el-card v-show="currentStep === 1" shadow="never" class="step-card mt-3">
  504. <template #header>
  505. <span class="text-lg font-bold">商品详情</span>
  506. </template>
  507. <el-form ref="detailFormRef" :model="productForm" label-width="120px" class="product-info-form">
  508. <!-- 商品主图 -->
  509. <el-form-item label="商品主图:" required>
  510. <upload-image v-model="productForm.productImage" :limit="1" width="178px" height="178px" imageText="选择图片" />
  511. <div class="form-item-tip">从图片库选择,建议尺寸300*300px</div>
  512. </el-form-item>
  513. <!-- 商品轮播图 -->
  514. <el-form-item label="商品轮播图:" required>
  515. <upload-image v-model="carouselImages" :limit="20" width="120px" height="120px" imageText="添加图片" />
  516. <div class="form-item-tip">从图片库选择,支持多选,建议尺寸300*300px</div>
  517. </el-form-item>
  518. <!-- 商品详情 -->
  519. <el-form-item label="商品详情:" required>
  520. <el-tabs v-model="activeDetailTab" type="border-card">
  521. <el-tab-pane label="电脑端详情" name="pc">
  522. <Editor v-model="productForm.pcDetail" :height="400" />
  523. </el-tab-pane>
  524. <el-tab-pane label="移动端详情" name="mobile">
  525. <Editor v-model="productForm.mobileDetail" :height="400" />
  526. </el-tab-pane>
  527. </el-tabs>
  528. </el-form-item>
  529. </el-form>
  530. </el-card>
  531. <!-- 定制说明 -->
  532. <el-card v-show="currentStep === 1" shadow="never" class="step-card mt-3">
  533. <template #header>
  534. <span class="text-lg font-bold">定制说明</span>
  535. </template>
  536. <el-form ref="customFormRef" :model="customForm" label-width="120px" class="product-info-form">
  537. <!-- 可定制开关 -->
  538. <el-form-item label="可定制:">
  539. <el-switch v-model="customForm.isCustomize" />
  540. </el-form-item>
  541. <!-- 定制内容 -->
  542. <template v-if="customForm.isCustomize">
  543. <!-- 定制方式 -->
  544. <el-form-item label="定制方式:">
  545. <div class="custom-options">
  546. <el-button
  547. v-for="option in customMethodOptions"
  548. :key="option.value"
  549. :type="customForm.selectedMethods.includes(option.value) ? 'primary' : 'default'"
  550. @click="toggleMethod(option.value)"
  551. >
  552. {{ option.label }}
  553. </el-button>
  554. </div>
  555. </el-form-item>
  556. <!-- 定制工艺 -->
  557. <el-form-item label="定制工艺:">
  558. <div class="custom-options">
  559. <el-button
  560. v-for="craft in customCraftOptions"
  561. :key="craft.value"
  562. :type="customForm.selectedCrafts.includes(craft.value) ? 'primary' : 'default'"
  563. @click="toggleCraft(craft.value)"
  564. >
  565. {{ craft.label }}
  566. </el-button>
  567. </div>
  568. </el-form-item>
  569. <!-- 定制方式表格 -->
  570. <el-form-item label="" label-width="120">
  571. <el-table :data="customForm.customDetails" border class="custom-table">
  572. <el-table-column label="装饰方法" width="120">
  573. <template #default="{ row }">
  574. <span>{{ row.decorationMethod }}</span>
  575. </template>
  576. </el-table-column>
  577. <el-table-column label="定制工艺" width="120">
  578. <template #default="{ row }">
  579. <span>{{ row.craft }}</span>
  580. </template>
  581. </el-table-column>
  582. <el-table-column label="起订数量" width="150">
  583. <template #default="{ row }">
  584. <el-input v-model="row.minOrderQty" placeholder="请输入" />
  585. </template>
  586. </el-table-column>
  587. <el-table-column label="起订价格" width="150">
  588. <template #default="{ row }">
  589. <el-input
  590. v-model="row.minOrderPrice"
  591. type="number"
  592. :min="0"
  593. placeholder="请输入"
  594. @blur="formatRowPrice(row, 'minOrderPrice')"
  595. />
  596. </template>
  597. </el-table-column>
  598. <el-table-column label="打样工期[天]" width="150">
  599. <template #default="{ row }">
  600. <el-input v-model="row.samplePeriod" placeholder="请输入" />
  601. </template>
  602. </el-table-column>
  603. <el-table-column label="生产周期[天]" width="150">
  604. <template #default="{ row }">
  605. <el-input v-model="row.productionPeriod" placeholder="请输入" />
  606. </template>
  607. </el-table-column>
  608. <el-table-column label="操作" width="100" fixed="right">
  609. <template #default="{ $index }">
  610. <el-link type="danger" :underline="false" @click="removeCustomDetail($index)"> 删除 </el-link>
  611. </template>
  612. </el-table-column>
  613. </el-table>
  614. </el-form-item>
  615. <!-- 定制说明 -->
  616. <el-form-item label="定制说明:">
  617. <el-input v-model="customForm.customDescription" type="textarea" :rows="5" placeholder="请输入定制说明" />
  618. </el-form-item>
  619. </template>
  620. </el-form>
  621. </el-card>
  622. <!-- 步骤3: 完成 -->
  623. <el-card v-show="currentStep === 2" shadow="never" class="step-card completion-card">
  624. <div class="completion-content">
  625. <div class="success-icon">
  626. <el-icon :size="80" color="#67c23a">
  627. <CircleCheck />
  628. </el-icon>
  629. </div>
  630. <div class="completion-text">商品编辑完成,请点击返回,继续其他操作</div>
  631. <div class="completion-action">
  632. <el-button type="primary" @click="handleBackToList">返回</el-button>
  633. </div>
  634. </div>
  635. </el-card>
  636. </div>
  637. <!-- 底部操作按钮 -->
  638. <el-card v-if="currentStep < 2" shadow="never" class="mt-3">
  639. <div class="flex justify-center gap-4">
  640. <el-button v-if="currentStep > 0" @click="prevStep">上一步</el-button>
  641. <el-button v-if="currentStep < 2" type="primary" @click="nextStep">下一步</el-button>
  642. <el-button @click="handleBack">取消</el-button>
  643. </div>
  644. </el-card>
  645. </div>
  646. </div>
  647. </template>
  648. <script setup lang="ts">
  649. import { ref, reactive, computed, onMounted, watch, nextTick } from 'vue';
  650. import { useRoute, useRouter } from 'vue-router';
  651. import { ElMessage } from 'element-plus';
  652. import { Warning, ArrowRight, Check, Plus, CircleCheck, Search } from '@element-plus/icons-vue';
  653. import Editor from '@/components/Editor/index.vue';
  654. import UploadImage from '@/components/upload-image/index.vue';
  655. import TaxCodeSelect from '@/components/TaxCodeSelect/index.vue';
  656. import { categoryTreeVO, CategoryVO } from '@/api/product/category/types';
  657. import { BrandVO } from '@/api/product/brand/types';
  658. import { BaseForm } from '@/api/product/base/types';
  659. import { ClassificationDiyForm } from '@/api/product/classificationDiy/types';
  660. import { AttributesVO } from '@/api/product/attributes/types';
  661. import {
  662. addBase,
  663. updateBase,
  664. getBase,
  665. categoryTree,
  666. categoryList,
  667. categoryAttributeList,
  668. getAfterSaleList,
  669. getServiceList,
  670. getUnitList,
  671. getTaxRateList
  672. } from '@/api/product/base';
  673. import {
  674. addBaseAudit,
  675. updateBaseAudit,
  676. getBaseAudit,
  677. } from '@/api/product/baseAudit';
  678. import { BaseAuditVO, BaseAuditQuery, BaseAuditForm } from '@/api/product/baseAudit/types';
  679. import { getTaxCode } from '@/api/system/taxCode';
  680. import { listBrand, getBrand } from '@/api/product/brand';
  681. import { listInfo } from '@/api/customer/supplierInfo';
  682. import { InfoVO } from '@/api/customer/supplierInfo/types';
  683. import { listComStaff } from '@/api/system/comStaff';
  684. import { ComStaffVO } from '@/api/system/comStaff/types';
  685. const route = useRoute();
  686. const router = useRouter();
  687. const currentStep = ref(0);
  688. const loading = ref(false);
  689. const submitLoading = ref(false);
  690. const productFormRef = ref();
  691. // 服务保障和安装服务的多选框
  692. const serviceGuarantees = ref<(string | number)[]>([]);
  693. const installationServices = ref<string[]>([]);
  694. // 商品详情选项卡
  695. const activeDetailTab = ref('pc');
  696. // 轮播图URL数组(UI管理用)
  697. const carouselImages = ref<string[]>([]);
  698. // 税率选项
  699. const taxRateOptions = ref<any[]>([]);
  700. // 税率编码选择组件
  701. const taxCodeSelectRef = ref();
  702. // 已选的税率编码(显示用)
  703. const taxCodeNo = ref('');
  704. // 处理税率编码选择
  705. const handleTaxCodeSelect = async (row: any) => {
  706. (productForm as any).taxationId = row.id;
  707. try {
  708. const taxRes = await getTaxCode(row.id);
  709. if (taxRes.data) {
  710. taxCodeNo.value = `${taxRes.data.taxationNo},${taxRes.data.name}`;
  711. } else {
  712. taxCodeNo.value = row.taxationNo ? `${row.taxationNo},${row.name}` : (row.name || '');
  713. }
  714. } catch (e) {
  715. console.error('获取税率编码详情失败:', e);
  716. taxCodeNo.value = row.taxationNo ? `${row.taxationNo},${row.name}` : (row.name || '');
  717. }
  718. // 同时将显示值存入 form,方便编辑回显时直接读取
  719. (productForm as any).taxationNo = taxCodeNo.value;
  720. };
  721. // 定制说明表单
  722. const customForm = reactive({
  723. isCustomize: false,
  724. selectedMethods: [] as string[],
  725. selectedCrafts: [] as string[],
  726. customDetails: [] as Array<{
  727. decorationMethod: string;
  728. craft: string;
  729. minOrderQty: string;
  730. minOrderPrice: string;
  731. samplePeriod: string;
  732. productionPeriod: string;
  733. }>,
  734. customDescription: ''
  735. });
  736. // 定制方式选项
  737. const customMethodOptions = [
  738. { label: '包装定制', value: 'package' },
  739. { label: '商品定制', value: 'product' },
  740. { label: '开模定制', value: 'mold' }
  741. ];
  742. // 定制工艺选项
  743. const customCraftOptions = [
  744. { label: '丝印', value: 'silkScreen' },
  745. { label: '热转印', value: 'thermalTransfer' },
  746. { label: '激光', value: 'laser' },
  747. { label: '烤花', value: 'baking' },
  748. { label: '压印', value: 'embossing' }
  749. ];
  750. // 定制方式映射
  751. const customMethodMap: Record<string, string> = {
  752. 'package': '包装定制',
  753. 'product': '商品定制',
  754. 'mold': '开模定制'
  755. };
  756. // 定制工艺映射
  757. const customCraftMap: Record<string, string> = {
  758. 'silkScreen': '丝印',
  759. 'thermalTransfer': '热转印',
  760. 'laser': '激光',
  761. 'baking': '烤花',
  762. 'embossing': '压印'
  763. };
  764. // 服务保障选择不需要watch,在提交时直接转换为逗号分隔字符串
  765. // 监听安装服务复选框变化,同步到表单
  766. watch(
  767. installationServices,
  768. (newVal) => {
  769. productForm.freeInstallation = newVal.includes('freeInstallation') ? '1' : '0';
  770. },
  771. { deep: true }
  772. );
  773. // 监听定制方式和工艺选择变化,更新表格数据
  774. watch(
  775. [() => customForm.selectedMethods, () => customForm.selectedCrafts],
  776. ([newMethods, newCrafts]) => {
  777. const newDetails: typeof customForm.customDetails = [];
  778. // 遍历所有选中的定制方式和工艺组合
  779. newMethods.forEach((method) => {
  780. const decorationMethod = customMethodMap[method];
  781. newCrafts.forEach((craft) => {
  782. const craftName = customCraftMap[craft];
  783. // 查找是否已存在该组合的数据
  784. const existing = customForm.customDetails.find((item) => item.decorationMethod === decorationMethod && item.craft === craftName);
  785. newDetails.push(
  786. existing || {
  787. decorationMethod,
  788. craft: craftName,
  789. minOrderQty: '',
  790. minOrderPrice: '',
  791. samplePeriod: '',
  792. productionPeriod: ''
  793. }
  794. );
  795. });
  796. });
  797. customForm.customDetails = newDetails;
  798. },
  799. { deep: true }
  800. );
  801. // 切换定制方式选择
  802. const toggleMethod = (method: string) => {
  803. const index = customForm.selectedMethods.indexOf(method);
  804. if (index > -1) {
  805. customForm.selectedMethods.splice(index, 1);
  806. } else {
  807. customForm.selectedMethods.push(method);
  808. }
  809. };
  810. // 切换定制工艺选择
  811. const toggleCraft = (craft: string) => {
  812. const index = customForm.selectedCrafts.indexOf(craft);
  813. if (index > -1) {
  814. customForm.selectedCrafts.splice(index, 1);
  815. } else {
  816. customForm.selectedCrafts.push(craft);
  817. }
  818. };
  819. // 删除定制详情行
  820. const removeCustomDetail = (index: number) => {
  821. customForm.customDetails.splice(index, 1);
  822. };
  823. const pageTitle = computed(() => {
  824. return route.params.id ? '编辑商品' : '新增商品';
  825. });
  826. // 分类选择表单
  827. const categoryForm = reactive({
  828. topCategoryId: undefined as string | number | undefined,
  829. mediumCategoryId: undefined as string | number | undefined,
  830. bottomCategoryId: undefined as string | number | undefined
  831. });
  832. const autoCreateCategory = ref(false);
  833. const manualCategoryInput = ref('');
  834. // 商品信息表单
  835. const productForm = reactive<BaseForm>({
  836. id: undefined,
  837. productNo: undefined,
  838. itemName: undefined,
  839. brandId: undefined,
  840. topCategoryId: undefined,
  841. mediumCategoryId: undefined,
  842. bottomCategoryId: undefined,
  843. unitId: undefined,
  844. productImage: undefined,
  845. imageUrl: undefined,
  846. isSelf: 0,
  847. productReviewStatus: 0,
  848. homeRecommended: 0,
  849. categoryRecommendation: 0,
  850. cartRecommendation: 0,
  851. recommendedProductOrder: 0,
  852. isPopular: 0,
  853. isNew: 0,
  854. productStatus: '0',
  855. remark: undefined,
  856. a10ProductName: undefined,
  857. specificationsCode: undefined,
  858. barCoding: undefined,
  859. invoiceName: undefined,
  860. invoiceSpecs: undefined,
  861. packagingSpec: undefined,
  862. productDescription: undefined,
  863. referenceLink: undefined,
  864. productWeight: undefined,
  865. weightUnit: 'kg',
  866. productVolume: undefined,
  867. volumeUnit: 'm3',
  868. mainLibraryIntro: undefined,
  869. afterSalesService: undefined,
  870. serviceGuarantee: undefined, // 服务保障ID列表,逗号分隔
  871. freeInstallation: '0',
  872. marketPrice: undefined,
  873. memberPrice: undefined,
  874. minSellingPrice: undefined,
  875. purchasingPrice: undefined,
  876. maxPurchasePrice: undefined,
  877. supplyPrice: undefined,
  878. supplyValidityPeriod: undefined,
  879. supplyPostStatus: undefined,
  880. productNature: '1',
  881. purchasingPersonnel: '1',
  882. pcDetail: undefined,
  883. mobileDetail: undefined,
  884. taxRate: undefined,
  885. currency: 'RMB',
  886. minOrderQuantity: undefined,
  887. salesVolume: undefined
  888. });
  889. // 表单验证规则
  890. const productRules = {
  891. // productNo: [{ required: true, message: '商品编号不能为空', trigger: 'blur' }],
  892. itemName: [{ required: true, message: '商品名称不能为空', trigger: 'blur' }],
  893. brandId: [{ required: true, message: '商品品牌不能为空', trigger: 'change' }],
  894. marketPrice: [{ required: true, message: '市场价不能为空', trigger: 'blur' }],
  895. memberPrice: [{ required: true, message: '平台售价不能为空', trigger: 'blur' }],
  896. minSellingPrice: [{ required: true, message: '最低售价不能为空', trigger: 'blur' }],
  897. // purchasingPrice: [{ required: true, message: '采购价不能为空', trigger: 'blur' }],
  898. productNature: [{ required: true, message: '产品经理不能为空', trigger: 'change' }],
  899. purchasingPersonnel: [{ required: true, message: '采购人员不能为空', trigger: 'change' }],
  900. taxRate: [{ required: true, message: '税率不能为空', trigger: 'change' }],
  901. minOrderQuantity: [{ required: true, message: '最低起订量不能为空', trigger: 'blur' }]
  902. };
  903. // 分类和品牌选项
  904. const categoryOptions = ref<categoryTreeVO[]>([]);
  905. const brandOptions = ref<BrandVO[]>([]);
  906. const brandLoading = ref(false);
  907. let brandSearchTimer: ReturnType<typeof setTimeout> | null = null;
  908. // 商品属性列表
  909. const attributesList = ref<AttributesVO[]>([]);
  910. const productAttributesValues = ref<Record<string | number, any>>({});
  911. // 售后服务和服务保障选项
  912. const afterSalesOptions = ref<any[]>([]);
  913. const serviceGuaranteeOptions = ref<any[]>([]);
  914. // 单位选项
  915. const unitOptions = ref<any[]>([]);
  916. // 主供应商选项
  917. const supplierOptions = ref<InfoVO[]>([]);
  918. // 自定义属性列表
  919. const diyAttributesList = ref<ClassificationDiyForm[]>([]);
  920. // 添加自定义属性行
  921. const addDiyAttribute = () => {
  922. diyAttributesList.value.push({ attributeKey: '', attributeValue: '' });
  923. };
  924. // 删除自定义属性行
  925. const removeDiyAttribute = (index: number) => {
  926. diyAttributesList.value.splice(index, 1);
  927. };
  928. // 采购人员选项
  929. const staffOptions = ref<ComStaffVO[]>([]);
  930. // 搜索关键词
  931. const searchLevel1 = ref('');
  932. const searchLevel2 = ref('');
  933. const searchLevel3 = ref('');
  934. // 三级分类下拉搜索
  935. const level3SearchValue = ref<string | number | null>(null);
  936. const level3SearchOptions = ref<CategoryVO[]>([]);
  937. const level3SearchLoading = ref(false);
  938. // 一级分类列表
  939. const level1Categories = computed(() => {
  940. return categoryOptions.value || [];
  941. });
  942. // 二级分类列表
  943. const level2Categories = ref<categoryTreeVO[]>([]);
  944. // 三级分类列表
  945. const level3Categories = ref<categoryTreeVO[]>([]);
  946. // 过滤后的一级分类列表
  947. const filteredLevel1Categories = computed(() => {
  948. if (!searchLevel1.value) {
  949. return level1Categories.value;
  950. }
  951. return level1Categories.value.filter((item) => item.label.toLowerCase().includes(searchLevel1.value.toLowerCase()));
  952. });
  953. // 过滤后的二级分类列表
  954. const filteredLevel2Categories = computed(() => {
  955. if (!searchLevel2.value) {
  956. return level2Categories.value;
  957. }
  958. return level2Categories.value.filter((item) => item.label.toLowerCase().includes(searchLevel2.value.toLowerCase()));
  959. });
  960. // 过滤后的三级分类列表
  961. const filteredLevel3Categories = computed(() => {
  962. if (!searchLevel3.value) {
  963. return level3Categories.value;
  964. }
  965. return level3Categories.value.filter((item) => item.label.toLowerCase().includes(searchLevel3.value.toLowerCase()));
  966. });
  967. // 搜索三级分类(调用接口)
  968. const handleLevel3Search = async (keyword: string) => {
  969. if (!keyword) {
  970. level3SearchOptions.value = [];
  971. return;
  972. }
  973. level3SearchLoading.value = true;
  974. try {
  975. const res = await categoryList({ classLevel: 3, categoryName: keyword, pageNum: 1, pageSize: 50 });
  976. level3SearchOptions.value = (res as any).data || (res as any).rows || [];
  977. } catch (error) {
  978. console.error('搜索三级分类失败:', error);
  979. } finally {
  980. level3SearchLoading.value = false;
  981. }
  982. };
  983. // 选择三级分类搜索结果后,自动在树中定位
  984. const handleLevel3SearchSelect = async (categoryId: string | number) => {
  985. if (!categoryId) return;
  986. const selectedCategory = level3SearchOptions.value.find((item) => String(item.id) === String(categoryId));
  987. if (!selectedCategory) return;
  988. // 在分类树中查找对应的二级节点(三级的父节点)
  989. const level2Node = findCategoryById(categoryOptions.value, selectedCategory.parentId);
  990. if (!level2Node) return;
  991. // 在一级列表中查找(二级的父节点)
  992. const level1Node = level1Categories.value.find((item) => String(item.id) === String(level2Node.parentId));
  993. if (!level1Node) return;
  994. // 依次选中一级、二级、三级
  995. categoryForm.topCategoryId = level1Node.id;
  996. selectedLevel1Name.value = level1Node.label;
  997. level2Categories.value = level1Node.children || [];
  998. await nextTick();
  999. categoryForm.mediumCategoryId = level2Node.id;
  1000. selectedLevel2Name.value = level2Node.label;
  1001. level3Categories.value = level2Node.children || [];
  1002. await nextTick();
  1003. // 精确查找三级节点
  1004. const level3Node = level3Categories.value.find((item) => String(item.id) === String(selectedCategory.id));
  1005. if (level3Node) {
  1006. categoryForm.bottomCategoryId = level3Node.id;
  1007. selectedLevel3Name.value = level3Node.label;
  1008. await loadCategoryAttributes(level3Node.id);
  1009. } else {
  1010. categoryForm.bottomCategoryId = selectedCategory.id;
  1011. selectedLevel3Name.value = selectedCategory.categoryName;
  1012. await loadCategoryAttributes(selectedCategory.id);
  1013. }
  1014. // 清空搜索框
  1015. level3SearchValue.value = null;
  1016. level3SearchOptions.value = [];
  1017. };
  1018. // 选中的分类名称
  1019. const selectedLevel1Name = ref('');
  1020. const selectedLevel2Name = ref('');
  1021. const selectedLevel3Name = ref('');
  1022. // 选择一级分类
  1023. const selectLevel1 = (item: categoryTreeVO) => {
  1024. if (!item.children || item.children.length === 0) {
  1025. ElMessage.warning('该分类无子分类,请选择含三级分类的类别');
  1026. return;
  1027. }
  1028. categoryForm.topCategoryId = item.id;
  1029. categoryForm.mediumCategoryId = undefined;
  1030. categoryForm.bottomCategoryId = undefined;
  1031. selectedLevel1Name.value = item.label;
  1032. selectedLevel2Name.value = '';
  1033. selectedLevel3Name.value = '';
  1034. level2Categories.value = item.children || [];
  1035. level3Categories.value = [];
  1036. };
  1037. // 选择二级分类
  1038. const selectLevel2 = (item: categoryTreeVO) => {
  1039. if (!item.children || item.children.length === 0) {
  1040. ElMessage.warning('该分类无子分类,请选择含三级分类的类别');
  1041. return;
  1042. }
  1043. categoryForm.mediumCategoryId = item.id;
  1044. categoryForm.bottomCategoryId = undefined;
  1045. selectedLevel2Name.value = item.label;
  1046. selectedLevel3Name.value = '';
  1047. level3Categories.value = item.children || [];
  1048. };
  1049. // 选择三级分类
  1050. const selectLevel3 = async (item: categoryTreeVO) => {
  1051. categoryForm.bottomCategoryId = item.id;
  1052. selectedLevel3Name.value = item.label;
  1053. // 加载该分类下的属性列表
  1054. await loadCategoryAttributes(item.id);
  1055. };
  1056. // 获取分类路径
  1057. const getCategoryPath = () => {
  1058. const parts = [];
  1059. if (selectedLevel1Name.value) parts.push(selectedLevel1Name.value);
  1060. if (selectedLevel2Name.value) parts.push(selectedLevel2Name.value);
  1061. if (selectedLevel3Name.value) parts.push(selectedLevel3Name.value);
  1062. return parts.join(' > ') || '请选择分类';
  1063. };
  1064. // 清除分类
  1065. const clearCategory = () => {
  1066. categoryForm.topCategoryId = undefined;
  1067. categoryForm.mediumCategoryId = undefined;
  1068. categoryForm.bottomCategoryId = undefined;
  1069. selectedLevel1Name.value = '';
  1070. selectedLevel2Name.value = '';
  1071. selectedLevel3Name.value = '';
  1072. level2Categories.value = [];
  1073. level3Categories.value = [];
  1074. attributesList.value = [];
  1075. productAttributesValues.value = {};
  1076. };
  1077. // 下一步
  1078. const nextStep = async () => {
  1079. if (currentStep.value === 0) {
  1080. // 验证分类选择
  1081. if (!categoryForm.topCategoryId) {
  1082. ElMessage.warning('请选择一级分类');
  1083. return;
  1084. }
  1085. if (!categoryForm.mediumCategoryId) {
  1086. ElMessage.warning('请选择二级分类');
  1087. return;
  1088. }
  1089. if (!categoryForm.bottomCategoryId) {
  1090. ElMessage.warning('请选择三级分类');
  1091. return;
  1092. }
  1093. // 将分类信息同步到商品表单
  1094. productForm.topCategoryId = categoryForm.topCategoryId;
  1095. productForm.mediumCategoryId = categoryForm.mediumCategoryId;
  1096. productForm.bottomCategoryId = categoryForm.bottomCategoryId;
  1097. currentStep.value++;
  1098. } else if (currentStep.value === 1) {
  1099. // 验证商品信息表单并提交
  1100. try {
  1101. await productFormRef.value?.validate();
  1102. // 调用提交函数
  1103. await handleSubmit();
  1104. } catch (error) {
  1105. ElMessage.warning('请完善商品信息');
  1106. return;
  1107. }
  1108. }
  1109. };
  1110. // 上一步
  1111. const prevStep = () => {
  1112. if (currentStep.value > 0) {
  1113. currentStep.value--;
  1114. }
  1115. };
  1116. // 提交
  1117. const handleSubmit = async () => {
  1118. try {
  1119. submitLoading.value = true;
  1120. // 校验商品主图、轮播图、详情必填
  1121. if (!productForm.productImage) {
  1122. ElMessage.warning('请上传商品主图');
  1123. submitLoading.value = false;
  1124. return;
  1125. }
  1126. if (!carouselImages.value || carouselImages.value.length === 0) {
  1127. ElMessage.warning('请上传商品轮播图');
  1128. submitLoading.value = false;
  1129. return;
  1130. }
  1131. if (!productForm.pcDetail) {
  1132. ElMessage.warning('请填写电脑端商品详情');
  1133. submitLoading.value = false;
  1134. return;
  1135. }
  1136. // 校验价格关系:市场价 > 官网价 > 最低售价
  1137. const midRange = parseFloat(String(productForm.marketPrice));
  1138. const standard = parseFloat(String(productForm.memberPrice));
  1139. const certificate = parseFloat(String(productForm.minSellingPrice));
  1140. if (!isNaN(midRange) && !isNaN(standard) && !isNaN(certificate)) {
  1141. if (!(midRange > standard)) {
  1142. ElMessage.warning('市场价必须大于官网价');
  1143. submitLoading.value = false;
  1144. return;
  1145. }
  1146. if (!(standard > certificate)) {
  1147. ElMessage.warning('官网价必须大于最低售价');
  1148. submitLoading.value = false;
  1149. return;
  1150. }
  1151. }
  1152. // 准备提交数据,包含定制信息(A10产品名称由前端自动拼接,不传后端)
  1153. const submitProductData: any = {
  1154. ...productForm,
  1155. // 将服务保障ID数组转换为逗号分隔字符串
  1156. serviceGuarantee: serviceGuarantees.value.map((id) => String(id)).join(','),
  1157. // 轮播图URL逗号分隔
  1158. imageUrl: carouselImages.value.join(','),
  1159. // 将商品属性值转换为JSON字符串
  1160. attributesList: JSON.stringify(productAttributesValues.value),
  1161. isCustomize: customForm.isCustomize ? 1 : 0,
  1162. customizedStyle: customForm.selectedMethods.join(','),
  1163. customizedCraft: customForm.selectedCrafts.join(','),
  1164. customDescription: customForm.customDescription,
  1165. customDetailsJson: JSON.stringify(customForm.customDetails),
  1166. diyAttributesList: diyAttributesList.value.filter((item) => item.attributeKey || item.attributeValue)
  1167. };
  1168. // A10产品名称不传后端
  1169. delete submitProductData.a10ProductName;
  1170. const auditData: BaseAuditForm = {
  1171. id: route.params.id as string,
  1172. productData: JSON.stringify(submitProductData),
  1173. type: 0,
  1174. auditStatus: 0
  1175. };
  1176. if (auditData.id) {
  1177. await updateBaseAudit(auditData);
  1178. ElMessage.success('修改成功');
  1179. } else {
  1180. await addBaseAudit(auditData);
  1181. ElMessage.success('新增成功');
  1182. }
  1183. // 跳转到完成页面(步骤3)
  1184. currentStep.value = 2;
  1185. } catch (error) {
  1186. console.error('提交失败:', error);
  1187. } finally {
  1188. submitLoading.value = false;
  1189. }
  1190. };
  1191. // 返回
  1192. const handleBack = () => {
  1193. router.back();
  1194. };
  1195. // 返回列表
  1196. const handleBackToList = () => {
  1197. router.push('/product/base');
  1198. };
  1199. // UPC(69)条码只允许输入数字
  1200. const handleUpcInput = () => {
  1201. if (productForm.barCoding) {
  1202. productForm.barCoding = productForm.barCoding.replace(/\D/g, '');
  1203. }
  1204. };
  1205. // 销量人气只允许输入整数
  1206. const handleSalesVolumeInput = (val: string) => {
  1207. if (val !== undefined && val !== null && val !== '') {
  1208. const intVal = parseInt(String(val).replace(/[^\d]/g, ''), 10);
  1209. productForm.salesVolume = !isNaN(intVal) ? intVal : undefined;
  1210. } else {
  1211. productForm.salesVolume = undefined;
  1212. }
  1213. };
  1214. // A10产品名称自动拼接(品牌名 + 规格型号 + 产品分类 + 发票规格)
  1215. const a10ProductNameComputed = computed(() => {
  1216. const brand = brandOptions.value.find((b) => Number(b.id) === Number(productForm.brandId));
  1217. const brandName = brand?.brandName || '';
  1218. const specificationsCode = productForm.specificationsCode || '';
  1219. const categoryName = selectedLevel3Name.value || '';
  1220. const invoiceSpecs = productForm.invoiceSpecs || '';
  1221. return [brandName, specificationsCode, categoryName, invoiceSpecs].filter((s) => s.trim()).join(' ');
  1222. });
  1223. // 格式化价格为两位小数(不允许负数)
  1224. const formatPrice = (field: string) => {
  1225. const val = (productForm as any)[field];
  1226. if (val !== undefined && val !== null && val !== '') {
  1227. let num = parseFloat(String(val));
  1228. if (!isNaN(num)) {
  1229. // 不允许负数
  1230. if (num < 0) num = 0;
  1231. (productForm as any)[field] = num.toFixed(2);
  1232. }
  1233. }
  1234. };
  1235. // 格式化表格行中的价格为两位小数(不允许负数)
  1236. const formatRowPrice = (row: any, field: string) => {
  1237. const val = row[field];
  1238. if (val !== undefined && val !== null && val !== '') {
  1239. let num = parseFloat(String(val));
  1240. if (!isNaN(num)) {
  1241. // 不允许负数
  1242. if (num < 0) num = 0;
  1243. row[field] = num.toFixed(2);
  1244. }
  1245. }
  1246. };
  1247. // 获取分类树
  1248. const getCategoryTree = async () => {
  1249. try {
  1250. const res = await categoryTree();
  1251. categoryOptions.value = res.data || [];
  1252. } catch (error) {
  1253. console.error('获取分类树失败:', error);
  1254. }
  1255. };
  1256. // 加载品牌选项(默认100条)
  1257. const loadBrandOptions = async (keyword?: string) => {
  1258. brandLoading.value = true;
  1259. try {
  1260. const res = await listBrand({ pageNum: 1, pageSize: 100, brandName: keyword });
  1261. const newList = res.rows || [];
  1262. // 编辑模式下保留当前选中的品牌,避免被新列表覆盖后 A10产品名称 computed 失效
  1263. if (productForm.brandId) {
  1264. const exists = newList.find((item) => Number(item.id) === Number(productForm.brandId));
  1265. if (!exists) {
  1266. const currentBrand = brandOptions.value.find((item) => Number(item.id) === Number(productForm.brandId));
  1267. if (currentBrand) {
  1268. newList.unshift(currentBrand);
  1269. }
  1270. }
  1271. }
  1272. brandOptions.value = newList;
  1273. } catch (error) {
  1274. console.error('加载品牌列表失败:', error);
  1275. } finally {
  1276. brandLoading.value = false;
  1277. }
  1278. };
  1279. // 品牌远程搜索(防抖)
  1280. const handleBrandSearch = (query: string) => {
  1281. if (brandSearchTimer) clearTimeout(brandSearchTimer);
  1282. brandSearchTimer = setTimeout(() => {
  1283. loadBrandOptions(query || undefined);
  1284. }, 300);
  1285. };
  1286. // 处理品牌下拉框显示/隐藏
  1287. const handleBrandVisibleChange = (visible: boolean) => {
  1288. if (visible && brandOptions.value.length === 0) {
  1289. loadBrandOptions();
  1290. }
  1291. };
  1292. // 获取售后服务列表
  1293. const getAfterSalesOptions = async () => {
  1294. try {
  1295. const res = await getAfterSaleList();
  1296. afterSalesOptions.value = res.data || [];
  1297. // 如果是新增模式且有选项,设置第一个为默认值
  1298. if (!route.params.id && afterSalesOptions.value.length > 0 && !productForm.afterSalesService) {
  1299. productForm.afterSalesService = afterSalesOptions.value[0].id;
  1300. }
  1301. } catch (error) {
  1302. console.error('获取售后服务列表失败:', error);
  1303. }
  1304. };
  1305. // 获取服务保障列表
  1306. const getServiceGuaranteeOptions = async () => {
  1307. try {
  1308. const res = await getServiceList();
  1309. serviceGuaranteeOptions.value = res.data || [];
  1310. // 如果是新增模式且有选项,设置第一个为默认选中
  1311. if (!route.params.id && serviceGuaranteeOptions.value.length > 0 && serviceGuarantees.value.length === 0) {
  1312. serviceGuarantees.value = [serviceGuaranteeOptions.value[0].id];
  1313. }
  1314. } catch (error) {
  1315. console.error('获取服务保障列表失败:', error);
  1316. }
  1317. };
  1318. // 获取单位列表
  1319. const getUnitOptions = async () => {
  1320. try {
  1321. const res = await getUnitList();
  1322. unitOptions.value = res.data || [];
  1323. // 如果是新增模式且有选项,设置第一个为默认值
  1324. if (!route.params.id && unitOptions.value.length > 0 && !productForm.unitId) {
  1325. productForm.unitId = unitOptions.value[0].id;
  1326. }
  1327. } catch (error) {
  1328. console.error('获取单位列表失败:', error);
  1329. }
  1330. };
  1331. // 获取主供应商列表
  1332. const getSupplierOptions = async () => {
  1333. try {
  1334. const res = await listInfo();
  1335. console.log('供应商接口返回:', res);
  1336. // 处理可能的数据结构: res.data 或 res.rows
  1337. const dataList = res.data || res.rows || [];
  1338. supplierOptions.value = dataList;
  1339. console.log('供应商列表:', supplierOptions.value);
  1340. // 如果有选项且当前没有选中值,设置第一个为默认值
  1341. if (supplierOptions.value.length > 0 && !productForm.mainLibraryIntro) {
  1342. productForm.mainLibraryIntro = String(supplierOptions.value[0].id);
  1343. }
  1344. } catch (error) {
  1345. console.error('获取主供应商列表失败:', error);
  1346. }
  1347. };
  1348. // 获取采购人员列表
  1349. const getStaffOptions = async () => {
  1350. try {
  1351. const res = await listComStaff();
  1352. console.log('采购人员接口返回:', res);
  1353. // 处理可能的数据结构: res.data 或 res.rows
  1354. const dataList = res.data || res.rows || [];
  1355. staffOptions.value = dataList;
  1356. console.log('采购人员列表:', staffOptions.value);
  1357. // 如果有选项且当前没有选中值,设置第一个为默认值
  1358. if (staffOptions.value.length > 0 && !productForm.purchasingPersonnel) {
  1359. productForm.purchasingPersonnel = String(staffOptions.value[0].staffId);
  1360. }
  1361. } catch (error) {
  1362. console.error('获取采购人员列表失败:', error);
  1363. }
  1364. };
  1365. // 获取税率列表
  1366. const getTaxRateOptions = async () => {
  1367. try {
  1368. const res = await getTaxRateList();
  1369. taxRateOptions.value = res.rows || [];
  1370. } catch (error) {
  1371. console.error('获取税率列表失败:', error);
  1372. }
  1373. };
  1374. // 加载分类属性列表
  1375. const loadCategoryAttributes = async (categoryId: string | number) => {
  1376. try {
  1377. const res = await categoryAttributeList(categoryId);
  1378. attributesList.value = res.data || [];
  1379. // 清空之前的属性值
  1380. productAttributesValues.value = {};
  1381. // 如果是新增模式,为有选项的属性设置默认值
  1382. if (!route.params.id) {
  1383. attributesList.value.forEach((attr) => {
  1384. if (attr.entryMethod === '1' && attr.attributesList) {
  1385. // 下拉选择
  1386. const options = parseAttributesList(attr.attributesList);
  1387. if (options.length > 0) {
  1388. productAttributesValues.value[attr.productAttributesName] = options[0];
  1389. }
  1390. } else if (attr.entryMethod === '3' && attr.attributesList) {
  1391. // 多选
  1392. const options = parseAttributesList(attr.attributesList);
  1393. if (options.length > 0) {
  1394. productAttributesValues.value[attr.productAttributesName] = [options[0]];
  1395. }
  1396. }
  1397. });
  1398. }
  1399. } catch (error) {
  1400. console.error('加载分类属性失败:', error);
  1401. attributesList.value = [];
  1402. }
  1403. };
  1404. // 解析属性值列表(JSON数组或逗号分隔字符串)
  1405. const parseAttributesList = (attributesListStr: string): string[] => {
  1406. if (!attributesListStr) return [];
  1407. try {
  1408. // 尝试解析为JSON数组
  1409. const parsed = JSON.parse(attributesListStr);
  1410. if (Array.isArray(parsed)) {
  1411. return parsed;
  1412. }
  1413. } catch (e) {
  1414. // 如果不是JSON,按逗号分隔
  1415. return attributesListStr
  1416. .split(',')
  1417. .map((item) => item.trim())
  1418. .filter((item) => item);
  1419. }
  1420. return [];
  1421. };
  1422. // 加载商品详情(编辑模式)
  1423. const loadProductDetail = async () => {
  1424. const id = route.params.id;
  1425. if (id) {
  1426. try {
  1427. loading.value = true;
  1428. const res = await getBaseAudit(id as string);
  1429. Object.assign(productForm, res.data.productBaseVo);
  1430. // 回显产品经理 - 确保转换为字符串类型以匹配下拉框的value
  1431. if (res.data.productBaseVo.productNature !== undefined && res.data.productBaseVo.productNature !== null) {
  1432. productForm.productNature = String(res.data.productBaseVo.productNature);
  1433. }
  1434. // 回显采购人员 - 确保转换为字符串类型以匹配下拉框的value
  1435. if (res.data.productBaseVo.purchasingPersonnel !== undefined && res.data.productBaseVo.purchasingPersonnel !== null) {
  1436. productForm.purchasingPersonnel = String(res.data.productBaseVo.purchasingPersonnel);
  1437. }
  1438. // 回显税率编码显示值
  1439. const rawData = res.data.productBaseVo as any;
  1440. // 通过 taxationId 调接口获取中文名称回显
  1441. if (rawData.taxationId) {
  1442. try {
  1443. const taxRes = await getTaxCode(rawData.taxationId);
  1444. if (taxRes.data) {
  1445. taxCodeNo.value = `${taxRes.data.taxationNo},${taxRes.data.name}`;
  1446. }
  1447. } catch (e) {
  1448. console.error('获取税率编码失败:', e);
  1449. }
  1450. }
  1451. // 回显税率 - 在税率选项中查找匹配的值(处理浮点数精度问题)
  1452. if (res.data.productBaseVo.taxRate !== undefined && res.data.productBaseVo.taxRate !== null) {
  1453. const apiTaxRate = Number(res.data.productBaseVo.taxRate);
  1454. // 使用精度容差比较浮点数
  1455. const matchedOption = taxRateOptions.value.find((opt) => Math.abs(Number(opt.taxrate) - apiTaxRate) < 0.0001);
  1456. if (matchedOption) {
  1457. productForm.taxRate = matchedOption.taxrate;
  1458. } else {
  1459. productForm.taxRate = apiTaxRate;
  1460. }
  1461. }
  1462. // 回显单位 - 确保类型与下拉选项的id一致(数字类型)
  1463. if (res.data.productBaseVo.unitId !== undefined && res.data.productBaseVo.unitId !== null) {
  1464. productForm.unitId = Number(res.data.productBaseVo.unitId);
  1465. }
  1466. // 回显品牌 - 先加载对应的品牌信息到选项列表中
  1467. if (res.data.productBaseVo.brandId) {
  1468. productForm.brandId = Number(res.data.productBaseVo.brandId);
  1469. try {
  1470. const brandRes = await getBrand(res.data.productBaseVo.brandId);
  1471. if (brandRes.data) {
  1472. // 检查品牌是否已在选项列表中
  1473. const existBrand = brandOptions.value.find((item) => Number(item.id) === Number(res.data.productBaseVo.brandId));
  1474. if (!existBrand) {
  1475. brandOptions.value.unshift(brandRes.data);
  1476. }
  1477. }
  1478. } catch (e) {
  1479. console.error('加载品牌信息失败:', e);
  1480. }
  1481. }
  1482. // 回显售后服务 - 确保类型与下拉选项的id一致(数字类型)
  1483. if (res.data.productBaseVo.afterSalesService !== undefined && res.data.productBaseVo.afterSalesService !== null) {
  1484. productForm.afterSalesService = Number(res.data.productBaseVo.afterSalesService);
  1485. }
  1486. // 回显轮播图
  1487. if (res.data.productBaseVo.imageUrl) {
  1488. carouselImages.value = res.data.productBaseVo.imageUrl.split(',').filter((url: string) => url.trim());
  1489. } else {
  1490. carouselImages.value = [];
  1491. }
  1492. // 回显分类选择
  1493. categoryForm.topCategoryId = res.data.productBaseVo.topCategoryId;
  1494. categoryForm.mediumCategoryId = res.data.productBaseVo.mediumCategoryId;
  1495. categoryForm.bottomCategoryId = res.data.productBaseVo.bottomCategoryId;
  1496. // 回显服务保障复选框 - 将逗号分隔的ID字符串转换为数组
  1497. if (res.data.productBaseVo.serviceGuarantee) {
  1498. serviceGuarantees.value = res.data.productBaseVo.serviceGuarantee.split(',').map((id: string) => {
  1499. // 尝试转换为数字,如果失败则保持字符串
  1500. const numId = Number(id.trim());
  1501. return isNaN(numId) ? id.trim() : numId;
  1502. });
  1503. } else {
  1504. serviceGuarantees.value = [];
  1505. }
  1506. // 回显安装服务复选框
  1507. const services: string[] = [];
  1508. if (res.data.productBaseVo.freeInstallation === '1') services.push('freeInstallation');
  1509. installationServices.value = services;
  1510. // 回显分类名称 - 使用nextTick确保DOM更新后再查找子分类
  1511. await restoreCategorySelection();
  1512. // 回显商品属性值(必须在restoreCategorySelection之后,避免loadCategoryAttributes清空属性值)
  1513. if (res.data.productBaseVo.attributesList) {
  1514. try {
  1515. const parsedAttributes = JSON.parse(res.data.productBaseVo.attributesList);
  1516. productAttributesValues.value = parsedAttributes;
  1517. } catch (e) {
  1518. console.error('解析商品属性失败:', e);
  1519. productAttributesValues.value = {};
  1520. }
  1521. }
  1522. // 回显自定义属性列表
  1523. const rawResData = res.data as any;
  1524. if (Array.isArray(rawResData.productBaseVo.diyAttributesList) && rawResData.productBaseVo.diyAttributesList.length > 0) {
  1525. diyAttributesList.value = rawResData.productBaseVo.diyAttributesList;
  1526. } else {
  1527. diyAttributesList.value = [];
  1528. }
  1529. // 回显定制说明相关字段
  1530. const baseVo = res.data.productBaseVo as any;
  1531. // 可定制开关
  1532. customForm.isCustomize = Number(baseVo.isCustomize) === 1;
  1533. // 定制方式(逗号分隔字符串 → 数组)
  1534. if (baseVo.customizedStyle) {
  1535. customForm.selectedMethods = String(baseVo.customizedStyle)
  1536. .split(',')
  1537. .map((s: string) => s.trim())
  1538. .filter((s: string) => s);
  1539. } else {
  1540. customForm.selectedMethods = [];
  1541. }
  1542. // 定制工艺(逗号分隔字符串 → 数组)
  1543. if (baseVo.customizedCraft) {
  1544. customForm.selectedCrafts = String(baseVo.customizedCraft)
  1545. .split(',')
  1546. .map((s: string) => s.trim())
  1547. .filter((s: string) => s);
  1548. } else {
  1549. customForm.selectedCrafts = [];
  1550. }
  1551. // 定制说明
  1552. customForm.customDescription = baseVo.customDescription || '';
  1553. // 定制详情表格(JSON 字符串 → 数组),必须在 selectedMethods/selectedCrafts 赋值后覆盖,避免 watch 重建覆盖填写值
  1554. await nextTick();
  1555. if (baseVo.customDetailsJson) {
  1556. try {
  1557. const parsedDetails = JSON.parse(baseVo.customDetailsJson);
  1558. if (Array.isArray(parsedDetails)) {
  1559. customForm.customDetails = parsedDetails;
  1560. }
  1561. } catch (e) {
  1562. console.error('解析定制详情失败:', e);
  1563. }
  1564. }
  1565. } catch (error) {
  1566. console.error('加载商品详情失败:', error);
  1567. ElMessage.error('加载商品详情失败');
  1568. } finally {
  1569. loading.value = false;
  1570. }
  1571. }
  1572. };
  1573. // 递归查找分类节点
  1574. const findCategoryById = (categories: categoryTreeVO[], id: string | number): categoryTreeVO | null => {
  1575. for (const category of categories) {
  1576. if (String(category.id) === String(id)) {
  1577. return category;
  1578. }
  1579. if (category.children && category.children.length > 0) {
  1580. const found = findCategoryById(category.children, id);
  1581. if (found) return found;
  1582. }
  1583. }
  1584. return null;
  1585. };
  1586. // 恢复分类选择状态
  1587. const restoreCategorySelection = async () => {
  1588. // 先保存原始的分类ID值
  1589. const originalTopCategoryId = categoryForm.topCategoryId;
  1590. const originalMediumCategoryId = categoryForm.mediumCategoryId;
  1591. const originalBottomCategoryId = categoryForm.bottomCategoryId;
  1592. console.log('回显分类 - 原始ID:', {
  1593. top: originalTopCategoryId,
  1594. medium: originalMediumCategoryId,
  1595. bottom: originalBottomCategoryId
  1596. });
  1597. if (!originalTopCategoryId) return;
  1598. // 查找一级分类
  1599. const level1 = level1Categories.value.find((item) => String(item.id) === String(originalTopCategoryId));
  1600. console.log('查找一级分类:', level1);
  1601. if (!level1) return;
  1602. // 设置一级分类选中状态
  1603. categoryForm.topCategoryId = level1.id;
  1604. selectedLevel1Name.value = level1.label;
  1605. level2Categories.value = level1.children || [];
  1606. await nextTick();
  1607. // 查找二级分类
  1608. if (originalMediumCategoryId) {
  1609. // 先在当前一级分类的children中查找
  1610. let level2 = level2Categories.value.find((item) => String(item.id) === String(originalMediumCategoryId));
  1611. // 如果找不到,尝试在整个分类树中查找(容错处理)
  1612. if (!level2) {
  1613. console.log('二级分类在当前一级下未找到,尝试全局查找...');
  1614. level2 = findCategoryById(categoryOptions.value, originalMediumCategoryId);
  1615. }
  1616. console.log('查找二级分类:', level2);
  1617. if (level2) {
  1618. categoryForm.mediumCategoryId = level2.id;
  1619. selectedLevel2Name.value = level2.label;
  1620. level3Categories.value = level2.children || [];
  1621. await nextTick();
  1622. // 查找三级分类
  1623. if (originalBottomCategoryId) {
  1624. // 先在当前二级分类的children中查找
  1625. let level3 = level3Categories.value.find((item) => String(item.id) === String(originalBottomCategoryId));
  1626. // 如果找不到,尝试在整个分类树中查找(容错处理)
  1627. if (!level3) {
  1628. console.log('三级分类在当前二级下未找到,尝试全局查找...');
  1629. level3 = findCategoryById(categoryOptions.value, originalBottomCategoryId);
  1630. }
  1631. console.log('查找三级分类:', level3, '原始ID:', originalBottomCategoryId);
  1632. if (level3) {
  1633. categoryForm.bottomCategoryId = level3.id;
  1634. selectedLevel3Name.value = level3.label;
  1635. console.log('设置三级分类名称:', selectedLevel3Name.value);
  1636. await loadCategoryAttributes(level3.id);
  1637. }
  1638. }
  1639. }
  1640. }
  1641. };
  1642. onMounted(async () => {
  1643. // 编辑模式下先直接跳到第二步,再加载数据,避免闪烁步骤一
  1644. if (route.params.id) {
  1645. currentStep.value = 1;
  1646. }
  1647. await getCategoryTree();
  1648. await getUnitOptions();
  1649. await getAfterSalesOptions();
  1650. await getServiceGuaranteeOptions();
  1651. await getTaxRateOptions();
  1652. // 先加载商品详情(如果是编辑模式)
  1653. await loadProductDetail();
  1654. // 再加载下拉选项,这样如果详情中没有值,会自动设置第一个
  1655. await getSupplierOptions();
  1656. await getStaffOptions();
  1657. loadBrandOptions();
  1658. });
  1659. </script>
  1660. <style scoped lang="scss">
  1661. .product-wizard-page {
  1662. .category-selection {
  1663. margin-top: 12px;
  1664. }
  1665. .category-box {
  1666. border: 1px solid #e4e7ed;
  1667. border-radius: 4px;
  1668. overflow: hidden;
  1669. .category-header {
  1670. background-color: #f5f7fa;
  1671. padding: 10px 12px;
  1672. font-weight: 600;
  1673. border-bottom: 1px solid #e4e7ed;
  1674. text-align: center;
  1675. font-size: 14px;
  1676. }
  1677. .category-search {
  1678. padding: 10px;
  1679. border-bottom: 1px solid #e4e7ed;
  1680. background-color: #fff;
  1681. }
  1682. .category-list {
  1683. height: 280px;
  1684. overflow-y: auto;
  1685. .category-item {
  1686. padding: 10px 12px;
  1687. cursor: pointer;
  1688. display: flex;
  1689. justify-content: space-between;
  1690. align-items: center;
  1691. border-bottom: 1px solid #f0f0f0;
  1692. transition: all 0.3s;
  1693. &:hover {
  1694. background-color: #f5f7fa;
  1695. }
  1696. &.active {
  1697. background-color: #ecf5ff;
  1698. color: #409eff;
  1699. font-weight: 600;
  1700. }
  1701. &:last-child {
  1702. border-bottom: none;
  1703. }
  1704. &.disabled {
  1705. cursor: not-allowed;
  1706. opacity: 0.45;
  1707. pointer-events: none;
  1708. }
  1709. }
  1710. }
  1711. }
  1712. .confirm-info {
  1713. margin-top: 12px;
  1714. text-align: left;
  1715. }
  1716. .product-info-form {
  1717. .category-display {
  1718. display: flex;
  1719. align-items: center;
  1720. .category-text {
  1721. color: #606266;
  1722. }
  1723. }
  1724. .form-item-tip {
  1725. font-size: 12px;
  1726. color: #909399;
  1727. line-height: 1.5;
  1728. margin-top: 4px;
  1729. }
  1730. .currency-text {
  1731. color: #303133;
  1732. font-size: 14px;
  1733. }
  1734. }
  1735. .custom-options {
  1736. display: flex;
  1737. gap: 10px;
  1738. flex-wrap: wrap;
  1739. }
  1740. .custom-table {
  1741. width: 100%;
  1742. margin-top: 10px;
  1743. }
  1744. .completion-card {
  1745. min-height: 400px;
  1746. display: flex;
  1747. align-items: center;
  1748. justify-content: center;
  1749. .completion-content {
  1750. text-align: center;
  1751. padding: 40px 0;
  1752. .success-icon {
  1753. margin-bottom: 24px;
  1754. }
  1755. .completion-text {
  1756. font-size: 16px;
  1757. color: #606266;
  1758. margin-bottom: 32px;
  1759. line-height: 1.6;
  1760. }
  1761. .completion-action {
  1762. display: flex;
  1763. justify-content: center;
  1764. }
  1765. }
  1766. }
  1767. }
  1768. </style>