sales.vue 11 KB

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