sales-publish.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751
  1. <template>
  2. <view class="sales-publish-container">
  3. <!-- 表单内容 -->
  4. <view class="form-container">
  5. <!-- 产品名称 -->
  6. <view class="form-item">
  7. <view class="item-label">
  8. <text class="label-text">产品名称</text>
  9. <text class="required">*</text>
  10. </view>
  11. <view class="item-content">
  12. <input
  13. class="form-input"
  14. v-model="formData.productName"
  15. placeholder="请输入产品名称"
  16. placeholder-style="color: #999;"
  17. maxlength="20"
  18. @input="onNameInput"
  19. />
  20. <view class="char-count">{{ nameLength }}/20</view>
  21. </view>
  22. </view>
  23. <!-- 产品分类 -->
  24. <view class="form-item">
  25. <view class="item-label">
  26. <text class="label-text">产品分类</text>
  27. <text class="required">*</text>
  28. </view>
  29. <view class="item-content">
  30. <view class="category-selector" @click="showCategoryPicker = true">
  31. <text class="selector-text" :class="{ placeholder: !formData.category }">
  32. {{ formData.category || '请选择产品分类' }}
  33. </text>
  34. <text class="arrow-icon">></text>
  35. </view>
  36. </view>
  37. </view>
  38. <!-- 销售价格 -->
  39. <view class="form-item">
  40. <view class="item-label">
  41. <text class="label-text">销售价格</text>
  42. <text class="required">*</text>
  43. </view>
  44. <view class="item-content">
  45. <view class="input-with-unit">
  46. <text class="currency-symbol">¥</text>
  47. <input
  48. class="form-input"
  49. v-model="formData.price"
  50. placeholder="请输入销售价格"
  51. placeholder-style="color: #999;"
  52. type="digit"
  53. />
  54. <text class="unit-text">元/斤</text>
  55. </view>
  56. </view>
  57. </view>
  58. <!-- 产品简介 -->
  59. <view class="form-item">
  60. <view class="item-label">
  61. <text class="label-text">产品简介</text>
  62. </view>
  63. <view class="item-content">
  64. <textarea
  65. class="form-textarea"
  66. v-model="formData.description"
  67. placeholder="请简单介绍您的农产品特色、种植方式等"
  68. placeholder-style="color: #999;"
  69. maxlength="80"
  70. auto-height
  71. @input="onDescInput"
  72. />
  73. <view class="char-count">{{ descLength }}/80</view>
  74. </view>
  75. </view>
  76. <!-- 产品图片 -->
  77. <view class="form-item">
  78. <view class="item-label">
  79. <text class="label-text">产品图片</text>
  80. <text class="required">*</text>
  81. <text class="optional">(最多3张)</text>
  82. </view>
  83. <view class="item-content">
  84. <view class="image-upload-area">
  85. <view
  86. class="image-item"
  87. v-for="(image, index) in formData.images"
  88. :key="index"
  89. >
  90. <image class="uploaded-image" :src="image" mode="aspectFill"></image>
  91. <view class="image-delete" @click="removeImage(index)">×</view>
  92. </view>
  93. <view
  94. class="image-upload-btn"
  95. v-if="formData.images.length < 3"
  96. @click="chooseImage"
  97. >
  98. <text class="upload-icon">+</text>
  99. <text class="upload-text">上传图片</text>
  100. </view>
  101. </view>
  102. </view>
  103. </view>
  104. <!-- 产地信息 -->
  105. <view class="form-item">
  106. <view class="item-label">
  107. <text class="label-text">产地信息</text>
  108. </view>
  109. <view class="contact-info">
  110. <view class="contact-row">
  111. <text class="contact-label">产地:</text>
  112. <text class="contact-value">{{ locationInfo.address }}</text>
  113. </view>
  114. <view class="contact-row">
  115. <text class="contact-label">地块:</text>
  116. <text class="contact-value">{{ locationInfo.field }}</text>
  117. </view>
  118. </view>
  119. </view>
  120. <!-- 联系人信息 -->
  121. <view class="form-item">
  122. <view class="item-label">
  123. <text class="label-text">联系人信息</text>
  124. </view>
  125. <view class="item-content">
  126. <view class="contact-input-row">
  127. <text class="contact-label">联系人:</text>
  128. <input
  129. class="contact-input"
  130. v-model="formData.contactName"
  131. placeholder="请输入联系人姓名"
  132. placeholder-style="color: #999;"
  133. maxlength="10"
  134. />
  135. </view>
  136. <view class="contact-input-row">
  137. <text class="contact-label">电话:</text>
  138. <input
  139. class="contact-input"
  140. v-model="formData.contactPhone"
  141. placeholder="请输入联系电话"
  142. placeholder-style="color: #999;"
  143. type="number"
  144. maxlength="11"
  145. />
  146. </view>
  147. </view>
  148. </view>
  149. </view>
  150. <!-- 底部提交按钮 -->
  151. <view class="bottom-action-bar">
  152. <view class="submit-btn" @click="submitForm">
  153. <text class="btn-text">{{ isEditMode ? '保存修改' : '提交审核' }}</text>
  154. </view>
  155. </view>
  156. <!-- 分类选择弹窗 -->
  157. <view class="picker-modal" v-if="showCategoryPicker" @click="showCategoryPicker = false">
  158. <view class="picker-content" @click.stop>
  159. <view class="picker-header">
  160. <text class="picker-title">选择产品分类</text>
  161. <text class="picker-close" @click="showCategoryPicker = false">×</text>
  162. </view>
  163. <view class="picker-options">
  164. <view
  165. class="picker-option"
  166. v-for="category in categoryOptions"
  167. :key="category"
  168. @click="selectCategory(category)"
  169. >
  170. <text class="option-text">{{ category }}</text>
  171. </view>
  172. </view>
  173. </view>
  174. </view>
  175. </view>
  176. </template>
  177. <script>
  178. export default {
  179. data() {
  180. return {
  181. isEditMode: false, // 是否为编辑模式
  182. editProductId: '', // 编辑的产品ID
  183. productType: 'sale', // 产品类型:sale(销售)或 purchase(收购)
  184. formData: {
  185. productName: '',
  186. category: '',
  187. price: '',
  188. description: '',
  189. images: [],
  190. contactName: '',
  191. contactPhone: ''
  192. },
  193. locationInfo: {
  194. address: '张家村',
  195. field: '水稻田A区'
  196. },
  197. categoryOptions: ['蔬菜', '水果', '粮食', '畜产品', '水产品', '中药材'],
  198. showCategoryPicker: false,
  199. nameLength: 0,
  200. descLength: 0
  201. }
  202. },
  203. onLoad(options) {
  204. // 检查是否为编辑模式
  205. if (options.action === 'edit' && options.id) {
  206. this.isEditMode = true;
  207. this.editProductId = options.id;
  208. this.productType = options.type || 'sale';
  209. // 设置页面标题
  210. uni.setNavigationBarTitle({
  211. title: this.productType === 'sale' ? '编辑销售信息' : '编辑收购信息'
  212. });
  213. // 加载产品数据
  214. this.loadProductData();
  215. } else {
  216. // 新建模式
  217. this.isEditMode = false;
  218. uni.setNavigationBarTitle({
  219. title: '发布农产品'
  220. });
  221. }
  222. },
  223. methods: {
  224. // 加载产品数据(编辑模式)
  225. loadProductData() {
  226. // 模拟从API加载数据,实际应用中需要根据ID和类型调用相应的API
  227. uni.showLoading({ title: '加载中...' });
  228. setTimeout(() => {
  229. let mockData;
  230. if (this.productType === 'sale') {
  231. // 销售信息的模拟数据
  232. mockData = {
  233. productName: '2024年红富士苹果',
  234. category: '水果',
  235. price: '8.5',
  236. description: '自家果园种植的红富士苹果,个大味甜,果形端正,色泽鲜艳。采用有机种植方式,无农药残留,口感清脆香甜。',
  237. images: [
  238. '/static/images/products/corn-seeds-new.jpg',
  239. '/static/images/products/rice-seeds.jpg'
  240. ],
  241. contactName: '张先生',
  242. contactPhone: '18812341234'
  243. };
  244. } else {
  245. // 收购信息的模拟数据
  246. mockData = {
  247. productName: '高价收购优质土豆',
  248. category: '蔬菜',
  249. price: '3.5',
  250. description: '大量收购优质土豆,要求新鲜无病害,无青皮,规格统一。支持长期合作,价格优惠,现金结算。',
  251. images: [
  252. '/static/images/products/agriculture-tools.jpg'
  253. ],
  254. contactName: '李先生',
  255. contactPhone: '13856785678'
  256. };
  257. }
  258. // 填充表单数据
  259. this.formData = { ...mockData };
  260. // 更新字符计数
  261. this.nameLength = this.formData.productName.length;
  262. this.descLength = this.formData.description.length;
  263. uni.hideLoading();
  264. }, 1000);
  265. },
  266. // 产品名称输入处理
  267. onNameInput(e) {
  268. this.nameLength = e.detail.value.length;
  269. },
  270. // 描述输入处理
  271. onDescInput(e) {
  272. this.descLength = e.detail.value.length;
  273. },
  274. // 选择分类
  275. selectCategory(category) {
  276. this.formData.category = category;
  277. this.showCategoryPicker = false;
  278. },
  279. // 选择图片
  280. chooseImage() {
  281. const remainingCount = 3 - this.formData.images.length;
  282. uni.chooseImage({
  283. count: remainingCount,
  284. sizeType: ['compressed'],
  285. sourceType: ['album', 'camera'],
  286. success: (res) => {
  287. this.formData.images = this.formData.images.concat(res.tempFilePaths);
  288. },
  289. fail: (err) => {
  290. console.error('选择图片失败:', err);
  291. }
  292. });
  293. },
  294. // 删除图片
  295. removeImage(index) {
  296. this.formData.images.splice(index, 1);
  297. },
  298. // 表单验证
  299. validateForm() {
  300. if (!this.formData.productName.trim()) {
  301. uni.showToast({
  302. title: '请输入产品名称',
  303. icon: 'none'
  304. });
  305. return false;
  306. }
  307. if (!this.formData.category) {
  308. uni.showToast({
  309. title: '请选择产品分类',
  310. icon: 'none'
  311. });
  312. return false;
  313. }
  314. if (!this.formData.price || this.formData.price <= 0) {
  315. uni.showToast({
  316. title: '请输入有效的销售价格',
  317. icon: 'none'
  318. });
  319. return false;
  320. }
  321. if (this.formData.images.length === 0) {
  322. uni.showToast({
  323. title: '请至少上传一张产品图片',
  324. icon: 'none'
  325. });
  326. return false;
  327. }
  328. if (!this.formData.contactName.trim()) {
  329. uni.showToast({
  330. title: '请输入联系人姓名',
  331. icon: 'none'
  332. });
  333. return false;
  334. }
  335. if (!this.formData.contactPhone.trim()) {
  336. uni.showToast({
  337. title: '请输入联系电话',
  338. icon: 'none'
  339. });
  340. return false;
  341. }
  342. // 简单的手机号格式验证
  343. const phoneRegex = /^1[3-9]\d{9}$/;
  344. if (!phoneRegex.test(this.formData.contactPhone)) {
  345. uni.showToast({
  346. title: '请输入正确的手机号码',
  347. icon: 'none'
  348. });
  349. return false;
  350. }
  351. return true;
  352. },
  353. // 提交表单
  354. submitForm() {
  355. if (!this.validateForm()) {
  356. return;
  357. }
  358. // 显示加载提示
  359. const loadingTitle = this.isEditMode ? '保存中...' : '提交中...';
  360. uni.showLoading({
  361. title: loadingTitle
  362. });
  363. // 模拟提交
  364. setTimeout(() => {
  365. uni.hideLoading();
  366. if (this.isEditMode) {
  367. // 编辑模式 - 保存修改
  368. uni.showModal({
  369. title: '保存成功',
  370. content: '您的修改已保存成功!',
  371. showCancel: false,
  372. success: () => {
  373. uni.navigateBack();
  374. }
  375. });
  376. } else {
  377. // 新建模式 - 提交审核
  378. uni.showModal({
  379. title: '提交成功',
  380. content: '您的农产品信息已提交审核,审核通过后将在销售页面展示。',
  381. showCancel: false,
  382. success: () => {
  383. uni.navigateBack();
  384. }
  385. });
  386. }
  387. }, 2000);
  388. }
  389. }
  390. }
  391. </script>
  392. <style lang="scss">
  393. .sales-publish-container {
  394. min-height: 100vh;
  395. background-color: #f5f5f5;
  396. padding-bottom: calc(128rpx + env(safe-area-inset-bottom));
  397. }
  398. .form-container {
  399. padding: 20rpx;
  400. }
  401. .form-item {
  402. background-color: #fff;
  403. border-radius: 12rpx;
  404. padding: 24rpx;
  405. margin-bottom: 16rpx;
  406. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.05);
  407. }
  408. .item-label {
  409. display: flex;
  410. align-items: center;
  411. margin-bottom: 16rpx;
  412. }
  413. .label-text {
  414. font-size: 28rpx;
  415. color: #333;
  416. font-weight: bold;
  417. }
  418. .required {
  419. color: #ff4d4f;
  420. font-size: 28rpx;
  421. margin-left: 4rpx;
  422. }
  423. .optional {
  424. color: #999;
  425. font-size: 24rpx;
  426. margin-left: 8rpx;
  427. }
  428. .item-content {
  429. position: relative;
  430. }
  431. .form-input {
  432. width: 100%;
  433. height: 44rpx;
  434. font-size: 28rpx;
  435. color: #333;
  436. line-height: 44rpx;
  437. }
  438. .form-textarea {
  439. width: 100%;
  440. min-height: 120rpx;
  441. font-size: 28rpx;
  442. color: #333;
  443. line-height: 1.5;
  444. }
  445. .char-count {
  446. position: absolute;
  447. right: 0;
  448. bottom: -4rpx;
  449. font-size: 24rpx;
  450. color: #999;
  451. }
  452. // 分类选择器
  453. .category-selector {
  454. display: flex;
  455. align-items: center;
  456. justify-content: space-between;
  457. padding: 12rpx 0;
  458. border-bottom: 1rpx solid #f0f0f0;
  459. }
  460. .selector-text {
  461. font-size: 28rpx;
  462. color: #333;
  463. &.placeholder {
  464. color: #999;
  465. }
  466. }
  467. .arrow-icon {
  468. font-size: 24rpx;
  469. color: #999;
  470. }
  471. // 带单位的输入框
  472. .input-with-unit {
  473. display: flex;
  474. align-items: center;
  475. border-bottom: 1rpx solid #f0f0f0;
  476. padding: 12rpx 0;
  477. }
  478. .currency-symbol {
  479. font-size: 28rpx;
  480. color: #333;
  481. margin-right: 8rpx;
  482. }
  483. .unit-text {
  484. font-size: 28rpx;
  485. color: #666;
  486. margin-left: 8rpx;
  487. white-space: nowrap;
  488. }
  489. // 图片上传
  490. .image-upload-area {
  491. display: flex;
  492. flex-wrap: wrap;
  493. gap: 16rpx;
  494. }
  495. .image-item {
  496. position: relative;
  497. width: 160rpx;
  498. height: 160rpx;
  499. border-radius: 8rpx;
  500. overflow: hidden;
  501. }
  502. .uploaded-image {
  503. width: 100%;
  504. height: 100%;
  505. }
  506. .image-delete {
  507. position: absolute;
  508. top: -8rpx;
  509. right: -8rpx;
  510. width: 32rpx;
  511. height: 32rpx;
  512. background-color: #ff4d4f;
  513. color: #fff;
  514. border-radius: 50%;
  515. display: flex;
  516. align-items: center;
  517. justify-content: center;
  518. font-size: 20rpx;
  519. font-weight: bold;
  520. }
  521. .image-upload-btn {
  522. width: 160rpx;
  523. height: 160rpx;
  524. border: 2rpx dashed #ddd;
  525. border-radius: 8rpx;
  526. display: flex;
  527. flex-direction: column;
  528. align-items: center;
  529. justify-content: center;
  530. background-color: #fafafa;
  531. }
  532. .upload-icon {
  533. font-size: 48rpx;
  534. color: #999;
  535. margin-bottom: 8rpx;
  536. }
  537. .upload-text {
  538. font-size: 24rpx;
  539. color: #999;
  540. }
  541. // 产地信息
  542. .contact-info {
  543. background-color: #f8f9fa;
  544. border-radius: 8rpx;
  545. padding: 20rpx;
  546. }
  547. .contact-row {
  548. display: flex;
  549. align-items: center;
  550. margin-bottom: 12rpx;
  551. &:last-child {
  552. margin-bottom: 0;
  553. }
  554. }
  555. .contact-value {
  556. font-size: 26rpx;
  557. color: #333;
  558. }
  559. // 联系人信息输入
  560. .contact-input-row {
  561. display: flex;
  562. align-items: center;
  563. margin-bottom: 20rpx;
  564. &:last-child {
  565. margin-bottom: 0;
  566. }
  567. }
  568. .contact-label {
  569. font-size: 28rpx;
  570. color: #333;
  571. width: 120rpx;
  572. font-weight: bold;
  573. }
  574. .contact-input {
  575. flex: 1;
  576. height: 44rpx;
  577. font-size: 28rpx;
  578. color: #333;
  579. line-height: 44rpx;
  580. border-bottom: 1rpx solid #f0f0f0;
  581. padding: 12rpx 0;
  582. }
  583. // 底部提交按钮
  584. .bottom-action-bar {
  585. position: fixed;
  586. bottom: 0;
  587. left: 0;
  588. right: 0;
  589. width: 100%;
  590. background-color: #fff;
  591. border-top: 1rpx solid #f0f0f0;
  592. padding: 20rpx 30rpx;
  593. padding-bottom: calc(20rpx + env(safe-area-inset-bottom));
  594. z-index: 1000;
  595. box-shadow: 0 -2rpx 8rpx rgba(0, 0, 0, 0.05);
  596. box-sizing: border-box;
  597. }
  598. .submit-btn {
  599. width: 100%;
  600. height: 88rpx;
  601. background-color: #4CAF50;
  602. border-radius: 12rpx;
  603. display: flex;
  604. align-items: center;
  605. justify-content: center;
  606. transition: background-color 0.2s ease;
  607. box-sizing: border-box;
  608. &:active {
  609. background-color: #45a049;
  610. }
  611. .btn-text {
  612. font-size: 32rpx;
  613. color: #fff;
  614. font-weight: bold;
  615. }
  616. }
  617. // 分类选择弹窗
  618. .picker-modal {
  619. position: fixed;
  620. top: 0;
  621. left: 0;
  622. width: 100%;
  623. height: 100%;
  624. background-color: rgba(0, 0, 0, 0.5);
  625. z-index: 2000;
  626. display: flex;
  627. align-items: flex-end;
  628. }
  629. .picker-content {
  630. width: 100%;
  631. background-color: #fff;
  632. border-radius: 24rpx 24rpx 0 0;
  633. padding: 0;
  634. }
  635. .picker-header {
  636. display: flex;
  637. justify-content: space-between;
  638. align-items: center;
  639. padding: 30rpx;
  640. border-bottom: 1rpx solid #f0f0f0;
  641. }
  642. .picker-title {
  643. font-size: 32rpx;
  644. font-weight: bold;
  645. color: #333;
  646. }
  647. .picker-close {
  648. font-size: 36rpx;
  649. color: #999;
  650. }
  651. .picker-options {
  652. padding: 20rpx 0;
  653. }
  654. .picker-option {
  655. padding: 24rpx 30rpx;
  656. border-bottom: 1rpx solid #f8f8f8;
  657. transition: background-color 0.2s ease;
  658. &:last-child {
  659. border-bottom: none;
  660. }
  661. &:active {
  662. background-color: #f5f5f5;
  663. }
  664. }
  665. .option-text {
  666. font-size: 30rpx;
  667. color: #333;
  668. }
  669. </style>