import columnarOption from "../../components/option/columnarOption" import Decimal from "decimal.js/decimal.js" 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.getTabBar().init(); 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 sSeriesName = wx.getStorageSync("sSeriesName") || ''; let obj = { action: "getHealthIndex", sType: "BrandOverview", sTimeType: sTimeType, sBrand: this.data.sBrand, sStartTime: sStartTime, sEndTime: sEndTime, // sSeriesName: sSeriesName, 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 = Math.round((new Decimal(res.affections[0].value).div(new Decimal(this.data.totalNum))).toFixed(2) * 100); let negativeDx = Math.round((new Decimal(res.affections[2].value).div(new Decimal(this.data.totalNum))).toFixed(2) * 100); let neutralDx = Math.round((new Decimal(res.affections[1].value).div(new Decimal(this.data.totalNum))).toFixed(2) * 100); let lowLevelCrisis = Math.round((new Decimal(res.crisis[0].value).div(new Decimal(negativeNum))).toFixed(2) * 100); let intermediateCrisis = Math.round((new Decimal(res.crisis[1].value).div(new Decimal(negativeNum))).toFixed(2) * 100); let seniorCrisis = Math.round((new Decimal(res.crisis[2].value).div(new Decimal(negativeNum))).toFixed(2) * 100); this.setData({ healthIndex: 100, 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 sCrisis = wx.getStorageSync("sCrisis") || '1,2,3'; let sSeriesName = wx.getStorageSync("sSeriesName") || ''; let obj = { action: "getList", sTimeType: sTimeType, sStartTime: sStartTime, sEndTime: sEndTime, iPageIndex: 1, iPageSize: 5, sType: "BrandData", sCrisis: sCrisis, sBrand: this.data.sBrand, // sSeriesName: sSeriesName, 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 sSeriesName = wx.getStorageSync("sSeriesName") || ''; let obj = { action: "getHotEventsList0528", sType: "HotEvent", iPageIndex: 1, iPageSize: 5, sTimeType: sTimeType, sBrand: this.data.sBrand, sStartTime: sStartTime, sEndTime: sEndTime, // sSeriesName: sSeriesName, 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 sSeriesName = wx.getStorageSync("sSeriesName") || ''; let obj = { action: "getWebsite", sType: "BrandOverview", sTimeType: sTimeType, sStartTime: sStartTime, sEndTime: sEndTime, sBrand: this.data.sBrand, // sSeriesName: sSeriesName, 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 }) }) }, handlerCrisis(e) { let row = e.currentTarget.dataset.row; let id = row._id; wx.navigateTo({ url: '/pages/detail/index?id=' + id }) }, handlerSet() { wx.navigateTo({ url: '/pages/brandCrisis/crisiSet/index?brand=' + this.data.sBrand }) }, handlerGoList() { wx.navigateTo({ url: '/pages/brandCrisis/crisisList/index?brand=' + this.data.sBrand }) } })