index.js 5.0 KB

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