index.js 4.5 KB

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