add.vue 69 KB

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