index.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. import $ from './../../utils/Tool'
  2. import router from './../../utils/router'
  3. import {getSpaceNum ,getfeedbackSeason,getCurrentSeason} from '../../requests/api';
  4. function chartFn(data=[]) {
  5. return function onInitChart(canvas, width, height, F2) { // 使用 F2 绘制图表F2, config
  6. const chart = new F2.Chart({
  7. el: canvas,
  8. width,
  9. height,
  10. // padding:[10,-10,0,30]
  11. });
  12. chart.legend(false);
  13. chart.source(data, {
  14. 数值: {
  15. tickCount: 2,
  16. formatter: (v) => {
  17. return v +'次'
  18. },
  19. }
  20. });
  21. chart.axis("数值",{
  22. grid:null,
  23. });
  24. chart.interval()
  25. .position('温度*数值')
  26. .color('name',['#04B49C','#FF8800']).size(10).adjust({
  27. type: 'dodge',
  28. marginRatio: 0.001 // 设置分组间柱子的间距
  29. });
  30. // .adjust('stack');
  31. chart.render();
  32. return chart;
  33. }
  34. }
  35. Page({
  36. data: {
  37. headerShow:false,
  38. seasonList:[ //Warm, Cooling, Transition
  39. {name:"供冷季",id:"Cooling"},
  40. {name:"供暖季",id:"Warm"},
  41. {name:"过渡季",id:"Transition"}
  42. ],
  43. seasonType:"",
  44. opts:{
  45. // onInit: onInitChart
  46. },
  47. spaceFeedbackNum:0,
  48. adjustSpaceNum:0,
  49. currentSeason:'',
  50. nochartDate:false,
  51. bgSeasonType:'Cooling',
  52. spaceIds:[],
  53. },
  54. goBack(){
  55. router.pop();
  56. },
  57. gotoFeedback(e){
  58. console.log(e)
  59. router.push("feedback")
  60. },
  61. gotoAdjustlog(e){
  62. let {type} =e.currentTarget.dataset;
  63. router.push("adjustlog",{spaceFeedbackNum:this.data.spaceFeedbackNum,type:type})
  64. },
  65. gotoSpacelog(e){
  66. router.push("spacelog",this.data.spaceIds)
  67. },
  68. changeSeason(e){
  69. let type=e.currentTarget.dataset.index;
  70. this.setData({seasonType:type},()=>{
  71. this.getSeasonchart();
  72. })
  73. },
  74. // opts.onInit.changeData
  75. getSeasonchart(){
  76. let data={
  77. "criteria": {
  78. "projectId":$.store.get('projectId') ,
  79. "openid":$.store.get('openId'),
  80. "userId":$.store.get('userId'),
  81. "seasonType":this.data.seasonType// 季节类型 Warm, Cooling, Transition
  82. },
  83. "orders": [
  84. {
  85. "column": "fbTemp",
  86. "asc": true
  87. }
  88. ]
  89. }
  90. getfeedbackSeason(data).then(res=>{
  91. if(res.count){
  92. let {content} =res;
  93. let arrChart=[];
  94. content.forEach(item => {
  95. if(item.fbTemp=="-9999"){
  96. return
  97. }
  98. let objCold = {
  99. name:'冷',
  100. 温度:item.fbTemp+'°C',
  101. 数值:item.fbColdNum
  102. };
  103. let objHot= {
  104. name:'热',
  105. 温度:item.fbTemp+'°C',
  106. 数值:item.fbHotNum
  107. };
  108. arrChart.push(objCold);
  109. arrChart.push(objHot);
  110. });
  111. if(arrChart.length){
  112. this.setData({nochartDate:false})
  113. let chartdom = this.selectComponent('#column-dom');
  114. chartdom.init(chartFn(arrChart));
  115. }else{
  116. this.setData({nochartDate:true})
  117. }
  118. }else{
  119. this.setData({nochartDate:true})
  120. }
  121. })
  122. },
  123. getSpacefeedNum(){
  124. let data={
  125. "criteria": {
  126. "projectId":$.store.get('projectId'),
  127. "userId":$.store.get('userId')
  128. },
  129. "orders": [
  130. {
  131. "column": "createTime",
  132. "asc": false
  133. }
  134. ]
  135. }
  136. getSpaceNum(data).then(res=>{
  137. this.setData({
  138. spaceFeedbackNum:res.spaceFeedbackNum,
  139. adjustSpaceNum:res.adjustSpaceNum,
  140. spaceIds:res.spaceIds||[],
  141. })
  142. })
  143. },
  144. async getnowSeason(){
  145. let day = new Date();
  146. let year = day.getFullYear();
  147. let month = day.getMonth() + 1;
  148. let today = day.getDate();
  149. const data={
  150. projectId:$.store.get('projectId'),
  151. date:`${year}${month}${today}`
  152. }
  153. await getCurrentSeason(data).then(res=>{
  154. if(res.result=="success"){
  155. this.setData({seasonType:res.data,bgSeasonType:res.data},()=>{
  156. })
  157. }
  158. })
  159. },
  160. /**
  161. * 生命周期函数--监听页面加载
  162. */
  163. async onLoad(options) {
  164. this.getSpacefeedNum();
  165. await this.getnowSeason();
  166. this.getSeasonchart();
  167. },
  168. /**
  169. * 生命周期函数--监听页面初次渲染完成
  170. */
  171. onReady: function () {
  172. setTimeout(()=>{
  173. this.setData({headerShow:true})
  174. },500)
  175. },
  176. /**
  177. * 生命周期函数--监听页面显示
  178. */
  179. onShow: function () {
  180. },
  181. })