details.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  1. <template>
  2. <view class="main-content">
  3. <view class="content-box">
  4. <view class="tabs-container">
  5. <Tabs :list="list1" @change="handlTabs" ref="tabRef" />
  6. </view>
  7. <!-- 瀑布流 -->
  8. <view v-if="userType == '1'">
  9. <up-waterfall v-model="flowList" v-if="pages.total >0">
  10. <template #left>
  11. <view class="demo-warter" v-for="(item, index) in leftList" :key="index" @click="goToDetail(item)">
  12. <up-lazy-load threshold="-450" border-radius="10" :image="getVolunteerPicture(item)"
  13. :index="index"></up-lazy-load>
  14. <view class="demo-title-container">
  15. <view class="demo-title">
  16. {{ item.businessTierName }}
  17. </view>
  18. </view>
  19. <view class="demo-skillDescribe">
  20. {{item.skillDescribe}}
  21. </view>
  22. <view class="demo-PriceDome">
  23. <view class="demo-price">
  24. <image :src="getVolunteerPicture(item)" class="name-image"></image>
  25. <text class="name-text">{{ item.name }}</text>
  26. </view>
  27. <view class="demo-price">
  28. <image src="/static/img/1x.png" class="image-1x"></image>
  29. <text class="name-textNumber">1w</text>
  30. </view>
  31. </view>
  32. </view>
  33. </template>
  34. <template #right>
  35. <view class="demo-warter" v-for="(item, index) in rightList" :key="index" @click="goToDetail(item)">
  36. <up-lazy-load threshold="-450" border-radius="10" :image="getVolunteerPicture(item)"
  37. :index="index"></up-lazy-load>
  38. <view class="demo-title-container">
  39. <view class="demo-title">
  40. {{ item.businessTierName }}
  41. </view>
  42. </view>
  43. <view class="demo-skillDescribe">
  44. {{item.skillDescribe}}
  45. </view>
  46. <view class="demo-PriceDome">
  47. <view class="demo-price">
  48. <image :src="getVolunteerPicture(item)" class="name-image"></image>
  49. <text class="name-text">{{ item.name }}</text>
  50. </view>
  51. <view class="demo-price">
  52. <image src="/static/img/1x.png" class="image-1x"></image>
  53. <text class="name-textNumber">1w</text>
  54. </view>
  55. </view>
  56. </view>
  57. </template>
  58. </up-waterfall>
  59. <view v-else>
  60. <NoneView />
  61. </view>
  62. </view>
  63. <up-loadmore style="margin-top: 40rpx;" :status="loadmoreInfo.status" :loadmoreText="loadmoreInfo.loadingText"
  64. :loadingText="loadmoreInfo.loadmoreText" :nomoreText="loadmoreInfo.nomoreText" @loadmore="handleLoadmore"
  65. v-if="userType == 1 && pages.total >0" />
  66. </view>
  67. </view>
  68. </template>
  69. <script setup>
  70. import {
  71. ref,
  72. onMounted,
  73. reactive,
  74. } from 'vue';
  75. import {
  76. onLoad,
  77. onReachBottom
  78. } from "@dcloudio/uni-app";
  79. import {
  80. volunteerinfolist
  81. } from "@/api/volunteerDetailsApi/details.js"
  82. import store from '@/store'
  83. import Tabs from "@/pages_home/components/tabs/index.vue"
  84. import NoneView from '@/components/NoneView/index.vue'
  85. const list1 = ref([])
  86. const list2 = ref([])
  87. const flowList = ref([]); //list数据
  88. const rightList = ref([])
  89. const currentTabs2 = ref(0)
  90. const serviceCategory = ref('')
  91. const leftList = ref([])
  92. const showDropdown = ref(false)
  93. const tabRef = ref(null)
  94. const businessManagementId = ref(null)
  95. const data = reactive({
  96. address: store.state.user.addressInfo,
  97. })
  98. const userType = uni.getStorageSync('userType') //读取本地存储
  99. // 获取志愿者图片
  100. const getVolunteerPicture = (item) => {
  101. // volunteerPicture是用逗号拼接的多张图片,取第一张
  102. const pictures = item.volunteerPicture.split(',');
  103. return pictures[0];
  104. };
  105. function handlTabs(record) {
  106. clearList();
  107. serviceCategory.value = record.parentId;
  108. businessManagementId.value = record.id;
  109. // 重置分页状态
  110. pages.value.current = 1;
  111. pages.value.total = 0;
  112. loadmoreInfo.value.status = 'loadmore';
  113. getList();
  114. }
  115. const goToDetail = async (item) => {
  116. const params = {
  117. volunteerId: item.volunteerId, // 获取 volunteerId
  118. serviceCategory: item.serviceCategory, // 获取 serviceCategory
  119. businessManagementId: item.businessManagementId, //获取 businessManagementId
  120. };
  121. uni.navigateTo({
  122. url: `/pages_home/pages/Volunteerside/goodsDetails?params=${JSON.stringify(params)}`
  123. });
  124. }
  125. onLoad((options) => {
  126. const dataList = JSON.parse(decodeURIComponent(options.dataList));
  127. serviceCategory.value = options.serviceCategory
  128. list1.value = dataList
  129. list2.value = dataList[0].children
  130. // 新增:动态设置顶部标题
  131. if (options.title) {
  132. uni.setNavigationBarTitle({ title: decodeURIComponent(options.title) });
  133. }
  134. })
  135. // 分页
  136. const pages = ref({
  137. current: 1,
  138. pageSize: 10,
  139. total: 0
  140. })
  141. const loadmoreInfo = ref({
  142. status: 'loadmore',
  143. loadingText: '努力加载中...',
  144. loadmoreText: '点击加载更多~',
  145. nomoreText: '已经到底啦~'
  146. })
  147. // 加载更多
  148. async function handleLoadmore(e) {
  149. if (pages.value.current < Math.ceil(pages.value.total / pages.value.pageSize)) {
  150. pages.value.current += 1;
  151. loadmoreInfo.value.status = 'loading';
  152. await getList();
  153. } else {
  154. loadmoreInfo.value.status = 'nomore';
  155. }
  156. }
  157. const getList = async () => {
  158. try {
  159. loadmoreInfo.value.status = 'loading';
  160. // 检查 businessManagementId 是否存在
  161. if (!businessManagementId.value) {
  162. console.log('No businessManagementId selected');
  163. return;
  164. }
  165. const { address } = data
  166. const { cityCode, latitude, longitude } = address
  167. console.log('volunteerinfolist ==>',address);
  168. // 请求时传递分页参数
  169. const res = await volunteerinfolist({
  170. pageNum: pages.value.current, // 当前页码
  171. pageSize: pages.value.pageSize, // 每页大小
  172. businessManagementId: businessManagementId.value,
  173. provinceName: cityCode.data[0], // 省
  174. provinceCode: cityCode.code[0],
  175. cityName: cityCode.data[1], // 市
  176. cityCode: cityCode.code[1],
  177. districtName: cityCode.data[2],
  178. districtCode: cityCode.code[2],
  179. latitude,
  180. longitude,
  181. });
  182. if (!res || !res.rows) {
  183. return;
  184. }
  185. // 如果是第一页,先清空
  186. if (pages.value.current === 1) {
  187. leftList.value = [];
  188. rightList.value = [];
  189. }
  190. // 将数据分成左右两列
  191. res.rows.forEach((item, index) => {
  192. index % 2 !== 0 ? rightList.value.push(item) : leftList.value.push(item);
  193. });
  194. pages.value.total = res.total;
  195. // 判断是否已经到了最后一页
  196. if (pages.value.current >= Math.ceil(res.total / pages.value.pageSize)) {
  197. loadmoreInfo.value.status = 'nomore';
  198. } else {
  199. loadmoreInfo.value.status = 'loadmore';
  200. }
  201. } catch (error) {
  202. clearList();
  203. console.error('Error fetching data:', error);
  204. }
  205. };
  206. const clearList = () => {
  207. leftList.value = [];
  208. rightList.value = [];
  209. loadmoreInfo.value.status = 'loadmore';
  210. pages.value.total = 0;
  211. }
  212. onReachBottom(() => {
  213. if (pages.value.current < Math.ceil(pages.value.total / pages.value.pageSize)) {
  214. pages.value.current += 1;
  215. loadmoreInfo.value.status = 'loading';
  216. getList();
  217. }
  218. })
  219. onMounted(() => {
  220. // 如果有默认选中的 tab,则初始化数据
  221. if (list1.value.length > 0) {
  222. const defaultTab = list1.value[0];
  223. businessManagementId.value = defaultTab.id;
  224. getList();
  225. }
  226. })
  227. </script>
  228. <style scoped lang="scss">
  229. .main-content {
  230. width: 100%;
  231. height: 100vh;
  232. background: #fff;
  233. }
  234. .content-box {
  235. width: 100%;
  236. height: 100%;
  237. padding-bottom: 40rpx;
  238. }
  239. .Wrapper {
  240. display: flex;
  241. align-items: center;
  242. gap: 10rpx;
  243. }
  244. .Wrapper-img {
  245. width: 50rpx;
  246. height: 50rpx;
  247. margin-left: 10rpx;
  248. }
  249. .Wrapper-content {
  250. color: rgba(16, 16, 16, 1);
  251. font-size: 25rpx;
  252. font-family: PingFangSC-regular;
  253. line-height: 20rpx;
  254. }
  255. /* 外层容器 */
  256. .tabs-container {
  257. width: 100%;
  258. background: #fff;
  259. padding: 10px 0;
  260. }
  261. /* Flex 布局容器 */
  262. .tabs-wrapper {
  263. display: flex;
  264. align-items: center;
  265. position: relative;
  266. }
  267. /* 可横向滚动的 scroll-view */
  268. .tabs-scroll {
  269. flex: 1;
  270. /* 占据剩余空间 */
  271. overflow-x: auto;
  272. /* 允许横向滚动 */
  273. white-space: nowrap;
  274. /* 禁止换行 */
  275. -webkit-overflow-scrolling: touch;
  276. /* iOS 平滑滚动 */
  277. }
  278. /* 隐藏滚动条(可选) */
  279. .tabs-scroll::-webkit-scrollbar {
  280. display: none;
  281. }
  282. /* 固定图标(始终显示在右侧) */
  283. .fixed-icon {
  284. width: 30px;
  285. height: 30px;
  286. margin-left: 10px;
  287. /* 与 tabs 的间距 */
  288. flex-shrink: 0;
  289. /* 禁止压缩 */
  290. }
  291. .demo-warter {
  292. border-radius: 8px;
  293. margin: 5px;
  294. background-color: #ffffff;
  295. }
  296. .u-close {
  297. position: absolute;
  298. top: 32rpx;
  299. right: 32rpx;
  300. }
  301. .demo-image {
  302. width: 100%;
  303. border-radius: 4px;
  304. }
  305. .demo-title-container {
  306. display: flex;
  307. flex-direction: column;
  308. justify-content: center;
  309. align-items: center;
  310. padding: 4rpx 12rpx;
  311. /* z-index: 0; */
  312. margin-top: 10rpx;
  313. border-radius: 10rpx;
  314. box-sizing: border-box;
  315. border: 1rpx solid rgba(237, 93, 49, 0.8);
  316. }
  317. .demo-title {
  318. font-size: 22rpx;
  319. color: #ED5D31;
  320. display: -webkit-box;
  321. -webkit-box-orient: vertical;
  322. -webkit-line-clamp: 3;
  323. overflow: hidden;
  324. text-overflow: ellipsis;
  325. word-break: break-all;
  326. }
  327. .demo-skillDescribe {
  328. width: 298rpx;
  329. font-family: PingFang SC;
  330. font-size: 26rpx;
  331. font-weight: 500;
  332. line-height: 36rpx;
  333. letter-spacing: normal;
  334. color: #141414;
  335. margin-top: 5px;
  336. display: -webkit-box;
  337. -webkit-box-orient: vertical;
  338. -webkit-line-clamp: 2;
  339. overflow: hidden;
  340. text-overflow: ellipsis;
  341. word-break: break-all;
  342. }
  343. .demo-img {
  344. width: 40rpx;
  345. height: 40rpx;
  346. border-radius: 50%;
  347. }
  348. .demo-PriceDome {
  349. display: flex;
  350. justify-content: space-between;
  351. align-items: center;
  352. width: 100%;
  353. margin-top: 15rpx;
  354. }
  355. .demo-price {
  356. display: flex;
  357. align-items: center;
  358. overflow: hidden;
  359. /* 防止内容溢出 */
  360. }
  361. .image-1x {
  362. width: 20rpx;
  363. height: 20rpx;
  364. z-index: 0;
  365. }
  366. .name-textNumber {
  367. font-size: 22rpx;
  368. font-weight: normal;
  369. line-height: 24rpx;
  370. text-align: right;
  371. letter-spacing: -0.04em;
  372. color: #FF6E51;
  373. }
  374. .name-text {
  375. width: 117rpx;
  376. height: 34rpx;
  377. font-family: PingFang SC;
  378. font-size: 24rpx;
  379. font-weight: normal;
  380. line-height: 34rpx;
  381. letter-spacing: -0.04em;
  382. color: rgba(0, 0, 0, 0.8);
  383. }
  384. .name-image {
  385. width: 40rpx;
  386. height: 40rpx;
  387. margin-right: 10rpx;
  388. border-radius: 50%;
  389. }
  390. .name-text {
  391. white-space: nowrap;
  392. /* 禁止换行 */
  393. overflow: hidden;
  394. /* 超出部分隐藏 */
  395. text-overflow: ellipsis;
  396. /* 显示省略号 */
  397. max-width: 120rpx;
  398. /* 6个中文字符大约占120rpx */
  399. }
  400. </style>