home.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  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"></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. /**
  147. * 更换主题
  148. */
  149. async fetchTabbar() {
  150. this.tabbar = tabbar
  151. if (this.vuex_theme.bgColor) {
  152. this.tabbar.activeColor = this.vuex_theme.bgColor
  153. } else {
  154. this.tabbar.activeColor = this.$config.themeRed.theme.bgColor
  155. }
  156. },
  157. /**
  158. * 获取活动详情
  159. */
  160. async activeDetail() {
  161. let params = {
  162. id: this.activeId
  163. }
  164. this.$api.activerecord.detail(params).then(res => {
  165. this.activeInfo = res.data.data;
  166. })
  167. },
  168. /**
  169. * 获取通知公告
  170. */
  171. async getNotice() {
  172. let params = {
  173. activeId: this.activeId,
  174. title: '活动通知'
  175. }
  176. this.$api.notice.list(params).then(res => {
  177. let notices = res.data.data.records
  178. if (this.$isNotEmpty(notices) && this.$isNotEmpty(notices[0].content)) {
  179. this.noticeContent.push(util.formatHtml(notices[0].content))
  180. }
  181. })
  182. },
  183. /**
  184. * 处理路由转发
  185. */
  186. async handelRoute(options) {
  187. const {
  188. path
  189. } = options;
  190. await this.initParams(options);
  191. if (this.$isNotEmpty(path)) {
  192. this.$jump(decodeURIComponent(path))
  193. }
  194. },
  195. /**
  196. * 获取默认活动id
  197. */
  198. async getDefaultActiveId() {
  199. let params = {
  200. platformSettingEnum: 'COMMON_SETTING'
  201. }
  202. let defaultActiveId = JSON.parse((await this.$api.platform.getPlatformValue(params)).data.data)
  203. .defaultActiveId;
  204. return defaultActiveId
  205. },
  206. /**
  207. * 获取活动参数
  208. */
  209. async getActivityParams() {
  210. let params = {
  211. activeId: this.activeId,
  212. platformSettingEnum: 'ACTIVE_SETTING'
  213. }
  214. let activeSetting = JSON.parse((await this.$api.platform.getPlatformValue(params)).data.data);
  215. this.$config.setTheme(activeSetting.theme, this)
  216. // #ifdef H5
  217. if (this.$isNotEmpty(activeSetting.shareParam)) {
  218. let shareParam = activeSetting.shareParam
  219. shareParam.link = window.location.href
  220. this.$shareConfig.H5Share(shareParam)
  221. }
  222. // #endif
  223. activeSetting.defaultActiveId = this.activeId
  224. this.$u.vuex('vuex_active_setting', activeSetting);
  225. },
  226. /**
  227. * 获取首页参数
  228. */
  229. async initParams(options) {
  230. const activeId = options.activeId
  231. if (this.$isNotEmpty(activeId)) {
  232. //活动列表传进来
  233. this.activeId = activeId
  234. } else if (this.$isNotEmpty(this.vuex_active_setting) &&
  235. this.$isNotEmpty(this.vuex_active_setting.defaultActiveId)) {
  236. //缓存中有活动id
  237. this.activeId = this.vuex_active_setting.defaultActiveId
  238. } else {
  239. //获取默认的活动id
  240. this.activeId = await this.getDefaultActiveId()
  241. }
  242. await this.getActivityParams(activeId)
  243. this.getNotice()
  244. this.activeDetail();
  245. //获取排行榜
  246. this.mescroll.resetUpScroll();
  247. //获取轮播图
  248. let gridList = this.vuex_active_setting.functionItemList
  249. if (this.$isNotEmpty(gridList)) {
  250. this.gridList = gridList.filter(item => item.show == 1)
  251. this.gridClass = 'col-' + this.gridList.length
  252. }
  253. // console.log(gridList, "gridList");
  254. this.swiperList = this.vuex_active_setting.indexImageList
  255. },
  256. jump(item) {
  257. if (item.name == '排行榜') {
  258. item.path = '/pages/rank/rank?activeId=' + this.activeId
  259. }
  260. if (item.name == '报名参赛') {
  261. //登录后才可以参赛
  262. this.applyUrl = `${item.path}?activeId=${this.activeId}&activeType=${this.activeInfo.type}`
  263. this.login()
  264. return;
  265. }
  266. uni.navigateTo({
  267. url: item.path
  268. })
  269. },
  270. init() {
  271. this.goApply()
  272. },
  273. goApply() {
  274. let nowTime = new Date().getTime();
  275. let startTime = this.$dateTime.getTime(this.activeInfo.uploadProductStartTime)
  276. let endTime = this.$dateTime.getTime(this.activeInfo.uploadProductEndTime)
  277. if (nowTime < startTime) {
  278. this.$refs.toast.info("报名未开始");
  279. } else if (nowTime > endTime) {
  280. this.$refs.toast.info("报名已结束");
  281. } else {
  282. uni.navigateTo({
  283. url: this.applyUrl
  284. })
  285. }
  286. },
  287. searchWorks() {
  288. let params = {
  289. activeId: this.activeId,
  290. keyword: this.keyword
  291. }
  292. this.$api.activity.searchWork(params).then(res => {
  293. this.worksList = res.data.data;
  294. })
  295. },
  296. downCallback() {
  297. setTimeout(() => {
  298. this.mescroll.resetUpScroll();
  299. }, 1000)
  300. },
  301. upCallback(mescroll) {
  302. try {
  303. let params = {
  304. current: mescroll.num,
  305. size: mescroll.size,
  306. activeId: this.activeId
  307. }
  308. this.$api.activity.sortListQuery(params).then(res => {
  309. // console.log(res.data.data.records);
  310. let data = res.data.data.records
  311. let total = res.data.data.total
  312. mescroll.endBySize(data.length, total);
  313. if (mescroll.num == 1) this.worksList = []; //如果是第一页需手动制空列表
  314. this.worksList = this.worksList.concat(data); //追加新数据
  315. })
  316. } catch (e) {
  317. console.error(e);
  318. this.mescroll.endErr()
  319. }
  320. },
  321. }
  322. }
  323. </script>
  324. <style>
  325. page {
  326. background-color: #FFFFFF;
  327. }
  328. </style>
  329. <style lang="scss" scoped>
  330. .shadow {
  331. box-shadow: #f8f8f8 0px 0px 10rpx 10rpx
  332. }
  333. .rank-tag {
  334. color: #FFFFFF;
  335. width: 40rpx;
  336. height: 46rpx;
  337. position: absolute;
  338. left: 10rpx;
  339. top: 0rpx;
  340. z-index: 999;
  341. }
  342. .card {
  343. position: relative;
  344. margin-top: 30rpx;
  345. border-radius: 10rpx;
  346. padding: 15rpx;
  347. display: flex;
  348. .left {
  349. display: flex;
  350. justify-content: center;
  351. align-items: center;
  352. image {
  353. width: 210rpx;
  354. height: 210rpx;
  355. border-radius: 10rpx;
  356. }
  357. }
  358. .right {
  359. margin-left: 20rpx;
  360. display: flex;
  361. flex-direction: column;
  362. justify-content: space-between;
  363. .title {
  364. font-weight: 800;
  365. color: #353535;
  366. font-size: 32rpx;
  367. }
  368. .desc {
  369. color: #888888;
  370. line-height: 40rpx;
  371. padding-top: 20rpx;
  372. font-size: 26rpx;
  373. }
  374. .bottom {
  375. display: flex;
  376. justify-content: space-between;
  377. width: 100%;
  378. }
  379. }
  380. }
  381. .canvas-hide {
  382. position: fixed;
  383. right: 100vw;
  384. bottom: 100vh;
  385. z-index: -9999;
  386. opacity: 0;
  387. }
  388. </style>