123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 |
- import $ from './../../utils/Tool'
- import router from './../../utils/router'
- import {getSpaceNum ,getfeedbackSeason,getCurrentSeason} from '../../requests/api';
- function chartFn(data=[]) {
- return function onInitChart(canvas, width, height, F2) { // 使用 F2 绘制图表F2, config
- const chart = new F2.Chart({
- el: canvas,
- width,
- height,
- // padding:[10,-10,0,30]
- });
- chart.legend(false);
- chart.source(data, {
- 数值: {
- tickCount: 2,
- formatter: (v) => {
- if(v==0){
- return v
- }
- return v +'次'
- },
- }
- });
- chart.axis("数值",{
- grid:null,
- });
- let size = 9;
- if(data&&data.length&&data.length>=20){
- size=6;
- }
- chart.interval()
- .position('温度*数值')
- .color('name',['#04B49C','#FF8800']).size(size).adjust({
- type: 'dodge',
- marginRatio: 0.001 // 设置分组间柱子的间距
- });
- // .adjust('stack');
- chart.render();
- return chart;
- }
- }
- Page({
- data: {
- headerShow:false,
- seasonList:[ //Warm, Cooling, Transition
- {name:"供冷季",id:"Cooling"},
- {name:"供暖季",id:"Warm"},
- {name:"过渡季",id:"Transition"}
- ],
- seasonType:"",
- opts:{
- // onInit: onInitChart
- },
- spaceFeedbackNum:0,
- adjustSpaceNum:0,
- currentSeason:'',
- nochartDate:false,
- bgSeasonType:'Cooling',
- spaceIds:[],
- },
- goBack(){
- router.pop();
- },
- gotoFeedback(e){
- console.log(e)
- router.push("feedback")
- },
- gotoAdjustlog(e){
- let {type} =e.currentTarget.dataset;
- router.push("adjustlog",{spaceFeedbackNum:this.data.spaceFeedbackNum,type:type})
- },
- gotoSpacelog(e){
- router.push("spacelog",this.data.spaceIds)
- },
- changeSeason(e){
- let type=e.currentTarget.dataset.index;
- this.setData({seasonType:type},()=>{
- this.getSeasonchart();
- })
- },
- // opts.onInit.changeData
- getSeasonchart(){
- let data={
- "criteria": {
- "projectId":$.store.get('projectId') ,
- "openid":$.store.get('openId'),
- "userId":$.store.get('userId'),
- "seasonType":this.data.seasonType// 季节类型 Warm, Cooling, Transition
- },
- "orders": [
- {
- "column": "fbTemp",
- "asc": true
- }
- ]
- }
- getfeedbackSeason(data).then(res=>{
- if(res.count){
- let {content} =res;
- let arrChart=[];
- let arrlength = content&&(content.length-1);
- content.forEach((item,index) => {
- if(item.fbTemp=="-9999"){
- return
- }
- let objCold = {
- name:'冷',
- 温度:item.fbTemp+'',
- 数值:item.fbColdNum
- };
- let objHot= {
- name:'热',
- 温度:item.fbTemp+'',
- 数值:item.fbHotNum
- };
- if(arrlength===index){
- objCold = {
- name:'冷',
- 温度:item.fbTemp+'°C',
- 数值:item.fbColdNum
- };
- objHot= {
- name:'热',
- 温度:item.fbTemp+'°C',
- 数值:item.fbHotNum
- };
- }
- arrChart.push(objCold);
- arrChart.push(objHot);
- });
- if(arrChart.length){
- this.setData({nochartDate:false})
- let chartdom = this.selectComponent('#column-dom');
- chartdom.init(chartFn(arrChart));
- }else{
- this.setData({nochartDate:true})
- }
- }else{
- this.setData({nochartDate:true})
- }
- })
- },
- getSpacefeedNum(){
- let data={
- "criteria": {
- "projectId":$.store.get('projectId'),
- "userId":$.store.get('userId')
- },
- "orders": [
- {
- "column": "createTime",
- "asc": false
- }
- ]
- }
- getSpaceNum(data).then(res=>{
- this.setData({
- spaceFeedbackNum:res.spaceFeedbackNum,
- adjustSpaceNum:res.adjustSpaceNum,
- spaceIds:res.spaceIds||[],
- })
- })
- },
- async getnowSeason(){
- let day = new Date();
- let year = day.getFullYear();
- let month = day.getMonth() + 1;
- month=month<10?('0'+month):month;
- let today = day.getDate();
- today=today<10?('0'+today):today;
- const data={
- projectId:$.store.get('projectId')||$.storage.get('projectId'),
- date:`${year}${month}${today}`
- }
- await getCurrentSeason(data).then(res=>{
- if(res.result=="success"){
- this.setData({seasonType:res.data,bgSeasonType:res.data},()=>{
- })
- }
- })
- },
- /**
- * 生命周期函数--监听页面加载
- */
- async onLoad(options) {
- this.getSpacefeedNum();
- await this.getnowSeason();
- this.getSeasonchart();
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- setTimeout(()=>{
- this.setData({headerShow:true})
- },500)
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- })
|