index.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. <template>
  2. <view class="main-content">
  3. <view class="home-banner" :style="`height: ${globalData.navBarHeight}px `">
  4. <view class="home-banner-left" @click="cityClick">
  5. <up-icon name="map" color="#fff" size="25"></up-icon>
  6. <text class="address-text">{{ data.address.name }}</text>
  7. </view>
  8. <view class="home-banner-cente">金邻助家</view>
  9. <view class="home-banner-rigth">
  10. <!-- <up-icon name="bell" :size="25" color="rgba(46, 46, 46, 1)"></up-icon> -->
  11. </view>
  12. </view>
  13. <view class="home-box" :style="`margin-top: ${globalData.navBarHeight}px `">
  14. <view class="home-main">
  15. <view class="custom-swiper">
  16. <up-swiper :list="list3" indicator indicatorMode="line" circular></up-swiper>
  17. </view>
  18. </view>
  19. <view class="home-grid">
  20. <Client />
  21. </view>
  22. <view class="home-grid hot-box" v-if="userType === 1">
  23. <view v-for="(item, index) in hotList" :key="index + 'hot'" class="hot-item">
  24. <img :src="item" alt="" style="width: 100%;height: 160rpx;">
  25. </view>
  26. </view>
  27. <view class="home-g-bgc">
  28. <view class="home-grid2">
  29. <view class="serve-title hot-box-title" v-if="userType === 1">超值专区</view>
  30. <view class="hot-swiper">
  31. <up-swiper :list="ValueZone" :indicator="false" indicatorMode="line" circular></up-swiper>
  32. </view>
  33. </view>
  34. <view class="home-ranking home-grid2">
  35. <ServIces :leftList="leftList" :rightList="rightList" v-if="userType == 1"></ServIces>
  36. <RankingList v-if="userType === 2" />
  37. </view>
  38. </view>
  39. <up-loadmore style="margin-top: 40rpx;" :status="loadmoreInfo.status"
  40. :loadmoreText="loadmoreInfo.loadingText" :loadingText="loadmoreInfo.loadmoreText"
  41. :nomoreText="loadmoreInfo.nomoreText" @loadmore="handleLoadmore" v-if="userType == 1" />
  42. </view>
  43. <custom-tab-bar page="home" />
  44. </view>
  45. </template>
  46. <script setup>
  47. import {
  48. ref,
  49. reactive,
  50. onMounted
  51. } from 'vue';
  52. import {
  53. provide
  54. } from 'vue';
  55. import {
  56. onLoad,
  57. onShow,
  58. onReachBottom,
  59. onUnload
  60. } from "@dcloudio/uni-app";
  61. import RankingList from '@/pages/common/rankingList/index.vue';
  62. import ServIces from "@/components/Services/services.vue"
  63. import {
  64. Client
  65. } from "@/components/Client/new_file.vue"
  66. import {
  67. volunteerinfolist,
  68. } from "@/api/volunteerDetailsApi/details.js"
  69. import {
  70. slideshow,
  71. settingHomeAddress
  72. } from '@/api/home.js'
  73. import {
  74. useDict
  75. } from '@/utils/dict.js';
  76. import { chooseLocationInit,locateTheCurrentAddress } from '@/utils/adress'
  77. import CustomTabBar from '@/components/CustomTabBar/index.vue'
  78. const rightList = ref([])
  79. const leftList = ref([])
  80. const list3 = ref([]);
  81. const ValueZone = ref([]);
  82. const hotList = ref([])
  83. const userType = uni.getStorageSync('userType') //读取本地存储
  84. const globalData = ref({
  85. statusBarHeight: 47,
  86. navBarHeight: 91
  87. });
  88. const data = reactive({
  89. address: {
  90. name: '重庆市',
  91. latitude: 29.333000000000002,
  92. longitude: 105.94909000000001,
  93. cityCode:{
  94. code:[500000, 500100, 500118],
  95. data:["重庆市", "重庆市", "永川区"],
  96. index: [21, 0, 17]
  97. }
  98. },
  99. queryValue: ''
  100. })
  101. // 分页
  102. const pages = ref({
  103. current: 1,
  104. pageSize: 10,
  105. total: 0,
  106. serviceCategory: '',
  107. // appStatus:"2",
  108. })
  109. const cityClick = async () => {
  110. const {latitude,longitude} = data.address;
  111. const address = await chooseLocationInit({latitude,longitude});
  112. data.address = {...data.address,...address};
  113. settingAddress();
  114. console.log('address', address);
  115. }
  116. const loadmoreInfo = ref({
  117. status: 'loadmore',
  118. loadingText: '努力加载中...',
  119. loadmoreText: '点击加载更多~',
  120. nomoreText: '已经到底啦~'
  121. })
  122. // 加载更多
  123. async function handleLoadmore(e) {
  124. if (pages.value.current < Math.ceil(pages.value.total / pages.value.pageSize)) {
  125. pages.value.current += 1;
  126. loadmoreInfo.value.status = 'loading';
  127. await getList();
  128. } else {
  129. loadmoreInfo.value.status = 'nomore';
  130. }
  131. }
  132. const getList = async () => {
  133. try {
  134. loadmoreInfo.value.status = 'loading';
  135. const params = {
  136. pageNum: pages.value.current,
  137. pageSize: pages.value.pageSize,
  138. serviceCategory: pages.value.serviceCategory || '',
  139. businessManagementId: 0,
  140. // appStatus:pages.value.appStatus,
  141. };
  142. const res = await volunteerinfolist(params);
  143. if (!res || !res.rows) {
  144. return;
  145. }
  146. console.log('判断是否已经到了最后一页',pages.value.current >= Math.ceil(res.total / pages.value.pageSize));
  147. // 如果是第一页,先清空
  148. if (pages.value.current === 1) {
  149. leftList.value = [];
  150. rightList.value = [];
  151. }
  152. // 每次都追加新数据
  153. res.rows.forEach((item, index) => {
  154. index % 2 !== 0 ? leftList.value.push(item) : rightList.value.push(item);
  155. });
  156. pages.value.total = res.total;
  157. if (pages.value.current >= Math.ceil(res.total / pages.value.pageSize)) {
  158. loadmoreInfo.value.status = 'nomore';
  159. } else {
  160. loadmoreInfo.value.status = 'loadmore';
  161. }
  162. } catch (error) {
  163. leftList.value = [];
  164. rightList.value = [];
  165. loadmoreInfo.value.status = 'loadmore';
  166. pages.value.total = 0;
  167. console.error('Error fetching data:', error);
  168. }
  169. };
  170. onReachBottom(() => {
  171. if (pages.value.current < Math.ceil(pages.value.total / pages.value.pageSize)) {
  172. pages.value.current = pages.value.current + 1
  173. loadmoreInfo.value.status = 'nomore'
  174. getList()
  175. }
  176. })
  177. const getBanners = async () => {
  178. try {
  179. const res = await slideshow(7);
  180. if (res.code === 200 && res.data.picture) {
  181. list3.value = res.data.picture.split(',');
  182. }
  183. const value_res = await slideshow(8);
  184. if (value_res.code === 200 && value_res.data.picture) {
  185. ValueZone.value = value_res.data.picture.split(',');
  186. }
  187. const hot_res = await slideshow(11);
  188. if (hot_res.code === 200 && hot_res.data.picture) {
  189. hotList.value = hot_res.data.picture.split(',');
  190. }
  191. } catch (error) {
  192. console.log('error', error);
  193. }
  194. }
  195. const settingAddress = async() => {
  196. try {
  197. console.log('data',data);
  198. const {address}=data;
  199. const {cityCode,latitude,longitude} = address;
  200. const parmas = {
  201. provinceName: cityCode.data[0], // 省
  202. provinceCode: cityCode.code[0],
  203. provinceInd: cityCode.index[0],
  204. cityName: cityCode.data[1], // 市
  205. cityCode: cityCode.code[1],
  206. cityInd: cityCode.index[1],
  207. districtName: cityCode.data[2],
  208. districtCode: cityCode.code[2],
  209. districtInd: cityCode.index[2],
  210. address: address.name,
  211. latitude,
  212. longitude
  213. }
  214. const res = await settingHomeAddress(parmas);
  215. console.log('res',res);
  216. userType === 1 && getList();
  217. } catch (error) {
  218. console.log('设置地址失败',error);
  219. }
  220. }
  221. onShow(() => {
  222. getBanners();
  223. // 在 App.vue 中初始化
  224. uni.getSystemInfo({
  225. success: (res) => {
  226. const statusBarHeight = res.statusBarHeight;
  227. console.log('res', res);
  228. const navBarHeight = res.platform === 'android' ? 48 : 44 + res.statusBarHeight;
  229. globalData.value = { statusBarHeight, navBarHeight };
  230. }
  231. });
  232. })
  233. onMounted(() => {
  234. locateTheCurrentAddress().then(res => {
  235. console.log('locateTheCurrentAddress',res);
  236. data.address = res;
  237. settingAddress();
  238. }).catch(error => {
  239. console.log('获取地址失败!',error);
  240. getList()
  241. })
  242. })
  243. onUnload(() => {
  244. })
  245. </script>
  246. <style scoped lang="scss">
  247. .main-content {
  248. background: rgba(255, 255, 255, 1);
  249. .home-banner {
  250. display: flex;
  251. align-items: flex-end;
  252. justify-content: space-between;
  253. // background: rgba(255, 255, 255, 1);
  254. // background-color: #ED806A;
  255. background-color: rgba(221, 60, 62, 1);
  256. box-shadow: 0rpx 0rpx 0rpx rgba(0, 0, 0, 0), 0rpx 0rpx 0rpx rgba(0, 0, 0, 0), 0rpx 2.08rpx 4.17rpx rgba(0, 0, 0, 0.05);
  257. padding: 20rpx 16rpx;
  258. color: #fff;
  259. position: fixed;
  260. top: 0px;
  261. left: 0px;
  262. right: 0;
  263. z-index: 99;
  264. bottom: 150rpx;
  265. }
  266. .home-box {
  267. padding-bottom: 150rpx;
  268. }
  269. .home-banner-left {
  270. display: flex;
  271. align-items: center;
  272. width: 30%;
  273. }
  274. .home-banner-center {
  275. flex: 1;
  276. font-size: 38rpx;
  277. }
  278. .home-banner-rigth {
  279. width: 30%;
  280. }
  281. .home-main {
  282. padding: 12px 16px 0;
  283. }
  284. .home-ranking {
  285. padding: 24rpx 16px;
  286. }
  287. }
  288. .hot-box-title {
  289. padding: 0 32rpx;
  290. }
  291. .hot-swiper {
  292. padding: 24rpx 32rpx 0;
  293. }
  294. .hot-box {
  295. padding: 24rpx 32rpx;
  296. display: grid;
  297. grid-template-columns: repeat(2, 1fr);
  298. gap: 8rpx;
  299. .hot-item {
  300. // padding: 32rpx 16rpx;
  301. // border-radius: 10rpx;
  302. }
  303. }
  304. .home-grid2 {
  305. margin-bottom: 32rpx;
  306. background: #fff;
  307. padding: 12px 0;
  308. border-radius: 8px;
  309. }
  310. .home-g-bgc {
  311. background: #f7f7f7;
  312. padding: 24rpx;
  313. }
  314. .address-text {
  315. white-space: nowrap;
  316. /* 禁止换行 */
  317. overflow: hidden;
  318. /* 隐藏溢出内容 */
  319. text-overflow: ellipsis;
  320. /* 超出部分显示省略号 */
  321. }
  322. </style>