home.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. <template>
  2. <view :style="vuex_skin">
  3. <!-- #ifdef MP-WEIXIN -->
  4. <u-navbar title-color="#000000" :is-back="fasle" title="首页"></u-navbar>
  5. <!-- #endif -->
  6. <mescroll-body ref="mescrollRef" @init="mescrollInit" :down="downOption" :up="upOption" @down="downCallback"
  7. @up="upCallback">
  8. <view v-if="noticeContent">
  9. <u-notice-bar mode="horizontal" :list="noticeContent"></u-notice-bar>
  10. </view>
  11. <view style="padding: 30rpx 30rpx 10rpx;">
  12. <u-swiper :list="swiperList" border-radius="12" name="url" mode="rect" height="300" @click="handleSwiper"></u-swiper>
  13. </view>
  14. <view class="">
  15. <view class="cu-list grid no-border" :class="gridClass" style="border-radius:20rpx ;">
  16. <view class="cu-item" @click.stop="jump(item)" v-for="(item,index) in gridList" :key="index">
  17. <view class="grid-icon">
  18. <image style="width: 88rpx;height: 88rpx;" :src="item.icon" />
  19. </view>
  20. <text style="color: #222222;font-size: 26rpx;">{{item.name}}</text>
  21. </view>
  22. </view>
  23. </view>
  24. <view class="" style="height: 20rpx;background-color: #f8f8f8"></view>
  25. <view style="padding: 30rpx 30rpx 0">
  26. <u-search placeholder="搜索关键词或编号" height="70" @search="searchWorks" v-model="keyword"
  27. :show-action="false">
  28. </u-search>
  29. </view>
  30. <view style="padding: 30rpx 30rpx 0;">
  31. <view class="text-bold" style="font-size: 34rpx;">
  32. {{vuex_active_setting.indexTitle || ''}}
  33. </view>
  34. <view @click="$jump('/pages/activity/activityDetail?id='+item.id)" class="card shadow"
  35. v-for="(item,index) in worksList" :key="item.id">
  36. <view v-if="index==0" class="center bg-img rank-tag"
  37. style="background-image: url(https://vote.guosen-fumao.cn/obsfile/5c923494fae24fdc91ee1dd6965c26b2-qnradpXLKHik8a7c1bd849a731b15ee6726a44cf4052.png);z-index: 2;">
  38. <text>1</text>
  39. </view>
  40. <view v-if="index==1" class="center bg-img rank-tag"
  41. style="background-image: url(https://vote.guosen-fumao.cn/obsfile/72001a127cab486cb4ad66621aa04e96-UpLGLMdL9kFV87f15988cc7debf4ec475216e800b786.png);z-index: 2;">
  42. <text>2</text>
  43. </view>
  44. <view v-if="index==2" class="center bg-img rank-tag"
  45. style="background-image: url(https://vote.guosen-fumao.cn/obsfile/5e65cfb76ccf49cf84661b85804c2455-LRRAX18iJBMH5489e35cc716d71257defce06d673af0.png);z-index: 2;">
  46. <text>3</text>
  47. </view>
  48. <view class="left">
  49. <image :src="item.imgUrl" mode="aspectFill"></image>
  50. </view>
  51. <view class="right" style="width: 100%;">
  52. <view class="flex-direction flex">
  53. <view class="flex">
  54. <view class="center ">
  55. <view class="cu-tag sm bg-tag radius margin-right-10" style="font-weight: 400;">
  56. 编号:{{item.productNo}}
  57. </view>
  58. </view>
  59. <view class="center">
  60. <text class="title text-cut-1">{{item.title}}</text>
  61. </view>
  62. </view>
  63. <rich-text class="desc text-cut-2" style="max-height: 80rpx;" :nodes="decodeURIComponent(item.content)">
  64. </rich-text>
  65. </view>
  66. <view class="bottom" style="width: 100%;">
  67. <view class="flex margin-top-10">
  68. <text class="cuIcon-hotfill text-base" style="font-size: 34rpx;"></text>
  69. <view class="center">
  70. <text
  71. style="color: #353535;margin-left: 6rpx;font-size:28rpx;">{{item.voteCount}}</text>
  72. </view>
  73. </view>
  74. <view class="cu-btn round sm line-base">
  75. 去投票
  76. </view>
  77. </view>
  78. </view>
  79. </view>
  80. </view>
  81. </mescroll-body>
  82. <!-- 海报 -->
  83. <login ref="login" @signIn="signIn" @phoneSuccess="phoneSuccess"></login>
  84. <toast ref="toast"></toast>
  85. <u-tabbar :bg-color="tabbar.bgColor" :icon-size="tabbar.iconSize" :height="100" :border-top="tabbar.borderTop"
  86. :inactive-color="tabbar.inactiveColor" :active-color="tabbar.activeColor" :list="tabbar.list">
  87. </u-tabbar>
  88. </view>
  89. </template>
  90. <script>
  91. import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
  92. import util from "@/utils/util.js";
  93. import {
  94. tabbar
  95. } from "@/assets/http/tabbar.js"
  96. export default {
  97. mixins: [MescrollMixin],
  98. data() {
  99. return {
  100. //tabbar
  101. tabbar: {},
  102. downOption: {
  103. auto: false
  104. },
  105. upOption: {
  106. auto: false,
  107. empty: {
  108. use: false
  109. }
  110. },
  111. //海报
  112. posetrParams: {
  113. avatar: '',
  114. title: '我是普法帮帮代言人',
  115. subTitle: ''
  116. },
  117. qrCodeImg: '',
  118. //活动id
  119. activeId: '',
  120. //排行榜
  121. worksList: [],
  122. //轮播图
  123. swiperList: [],
  124. //菜单
  125. gridClass: '',
  126. gridList: [],
  127. keyword: '',
  128. noticeContent: [],
  129. //活动详情
  130. activeInfo: {},
  131. //参赛的路径
  132. applyUrl: ""
  133. };
  134. },
  135. async onLoad(options) {
  136. await this.handelRoute(options)
  137. this.fetchTabbar()
  138. },
  139. onShow() {
  140. if (this.canReset) {
  141. this.mescroll.resetUpScroll();
  142. }
  143. this.canReset = true;
  144. },
  145. methods: {
  146. handleSwiper(index){
  147. let url = this.swiperList[index].path;
  148. if(!!url && (url.indexOf('http://') > -1 || url.indexOf('https://') > -1) ){
  149. window.location.href = url;
  150. }
  151. },
  152. /**
  153. * 更换主题
  154. */
  155. async fetchTabbar() {
  156. this.tabbar = tabbar
  157. if (this.vuex_theme.bgColor) {
  158. this.tabbar.activeColor = this.vuex_theme.bgColor
  159. } else {
  160. this.tabbar.activeColor = this.$config.themeRed.theme.bgColor
  161. }
  162. },
  163. /**
  164. * 获取活动详情
  165. */
  166. async activeDetail() {
  167. let params = {
  168. id: this.activeId
  169. }
  170. this.$api.activerecord.detail(params).then(res => {
  171. this.activeInfo = res.data.data;
  172. })
  173. },
  174. /**
  175. * 获取通知公告
  176. */
  177. async getNotice() {
  178. let params = {
  179. activeId: this.activeId,
  180. title: '活动通知'
  181. }
  182. this.$api.notice.list(params).then(res => {
  183. let notices = res.data.data.records
  184. if (this.$isNotEmpty(notices) && this.$isNotEmpty(notices[0].content)) {
  185. this.noticeContent.push(util.formatHtml(notices[0].content))
  186. }
  187. })
  188. },
  189. /**
  190. * 处理路由转发
  191. */
  192. async handelRoute(options) {
  193. const {
  194. path
  195. } = options;
  196. await this.initParams(options);
  197. if (this.$isNotEmpty(path)) {
  198. this.$jump(decodeURIComponent(path))
  199. }
  200. },
  201. /**
  202. * 获取默认活动id
  203. */
  204. async getDefaultActiveId() {
  205. let params = {
  206. platformSettingEnum: 'COMMON_SETTING'
  207. }
  208. let defaultActiveId = JSON.parse((await this.$api.platform.getPlatformValue(params)).data.data)
  209. .defaultActiveId;
  210. return defaultActiveId
  211. },
  212. /**
  213. * 获取活动参数
  214. */
  215. async getActivityParams() {
  216. let params = {
  217. activeId: this.activeId,
  218. platformSettingEnum: 'ACTIVE_SETTING'
  219. }
  220. let activeSetting = JSON.parse((await this.$api.platform.getPlatformValue(params)).data.data);
  221. this.$config.setTheme(activeSetting.theme, this)
  222. // #ifdef H5
  223. if (this.$isNotEmpty(activeSetting.shareParam)) {
  224. let shareParam = activeSetting.shareParam
  225. shareParam.link = window.location.href.split('?')[0] + '?activeId=' + this.activeId
  226. this.$shareConfig.H5Share(shareParam)
  227. }
  228. // #endif
  229. activeSetting.defaultActiveId = this.activeId
  230. this.$u.vuex('vuex_active_setting', activeSetting);
  231. },
  232. /**
  233. * 获取首页参数
  234. */
  235. async initParams(options) {
  236. const activeId = options.activeId
  237. // if (this.$isNotEmpty(activeId)) {
  238. // //活动列表传进来
  239. // this.activeId = activeId
  240. // } else if (this.$isNotEmpty(this.vuex_active_setting) &&
  241. // this.$isNotEmpty(this.vuex_active_setting.defaultActiveId)) {
  242. // //缓存中有活动id
  243. // this.activeId = this.vuex_active_setting.defaultActiveId
  244. // } else {
  245. // //获取默认的活动id
  246. // this.activeId = await this.getDefaultActiveId()
  247. // }
  248. if (this.$isNotEmpty(activeId)) {
  249. //活动列表传进来
  250. this.activeId = activeId
  251. } else {
  252. //获取默认的活动id
  253. this.activeId = await this.getDefaultActiveId()
  254. }
  255. await this.getActivityParams(activeId)
  256. this.getNotice()
  257. this.activeDetail();
  258. //获取排行榜
  259. this.mescroll.resetUpScroll();
  260. //获取轮播图
  261. let gridList = this.vuex_active_setting.functionItemList
  262. if (this.$isNotEmpty(gridList)) {
  263. this.gridList = gridList.filter(item => item.show == 1)
  264. this.gridClass = 'col-' + this.gridList.length
  265. }
  266. // console.log(gridList, "gridList");
  267. this.swiperList = this.vuex_active_setting.indexImageList
  268. console.log(this.swiperList, "swiperList");
  269. },
  270. jump(item) {
  271. if (item.path == '/pages/rank/rank') {
  272. item.path = `${item.path}?activeId=${this.activeId}`
  273. }
  274. if (item.path == '/pages/apply/apply') {
  275. //登录后才可以参赛
  276. this.applyUrl = `${item.path}?activeId=${this.activeId}&activeType=${this.activeInfo.type}`
  277. this.login()
  278. return;
  279. }
  280. uni.navigateTo({
  281. url: item.path
  282. })
  283. },
  284. init() {
  285. this.goApply()
  286. },
  287. goApply() {
  288. let nowTime = new Date().getTime();
  289. let startTime = this.$dateTime.getTime(this.activeInfo.uploadProductStartTime)
  290. let endTime = this.$dateTime.getTime(this.activeInfo.uploadProductEndTime)
  291. if (nowTime < startTime) {
  292. this.$refs.toast.info("报名未开始");
  293. } else if (nowTime > endTime) {
  294. this.$refs.toast.info("报名已结束");
  295. } else {
  296. uni.navigateTo({
  297. url: this.applyUrl
  298. })
  299. }
  300. },
  301. searchWorks() {
  302. let params = {
  303. activeId: this.activeId,
  304. keyword: this.keyword
  305. }
  306. this.$api.activity.searchWork(params).then(res => {
  307. this.worksList = res.data.data;
  308. })
  309. },
  310. downCallback() {
  311. setTimeout(() => {
  312. this.mescroll.resetUpScroll();
  313. }, 1000)
  314. },
  315. upCallback(mescroll) {
  316. try {
  317. let params = {
  318. current: mescroll.num,
  319. size: mescroll.size,
  320. activeId: this.activeId
  321. }
  322. this.$api.activity.sortListQuery(params).then(res => {
  323. // console.log(res.data.data.records);
  324. let data = res.data.data.records
  325. let total = res.data.data.total
  326. mescroll.endBySize(data.length, total);
  327. if (mescroll.num == 1) this.worksList = []; //如果是第一页需手动制空列表
  328. this.worksList = this.worksList.concat(data); //追加新数据
  329. })
  330. } catch (e) {
  331. console.error(e);
  332. this.mescroll.endErr()
  333. }
  334. },
  335. }
  336. }
  337. </script>
  338. <style>
  339. page {
  340. background-color: #FFFFFF;
  341. }
  342. </style>
  343. <style lang="scss" scoped>
  344. .shadow {
  345. box-shadow: #f8f8f8 0px 0px 10rpx 10rpx
  346. }
  347. .rank-tag {
  348. color: #FFFFFF;
  349. width: 40rpx;
  350. height: 46rpx;
  351. position: absolute;
  352. left: 10rpx;
  353. top: 0rpx;
  354. z-index: 999;
  355. }
  356. .card {
  357. position: relative;
  358. margin-top: 30rpx;
  359. border-radius: 10rpx;
  360. padding: 15rpx;
  361. display: flex;
  362. .left {
  363. display: flex;
  364. justify-content: center;
  365. align-items: center;
  366. image {
  367. width: 210rpx;
  368. height: 210rpx;
  369. border-radius: 10rpx;
  370. }
  371. }
  372. .right {
  373. margin-left: 20rpx;
  374. display: flex;
  375. flex-direction: column;
  376. justify-content: space-between;
  377. .title {
  378. font-weight: 800;
  379. color: #353535;
  380. font-size: 32rpx;
  381. }
  382. .desc {
  383. color: #888888;
  384. line-height: 40rpx;
  385. padding-top: 20rpx;
  386. font-size: 26rpx;
  387. }
  388. .bottom {
  389. display: flex;
  390. justify-content: space-between;
  391. width: 100%;
  392. }
  393. }
  394. }
  395. .canvas-hide {
  396. position: fixed;
  397. right: 100vw;
  398. bottom: 100vh;
  399. z-index: -9999;
  400. opacity: 0;
  401. }
  402. </style>