// pages/channelRanking/index.ts const chartCatch: antvChart = { toufangfenxiChart: undefined } let { getChannelRank } = require('../../utils/api') Page({ /** * 页面的初始数据 */ data: { array: [ { key: "fee", name: "费用", unit: "元", type: 1, }, { key: "timeSize", name: "时长", unit: "分", type: 2, }, { key: "pinci", name: "频次", unit: "次", type: 3, } ], list: [], array_act: 0, showCalendar: false, start: "", end: '', startDate: new Date(2022, 0, 1).getTime(), endDate: 0, }, formmater(date: any): string[] { const d = new Date(date); let month: string | number = d.getMonth() + 1; let day: string | number = d.getDate(); month > 9 ? "" : month = '0' + month; day > 9 ? "" : day = '0' + day; return [ d.getFullYear().toString(), month.toString(), day.toString() ] }, confirm(e: any) { const start: string = this.formmater(e.detail[0]).join('-'); const end: string = this.formmater(e.detail[1]).join('-'); this.setData({ start, end, showCalendar: false }, () => this.getselect()) }, onClose() { this.setData({ showCalendar: false }) }, timeSelect() { this.setData({ showCalendar: true }) }, bindPickerChange(e: any) { this.setData({ array_act: e.detail.value }, () => this.getselect()) }, getselect() { let s = new Date(this.data.start + ' 00:00:00'), e = new Date(this.data.end + ' 23:59:59'); if (e.getTime() - s.getTime() < 0) return wx.showToast({ title: "时间选择错误", icon: "none" }) const p: any = { start: this.data.start, end: this.data.end, dataType: this.data.array[this.data.array_act].type } getChannelRank(p).then((res: any) => { p.list = (res || []) p.height = (res || []).length < 2 ? 20 : (res || []).length * 5; this.setData(p) }) return }, /** * 生命周期函数--监听页面加载 */ onLoad() { const nowDate = new Date(); const nTime = nowDate.getTime(); const date = new Date(nTime - 86400000); let month: string | number = date.getMonth() + 1; let day: string | number = date.getDate(); month > 9 ? "" : month = '0' + month; day > 9 ? "" : day = '0' + day; let start = [date.getFullYear(), month, day].join("-"); let end = [date.getFullYear(), month, day].join("-"); let dataType = this.data.array[this.data.array_act].type; getChannelRank({ start, end, dataType }).then((res: any) => { this.setData({ endDate: nTime, list: res || [], start, end, dataType }) }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { /** * 生命周期函数--监听页面隐藏 */ }, onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })