add1.vue 72 KB

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