details.vue 10 KB

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