releaseProduct.vue 25 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004
  1. <template>
  2. <view class="container">
  3. <view class="form-container">
  4. <up-form
  5. labelPosition="left"
  6. :model="formData"
  7. :rules="rules"
  8. ref="formRef"
  9. :labelWidth="100"
  10. >
  11. <!-- 商品分类 -->
  12. <view class="card-title">商品分类</view>
  13. <up-form-item
  14. class="form-item"
  15. label="商品分类"
  16. prop="categoryIds"
  17. :borderBottom="false"
  18. @click="showCategory = true"
  19. :required="true"
  20. >
  21. <up-input
  22. v-model="formData.categoryDisplayName"
  23. disabled
  24. disabledColor="#ffffff"
  25. placeholder="请选择商品分类"
  26. inputAlign="right"
  27. border="none"
  28. ></up-input>
  29. <template #right>
  30. <up-icon name="arrow-right"></up-icon>
  31. </template>
  32. </up-form-item>
  33. <!-- 商品信息 -->
  34. <view class="card-title">商品信息</view>
  35. <up-form-item
  36. label="商品名称"
  37. prop="storeName"
  38. :borderBottom="false"
  39. :required="true"
  40. >
  41. <up-input
  42. v-model="formData.storeName"
  43. placeholder="请输入商品名称"
  44. inputAlign="right"
  45. border="none"
  46. ></up-input>
  47. </up-form-item>
  48. <up-form-item
  49. label="商品关键字"
  50. prop="keyword"
  51. :borderBottom="false"
  52. :required="true"
  53. >
  54. <up-input
  55. v-model="formData.keyword"
  56. placeholder="请输入商品关键字"
  57. inputAlign="right"
  58. border="none"
  59. ></up-input>
  60. </up-form-item>
  61. <up-form-item
  62. label="商品简介"
  63. prop="storeInfo"
  64. :borderBottom="false"
  65. :required="true"
  66. >
  67. <up-textarea
  68. v-model="formData.storeInfo"
  69. placeholder="请输入商品简介"
  70. inputAlign="right"
  71. border="none"
  72. ></up-textarea>
  73. </up-form-item>
  74. <up-form-item
  75. label="单位"
  76. prop="unitName"
  77. :borderBottom="false"
  78. :required="true"
  79. >
  80. <up-input
  81. v-model="formData.unitName"
  82. placeholder="请输入单位"
  83. inputAlign="right"
  84. border="none"
  85. ></up-input>
  86. </up-form-item>
  87. <!-- 图片上传 -->
  88. <view class="upload-section">
  89. <view class="upload-item">
  90. <view class="upload-label"><text class="required">*</text>商品封面图</view>
  91. <up-upload
  92. :fileList="previewImages"
  93. @afterRead="async (e) => {
  94. await afterRead(e);
  95. getImage();
  96. }"
  97. @delete="onPreviewImageDelete"
  98. name="preview"
  99. max-count="1"
  100. :maxSize="5 * 1024 * 1024"
  101. accept=".png,.jpg,.jpeg"
  102. >
  103. <view class="upload-btn">
  104. <up-icon name="plus" size="20" color="#ccc"></up-icon>
  105. <text class="upload-tip">点击上传</text>
  106. </view>
  107. </up-upload>
  108. <text class="format-tip">支持上传PNG、JPG格式的图片,每张不超过5MB。</text>
  109. </view>
  110. </view>
  111. <view class="upload-section">
  112. <view class="upload-item">
  113. <view class="upload-label"><text class="required">*</text>商品图片</view>
  114. <up-upload
  115. :fileList="productImages"
  116. @afterRead="async (e) => {
  117. await afterRead(e);
  118. getImageProduct();
  119. }"
  120. @delete="onProductImageDelete"
  121. name="product"
  122. multiple
  123. :maxCount="10"
  124. :maxSize="5 * 1024 * 1024"
  125. accept=".png,.jpg,.jpeg"
  126. >
  127. <view class="upload-btn">
  128. <up-icon name="plus" size="20" color="#ccc"></up-icon>
  129. <text class="upload-tip">点击上传</text>
  130. </view>
  131. </up-upload>
  132. <text class="format-tip">支持上传PNG、JPG格式图片,每张不超过5MB,最多可上传5张。</text>
  133. </view>
  134. </view>
  135. <!-- 商品属性 -->
  136. <view class="card-title">商品属性</view>
  137. <up-form-item
  138. label="材质"
  139. prop="metalType"
  140. :borderBottom="false"
  141. :required="true"
  142. >
  143. <up-radio-group
  144. v-model="formData.metalType"
  145. placement="row"
  146. >
  147. <up-radio
  148. :customStyle="{marginRight: '20rpx'}"
  149. v-for="(item, index) in materialList"
  150. :key="index"
  151. :label="item.name"
  152. :name="item.code"
  153. >
  154. </up-radio>
  155. </up-radio-group>
  156. </up-form-item>
  157. <up-form-item
  158. label="重量"
  159. prop="weight"
  160. :borderBottom="false"
  161. :required="true"
  162. >
  163. <up-input
  164. v-model="formData.weight"
  165. placeholder="请输入重量"
  166. inputAlign="right"
  167. border="none"
  168. type="digit"
  169. ></up-input>
  170. <template #right>
  171. <text class="unit">g</text>
  172. </template>
  173. </up-form-item>
  174. <!-- 商品描述 -->
  175. <view class="card-title">商品描述</view>
  176. <view class="editor-section">
  177. <view class="editor-header">
  178. <text class="editor-label"><text class="required">*</text>商品描述</text>
  179. <text class="word-count">{{ descriptionText.length }}/500</text>
  180. </view>
  181. <sp-editor
  182. editorId="editor"
  183. :toolbar-config="toolbarConfig"
  184. :readOnly="readOnly"
  185. @input="onEditorInput"
  186. @upinImage="onUpinImage"
  187. @init="onEditorInit"
  188. @overMax="onOverMax"
  189. ></sp-editor>
  190. </view>
  191. <!-- 价格设置 -->
  192. <view class="card-title">价格设置</view>
  193. <up-form-item
  194. label="工费"
  195. prop="laborCost"
  196. :borderBottom="false"
  197. :required="true"
  198. >
  199. <up-input
  200. v-model="formData.laborCost"
  201. placeholder="请输入工费"
  202. inputAlign="right"
  203. border="none"
  204. type="digit"
  205. ></up-input>
  206. <template #right>
  207. <text class="unit">元/g</text>
  208. </template>
  209. </up-form-item>
  210. <up-form-item
  211. label="附加费"
  212. prop="additionalFee"
  213. :borderBottom="false"
  214. :required="true"
  215. >
  216. <up-input
  217. v-model="formData.additionalFee"
  218. placeholder="请输入附加费"
  219. inputAlign="right"
  220. border="none"
  221. type="digit"
  222. ></up-input>
  223. <template #right>
  224. <text class="unit">元</text>
  225. </template>
  226. </up-form-item>
  227. <up-form-item
  228. class="form-item"
  229. label="运费模板"
  230. prop="tempIds"
  231. :borderBottom="false"
  232. @click="showTemp = true"
  233. :required="true"
  234. >
  235. <up-input
  236. v-model="formData.tempName"
  237. disabled
  238. disabledColor="#ffffff"
  239. placeholder="请选择运费模板"
  240. inputAlign="right"
  241. border="none"
  242. ></up-input>
  243. <template #right>
  244. <up-icon name="arrow-right"></up-icon>
  245. </template>
  246. </up-form-item>
  247. <up-form-item
  248. label="库存"
  249. prop="stock"
  250. :borderBottom="false"
  251. :required="true"
  252. >
  253. <up-input
  254. v-model="formData.stock"
  255. placeholder="请输入库存"
  256. inputAlign="right"
  257. border="none"
  258. type="number"
  259. ></up-input>
  260. </up-form-item>
  261. <up-form-item
  262. label="商品编号"
  263. prop="barCode"
  264. :borderBottom="false"
  265. :required="true"
  266. >
  267. <up-input
  268. v-model="formData.barCode"
  269. placeholder="请输入商品编号"
  270. inputAlign="right"
  271. border="none"
  272. type="number"
  273. ></up-input>
  274. </up-form-item>
  275. <view class="upload-section">
  276. <view class="upload-item">
  277. <view class="upload-label"><text class="required">*</text>规格图片</view>
  278. <up-upload
  279. :fileList="productImagesGg"
  280. @afterRead="async (e) => {
  281. await afterRead(e);
  282. getImageProductGg();
  283. }"
  284. @delete="onProductImageGgDelete"
  285. name="productGg"
  286. :maxCount="1"
  287. :maxSize="5 * 1024 * 1024"
  288. accept=".png,.jpg,.jpeg"
  289. >
  290. <view class="upload-btn">
  291. <up-icon name="plus" size="20" color="#ccc"></up-icon>
  292. <text class="upload-tip">点击上传</text>
  293. </view>
  294. </up-upload>
  295. <text class="format-tip">支持上传PNG、JPG格式图片,每张不超过5MB,最多可上传5张。</text>
  296. </view>
  297. </view>
  298. <up-form-item
  299. label="商品排序"
  300. prop="sort"
  301. :borderBottom="false"
  302. >
  303. <up-input
  304. v-model="formData.sort"
  305. placeholder="请输入排序号"
  306. inputAlign="right"
  307. border="none"
  308. type="number"
  309. ></up-input>
  310. </up-form-item>
  311. </up-form>
  312. </view>
  313. <!-- 发布按钮 -->
  314. <view class="btn-view">
  315. <button class="submit" @click="submitForm">立即发布</button>
  316. </view>
  317. <!-- 类目选择弹窗 -->
  318. <up-popup
  319. :show="showCategory"
  320. @close="showCategory = false"
  321. mode="bottom"
  322. round="20"
  323. :closeable="true"
  324. >
  325. <view class="popup-content">
  326. <view class="popup-header">
  327. <text class="popup-title">选择商品分类</text>
  328. </view>
  329. <category-selector
  330. :categoryList="categoryData"
  331. :selectedIds="formData.categoryIds"
  332. @change="onCategoryChange"
  333. ref="categoryRef"
  334. />
  335. <view class="popup-actions">
  336. <button class="action-btn cancel" @click="showCategory = false">取消</button>
  337. <button class="action-btn confirm" @click="confirmCategory">确定</button>
  338. </view>
  339. </view>
  340. </up-popup>
  341. <!-- 运费模板-->
  342. <up-picker :show="showTemp" v-model="formData.tempIds" :columns="tempColumns" keyName="name" valueName ="id"
  343. confirmColor="#F8C008"
  344. @close="showTemp = false" @confirm="tempConfirm" @cancel="showTemp = false"></up-picker>
  345. </view>
  346. </template>
  347. <script setup>
  348. import { ref, computed, watch } from 'vue';
  349. import { onShow } from "@dcloudio/uni-app";
  350. import { productCategory,productSave,templatesList } from "@/api/merchant";
  351. import CategorySelector from '@/components/CategorySelector';
  352. import { useAppStore } from "@/stores/app";
  353. import { useImageUpload } from "@/hooks/useImageUpload";
  354. import { useToast } from "@/hooks/useToast";
  355. const { Toast } = useToast();
  356. const { imageList, afterRead, deletePic, uploadLoading } = useImageUpload({
  357. pid: 1,
  358. model: "product",
  359. });
  360. const appStore = useAppStore();
  361. const merchantInfo = appStore.userInfo.merchant
  362. // 表单数据
  363. const formData = ref({
  364. categoryIds: [], // 选中的分类ID数组
  365. categoryDisplayName: '', // 显示的分类名称
  366. tempName: '', // 显示的运费模板名称
  367. tempIds: [],
  368. storeName: '',
  369. keyword: '',
  370. storeInfo: '',
  371. unitName: '',
  372. metalType: '',
  373. weight: '',
  374. laborCost: '',
  375. additionalFee: '',
  376. sort: '',
  377. content: '',
  378. stock: '',
  379. barCode: ''
  380. });
  381. // 编辑器相关
  382. const editorIns = ref(null);
  383. const readOnly = ref(false);
  384. const descriptionText = ref('');
  385. const toolbarConfig = ref({
  386. iconSize: '20px',
  387. iconColumns: 10,
  388. excludeKeys: ['direction', 'date', 'lineHeight', 'letterSpacing', 'listCheck']
  389. });
  390. // 分类相关
  391. const showCategory = ref(false);
  392. const categoryData = ref([]);
  393. const categoryRef = ref();
  394. const showTemp = ref(false);
  395. const tempColumns = ref([])
  396. // 图片列表
  397. const previewImages = ref([]);
  398. const productImages = ref([]);
  399. const productImagesGg = ref([]);
  400. // 材质列表
  401. const materialList = ref([
  402. { name: '黄金',code:'au' },
  403. { name: '铂金' ,code:'pt'},
  404. { name: '白银',code:'ag' }
  405. ]);
  406. // 验证规则
  407. const rules = ref({
  408. categoryIds: {
  409. type: 'array',
  410. required: true,
  411. message: '请选择商品分类',
  412. trigger: ['change']
  413. },
  414. storeName: {
  415. type: 'string',
  416. required: true,
  417. message: '请输入商品名称',
  418. trigger: ['blur', 'change']
  419. },
  420. keyword: {
  421. type: 'string',
  422. required: true,
  423. message: '请输入商品关键字',
  424. trigger: ['blur', 'change']
  425. },
  426. storeInfo: {
  427. type: 'string',
  428. required: true,
  429. message: '请输入商品关键字',
  430. trigger: ['blur', 'change']
  431. },
  432. unitName: {
  433. type: 'string',
  434. required: true,
  435. message: '请输入单位',
  436. trigger: ['blur', 'change']
  437. },
  438. tempIds: {
  439. type: 'array',
  440. required: true,
  441. message: '请选择运费模板',
  442. trigger: ['blur', 'change']
  443. },
  444. metalType: {
  445. type: 'string',
  446. required: true,
  447. message: '请选择材质',
  448. trigger: ['change']
  449. },
  450. weight: {
  451. type: 'string',
  452. required: true,
  453. pattern: /^\d+(\.\d+)?$/,
  454. message: '重量必须是数字,可以是小数',
  455. trigger: ['blur', 'change']
  456. },
  457. laborCost: {
  458. type: 'string',
  459. required: true,
  460. pattern: /^\d+(\.\d+)?$/,
  461. message: '工费必须是数字,可以是小数',
  462. trigger: ['blur', 'change']
  463. },
  464. additionalFee: {
  465. type: 'string',
  466. required: true,
  467. pattern: /^\d+(\.\d+)?$/,
  468. message: '附加费必须是数字,可以是小数',
  469. trigger: ['blur', 'change']
  470. },
  471. sort: {
  472. type: 'string',
  473. pattern: /^\d*$/,
  474. message: '排序号必须是整数',
  475. trigger: ['blur', 'change']
  476. },
  477. stock: {
  478. type: 'string',
  479. required: true,
  480. pattern: /^\d*$/,
  481. message: '库存必须是整数',
  482. trigger: ['blur', 'change']
  483. },
  484. barCode: {
  485. type: 'string',
  486. required: true,
  487. pattern: /^\d*$/,
  488. message: '商品编号必须是整数',
  489. trigger: ['blur', 'change']
  490. },
  491. });
  492. // 页面加载
  493. onShow(() => {
  494. getProductCategory();
  495. getTempData();
  496. })
  497. // 获取商品分类
  498. async function getProductCategory(){
  499. let obj = {
  500. type: 1,
  501. status: -1
  502. }
  503. try {
  504. const { data } = await productCategory(obj)
  505. console.log('原始分类数据:', data);
  506. const newArr = []
  507. data.forEach((value, index) => {
  508. newArr[index] = value
  509. if (value.child) newArr[index].child = value.child.filter(item => item.status === true)
  510. })
  511. // 过滤商品分类设置为隐藏的子分类不出现在树形列表里
  512. categoryData.value = newArr.filter(item => item.code !== 'bb_mall')
  513. console.log('转换后的分类数据:', categoryData.value);
  514. } catch (error) {
  515. console.error('获取商品分类失败:', error);
  516. uni.showToast({ title: '获取分类失败', icon: 'none' });
  517. }
  518. }
  519. async function getTempData(){
  520. let obj = {
  521. page:1,
  522. limit:9999
  523. }
  524. try {
  525. const { data } = await templatesList()
  526. tempColumns.value[0] = data.list;
  527. } catch (error) {
  528. console.error('获取商品分类失败:', error);
  529. uni.showToast({ title: '获取分类失败', icon: 'none' });
  530. }
  531. }
  532. function tempConfirm(obj){
  533. formData.value.tempId = obj.value[0].id;
  534. formData.value.tempName = obj.value[0].name;
  535. showTemp.value = false;
  536. // setTimeout(() => {
  537. // if (formRef.value) {
  538. // formRef.value.validateField('tempId').catch(() => {});
  539. // }
  540. // }, 100);
  541. }
  542. // 分类选择变化
  543. const onCategoryChange = (result) => {
  544. console.log('分类选择变化:', result);
  545. // 这里只更新显示,不直接更新表单数据,等用户点击确定
  546. }
  547. // 确认分类选择
  548. const confirmCategory = () => {
  549. if (categoryRef.value) {
  550. const selectedIds = categoryRef.value.getSelectedIds()
  551. if (selectedIds.length === 0) {
  552. uni.showToast({ title: '请至少选择一个分类', icon: 'none' })
  553. return
  554. }
  555. // 更新表单数据
  556. formData.value.categoryIds = selectedIds
  557. formData.value.categoryDisplayName = getCategoryDisplayName(selectedIds)
  558. showCategory.value = false
  559. console.log('最终选中的分类ID:', selectedIds)
  560. }
  561. }
  562. // 根据选中的ID生成显示名称
  563. const getCategoryDisplayName = (selectedIds) => {
  564. if (selectedIds.length === 0) return ''
  565. const names = []
  566. selectedIds.forEach(id => {
  567. // 查找一级分类
  568. const firstLevel = categoryData.value.find(item => item.id === id)
  569. if (firstLevel) {
  570. names.push(firstLevel.name)
  571. } else {
  572. // 查找二级分类
  573. for (const parent of categoryData.value) {
  574. if (parent.child) {
  575. const secondLevel = parent.child.find(child => child.id === id)
  576. if (secondLevel) {
  577. names.push(`${parent.name}-${secondLevel.name}`)
  578. }
  579. }
  580. }
  581. }
  582. })
  583. return names.join('、')
  584. }
  585. async function getImage() {
  586. console.log(imageList.value)
  587. if (imageList.value.length > 0) {
  588. if (imageList.value[0].status == "success") {
  589. previewImages.value = imageList.value;
  590. // change();
  591. } else {
  592. Toast({ title: "上传失败" });
  593. }
  594. }
  595. imageList.value = [];
  596. }
  597. async function getImageProduct() {
  598. console.log(imageList.value)
  599. if (imageList.value.length > 0) {
  600. if (imageList.value[0].status == "success") {
  601. productImages.value = [...productImages.value,...imageList.value];
  602. // change();
  603. } else {
  604. Toast({ title: "上传失败" });
  605. }
  606. }
  607. imageList.value = [];
  608. }
  609. async function getImageProductGg() {
  610. console.log(imageList.value)
  611. if (imageList.value.length > 0) {
  612. if (imageList.value[0].status == "success") {
  613. productImagesGg.value = imageList.value;
  614. // change();
  615. } else {
  616. Toast({ title: "上传失败" });
  617. }
  618. }
  619. imageList.value = [];
  620. }
  621. const onPreviewImageDelete =(e) => {
  622. previewImages.value.splice(e.index, 1);
  623. };
  624. const onProductImageDelete = (e) => {
  625. productImages.value.splice(e.index, 1);
  626. };
  627. const onProductImageGgDelete = (e) => {
  628. productImagesGg.value.splice(e.index, 1);
  629. };
  630. // 编辑器相关方法
  631. const onEditorInput = (e) => {
  632. descriptionText.value = e.text || '';
  633. formData.value.content = e.html || '';
  634. };
  635. const onEditorInit = (editor) => {
  636. editorIns.value = editor;
  637. };
  638. const onOverMax = (e) => {
  639. uni.showToast({ title: '内容长度超出限制', icon: 'none' });
  640. };
  641. const onUpinImage = (tempFiles, editorCtx) => {
  642. const filePath = tempFiles[0].tempFilePath || tempFiles[0].path;
  643. editorCtx.insertImage({
  644. src: filePath,
  645. width: '80%',
  646. success: () => {
  647. uni.showToast({ title: '图片插入成功', icon: 'success' });
  648. }
  649. });
  650. };
  651. // 表单验证和提交
  652. const formRef = ref(null);
  653. const validateForm = async () => {
  654. try {
  655. const valid = await formRef.value.validate();
  656. return valid;
  657. } catch (error) {
  658. console.error('表单验证失败:', error);
  659. return false;
  660. }
  661. };
  662. const submitForm = async () => {
  663. console.log(formData.value)
  664. // 检查商品描述
  665. if (!descriptionText.value.trim()) {
  666. uni.showToast({ title: '请输入商品描述', icon: 'none' });
  667. return;
  668. }
  669. // 检查图片上传
  670. if (previewImages.value.length === 0) {
  671. uni.showToast({ title: '请上传商品预览图', icon: 'none' });
  672. return;
  673. }
  674. if (productImages.value.length === 0) {
  675. uni.showToast({ title: '请上传商品图片', icon: 'none' });
  676. return;
  677. }
  678. if (productImagesGg.value.length === 0) {
  679. uni.showToast({ title: '请上传商品规格图片', icon: 'none' });
  680. return;
  681. }
  682. // 验证数字字段
  683. if (!/^\d+(\.\d+)?$/.test(formData.value.weight)) {
  684. uni.showToast({ title: '重量格式不正确', icon: 'none' });
  685. return;
  686. }
  687. if (!/^\d+(\.\d+)?$/.test(formData.value.laborCost)) {
  688. uni.showToast({ title: '工费格式不正确', icon: 'none' });
  689. return;
  690. }
  691. if (!/^\d+(\.\d+)?$/.test(formData.value.additionalFee)) {
  692. uni.showToast({ title: '附加费格式不正确', icon: 'none' });
  693. return;
  694. }
  695. if (!/^\d+$/.test(formData.value.stock)) {
  696. uni.showToast({ title: '库存必须是整数', icon: 'none' });
  697. return;
  698. }
  699. if (!/^\d+$/.test(formData.value.barCode)) {
  700. uni.showToast({ title: '商品编号必须是整数', icon: 'none' });
  701. return;
  702. }
  703. if (formData.value.sort && !/^\d+$/.test(formData.value.sort)) {
  704. uni.showToast({ title: '排序号必须是整数', icon: 'none' });
  705. return;
  706. }
  707. const valid = await validateForm();
  708. if (valid) {
  709. const submitData = {
  710. ...formData.value
  711. };
  712. submitData.cateId =formData.value.categoryIds.join(',');
  713. submitData.image =previewImages.value[0].url;
  714. const urlString = productImages.value.map(item => item.url).join(',');
  715. submitData.sliderImage =urlString;
  716. submitData.merchantId =parseInt(merchantInfo.id);
  717. submitData.specType = 0;
  718. submitData.isSub = false;
  719. submitData.attr =[
  720. {
  721. "attrName":"规格",
  722. "attrValues": "默认",
  723. "id": 0
  724. }
  725. ];
  726. submitData.attrValue =[
  727. {
  728. additionalAmount :formData.value.additionalFee,
  729. attrValue:"{\"规格\":\"默认\"}",
  730. barCode : formData.value.barCode,
  731. image : productImagesGg.value[0].url,
  732. price : formData.value.laborCost,
  733. stock : formData.value.stock,
  734. weight :formData.value.weight
  735. }
  736. ];
  737. console.log('提交数据:', submitData);
  738. const {data} = await productSave(submitData);
  739. uni.showToast({ title: '发布成功', icon: 'success' });
  740. }
  741. };
  742. </script>
  743. <style scoped lang="scss">
  744. .container {
  745. background-color: #f8f8f8;
  746. min-height: 100vh;
  747. padding-bottom: 140rpx;
  748. }
  749. .form-container {
  750. padding: 30rpx;
  751. }
  752. .upload-section {
  753. margin-top: 20rpx;
  754. margin-bottom: 20rpx;
  755. background: white;
  756. border-radius: 16rpx;
  757. padding: 30rpx;
  758. }
  759. .upload-item {
  760. margin-bottom: 40rpx;
  761. &:last-child {
  762. margin-bottom: 0;
  763. }
  764. }
  765. .upload-label {
  766. display: block;
  767. font-size: 28rpx;
  768. color: #333;
  769. margin-bottom: 20rpx;
  770. position: relative;
  771. }
  772. .required {
  773. position: absolute;
  774. left: -9px;
  775. color: #f56c6c;
  776. line-height: 20px;
  777. font-size: 20px;
  778. top: 3px;
  779. }
  780. .upload-btn {
  781. display: flex;
  782. flex-direction: column;
  783. align-items: center;
  784. justify-content: center;
  785. width: 200rpx;
  786. height: 200rpx;
  787. border: 2rpx dashed #ccc;
  788. border-radius: 12rpx;
  789. background: #fafafa;
  790. }
  791. .upload-tip {
  792. font-size: 24rpx;
  793. color: #999;
  794. margin-top: 10rpx;
  795. }
  796. .format-tip {
  797. display: block;
  798. font-size: 24rpx;
  799. color: #999;
  800. margin-top: 15rpx;
  801. }
  802. .card-title {
  803. font-size: 36rpx;
  804. color: #333;
  805. line-height: 60rpx;
  806. margin-bottom: 20rpx;
  807. }
  808. :deep(.u-form-item) {
  809. background-color: #fff;
  810. border-radius: 16rpx;
  811. padding: 8rpx 30rpx;
  812. box-sizing: border-box;
  813. margin-bottom: 20rpx;
  814. }
  815. :deep(.u-form-item__body__left__content__label) {
  816. font-size: 28rpx !important;
  817. color: #333 !important;
  818. }
  819. :deep(.u-radio-group--row) {
  820. justify-content: flex-end;
  821. }
  822. .btn-view {
  823. position: fixed;
  824. bottom: 0;
  825. left: 0;
  826. right: 0;
  827. background-color: #FFF;
  828. padding: 20rpx 30rpx;
  829. box-shadow: 0 -2rpx 10rpx rgba(0,0,0,0.1);
  830. }
  831. .submit {
  832. height: 88rpx;
  833. line-height: 88rpx;
  834. background: #F8C008;
  835. border-radius: 16rpx;
  836. font-size: 32rpx;
  837. color: #333333;
  838. border: none;
  839. width: 100%;
  840. &:active {
  841. opacity: 0.8;
  842. }
  843. }
  844. .unit {
  845. color: #999;
  846. font-size: 28rpx;
  847. margin-left: 10rpx;
  848. }
  849. /* 编辑器样式 */
  850. .editor-section {
  851. background: white;
  852. border-radius: 16rpx;
  853. margin-bottom: 20rpx;
  854. overflow: hidden;
  855. }
  856. .editor-header {
  857. display: flex;
  858. justify-content: space-between;
  859. align-items: center;
  860. padding: 30rpx;
  861. border-bottom: 1rpx solid #f0f0f0;
  862. }
  863. .editor-label {
  864. font-size: 28rpx;
  865. color: #333;
  866. font-weight: 500;
  867. }
  868. .word-count {
  869. font-size: 24rpx;
  870. color: #999;
  871. }
  872. :deep(.sp-editor) {
  873. min-height: 400rpx;
  874. }
  875. /* 弹窗样式 */
  876. .popup-content {
  877. background: #fff;
  878. border-radius: 20rpx 20rpx 0 0;
  879. padding-bottom: env(safe-area-inset-bottom);
  880. }
  881. .popup-header {
  882. padding: 30rpx;
  883. text-align: center;
  884. border-bottom: 1rpx solid #f0f0f0;
  885. position: relative;
  886. }
  887. .popup-title {
  888. font-size: 32rpx;
  889. font-weight: 600;
  890. color: #333;
  891. }
  892. .popup-actions {
  893. display: flex;
  894. padding: 30rpx;
  895. gap: 20rpx;
  896. }
  897. .action-btn {
  898. flex: 1;
  899. height: 80rpx;
  900. line-height: 80rpx;
  901. border-radius: 12rpx;
  902. font-size: 28rpx;
  903. border: none;
  904. &.cancel {
  905. background: #f0f0f0;
  906. color: #666;
  907. }
  908. &.confirm {
  909. background: #F8C008;
  910. color: #333;
  911. }
  912. }
  913. :deep(.u-tabs__wrapper__nav__line){
  914. background-color: #F8C008 !important;
  915. }
  916. :deep(.u-form-item__body__right__message){
  917. text-align: right;
  918. }
  919. :deep(.u-textarea__field){
  920. text-align: right;
  921. }
  922. </style>