You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

273 lines
9.9 KiB

import histogram from "../../../components/option/singleColumnarOption"
import stack from "../../../components/option/stackedBarChart"
import sHistogram from "../../../components/option/sColumnarOption"
import pictographicOption from '../../../components/option/pictographicOption'
import negaposiOption from '../../../components/option/negaposiOption2'
const app = getApp()
const dColor = ['#FF4852', '#FF6E25', '#FFBF00', '#20CC62', '#00D6D6', '#00AAFF', '#7257FF']
Component({
data: {
imageUrl: getApp().globalData.imageUrl,
showChart: true,
brandOption: histogram([], [], [], '#0084FF'),
brandOption2: histogram([], [], [], '#20cc62'),
brandOption4: sHistogram(),
stackOption: stack([], [], ['#00aaff', '#20cc62', '#ff4852']),
genderOption: negaposiOption([], {}),
genderOptio2: negaposiOption([], {}),
boxArr: new Array(6),
topActive: 0, //品牌传播
userActive: 0, //活跃用户信息
brandTop: [],
brandTopData: [],
areaActive: 0,
areaData: [],
area: []
},
lifetimes: {
attached() {
let brandRatioTime = wx.getStorageSync('brandRatioTime') || 34
let sBrand = wx.getStorageSync('sBrand')
this.setData({
boxArr: wx.getStorageSync('modelsData')
})
let SeriesName = []
this.data.boxArr.forEach((ele) => {
if (ele) SeriesName.push(ele.name)
})
//微博信息量对比
app.globalData.request({
action: 'getContrastCount0528C',
token: wx.getStorageSync('token'),
sType: 'BrandWeiBo',
...brandRatioTime,
iContrastType: '2',
sBrand: sBrand.join(','),
sSeriesName: SeriesName.join(',')
}).then(res => {
let dx = []
let dy = []
for (let i of res) {
dx.push(i.key)
dy.push(i.value)
}
this.setData({
brandOption: histogram(dx, dy, [], '#0084FF'),
})
})
//微博互动人数
app.globalData.request({
action: 'getInteractCount0528C',
token: wx.getStorageSync('token'),
sType: 'BrandWeiBo',
...brandRatioTime,
iContrastType: '2',
sBrand: sBrand.join(','),
sSeriesName: SeriesName.join(',')
}).then(res => {
let dx = []
let dy = []
for (let i of res) {
dx.push(i.key)
dy.push(i.value)
}
this.setData({
brandOption2: histogram(dx, dy, [], '#20cc62'),
})
})
//微博调性对比
app.globalData.request({
action: 'getAffectionsC',
token: wx.getStorageSync('token'),
sType: 'BrandWeiBo',
...brandRatioTime,
iContrastType: '2',
sBrand: sBrand.join(','),
sSeriesName: SeriesName.join(',')
}).then(res => {
let yMsg = []
let data = [
[],
[],
[]
]
for (let i of res) {
yMsg.push(i.Name)
data[0].push(i.Data['正面'])
data[1].push(i.Data['中性'])
data[2].push(i.Data['负面'])
}
this.setData({
stackOption: stack(yMsg, data,dColor )//['#00aaff', '#20cc62', '#ff4852']
})
})
//微博大V
app.globalData.request({
action: 'getBoauthen0528C',
token: wx.getStorageSync('token'),
sType: 'BrandWeiBo',
...brandRatioTime,
iContrastType: '2',
sBrand: sBrand.join(','),
sSeriesName: SeriesName.join(',')
}).then(res => {
let xMsg = []
for (let i of res[0].value) {
xMsg.push(i.key)
}
let data = new Array(res.length).fill([])
data = data.map(ele => {
ele = JSON.stringify(ele)
ele = JSON.parse(ele)
return ele
})
for (let [index, i] of res.entries()) {
for (let j of i.value) {
data[index].push(j.value)
}
}
//横轴,数据,纵轴
this.setData({
brandOption4: sHistogram(xMsg, data, SeriesName, dColor)
})
})
//微博内容方向对比
app.globalData.request({
action: 'getDirect0528C',
token: wx.getStorageSync('token'),
sType: 'BrandWeiBo',
...brandRatioTime,
iContrastType: '2',
sBrand: sBrand.join(','),
sSeriesName: SeriesName.join(',')
}).then(res => {
for(let i of res){
i = i.Data.sort((a,b)=>{
return Number(b.value) - Number(a.value)
})
}
this.setData({
brandTop: [res[0], res[1]],
brandTopData: res
})
})
//活跃用户信息
app.globalData.request({
action: 'getRegionWeiBoC',
token: wx.getStorageSync('token'),
sType: 'BrandWeiBo',
...brandRatioTime,
iContrastType: '2',
sBrand: sBrand.join(','),
sSeriesName: SeriesName.join(',')
}).then(res => {
let newRes = []
for (let i of res) {
let obj = {
name: i.Name,
region: [],
value: [],
sum: 0
}
let arr = []
Object.keys(i.Data).forEach(ele => {
arr.push({
name: ele,
value: i.Data[ele]
})
})
arr = arr.sort((a, b) => {
return a.value * 1 - b.value * 1
})
for (let j of arr) {
obj.region.push(j.name)
obj.value.push(j.value)
obj.sum += j.value * 1
}
newRes.push(obj)
}
newRes = newRes.map(ele => {
ele.func = [pictographicOption(ele.region.slice(0, 5), ele.value.slice(0, 5), ele.sum),
pictographicOption(ele.region.slice(5, 10), ele.value.slice(5, 10), ele.sum)
]
return ele
})
this.setData({
areaData: newRes,
area: [newRes[0], newRes[1]]
})
})
//男女-认证用户
app.globalData.request({
action: 'getSexMergeWeiBoC',
token: wx.getStorageSync('token'),
sType: 'BrandWeiBo',
...brandRatioTime,
iContrastType: '2',
sBrand: sBrand.join(','),
sSeriesName: SeriesName.join(',')
}).then(res => {
Array.prototype.sum = function () {
let x = 0
this.forEach(ele => {
x += ele
})
return x
}
let sex = {
'男': [],
'未设性别': [],
'女': [],
}
let attestation = {
'普通认证': [],
'机构认证': [],
'非认证': [],
}
for (let i of res) {
Object.keys(i.Data.sex).forEach(ele => {
sex[ele].push(i.Data.sex[ele])
})
Object.keys(i.Data.attestation).forEach(ele => {
attestation[ele].push(i.Data.attestation[ele])
})
}
this.setData({
genderOption: negaposiOption(SeriesName, sex),
genderOption2: negaposiOption(SeriesName, attestation)
})
})
},
},
methods: {
//品牌传播top媒体
changeModalHot(event) {
let obj = {
0: [this.data.brandTopData[0] || {}, this.data.brandTopData[1] || {}],
1: [this.data.brandTopData[2] || {}, this.data.brandTopData[3] || {}],
2: [this.data.brandTopData[4] || {}, this.data.brandTopData[5] || {}]
}
let index = event.detail.index
this.setData({
topActive: index,
brandTop: obj[index]
})
},
changeActiveUser(event) {
let obj = {
0: [this.data.areaData[0] || {}, this.data.areaData[1] || {}],
1: [this.data.areaData[2] || {}, this.data.areaData[3] || {}],
2: [this.data.areaData[4] || {}, this.data.areaData[5] || {}]
}
let index = event.detail.index
this.setData({
areaActive: index,
area: obj[index]
})
},
}
})