my-publish.vue 14 KB

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