import columnarOption from "../../components/option/columnarOption" import {floatDivide} from "../../utils/decimal" const app = getApp(); Page({ data: { imageUrl: getApp().globalData.imageUrl, healthCrisis: "background-image: url(" + getApp().globalData.imageUrl + "/health-crisis.png);margin-top: 0px; height: 750rpx;", healthGood: "background-image: url(" + getApp().globalData.imageUrl + "/health-good.png);", healthGenerally: "background-image: url(" + getApp().globalData.imageUrl + "/health-generally.png);", healthMedium: "background-image: url(" + getApp().globalData.imageUrl + "/health-medium.png);", healthWarning: "background-image: url(" + getApp().globalData.imageUrl + "/health-warning.png);margin-top: 0px; height: 750rpx;", healthIndex: 100, healthIndexMsg: '非常健康', headlBrand: "", topBg: '', sBrand: '奥迪', crisisList: [], crisisNum: 0, totalNum: 0, negativeNum: 0, frontDx: 0, negativeDx: 0, neutralDx: 0, lowLevelCrisis: 0, intermediateCrisis: 0, seniorCrisis: 0, hotEventsList: [], showChart: false, dataOption: {} }, onShow() { this.getBrand().then((res) => { let headlBrand = res; this.setData({ headlBrand: headlBrand }) this.getData(); this.getCrisis(); this.getHotEventsList(); this.getMediaData(); }) }, changeTime(e) { // let sTimeType = e.detail.sTimeType; // let sStartTime = e.detail.sStartTime; // let sEndTime = e.detail.sEndTime; this.getData(); this.getCrisis(); this.getHotEventsList(); this.getMediaData(); }, getBrand() { return new Promise((resolve, reject) => { app.globalData.request({ action: 'getUserMainBrand', token: wx.getStorageSync('token') || 't%2BrswgjvzGM=' }).then(res => { this.setData({ sBrand: res }) resolve(res) }).catch(() => { reject(false) }) }) }, getData() { let sTimeType = wx.getStorageSync("sTimeType") || 34; let sStartTime = wx.getStorageSync("sStartTime") || ''; let sEndTime = wx.getStorageSync("sEndTime") || ''; let obj = { action: "getHealthIndex", sType: "BrandOverview", sTimeType: sTimeType, sBrand: this.data.sBrand, sStartTime: sStartTime, sEndTime: sEndTime, token: wx.getStorageSync('token') || 't%2BrswgjvzGM=', } app.globalData.request(obj, (val) => { this.setData({ totalNum: val.totalNum }) }).then(res => { let healthIndex = res.healthIndex; let healthIndexMsg = res.healthIndexMsg; let topBg = ""; if (healthIndex >= 90) { topBg = '#0084FF' } else if (80 <= healthIndex && healthIndex < 90) { topBg = '#00CA2F' } else if (70 <= healthIndex && healthIndex < 80) { topBg = '#FFCC01' } else if (60 <= healthIndex && healthIndex < 70) { topBg = '#FFA419' } else { topBg = '#FF463C' } let negativeNum = 0; res.crisis.forEach(ele => { negativeNum += ele.value; }) let frontNum = floatDivide(res.affections[0].value,this.data.totalNum).toFixed(2)*100; let negativeDx = floatDivide(res.affections[2].value,this.data.totalNum).toFixed(2)*100; let neutralDx = floatDivide(res.affections[1].value,this.data.totalNum).toFixed(2)*100; let lowLevelCrisis = floatDivide(res.crisis[0].value,negativeNum).toFixed(2)*100; let intermediateCrisis = floatDivide(res.crisis[1].value,negativeNum).toFixed(2)*100; let seniorCrisis = floatDivide(res.crisis[2].value,negativeNum).toFixed(2)*100; this.setData({ healthIndex: healthIndex, topBg: topBg, healthIndexMsg: healthIndexMsg, negativeNum: negativeNum, frontDx: frontNum, negativeDx: negativeDx, neutralDx: neutralDx, lowLevelCrisis: lowLevelCrisis, intermediateCrisis: intermediateCrisis, seniorCrisis: seniorCrisis }) }) }, getCrisis() { let sTimeType = wx.getStorageSync("sTimeType") || 34; let sStartTime = wx.getStorageSync("sStartTime") || ''; let sEndTime = wx.getStorageSync("sEndTime") || ''; let obj = { action: "getList", sTimeType: sTimeType, sStartTime: sStartTime, sEndTime: sEndTime, iPageIndex: 1, iPageSize: 5, sType: "BrandData", sCrisis: '3', sBrand: this.data.sBrand, token: wx.getStorageSync('token') || 't%2BrswgjvzGM=' } app.globalData.request(obj, (val) => { this.setData({ crisisNum: val.totalNum }) }).then(res => { this.setData({ crisisList: res }) }) }, getHotEventsList() { let sTimeType = wx.getStorageSync("sTimeType") || 34; let sStartTime = wx.getStorageSync("sStartTime") || ''; let sEndTime = wx.getStorageSync("sEndTime") || ''; let obj = { action: "getHotEventsList0528", sType: "HotEvent", iPageIndex: 1, iPageSize: 5, sTimeType: sTimeType, sBrand: this.data.sBrand, sStartTime: sStartTime, sEndTime: sEndTime, iTimeType: 0, token: wx.getStorageSync('token') || 't%2BrswgjvzGM=' } app.globalData.request(obj).then(res => { this.setData({ hotEventsList: res }) }) }, getMediaData() { this.setData({ showChart: false }) let sTimeType = wx.getStorageSync("sTimeType") || 34; let sStartTime = wx.getStorageSync("sStartTime") || ''; let sEndTime = wx.getStorageSync("sEndTime") || ''; let obj = { action: "getWebsite", sType: "BrandOverview", sTimeType: sTimeType, sStartTime: sStartTime, sEndTime: sEndTime, sBrand: this.data.sBrand, token: wx.getStorageSync('token') || 't%2BrswgjvzGM=' } app.globalData.request(obj).then(res => { let dx = []; let dy = []; for (let key in res) { dx.push(key); dy.push(res[key]) } let option = columnarOption(dx, dy, '#0084FF'); this.setData({ dataOption: option, showChart: true }) }) } })