123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- import {
- getActivities
- } from '~/api/global'
- Component({
- properties: {
- classify: {
- type: Number,
- value: 1
- }
- },
- /**
- * 组件的初始数据
- */
- data: {
- //1:图片,2:邀新榜,3:热播榜,4:挑战pk榜,5,朗读赛,6,领取勋章,7年包红包8,次数红包
- type: '4',
- activityList: [],
- dsqList: []
- },
- lifetimes: {
- attached() {
- this.getActivities()
- },
- detached() {
- this.data.dsqList.forEach(item => {
- clearInterval(item)
- })
- }
- },
- /**
- * 组件的方法列表
- */
- methods: {
- async getActivities() {
- let activityList = await getActivities({
- classify: this.properties.classify
- })
- console.log(activityList);
- this.setData({
- activityList
- })
- // console.log(activityList);
- // 下面这个处理限时活动的,第一版先不上
- // activityList.forEach((item, index) => {
- // if (item.bannerType == 4 && item.voucherType) {
- // // this.activityTimeOut(1677109150000, index)
- // this.activityTimeOut(item.endTime, index)
- // }
- // })
- },
- jumpUserInfo({
- currentTarget
- }) {
- if (!currentTarget.dataset.uid) {
- return
- }
- wx.navigateTo({
- url: `/pages/personal/index?uid=${currentTarget.dataset.uid}&type=user`,
- })
- },
- activityTimeOut(oTime, index) {
- let inputTime = new Date(oTime)
- let dsq = setInterval(() => {
- console.log('1');
- var nowTime = new Date();
- //把剩余时间毫秒数转化为秒
- var times = (inputTime - nowTime) / 1000;
- if (times <= 0) {
- this.setData({
- [`activityList[${index}].hour`]: '00',
- [`activityList[${index}].minute`]: '00',
- [`activityList[${index}].second`]: '00',
- })
- return clearInterval(dsq)
- }
- //计算小时数 转化为整数
- var h = parseInt(times / 60 / 60 % 24);
- //如果小时数小于 10,要变成 0 + 数字的形式 赋值给盒子
- let hour = h < 10 ? "0" + h : h;
- //计算分钟数 转化为整数
- var m = parseInt(times / 60 % 60);
- //如果分钟数小于 10,要变成 0 + 数字的形式 赋值给盒子
- let minute = m < 10 ? "0" + m : m;
- //计算描述 转化为整数
- var s = parseInt(times % 60);
- //如果秒钟数小于 10,要变成 0 + 数字的形式 赋值给盒子
- let second = s < 10 ? "0" + s : s;
- this.setData({
- [`activityList[${index}].hour`]: hour,
- [`activityList[${index}].minute`]: minute,
- [`activityList[${index}].second`]: second,
- })
- times = --times;
- }, 1000);
- this.setData({
- dsqList: [...this.data.dsqList, dsq]
- })
- },
- activityEvent({
- currentTarget
- }) {
- //1:图片,2:邀新榜,3:热播榜,4:挑战pk榜,5,朗读赛,6,领取勋章
- let {
- type,
- id,
- title,
- explain
- } = currentTarget.dataset.info
- if (type == 1) {
- wx.navigateTo({
- url: `/pages/rankIntro/index?title=${title}&img=${explain}`,
- })
- }
- if (type == 5) {
- wx.navigateTo({
- url: `/pages/match/index`,
- })
- }
- if ([2, 3, 4].includes(type)) {
- wx.navigateTo({
- url: `/pages/ranking/index?id=${id}&type=${type}`,
- })
- }
- },
- drawVoucher({
- currentTarget
- }) {
- let info = currentTarget.dataset.info
- this.selectComponent('#voucher').open({
- type: info.type,
- id: info.id,
- voucherType: info.voucherType,
- preferential: info.price
- })
- }
- }
- })
|