my-publish.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  1. <template>
  2. <view class="my-publish-container">
  3. <!-- 顶部Tab标签页 -->
  4. <view class="tab-header">
  5. <view class="tab-list">
  6. <view
  7. class="tab-item"
  8. :class="{ active: activeTab === 'published' }"
  9. @click="switchTab('published')"
  10. >
  11. <text class="tab-text">销售信息</text>
  12. </view>
  13. <view
  14. class="tab-item"
  15. :class="{ active: activeTab === 'purchase' }"
  16. @click="switchTab('purchase')"
  17. >
  18. <text class="tab-text">收购信息</text>
  19. </view>
  20. </view>
  21. <view class="tab-indicator" :style="{ left: activeTab === 'published' ? '0' : '50%' }"></view>
  22. </view>
  23. <!-- 我的发布页面 -->
  24. <view v-if="activeTab === 'published'" class="tab-content">
  25. <!-- 搜索筛选 -->
  26. <view class="search-section">
  27. <view class="search-box">
  28. <image class="search-icon" src="/static/icons/search.png" mode="aspectFit"></image>
  29. <input
  30. class="search-input"
  31. placeholder="搜索我的农产品"
  32. placeholder-style="color: #999;"
  33. v-model="searchKeyword"
  34. @confirm="handleSearch"
  35. />
  36. </view>
  37. </view>
  38. <!-- 我的发布列表 -->
  39. <view class="products-container">
  40. <view class="products-list">
  41. <view
  42. class="published-card"
  43. v-for="item in filteredPublishedProducts"
  44. :key="item.id"
  45. @click="navigateToDetail(item)"
  46. >
  47. <view class="card-content">
  48. <view class="product-image">
  49. <image :src="item.image" mode="aspectFill"></image>
  50. </view>
  51. <view class="product-info">
  52. <view class="product-header">
  53. <view class="product-name">{{ item.name }}</view>
  54. <view class="price-info">¥{{ item.price }} 元/{{ item.unit }}</view>
  55. </view>
  56. <view class="product-desc">{{ item.description }}</view>
  57. <view class="product-footer">
  58. <view class="publish-time">{{ item.publishTime }}</view>
  59. <view class="status-tag" :class="item.status">
  60. {{ getStatusText(item.status) }}
  61. </view>
  62. </view>
  63. </view>
  64. </view>
  65. </view>
  66. </view>
  67. </view>
  68. </view>
  69. <!-- 收购信息页面 -->
  70. <view v-if="activeTab === 'purchase'" class="tab-content">
  71. <!-- 搜索筛选 -->
  72. <view class="search-section">
  73. <view class="search-box">
  74. <image class="search-icon" src="/static/icons/search.png" mode="aspectFit"></image>
  75. <input
  76. class="search-input"
  77. placeholder="搜索收购信息"
  78. placeholder-style="color: #999;"
  79. v-model="purchaseSearchKeyword"
  80. @confirm="handlePurchaseSearch"
  81. />
  82. </view>
  83. </view>
  84. <!-- 收购信息列表 -->
  85. <view class="products-container">
  86. <view class="products-list">
  87. <view
  88. class="published-card"
  89. v-for="item in filteredPurchaseList"
  90. :key="item.id"
  91. @click="navigateToPurchaseDetail(item)"
  92. >
  93. <view class="card-content">
  94. <view class="product-image">
  95. <image :src="getPurchaseImage(item)" mode="aspectFill"></image>
  96. </view>
  97. <view class="product-info">
  98. <view class="product-header">
  99. <view class="product-name">{{ item.title }}</view>
  100. <view class="price-info">¥{{ item.budgetPrice }} 元/{{ item.unit }}</view>
  101. </view>
  102. <view class="product-desc">需求数量:{{ item.quantity }}</view>
  103. <view class="product-footer">
  104. <view class="publish-time">{{ item.publishTime }}</view>
  105. <view class="status-tag" :class="item.status">
  106. {{ getStatusText(item.status) }}
  107. </view>
  108. </view>
  109. </view>
  110. </view>
  111. </view>
  112. </view>
  113. </view>
  114. </view>
  115. <!-- 底部固定按钮 -->
  116. <view class="bottom-action-bar">
  117. <view class="action-btn" @click="showPublishModal = true">
  118. <text class="btn-text">发布</text>
  119. </view>
  120. </view>
  121. <!-- 发布选择弹窗 -->
  122. <view class="publish-modal" v-if="showPublishModal" @click="showPublishModal = false">
  123. <view class="publish-content" @click.stop>
  124. <view class="publish-header">
  125. <text class="publish-title">选择发布类型</text>
  126. <text class="publish-close" @click="showPublishModal = false">✕</text>
  127. </view>
  128. <view class="publish-options">
  129. <view class="option-item" @click="navigateToPublish">
  130. <view class="option-text">
  131. <text class="option-title">发布农产品</text>
  132. <text class="option-desc">出售我的农产品</text>
  133. </view>
  134. </view>
  135. <view class="option-item" @click="navigateToPurchasePublish">
  136. <view class="option-text">
  137. <text class="option-title">发布收购信息</text>
  138. <text class="option-desc">收购农产品需求</text>
  139. </view>
  140. </view>
  141. </view>
  142. </view>
  143. </view>
  144. </view>
  145. </template>
  146. <script>
  147. export default {
  148. data() {
  149. return {
  150. activeTab: 'published',
  151. searchKeyword: '',
  152. purchaseSearchKeyword: '',
  153. showPublishModal: false,
  154. // 我的发布列表
  155. publishedProductsList: [
  156. {
  157. id: 1,
  158. name: '有机苹果',
  159. description: '新鲜采摘,香甜可口',
  160. price: '8.5',
  161. unit: '斤',
  162. image: '/static/images/products/corn-seeds-new.jpg',
  163. publishTime: '今天',
  164. status: 'approved'
  165. },
  166. {
  167. id: 2,
  168. name: '优质大米',
  169. description: '当季新米,粒粒饱满',
  170. price: '6.8',
  171. unit: '斤',
  172. image: '/static/images/products/rice-seeds.jpg',
  173. publishTime: '昨天',
  174. status: 'pending'
  175. },
  176. {
  177. id: 3,
  178. name: '新鲜蔬菜包',
  179. description: '时令蔬菜,营养丰富',
  180. price: '25',
  181. unit: '份',
  182. image: '/static/images/products/organic-fertilizer-new.jpg',
  183. publishTime: '2天前',
  184. status: 'approved'
  185. },
  186. {
  187. id: 4,
  188. name: '土鸡蛋',
  189. description: '散养土鸡,营养价值高',
  190. price: '2.5',
  191. unit: '个',
  192. image: '/static/images/products/seeds-packets.jpg',
  193. publishTime: '3天前',
  194. status: 'rejected'
  195. }
  196. ],
  197. // 收购信息列表
  198. purchaseList: [
  199. {
  200. id: 1,
  201. title: '高价收购优质土豆',
  202. category: '蔬菜',
  203. quantity: '1000斤',
  204. budgetPrice: '3.5',
  205. unit: '斤',
  206. contact: '张**',
  207. location: '本地',
  208. publishTime: '今天',
  209. status: 'approved'
  210. },
  211. {
  212. id: 2,
  213. title: '大量收购新鲜玉米',
  214. category: '粮食',
  215. quantity: '5000斤',
  216. budgetPrice: '2.8',
  217. unit: '斤',
  218. contact: '李**',
  219. location: '周边',
  220. publishTime: '昨天',
  221. status: 'pending'
  222. },
  223. {
  224. id: 3,
  225. title: '收购有机蔬菜',
  226. category: '蔬菜',
  227. quantity: '500斤',
  228. budgetPrice: '8.0',
  229. unit: '斤',
  230. contact: '王**',
  231. location: '本地',
  232. publishTime: '2天前',
  233. status: 'rejected'
  234. }
  235. ]
  236. }
  237. },
  238. computed: {
  239. filteredPublishedProducts() {
  240. let products = this.publishedProductsList;
  241. if (this.searchKeyword.trim()) {
  242. const keyword = this.searchKeyword.trim().toLowerCase();
  243. products = products.filter(item =>
  244. item.name.toLowerCase().includes(keyword) ||
  245. item.description.toLowerCase().includes(keyword)
  246. );
  247. }
  248. return products;
  249. },
  250. filteredPurchaseList() {
  251. let list = this.purchaseList;
  252. if (this.purchaseSearchKeyword.trim()) {
  253. const keyword = this.purchaseSearchKeyword.trim().toLowerCase();
  254. list = list.filter(item =>
  255. item.title.toLowerCase().includes(keyword) ||
  256. item.category.toLowerCase().includes(keyword)
  257. );
  258. }
  259. return list;
  260. }
  261. },
  262. methods: {
  263. switchTab(tab) {
  264. this.activeTab = tab;
  265. },
  266. getStatusText(status) {
  267. const statusMap = {
  268. 'pending': '审核中',
  269. 'approved': '已上架',
  270. 'rejected': '已下架'
  271. };
  272. return statusMap[status] || '未知';
  273. },
  274. handleSearch() {
  275. // 搜索逻辑已在computed中处理
  276. },
  277. handlePurchaseSearch() {
  278. // 搜索逻辑已在computed中处理
  279. },
  280. navigateToDetail(product) {
  281. uni.navigateTo({
  282. url: `/pages/service/sales-detail?id=${product.id}&type=sale&name=${encodeURIComponent(product.name)}&source=myPublish&status=${product.status}`
  283. });
  284. },
  285. navigateToPurchaseDetail(item) {
  286. uni.navigateTo({
  287. url: `/pages/service/sales-detail?id=${item.id}&type=purchase&title=${encodeURIComponent(item.title)}&source=myPublish&status=${item.status}`
  288. });
  289. },
  290. navigateToPublish() {
  291. this.showPublishModal = false;
  292. uni.navigateTo({
  293. url: '/pages/service/sales-publish'
  294. });
  295. },
  296. navigateToPurchasePublish() {
  297. this.showPublishModal = false;
  298. uni.navigateTo({
  299. url: '/pages/service/purchase-publish'
  300. });
  301. },
  302. // 获取收购信息对应的图片
  303. getPurchaseImage(item) {
  304. // 根据分类返回对应的默认图片
  305. const categoryImages = {
  306. '蔬菜': '/static/images/products/organic-fertilizer-new.jpg',
  307. '粮食': '/static/images/products/corn-seeds-new.jpg',
  308. '水果': '/static/images/products/rice-seeds.jpg',
  309. '其他': '/static/images/products/agriculture-tools.jpg'
  310. };
  311. return categoryImages[item.category] || categoryImages['其他'];
  312. }
  313. }
  314. }
  315. </script>
  316. <style lang="scss">
  317. .my-publish-container {
  318. min-height: 100vh;
  319. background-color: #f5f5f5;
  320. padding-bottom: calc(128rpx + env(safe-area-inset-bottom));
  321. }
  322. .tab-header {
  323. background-color: #fff;
  324. position: relative;
  325. border-bottom: 1rpx solid #f0f0f0;
  326. }
  327. .tab-list {
  328. display: flex;
  329. align-items: center;
  330. }
  331. .tab-item {
  332. flex: 1;
  333. text-align: center;
  334. padding: 32rpx 0;
  335. position: relative;
  336. .tab-text {
  337. font-size: 30rpx;
  338. color: #666;
  339. font-weight: 500;
  340. transition: color 0.3s ease;
  341. }
  342. &.active .tab-text {
  343. color: #4CAF50;
  344. font-weight: bold;
  345. }
  346. }
  347. .tab-indicator {
  348. position: absolute;
  349. bottom: 0;
  350. left: 0;
  351. width: 50%;
  352. height: 4rpx;
  353. background-color: #4CAF50;
  354. transition: left 0.3s ease;
  355. }
  356. .tab-content {
  357. flex: 1;
  358. }
  359. .search-section {
  360. background-color: #fff;
  361. padding: 20rpx;
  362. border-bottom: 1rpx solid #f0f0f0;
  363. }
  364. .search-box {
  365. flex: 1;
  366. display: flex;
  367. align-items: center;
  368. background-color: #f8f8f8;
  369. border-radius: 32rpx;
  370. padding: 16rpx 24rpx;
  371. }
  372. .search-icon {
  373. width: 32rpx;
  374. height: 32rpx;
  375. margin-right: 16rpx;
  376. }
  377. .search-input {
  378. flex: 1;
  379. font-size: 28rpx;
  380. line-height: 1.5;
  381. }
  382. .products-container, .purchase-container {
  383. padding: 20rpx;
  384. }
  385. .products-list, .purchase-list {
  386. display: flex;
  387. flex-direction: column;
  388. gap: 16rpx;
  389. }
  390. .published-card {
  391. background-color: #fff;
  392. border-radius: 12rpx;
  393. overflow: hidden;
  394. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.05);
  395. transition: transform 0.2s ease;
  396. &:active {
  397. transform: scale(0.98);
  398. }
  399. }
  400. .card-content {
  401. display: flex;
  402. padding: 20rpx;
  403. gap: 20rpx;
  404. }
  405. .product-image {
  406. width: 160rpx;
  407. height: 160rpx;
  408. border-radius: 8rpx;
  409. overflow: hidden;
  410. flex-shrink: 0;
  411. image {
  412. width: 100%;
  413. height: 100%;
  414. }
  415. }
  416. .product-info {
  417. flex: 1;
  418. display: flex;
  419. flex-direction: column;
  420. justify-content: space-between;
  421. }
  422. .product-header {
  423. display: flex;
  424. justify-content: space-between;
  425. align-items: flex-start;
  426. margin-bottom: 12rpx;
  427. }
  428. .product-name {
  429. font-size: 30rpx;
  430. font-weight: bold;
  431. color: #4CAF50;
  432. flex: 1;
  433. margin-right: 16rpx;
  434. }
  435. .price-info {
  436. font-size: 26rpx;
  437. color: #333;
  438. font-weight: bold;
  439. white-space: nowrap;
  440. }
  441. .product-desc {
  442. font-size: 26rpx;
  443. color: #666;
  444. margin-bottom: 16rpx;
  445. overflow: hidden;
  446. text-overflow: ellipsis;
  447. white-space: nowrap;
  448. }
  449. .product-footer {
  450. display: flex;
  451. justify-content: space-between;
  452. align-items: center;
  453. }
  454. .publish-time {
  455. font-size: 24rpx;
  456. color: #999;
  457. }
  458. .status-tag {
  459. padding: 8rpx 16rpx;
  460. border-radius: 16rpx;
  461. font-size: 22rpx;
  462. &.pending {
  463. background-color: #fff7e6;
  464. color: #fa8c16;
  465. }
  466. &.approved {
  467. background-color: #f6ffed;
  468. color: #52c41a;
  469. }
  470. &.rejected {
  471. background-color: #fff2f0;
  472. color: #ff4d4f;
  473. }
  474. }
  475. // 收购信息现在使用统一的 .published-card 样式
  476. // 底部固定按钮
  477. .bottom-action-bar {
  478. position: fixed;
  479. bottom: 0;
  480. left: 0;
  481. right: 0;
  482. width: 100%;
  483. background-color: #fff;
  484. border-top: 1rpx solid #f0f0f0;
  485. padding: 20rpx 30rpx;
  486. padding-bottom: calc(20rpx + env(safe-area-inset-bottom));
  487. z-index: 1000;
  488. box-shadow: 0 -2rpx 8rpx rgba(0, 0, 0, 0.05);
  489. box-sizing: border-box;
  490. }
  491. .action-btn {
  492. width: 100%;
  493. height: 88rpx;
  494. background-color: #4CAF50;
  495. border-radius: 12rpx;
  496. display: flex;
  497. align-items: center;
  498. justify-content: center;
  499. transition: background-color 0.2s ease;
  500. box-sizing: border-box;
  501. &:active {
  502. background-color: #45a049;
  503. }
  504. .btn-text {
  505. font-size: 32rpx;
  506. color: #fff;
  507. font-weight: bold;
  508. }
  509. }
  510. .publish-modal {
  511. position: fixed;
  512. top: 0;
  513. left: 0;
  514. width: 100%;
  515. height: 100%;
  516. background-color: rgba(0, 0, 0, 0.5);
  517. z-index: 2000;
  518. display: flex;
  519. align-items: flex-end;
  520. }
  521. .publish-content {
  522. width: 100%;
  523. background-color: #fff;
  524. border-radius: 24rpx 24rpx 0 0;
  525. padding: 0;
  526. }
  527. .publish-header {
  528. display: flex;
  529. justify-content: space-between;
  530. align-items: center;
  531. padding: 30rpx;
  532. border-bottom: 1rpx solid #f0f0f0;
  533. .publish-title {
  534. font-size: 32rpx;
  535. font-weight: bold;
  536. color: #333;
  537. }
  538. .publish-close {
  539. font-size: 36rpx;
  540. color: #999;
  541. }
  542. }
  543. .publish-options {
  544. padding: 20rpx;
  545. }
  546. .option-item {
  547. display: flex;
  548. align-items: center;
  549. padding: 24rpx 20rpx;
  550. border-radius: 12rpx;
  551. margin-bottom: 16rpx;
  552. background-color: #f8f8f8;
  553. transition: background-color 0.2s ease;
  554. &:last-child {
  555. margin-bottom: 0;
  556. }
  557. &:active {
  558. background-color: #e8f5e8;
  559. }
  560. }
  561. .option-text {
  562. flex: 1;
  563. .option-title {
  564. font-size: 30rpx;
  565. font-weight: bold;
  566. color: #333;
  567. display: block;
  568. margin-bottom: 8rpx;
  569. }
  570. .option-desc {
  571. font-size: 26rpx;
  572. color: #666;
  573. display: block;
  574. }
  575. }
  576. </style>