my-publish.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  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="getImageUrl(item.imageUrl)" mode="aspectFill"></image>
  50. </view>
  51. <view class="product-info">
  52. <view class="product-header">
  53. <view class="product-name">{{ item.title }}</view>
  54. <view class="price-info">¥{{ item.price || 0 }}/{{ getUnitLabel(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="getStatusClassName(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="searchKeyword"
  80. @confirm="handleSearch"
  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="getImageUrl(item.imageUrl)" 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.price || 0 }}/{{ getUnitLabel(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="getStatusClassName(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. import {
  148. getProductInfoList
  149. } from '@/api/services/productInfo.js';
  150. import dictMixin from '@/utils/mixins/dictMixin';
  151. import storage from "@/utils/storage.js";
  152. export default {
  153. mixins: [dictMixin],
  154. data() {
  155. return {
  156. activeTab: 'published',
  157. searchKeyword: '',
  158. purchaseSearchKeyword: '',
  159. showPublishModal: false,
  160. pageNum: 1,
  161. pageSize: 10,
  162. noMoreData: false,
  163. isLoading: false,
  164. isRefreshing: false,
  165. dictTypeList: ['agricultural_unit'],
  166. currentUserInfo: storage.getUserInfo(),
  167. // 我的发布列表
  168. publishedProductsList: [],
  169. // 收购信息列表
  170. purchaseList: [],
  171. productsList: [], // 二和一存储
  172. }
  173. },
  174. computed: {
  175. filteredPublishedProducts() {
  176. // let products = this.publishedProductsList;
  177. let products = this.productsList;
  178. // if (this.searchKeyword.trim()) {
  179. // const keyword = this.searchKeyword.trim().toLowerCase();
  180. // products = products.filter(item =>
  181. // item.name.toLowerCase().includes(keyword) ||
  182. // item.description.toLowerCase().includes(keyword)
  183. // );
  184. // }
  185. return products;
  186. },
  187. filteredPurchaseList() {
  188. // let list = this.purchaseList;
  189. let list = this.productsList;
  190. // if (this.purchaseSearchKeyword.trim()) {
  191. // const keyword = this.purchaseSearchKeyword.trim().toLowerCase();
  192. // list = list.filter(item =>
  193. // item.title.toLowerCase().includes(keyword) ||
  194. // item.category.toLowerCase().includes(keyword)
  195. // );
  196. // }
  197. return list;
  198. }
  199. },
  200. onShow() {
  201. // console.log("my-publish",this.formData);
  202. this.loadMyPublishInfo()
  203. },
  204. // 页面加载时获取数据
  205. onLoad() {
  206. this.loadMyPublishInfo();
  207. },
  208. methods: {
  209. // 上拉加载更多
  210. loadMore() {
  211. if (!this.isLoading && !this.noMoreData) {
  212. this.pageNum++;
  213. this.loadMyPublishInfo();
  214. }
  215. },
  216. getImageUrl(item) {
  217. // 默认返回url或path
  218. if (item == null) return
  219. const imageUrls = item.split(',');
  220. // console.log("imageUrls", imageUrls);
  221. return imageUrls[0];
  222. },
  223. getUnitLabel(value) {
  224. const unit = this.dictData.agricultural_unit.find(u => u.dictValue == value)
  225. return unit ? unit.dictLabel : ''
  226. },
  227. loadMyPublishInfo(keyword) {
  228. this.isLoading = true;
  229. uni.showLoading({
  230. title: '加载中'
  231. });
  232. // 构建查询参数
  233. const params = {
  234. pageNum: this.pageNum,
  235. pageSize: this.pageSize,
  236. createBy: this.currentUserInfo.username,
  237. type: 0 // 默认查询出售信息
  238. };
  239. if (keyword != null && keyword != '') {
  240. params.searchKeyword = keyword
  241. }
  242. // 分类逻辑
  243. if (this.activeTab !== 'published' ) {
  244. // 默认场景:推荐查询
  245. params.type = 1;
  246. }
  247. getProductInfoList(params).then(res => {
  248. if (res.data.code === 200) {
  249. const {
  250. rows,
  251. total
  252. } = res.data;
  253. if (this.pageNum === 1) {
  254. this.productsList = rows;
  255. } else {
  256. this.productsList = [...this.productsList, ...rows];
  257. }
  258. // 判断是否还有更多数据
  259. this.noMoreData = this.productsList.length >= total;
  260. uni.hideLoading();
  261. } else {
  262. uni.showToast({
  263. title: res.data.msg || '获取农品列表失败',
  264. icon: 'none'
  265. });
  266. }
  267. }).catch(err => {
  268. console.error('获取农品列表失败:', err);
  269. uni.showToast({
  270. title: '获取农品列表失败',
  271. icon: 'none'
  272. });
  273. }).finally(() => {
  274. this.isLoading = false;
  275. this.isRefreshing = false;
  276. });
  277. },
  278. switchTab(tab) {
  279. this.activeTab = tab;
  280. // this.publishedProductsList = [] // 切换时置空数据数组
  281. // this.purchaseList = []
  282. this.productsList = []
  283. // 滚动到当前分类位置
  284. this.loadMyPublishInfo(this.searchKeyword.trim())
  285. },
  286. getStatusText(status) {
  287. const statusMap = {
  288. 1: '审核中',
  289. 2: '已上架',
  290. 3: '已下架',
  291. 4: '未通过'
  292. };
  293. return statusMap[status] || '未知';
  294. },
  295. getStatusClassName(status) {
  296. const statusMapClassName = {
  297. 1: 'pending',
  298. 2: 'approved',
  299. 3: 'rejected',
  300. 4: 'rejected'
  301. };
  302. return statusMapClassName[status] || '未知';
  303. },
  304. handleSearch() {
  305. const keyword = this.searchKeyword.trim().toLowerCase();
  306. this.loadMyPublishInfo(keyword)
  307. },
  308. navigateToDetail(product) {
  309. uni.navigateTo({
  310. url: `/pages/service/sales-detail?id=${product.id}&type=sale&name=${encodeURIComponent(product.title)}&source=myPublish&status=${product.status}`
  311. });
  312. },
  313. navigateToPurchaseDetail(item) {
  314. uni.navigateTo({
  315. url: `/pages/service/sales-detail?id=${item.id}&type=purchase&title=${encodeURIComponent(item.title)}&source=myPublish&status=${item.status}`
  316. });
  317. },
  318. navigateToPublish() {
  319. this.showPublishModal = false;
  320. uni.navigateTo({
  321. url: '/pages/service/sales-publish'
  322. });
  323. },
  324. navigateToPurchasePublish() {
  325. this.showPublishModal = false;
  326. uni.navigateTo({
  327. url: '/pages/service/purchase-publish'
  328. });
  329. },
  330. }
  331. }
  332. </script>
  333. <style lang="scss">
  334. .my-publish-container {
  335. min-height: 100vh;
  336. background-color: #f5f5f5;
  337. padding-bottom: calc(128rpx + env(safe-area-inset-bottom));
  338. }
  339. .tab-header {
  340. background-color: #fff;
  341. position: relative;
  342. border-bottom: 1rpx solid #f0f0f0;
  343. }
  344. .tab-list {
  345. display: flex;
  346. align-items: center;
  347. }
  348. .tab-item {
  349. flex: 1;
  350. text-align: center;
  351. padding: 32rpx 0;
  352. position: relative;
  353. .tab-text {
  354. font-size: 30rpx;
  355. color: #666;
  356. font-weight: 500;
  357. transition: color 0.3s ease;
  358. }
  359. &.active .tab-text {
  360. color: #4CAF50;
  361. font-weight: bold;
  362. }
  363. }
  364. .tab-indicator {
  365. position: absolute;
  366. bottom: 0;
  367. left: 0;
  368. width: 50%;
  369. height: 4rpx;
  370. background-color: #4CAF50;
  371. transition: left 0.3s ease;
  372. }
  373. .tab-content {
  374. flex: 1;
  375. }
  376. .search-section {
  377. background-color: #fff;
  378. padding: 20rpx;
  379. border-bottom: 1rpx solid #f0f0f0;
  380. }
  381. .search-box {
  382. flex: 1;
  383. display: flex;
  384. align-items: center;
  385. background-color: #f8f8f8;
  386. border-radius: 32rpx;
  387. padding: 16rpx 24rpx;
  388. }
  389. .search-icon {
  390. width: 32rpx;
  391. height: 32rpx;
  392. margin-right: 16rpx;
  393. }
  394. .search-input {
  395. flex: 1;
  396. font-size: 28rpx;
  397. line-height: 1.5;
  398. }
  399. .products-container, .purchase-container {
  400. padding: 20rpx;
  401. }
  402. .products-list, .purchase-list {
  403. display: flex;
  404. flex-direction: column;
  405. gap: 16rpx;
  406. }
  407. .published-card {
  408. background-color: #fff;
  409. border-radius: 12rpx;
  410. overflow: hidden;
  411. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.05);
  412. transition: transform 0.2s ease;
  413. &:active {
  414. transform: scale(0.98);
  415. }
  416. }
  417. .card-content {
  418. display: flex;
  419. padding: 20rpx;
  420. gap: 20rpx;
  421. }
  422. .product-image {
  423. width: 160rpx;
  424. height: 160rpx;
  425. border-radius: 8rpx;
  426. overflow: hidden;
  427. flex-shrink: 0;
  428. image {
  429. width: 100%;
  430. height: 100%;
  431. }
  432. }
  433. .product-info {
  434. flex: 1;
  435. display: flex;
  436. flex-direction: column;
  437. justify-content: space-between;
  438. }
  439. .product-header {
  440. display: flex;
  441. justify-content: space-between;
  442. align-items: flex-start;
  443. margin-bottom: 12rpx;
  444. }
  445. .product-name {
  446. font-size: 30rpx;
  447. font-weight: bold;
  448. color: #4CAF50;
  449. flex: 1;
  450. margin-right: 16rpx;
  451. }
  452. .price-info {
  453. font-size: 26rpx;
  454. color: #333;
  455. font-weight: bold;
  456. white-space: nowrap;
  457. }
  458. .product-desc {
  459. font-size: 26rpx;
  460. color: #666;
  461. margin-bottom: 16rpx;
  462. overflow: hidden;
  463. text-overflow: ellipsis;
  464. white-space: nowrap;
  465. }
  466. .product-footer {
  467. display: flex;
  468. justify-content: space-between;
  469. align-items: center;
  470. }
  471. .publish-time {
  472. font-size: 24rpx;
  473. color: #999;
  474. }
  475. .status-tag {
  476. padding: 8rpx 16rpx;
  477. border-radius: 16rpx;
  478. font-size: 22rpx;
  479. &.pending {
  480. background-color: #fff7e6;
  481. color: #fa8c16;
  482. }
  483. &.approved {
  484. background-color: #f6ffed;
  485. color: #52c41a;
  486. }
  487. &.rejected {
  488. background-color: #fff2f0;
  489. color: #ff4d4f;
  490. }
  491. }
  492. // 收购信息现在使用统一的 .published-card 样式
  493. // 底部固定按钮
  494. .bottom-action-bar {
  495. position: fixed;
  496. bottom: 0;
  497. left: 0;
  498. right: 0;
  499. width: 100%;
  500. background-color: #fff;
  501. border-top: 1rpx solid #f0f0f0;
  502. padding: 20rpx 30rpx;
  503. padding-bottom: calc(20rpx + env(safe-area-inset-bottom));
  504. z-index: 1000;
  505. box-shadow: 0 -2rpx 8rpx rgba(0, 0, 0, 0.05);
  506. box-sizing: border-box;
  507. }
  508. .action-btn {
  509. width: 100%;
  510. height: 88rpx;
  511. background-color: #4CAF50;
  512. border-radius: 12rpx;
  513. display: flex;
  514. align-items: center;
  515. justify-content: center;
  516. transition: background-color 0.2s ease;
  517. box-sizing: border-box;
  518. &:active {
  519. background-color: #45a049;
  520. }
  521. .btn-text {
  522. font-size: 32rpx;
  523. color: #fff;
  524. font-weight: bold;
  525. }
  526. }
  527. .publish-modal {
  528. position: fixed;
  529. top: 0;
  530. left: 0;
  531. width: 100%;
  532. height: 100%;
  533. background-color: rgba(0, 0, 0, 0.5);
  534. z-index: 2000;
  535. display: flex;
  536. align-items: flex-end;
  537. }
  538. .publish-content {
  539. width: 100%;
  540. background-color: #fff;
  541. border-radius: 24rpx 24rpx 0 0;
  542. padding: 0;
  543. }
  544. .publish-header {
  545. display: flex;
  546. justify-content: space-between;
  547. align-items: center;
  548. padding: 30rpx;
  549. border-bottom: 1rpx solid #f0f0f0;
  550. .publish-title {
  551. font-size: 32rpx;
  552. font-weight: bold;
  553. color: #333;
  554. }
  555. .publish-close {
  556. font-size: 36rpx;
  557. color: #999;
  558. }
  559. }
  560. .publish-options {
  561. padding: 20rpx;
  562. }
  563. .option-item {
  564. display: flex;
  565. align-items: center;
  566. padding: 24rpx 20rpx;
  567. border-radius: 12rpx;
  568. margin-bottom: 16rpx;
  569. background-color: #f8f8f8;
  570. transition: background-color 0.2s ease;
  571. &:last-child {
  572. margin-bottom: 0;
  573. }
  574. &:active {
  575. background-color: #e8f5e8;
  576. }
  577. }
  578. .option-text {
  579. flex: 1;
  580. .option-title {
  581. font-size: 30rpx;
  582. font-weight: bold;
  583. color: #333;
  584. display: block;
  585. margin-bottom: 8rpx;
  586. }
  587. .option-desc {
  588. font-size: 26rpx;
  589. color: #666;
  590. display: block;
  591. }
  592. }
  593. </style>