sales.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  1. <template>
  2. <view class="sales-container">
  3. <!-- 顶部Tab标签页 -->
  4. <view class="tab-header">
  5. <view class="tab-list">
  6. <view class="tab-item" :class="{ active: activeTab === 'all' }" @click="switchTab('all')">
  7. <text class="tab-text">全部</text>
  8. </view>
  9. <view class="tab-item" :class="{ active: activeTab === 'sale' }" @click="switchTab('sale')">
  10. <text class="tab-text">出售信息</text>
  11. </view>
  12. <view class="tab-item" :class="{ active: activeTab === 'purchase' }" @click="switchTab('purchase')">
  13. <text class="tab-text">收购信息</text>
  14. </view>
  15. </view>
  16. <view class="tab-indicator" :style="{ left: getIndicatorPosition() }"></view>
  17. </view>
  18. <!-- 搜索筛选 -->
  19. <view class="search-section">
  20. <view class="search-box">
  21. <image class="search-icon" src="/static/icons/search.png" mode="aspectFit"></image>
  22. <input class="search-input" placeholder="搜索农产品信息" placeholder-style="color: #999;"
  23. v-model="searchKeyword" @confirm="handleSearch" />
  24. </view>
  25. </view>
  26. <!-- 全部农产品信息列表 -->
  27. <scroll-view v-if="allInfoList.length > 0" scroll-y style="height: 100vh;" @scrolltolower="loadMore">
  28. <view class="content-container">
  29. <view class="info-list">
  30. <view class="info-card" v-for="item in filteredAllInfo" :key="`${item.type}_${item.id}`"
  31. @click="navigateToDetail(item)">
  32. <view class="card-content">
  33. <!-- 封面图片 -->
  34. <view class="info-image">
  35. <image :src="getImageUrl(item.imageUrl)" mode="aspectFill"></image>
  36. </view>
  37. <!-- 信息内容 -->
  38. <view class="info-content">
  39. <!-- 类型标签和标题 -->
  40. <view class="info-header">
  41. <view class="type-tag" :class="item.type === 0 ? 'sale' : 'purchase'">
  42. {{ item.type === 0 ? '出售' : '收购' }}
  43. </view>
  44. <view class="info-title"> {{ item.title }}
  45. ¥{{ item.price || 0 }}/{{ getUnitLabel(item.unit) }}</view>
  46. </view>
  47. <!-- 简要说明 -->
  48. <view class="info-desc">{{ item.description }}</view>
  49. <!-- 底部信息 -->
  50. <view class="info-footer">
  51. <view class="publish-info">
  52. <text class="publisher">{{ item.contactName }}</text>
  53. <text class="publish-time">{{ item.publishTime }}</text>
  54. </view>
  55. </view>
  56. </view>
  57. </view>
  58. </view>
  59. </view>
  60. <!-- 没有更多数据提示 -->
  61. <view class="no-more-data" v-if="noMoreData">
  62. <text>没有更多数据了</text>
  63. </view>
  64. </view>
  65. </scroll-view>
  66. <!-- 浮动发布按钮 -->
  67. <view class="floating-btn" @click="navigateToMyPublish">
  68. <view class="btn-icon">+</view>
  69. <text class="btn-text">我的发布</text>
  70. </view>
  71. </view>
  72. </template>
  73. <script setup>
  74. import { ref, computed, onMounted } from 'vue'
  75. import { getProductInfoList } from '@/api/services/productInfo.js'
  76. import { useDict } from '@/utils/composables/useDict'
  77. // 使用字典
  78. const { dictData } = useDict(['agricultural_unit'])
  79. const activeTab = ref('all')
  80. const searchKeyword = ref('')
  81. const pageNum = ref(1)
  82. const pageSize = ref(10)
  83. const noMoreData = ref(false)
  84. const isLoading = ref(false)
  85. const isRefreshing = ref(false)
  86. const allInfoList = ref([])
  87. const filteredAllInfo = computed(() => {
  88. let list = allInfoList.value
  89. // 按类型筛选
  90. if (activeTab.value === 'sale') {
  91. list = list.filter(item => item.type === 0)
  92. } else if (activeTab.value === 'purchase') {
  93. list = list.filter(item => item.type === 1)
  94. }
  95. return list
  96. })
  97. // 页面加载时获取数据
  98. onMounted(() => {
  99. loadProductInfo()
  100. })
  101. // 上拉加载更多
  102. const loadMore = () => {
  103. if (!isLoading.value && !noMoreData.value) {
  104. pageNum.value++
  105. loadProductInfo()
  106. }
  107. }
  108. const getImageUrl = (item) => {
  109. if (item == null) return
  110. const imageUrls = item.split(',')
  111. return imageUrls[0]
  112. }
  113. const getUnitLabel = (value) => {
  114. const unit = dictData.agricultural_unit?.find(u => u.dictValue == value)
  115. return unit ? unit.dictLabel : ''
  116. }
  117. const loadProductInfo = (keyword) => {
  118. isLoading.value = true
  119. uni.showLoading({
  120. title: '加载中'
  121. })
  122. // 构建查询参数
  123. const params = {
  124. pageNum: pageNum.value,
  125. pageSize: pageSize.value,
  126. status: 2 // 查询 已上架
  127. }
  128. if (keyword != null && keyword != '') {
  129. params.searchKeyword = keyword
  130. }
  131. // 分类逻辑
  132. if (activeTab.value !== 'all') {
  133. params.type = activeTab.value === 'sale' ? 0 : 1
  134. }
  135. getProductInfoList(params).then(res => {
  136. if (res.data.code === 200) {
  137. const { rows, total } = res.data
  138. if (pageNum.value === 1) {
  139. allInfoList.value = rows
  140. } else {
  141. allInfoList.value = [...allInfoList.value, ...rows]
  142. }
  143. // 判断是否还有更多数据
  144. noMoreData.value = allInfoList.value.length >= total
  145. uni.hideLoading()
  146. } else {
  147. uni.showToast({
  148. title: res.data.msg || '获取农品列表失败',
  149. icon: 'none'
  150. })
  151. }
  152. }).catch(err => {
  153. console.error('获取农品列表失败:', err)
  154. uni.showToast({
  155. title: '获取农品列表失败',
  156. icon: 'none'
  157. })
  158. }).finally(() => {
  159. isLoading.value = false
  160. isRefreshing.value = false
  161. })
  162. }
  163. // 切换Tab标签页
  164. const switchTab = (tab) => {
  165. activeTab.value = tab
  166. allInfoList.value = [] // 切换时置空数据数组
  167. pageNum.value = 1 // 重置页码
  168. // 滚动到当前分类位置
  169. loadProductInfo(searchKeyword.value.trim())
  170. }
  171. // 获取指示器位置
  172. const getIndicatorPosition = () => {
  173. const positions = {
  174. 'all': '0%',
  175. 'sale': '33.33%',
  176. 'purchase': '66.66%'
  177. }
  178. return positions[activeTab.value] || '0%'
  179. }
  180. // 搜索处理
  181. const handleSearch = () => {
  182. const keyword = searchKeyword.value.trim().toLowerCase()
  183. pageNum.value = 1 // 重置页码
  184. allInfoList.value = [] // 清空列表
  185. loadProductInfo(keyword)
  186. }
  187. // 导航到详情页
  188. const navigateToDetail = (item) => {
  189. uni.navigateTo({
  190. url: `/pages/service/sales-detail?id=${item.id}&type=${item.type}&title=${encodeURIComponent(item.title)}`
  191. })
  192. }
  193. // 导航到我的发布页面
  194. const navigateToMyPublish = () => {
  195. uni.navigateTo({
  196. url: '/pages/service/my-publish'
  197. })
  198. }
  199. </script>
  200. <style lang="scss">
  201. .sales-container {
  202. min-height: 100vh;
  203. background-color: #f5f5f5;
  204. padding-bottom: 120rpx;
  205. }
  206. .tab-header {
  207. background-color: #fff;
  208. position: relative;
  209. border-bottom: 1rpx solid #f0f0f0;
  210. }
  211. .tab-list {
  212. display: flex;
  213. align-items: center;
  214. }
  215. .tab-item {
  216. flex: 1;
  217. text-align: center;
  218. padding: 32rpx 0;
  219. position: relative;
  220. .tab-text {
  221. font-size: 30rpx;
  222. color: #666;
  223. font-weight: 500;
  224. transition: color 0.3s ease;
  225. }
  226. &.active .tab-text {
  227. color: #4CAF50;
  228. font-weight: bold;
  229. }
  230. }
  231. .tab-indicator {
  232. position: absolute;
  233. bottom: 0;
  234. left: 0;
  235. width: 33.33%;
  236. height: 4rpx;
  237. background-color: #4CAF50;
  238. transition: left 0.3s ease;
  239. }
  240. .search-section {
  241. background-color: #fff;
  242. padding: 20rpx;
  243. border-bottom: 1rpx solid #f0f0f0;
  244. }
  245. .search-box {
  246. flex: 1;
  247. display: flex;
  248. align-items: center;
  249. background-color: #f8f8f8;
  250. border-radius: 32rpx;
  251. padding: 16rpx 24rpx;
  252. }
  253. .search-icon {
  254. width: 32rpx;
  255. height: 32rpx;
  256. margin-right: 16rpx;
  257. }
  258. .search-input {
  259. flex: 1;
  260. font-size: 28rpx;
  261. line-height: 1.5;
  262. }
  263. .filter-btn {
  264. display: flex;
  265. align-items: center;
  266. padding: 16rpx 24rpx;
  267. background-color: #f8f8f8;
  268. border-radius: 24rpx;
  269. font-size: 28rpx;
  270. color: #666;
  271. .filter-icon {
  272. margin-left: 8rpx;
  273. font-size: 20rpx;
  274. }
  275. }
  276. .category-tags {
  277. background-color: #fff;
  278. border-bottom: 1rpx solid #f0f0f0;
  279. }
  280. .tags-scroll {
  281. white-space: nowrap;
  282. }
  283. .tags-list {
  284. display: inline-flex;
  285. padding: 0 20rpx;
  286. }
  287. .tag-item {
  288. flex-shrink: 0;
  289. padding: 20rpx 32rpx;
  290. margin-right: 8rpx;
  291. font-size: 28rpx;
  292. color: #666;
  293. border-radius: 32rpx;
  294. transition: all 0.2s ease;
  295. &.active {
  296. color: #4CAF50;
  297. background-color: #f0fdf4;
  298. font-weight: bold;
  299. }
  300. }
  301. // 内容容器
  302. .content-container {
  303. padding: 20rpx;
  304. }
  305. .info-list {
  306. display: flex;
  307. flex-direction: column;
  308. gap: 16rpx;
  309. }
  310. // 统一信息卡片样式
  311. .info-card {
  312. background-color: #fff;
  313. border-radius: 12rpx;
  314. overflow: hidden;
  315. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.05);
  316. transition: transform 0.2s ease;
  317. &:active {
  318. transform: scale(0.98);
  319. }
  320. }
  321. .card-content {
  322. display: flex;
  323. padding: 20rpx;
  324. gap: 20rpx;
  325. }
  326. // 封面图片
  327. .info-image {
  328. width: 160rpx;
  329. height: 160rpx;
  330. border-radius: 8rpx;
  331. overflow: hidden;
  332. flex-shrink: 0;
  333. image {
  334. width: 100%;
  335. height: 100%;
  336. }
  337. }
  338. // 信息内容
  339. .info-content {
  340. flex: 1;
  341. display: flex;
  342. flex-direction: column;
  343. justify-content: space-between;
  344. }
  345. // 信息头部
  346. .info-header {
  347. display: flex;
  348. align-items: flex-start;
  349. margin-bottom: 12rpx;
  350. gap: 12rpx;
  351. }
  352. .type-tag {
  353. padding: 6rpx 12rpx;
  354. border-radius: 12rpx;
  355. font-size: 20rpx;
  356. font-weight: bold;
  357. flex-shrink: 0;
  358. &.sale {
  359. background-color: #e8f5e8;
  360. color: #4CAF50;
  361. }
  362. &.purchase {
  363. background-color: #e6f7ff;
  364. color: #1890ff;
  365. }
  366. }
  367. .info-title {
  368. font-size: 28rpx;
  369. font-weight: bold;
  370. color: #333;
  371. flex: 1;
  372. line-height: 1.4;
  373. }
  374. // 简要说明
  375. .info-desc {
  376. font-size: 26rpx;
  377. color: #666;
  378. margin-bottom: 16rpx;
  379. overflow: hidden;
  380. text-overflow: ellipsis;
  381. white-space: nowrap;
  382. line-height: 1.4;
  383. }
  384. // 底部信息
  385. .info-footer {
  386. display: flex;
  387. justify-content: space-between;
  388. align-items: center;
  389. }
  390. .publish-info {
  391. display: flex;
  392. align-items: center;
  393. gap: 16rpx;
  394. }
  395. .publisher {
  396. font-size: 24rpx;
  397. color: #4CAF50;
  398. font-weight: bold;
  399. }
  400. .publish-time {
  401. font-size: 24rpx;
  402. color: #999;
  403. }
  404. // 浮动发布按钮
  405. .floating-btn {
  406. position: fixed;
  407. bottom: 120rpx;
  408. right: 30rpx;
  409. width: 140rpx;
  410. height: 140rpx;
  411. background-color: #4CAF50;
  412. border-radius: 70rpx;
  413. display: flex;
  414. flex-direction: column;
  415. align-items: center;
  416. justify-content: center;
  417. box-shadow: 0 8rpx 24rpx rgba(76, 175, 80, 0.3);
  418. z-index: 1000;
  419. transition: transform 0.2s ease;
  420. &:active {
  421. transform: scale(0.95);
  422. }
  423. .btn-icon {
  424. font-size: 56rpx;
  425. color: #fff;
  426. font-weight: 300;
  427. line-height: 1;
  428. margin-bottom: 2rpx;
  429. }
  430. .btn-text {
  431. font-size: 22rpx;
  432. color: #fff;
  433. font-weight: bold;
  434. }
  435. }
  436. .no-more-data{
  437. text-align: center;
  438. padding: 30rpx 0;
  439. }
  440. .no-more-data text {
  441. font-size: 24rpx;
  442. color: #999;
  443. margin-left: 10rpx;
  444. }
  445. </style>