home.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555
  1. <template>
  2. <view class="main">
  3. <view class="top-box" :class="showTopSearch?'':'hide'">
  4. <view :style="`height:${statusBarHeight}px`"></view>
  5. <!-- <view class="title">松河生活平台</view> -->
  6. <view class="input-box">
  7. <view class="status-bar" :style="`height:${statusBarHeight}px`"></view>
  8. <input @click="searchClick" placeholder="请输入搜索关键字" placeholder-class="input-placeholder" />
  9. <text class="iconfont2" @click="goToMsg()">
  10. &#xe67c;
  11. </text>
  12. </view>
  13. <view class="seat"></view>
  14. </view>
  15. <swiper class="swiper" circular indicator-dots autoplay>
  16. <swiper-item v-for="(item,index) in bannerList" :key="index">
  17. <image @click="imgLink(item.model_type, item.model_id, item.url, item.shop_id)" class="banner"
  18. src="./banner.png" mode="aspectFill"></image>
  19. </swiper-item>
  20. </swiper>
  21. <uni-notice-bar v-if="homeNotice" :speed="50" class="notice-box" show-icon background-color="#E8FEEA"
  22. color="#0B6C39" scrollable :text="homeNotice" />
  23. <view class="class-box">
  24. <view class="box" v-for="(item,index) in classList" :key="index"
  25. @click="goPage(item.url,item.method,item.needLogin)">
  26. <image class="icon" :class="index==1?'icon-2':''" mode="heightFix" :src="item.imgPath"></image>
  27. <view class="text">{{item.text}}</view>
  28. </view>
  29. </view>
  30. <view class="class-box2">
  31. <view @click="goPage('/pages/welfareBuy/index','navigateTo',false)" class="p1"
  32. style="background-image: url('/static/home/class2-icon1.png');">
  33. <view class="title">公益福利购</view>
  34. <view class="tip">公益商品申领</view>
  35. </view>
  36. <view class="p2-box">
  37. <view @click="goPage('/pages/entrepreneurshipZone/index','navigateTo',false)" class="p2"
  38. style="background-image: url('/static/home/class2-icon2.png');">
  39. <view class="title">创业专区</view>
  40. </view>
  41. <view @click="goPage('/pages/index/lidaPage','switchTab',false)" class="p2"
  42. style="background-image: url('/static/home/class2-icon3.png');">
  43. <view class="title">公益商品</view>
  44. </view>
  45. </view>
  46. </view>
  47. <donation-news :listData="listData"></donation-news>
  48. <u-loadmore :status="loadStatus" />
  49. <!-- 升级弹窗 -->
  50. </view>
  51. </template>
  52. <script>
  53. //TODO 消息列表有2中购买类型【去购买,去领取】,都是跳转商品详情。
  54. export default {
  55. data() {
  56. return {
  57. //手机状态栏高度
  58. statusBarHeight: uni.getSystemInfoSync().statusBarHeight,
  59. bannerList: [],
  60. classList: [{
  61. imgPath: '/static/home/class-icon1.png',
  62. text: '做公益',
  63. url: '/pages/publicWelfare/index',
  64. method: 'navigateTo',
  65. needLogin: false
  66. }, {
  67. imgPath: '/static/home/class-icon2.png',
  68. text: '去学习',
  69. url: '/pages/learningClassroom/index',
  70. method: 'navigateTo',
  71. needLogin: true
  72. }, {
  73. imgPath: '/static/home/class-icon3.png',
  74. text: '爱心购',
  75. url: '/pages/index/lidaPage',
  76. method: 'switchTab',
  77. needLogin: false
  78. }, {
  79. imgPath: '/static/home/class-icon4.png',
  80. text: '爱心任务',
  81. url: '/pages/signCenter/index',
  82. method: 'navigateTo',
  83. needLogin: true
  84. }],
  85. showTopSearch: true,
  86. pageParams: {
  87. page: 1,
  88. limit: 10
  89. },
  90. listData: [],
  91. loadStatus: 'loadmore', //loading / nomore
  92. totalPage: 1,
  93. homeNotice: ''
  94. }
  95. },
  96. onPageScroll: function(e) { //nvue暂不支持滚动监听,可用bindingx代替
  97. if (e.scrollTop > uni.upx2px(49 + 30)) {
  98. this.showTopSearch = false;
  99. } else {
  100. this.showTopSearch = true;
  101. }
  102. },
  103. onLoad() {
  104. let that = this;
  105. // #ifdef APP-PLUS
  106. // iosApp第一次安装APP时会询问"是否允许访问网络"
  107. if (plus.os.name == 'iOS') {
  108. // 首先获取一次网络状态
  109. uni.getNetworkType({
  110. success: function(res) {
  111. if (res.networkType != 'none') {
  112. that.initData();
  113. }
  114. }
  115. });
  116. // 监听网络变化
  117. uni.onNetworkStatusChange(function(res) {
  118. if (res.isConnected) {
  119. that.initData();
  120. }
  121. });
  122. } else {
  123. that.initData();
  124. this.getAppInfo()
  125. }
  126. // #endif
  127. // #ifdef H5
  128. that.initData();
  129. // #endif
  130. },
  131. onPullDownRefresh() {
  132. this.initData();
  133. uni.stopPullDownRefresh();
  134. },
  135. methods: {
  136. initData() {
  137. this.getBanner();
  138. this.getHomeNotice();
  139. this.getList(true);
  140. },
  141. // 获取更新信息
  142. getAppInfo() {
  143. this.$http.get('/app/config/info').then(res => {
  144. if (res && res.code == 200) {
  145. this.appInfo = res.data || {};
  146. // #ifdef APP-PLUS
  147. plus.runtime.getProperty(plus.runtime.appid, (info) => {
  148. this.versionCode = info.versionCode;
  149. if (this.appInfo.number > info.versionCode) {
  150. uni.navigateTo({
  151. url: "/components/appUpdatePop"
  152. })
  153. }
  154. })
  155. // #endif
  156. }
  157. })
  158. },
  159. getBanner() {
  160. this.bannerList = [{
  161. cover: './banner.png',
  162. model_type: '',
  163. model_id: '',
  164. url: './banner.png',
  165. shop_id: ''
  166. },
  167. {
  168. cover: './banner.png',
  169. model_type: '',
  170. model_id: '',
  171. url: '',
  172. shop_id: ''
  173. },
  174. {
  175. cover: './banner.png',
  176. model_type: '',
  177. model_id: '',
  178. url: '',
  179. shop_id: ''
  180. }
  181. ]
  182. // this.$http.get('/ad/ad/getByCode/home-banner',{})
  183. // .then(res=>{
  184. // if (res.code == 200) {
  185. // this.bannerList = res.list;
  186. // }
  187. // })
  188. },
  189. /**轮播图跳转 */
  190. imgLink(type, id, url, shopid) {
  191. if (type == "goods") {
  192. uni.navigateTo({
  193. url: "/pages/product/goods/goods?id=" + id + "&shopid=" + shopid,
  194. });
  195. } else if (type == "service") {
  196. // uni.navigateTo({
  197. // url: "/pages/product/goods/serviceGood?id=" + id
  198. // });
  199. } else if (type == "point_goods") {
  200. // uni.navigateTo({
  201. // url: "/pages/product/goods/IntegralGood?id=" + id
  202. // });
  203. } else if (type == "url") {
  204. if (/^http/.test(url)) {
  205. uni.navigateTo({
  206. url: "/pages/index/webView?linkUrl=" + url,
  207. });
  208. } else {
  209. uni.navigateTo({
  210. url
  211. });
  212. }
  213. }
  214. },
  215. goToMsg() {
  216. let token = uni.getStorageSync("apiToken")
  217. if (!token) {
  218. uni.navigateTo({
  219. url: "/pages/login/index"
  220. })
  221. } else {
  222. uni.navigateTo({
  223. url: "/pages/research/setup/myMsg"
  224. })
  225. }
  226. },
  227. goPage(url, method, needLogin) {
  228. let token = uni.getStorageSync("apiToken")
  229. if (!token && needLogin) {
  230. uni.navigateTo({
  231. url: "/pages/login/index"
  232. })
  233. return;
  234. }
  235. uni[method]({
  236. url
  237. })
  238. },
  239. searchClick() {
  240. uni.navigateTo({
  241. url: "/pages/research/homepage/search",
  242. });
  243. },
  244. getList(isRefresh, needLoading = false) {
  245. let that = this;
  246. // if (!isRefresh && this.loadStatus == 'nomore') {
  247. // return false;
  248. // }
  249. //无限滚动
  250. if (!isRefresh && this.totalPage == this.pageParams.page) {
  251. this.pageParams.page = 0;
  252. }
  253. this.pageParams.page = isRefresh ? 1 : this.pageParams.page + 1;
  254. this.listData = isRefresh ? [] : this.listData;
  255. if (needLoading) {
  256. uni.showLoading({
  257. title: '努力加载中...',
  258. mask: true
  259. });
  260. }
  261. this.loadStatus = 'loading';
  262. this.$http.get('/donation/msg/page', this.pageParams)
  263. .then(res => {
  264. if (res.code == 200) {
  265. let listData = that.listData;
  266. listData.push(...res.page.list);
  267. //that.loadStatus = that.listData.length >= res.page.totalCount?'nomore':'loadmore';
  268. //无限滚动
  269. that.totalPage = res.page.totalPage;
  270. that.loadStatus = 'loadmore';
  271. // 加载第一页,如果是空的,就停止无限滚动
  272. if (that.pageParams.page == 1 && res.page.list.length == 0) {
  273. that.loadStatus = 'nomore';
  274. }
  275. that.listData = listData;
  276. }
  277. })
  278. .finally(() => {
  279. if (needLoading) {
  280. uni.hideLoading();
  281. }
  282. })
  283. },
  284. // 公告
  285. getHomeNotice() {
  286. let that = this;
  287. this.$http.get('/notice/newest', {})
  288. .then(res => {
  289. if (res.code == 200 && res.data) {
  290. that.homeNotice = res.data.detail;
  291. }
  292. })
  293. }
  294. },
  295. onReachBottom() {
  296. if (this.loadStatus != 'nomore') {
  297. this.getList();
  298. }
  299. }
  300. }
  301. </script>
  302. <style lang="scss" scoped>
  303. .main {
  304. background-color: #fdfdfd;
  305. padding-bottom: 30rpx;
  306. .top-box {
  307. width: 100%;
  308. padding: 49rpx 0 0 0;
  309. background: linear-gradient(180deg, #2bba26 0%, #047753 100%);
  310. &.hide {
  311. padding: 0;
  312. .title {
  313. display: none;
  314. }
  315. .input-box {
  316. position: fixed;
  317. top: 0;
  318. left: 0;
  319. background: linear-gradient(180deg, #2bba26 0%, #047753 100%);
  320. .status-bar {
  321. display: block;
  322. }
  323. }
  324. .seat {
  325. display: block;
  326. }
  327. }
  328. .seat {
  329. display: none;
  330. height: 130rpx;
  331. }
  332. .title {
  333. margin: 0 auto;
  334. height: 45rpx;
  335. font-size: 32rpx;
  336. font-family: PingFang SC, PingFang SC-Bold;
  337. font-weight: 700;
  338. text-align: left;
  339. color: #ffffff;
  340. line-height: 28rpx;
  341. text-align: center;
  342. }
  343. .input-box {
  344. position: sticky;
  345. top: 0;
  346. z-index: 100;
  347. width: 100%;
  348. padding: 30rpx;
  349. input {
  350. box-sizing: border-box;
  351. display: inline-block;
  352. vertical-align: middle;
  353. width: 620rpx;
  354. height: 70rpx;
  355. background: rgba(2, 81, 43, 0.3);
  356. border-radius: 36px;
  357. padding-left: 80rpx;
  358. color: white;
  359. background-image: url('/static/home/search-icon.png');
  360. background-size: 30rpx 30rpx;
  361. background-position: 30rpx 50%;
  362. background-repeat: no-repeat;
  363. }
  364. text {
  365. margin-left: 20rpx;
  366. display: inline-block;
  367. vertical-align: middle;
  368. font-size: 28rpx;
  369. font-weight: 400;
  370. text-align: right;
  371. color: #ffffff;
  372. line-height: 24rpx;
  373. &.iconfont2 {
  374. font-size: 50rpx;
  375. }
  376. }
  377. .status-bar {
  378. display: none;
  379. }
  380. }
  381. .input-placeholder {
  382. color: #7BAA89;
  383. opacity: 0.74;
  384. font-size: 24rpx;
  385. font-family: PingFang SC, PingFang SC-Regular;
  386. font-weight: 400;
  387. text-align: left;
  388. color: #7baa89;
  389. line-height: 70rpx;
  390. }
  391. }
  392. .swiper {
  393. height: 370rpx;
  394. width: 100%;
  395. .banner {
  396. height: 100%;
  397. width: 100%;
  398. background-color: #f2f2f2;
  399. }
  400. ::v-deep .uni-swiper-dot {
  401. background-color: white;
  402. opacity: 0.3;
  403. height: 10rpx;
  404. width: 50rpx;
  405. border-radius: 5rpx;
  406. }
  407. ::v-deep .uni-swiper-dot-active {
  408. opacity: 1;
  409. }
  410. }
  411. .notice-box {
  412. height: 92rpx;
  413. font-size: 28rpx;
  414. margin-bottom: 0;
  415. ::v-deep .uni-noticebar-icon {
  416. width: 40rpx;
  417. background-image: url('/static/home/noticebar-icon.png');
  418. background-size: cover;
  419. color: transparent !important;
  420. }
  421. }
  422. .class-box {
  423. padding: 22rpx 30rpx;
  424. box-sizing: border-box;
  425. width: 100%;
  426. display: flex;
  427. justify-content: space-between;
  428. border-bottom: 1px solid #f2f2f2;
  429. .box {
  430. text-align: center;
  431. .icon {
  432. height: 71rpx;
  433. &-2 {
  434. transform: scale(1.1);
  435. }
  436. }
  437. .text {
  438. font-size: 28rpx;
  439. font-family: PingFang SC, PingFang SC-Regular;
  440. font-weight: 400;
  441. text-align: center;
  442. color: #1a1a1a;
  443. line-height: 30rpx;
  444. margin-top: 16rpx;
  445. }
  446. }
  447. }
  448. .class-box2 {
  449. width: 100%;
  450. height: 334rpx;
  451. padding: 0 30rpx;
  452. margin: 45rpx auto;
  453. display: flex;
  454. flex-wrap: wrap;
  455. box-sizing: border-box;
  456. .p1 {
  457. border-radius: 20rpx;
  458. background-size: cover;
  459. height: 100%;
  460. width: 50%;
  461. margin-right: 24rpx;
  462. flex: 1;
  463. text-align: center;
  464. .title {
  465. font-size: 36rpx;
  466. font-family: PingFang SC, PingFang SC-Bold;
  467. font-weight: 700;
  468. color: #ffffff;
  469. line-height: 24rpx;
  470. margin-top: 220rpx;
  471. }
  472. .tip {
  473. font-size: 24rpx;
  474. font-family: PingFang SC, PingFang SC-Regular;
  475. font-weight: 400;
  476. color: #ffffff;
  477. line-height: 24rpx;
  478. margin-top: 20rpx;
  479. }
  480. }
  481. .p2-box {
  482. height: 100%;
  483. width: 50%;
  484. display: flex;
  485. flex-wrap: wrap;
  486. flex: 1;
  487. }
  488. .p2 {
  489. border-radius: 20rpx;
  490. background-size: cover;
  491. height: calc(50% - 12rpx);
  492. width: 100%;
  493. display: flex;
  494. align-items: center;
  495. .title {
  496. font-size: 32rpx;
  497. font-family: PingFang SC, PingFang SC-Bold;
  498. font-weight: 700;
  499. text-align: left;
  500. color: #ffffff;
  501. line-height: 24rpx;
  502. margin-left: 175rpx;
  503. }
  504. &:nth-child(1) {
  505. margin-bottom: 24rpx;
  506. }
  507. }
  508. }
  509. .advert {
  510. width: 690rpx;
  511. margin: 0 30rpx;
  512. padding-bottom: 16rpx;
  513. }
  514. }
  515. </style>