// template/admission-box/admission-box.js var miucms = require('../../utils/miucms.js'); var common = require('../../utils/commonMethod.js'); const util = require("../../utils/util") const app = getApp() Component({ /** * 组件的属性列表 */ properties: { initFinish: { type: Boolean, value: false, observer(res) { if (res) this.getAdmissionsOfficer() } }, }, /** * 组件的初始数据 */ data: { urls: [], countdownInterval: null, countDown: { days: 0, hours: '00', minutes: '00', seconds: '00', }, admissionCurrent: 0, countDownState: false, }, /** * 组件的方法列表 */ methods: { getAdmissionsOfficer() { util.wxget('/api/project.other/admissionOfficerIn').then(res => { if (res.code != 200) return const data = res.data || [] const today = new Date() today.setHours(0, 0, 0, 0) let list = [] for (var i in data) { const item = data[i]; for (var ii in item) { const ite = item[ii]; list.push(...ite) } } let urls = [] console.log("list", list); list.forEach(element => { element.urls.forEach(ele => { urls.push({ ...ele, logo: element.schoollogo }) }) }) urls.sort((a, b) => b.rank - a.rank); urls.forEach(element => { let mold = null let timestamp = "" if (!element.date || (typeof element.date == 'string' && element.date.indexOf("答疑") >= 0)) mold = 3; else { const date = new Date(element.date); if (!isNaN(date.getTime())) { if (date >= today) mold = 1 else mold = 2 if (Date.now() < date.getTime()) timestamp = date.getTime() - Date.now() } else mold = 3 } element['mold'] = mold element['timestamp'] = timestamp }) this.setData({ urls, }) if (urls.length != 0) this.setCountDown(0) }) }, bindanimationfinish(e) { const current = e.detail.current || 0 this.setData({ admissionCurrent: current }) this.setCountDown(current) }, setCountDown(index) { const urls = this.data.urls clearTimeout(this.data.countdownInterval); if (urls[index]['timestamp']) this.startCountdown(urls[index]['timestamp']) else { this.setData({ countDownState: false, }) } }, startCountdown(duration) { clearTimeout(this.data.countdownInterval); let timer = duration; const days = Math.floor(timer / (24 * 60 * 60 * 1000)); const hours = Math.floor((timer % (24 * 60 * 60 * 1000)) / (60 * 60 * 1000)); const minutes = Math.floor((timer % (60 * 60 * 1000)) / (60 * 1000)); const seconds = Math.floor(timer % (60 * 1000) / 1000); this.setData({ countDown: { days, hours: hours.toString().padStart(2, '0'), minutes: minutes.toString().padStart(2, '0'), seconds: seconds.toString().padStart(2, '0'), }, countDownState: true, }); timer = timer - 1000 if (timer > 0) this.data.countdownInterval = setTimeout(() => this.startCountdown(timer), 1000) }, goPage(e) { const url = e.currentTarget.dataset.url common.goPage(url) }, } })