add.vue 61 KB

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