index.vue 9.8 KB

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