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