// components/toufang/index.ts namespace hangyezhanbi{ let { getRatio } = require('../../../../utils/api') let first = true; Component({ /** * 组件的属性列表 */ properties: { array: { type: Object }, channel: { type: Object }, }, observers: { 'array': function () { !first && this.upData() }, 'channel': function () { !first && this.upData() } }, ready() { this.init(); first = false; }, /** * 组件的初始数据 */ data: { onInitChart: undefined, DayList: [], select_act: 0, select: [ { text: "费用", proportionType: "fee", type: 3, unit: "元", }, { text: "时长", proportionType: "timeSize", type: 2, unit: "分", }, { text: "频次", proportionType: "pinci", type: 1, unit: "次", }, { text: "客户量", proportionType: "customer", type: 4, unit: "个", }, ] }, /** * 组件的方法列表 */ methods: { init() { let channelItem = this.data.channel; let arrayItem = this.data.array; Promise.all([ getRatio({ channelId: channelItem.channelId, order: this.data.select[this.data.select_act].type, end: arrayItem.endDate, start: arrayItem.startDate }), ]).then((res: adDay[][]) => { let total = 0, key = this.data.select[this.data.select_act].proportionType for (let i = 0; i < (res[0] || []).length; i++) { const v:any = (res[0] || [])[i] || {}; total += Number(v[this.data.select[this.data.select_act].proportionType] || 0) } this.setData({ DayList: (res[0] || []).map((v: any) => { v.p = Number(v[this.data.select[this.data.select_act].proportionType] / total * 100).toFixed(2) return v }).sort((a:any,b:any)=>{ return b[key] - a[key] }), }) }) }, upData() { let channelItem = this.data.channel; let arrayItem = this.data.array; Promise.all([ getRatio({ channelId: channelItem.channelId, order: this.data.select[this.data.select_act].type, end: arrayItem.endDate, start: arrayItem.startDate }), ]).then((res: adDay[][]) => { let total = 0, key = this.data.select[this.data.select_act].proportionType for (let i = 0; i < (res[0] || []).length; i++) { const v:any = (res[0] || [])[i] || {}; total += Number(v[this.data.select[this.data.select_act].proportionType] || 0) } this.setData({ DayList: (res[0] || []).map((v: any) => { v.p = Number(v[this.data.select[this.data.select_act].proportionType] / total * 100).toFixed(2) return v }).sort((a:any,b:any)=>{ return b[key] - a[key] }), }) // },()=>upLine.bind(this)()) }) }, channelChange(event:wxPicker){ this.setData({ select_act: Number(event.detail.value) },()=>this.upData()) } } }) }