my-publish.vue 14 KB

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