daypartingStatisticsWater.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. <template>
  2. <view>
  3. <u-navbar :title="title" title-color="#101010"></u-navbar>
  4. <view class="tabs">
  5. <u-picker v-model="tabsFrom.show1" :default-selector="[tabsFrom.show1Index]" mode="selector"
  6. :range="tabsFrom.selector1" range-key="label" @confirm="selector1confirm"></u-picker>
  7. <u-calendar v-model="tabsFrom.show2" mode="range" @change="selector2confirm">
  8. </u-calendar>
  9. <view class="tabsItem" @click="tabsFrom.show2=!tabsFrom.show2">
  10. {{formData.queryStartDate}}至{{formData.queryEndDate}}
  11. <u-icon
  12. name="arrow-up" v-if="tabsFrom.show2"></u-icon><u-icon v-else name="arrow-down"></u-icon></view>
  13. <view class="tabsItem" @click="tabsFrom.show1=!tabsFrom.show1">
  14. {{formData.timeNode}}时 <u-icon
  15. name="arrow-up" v-if="tabsFrom.show1"></u-icon><u-icon v-else name="arrow-down"></u-icon></view>
  16. </view>
  17. <view class="main">
  18. <view class="title">
  19. <view class="icon">
  20. </view>
  21. <view class="text">
  22. 各时段平均用水量 (m³)
  23. </view>
  24. </view>
  25. <!-- 图表 -->
  26. <view class="chart">
  27. <view id="barEcharts" style="min-height:740rpx;">
  28. </view>
  29. </view>
  30. </view>
  31. </view>
  32. </template>
  33. <script>
  34. import * as echarts from 'echarts';
  35. import * as API_water from '@/apis/pagejs/water.js'
  36. export default {
  37. data() {
  38. return {
  39. params: {
  40. year: true,
  41. month: true,
  42. day: true,
  43. hour: false,
  44. minute: false,
  45. second: false
  46. },
  47. title:"",
  48. formData:{
  49. meterId:"",
  50. queryStartDate:"",
  51. queryEndDate:"",
  52. timeNode:"",
  53. },
  54. info:{},
  55. data:{},
  56. myChart:null,
  57. tabsFrom: {
  58. show1: false,
  59. show1Index: 0,
  60. show2Index: '',
  61. show2: false,
  62. show1Text: "全部类型",
  63. show2Text: "全部时间",
  64. selector1: [
  65. ]
  66. },
  67. }
  68. },
  69. onLoad(op) {
  70. this.formData.meterId=op.meterId
  71. this.formData.queryStartDate=op.queryStartDate
  72. this.formData.queryEndDate=op.queryEndDate
  73. this.formData.timeNode=op.timeNode
  74. this.title=op.title
  75. this.getData()
  76. },
  77. methods: {
  78. selector2confirm(e){
  79. console.log(e)
  80. this.formData.queryStartDate=e.startDate
  81. this.formData.queryEndDate=e.endDate
  82. this.getInfo()
  83. },
  84. selector1confirm(e){
  85. console.log(e)
  86. this.tabsFrom.show1Index=e
  87. this.formData.timeNode=this.tabsFrom.selector1[e].value
  88. this.getInfo()
  89. },
  90. getData(){
  91. uni.showLoading({
  92. title: "加载中",
  93. mask: true,
  94. })
  95. API_water.meterHourConsumption({
  96. meterId:this.formData.meterId
  97. }).then((response) => {
  98. uni.hideLoading();
  99. this.data=response.data
  100. this.tabsFrom.selector1=[]
  101. for(var i in this.data.hourMap ){
  102. this.tabsFrom.selector1.push({
  103. label:i+'时',
  104. value:i
  105. })
  106. if(!this.formData.timeNode){
  107. this.formData.timeNode=i
  108. }
  109. }
  110. this.getInfo()
  111. }).catch(error => {
  112. uni.showToast({
  113. title: error,
  114. icon: "none"
  115. })
  116. })
  117. },
  118. getBarChartsWater(){
  119. var data1 = [];
  120. var data2 = [];
  121. var list=this.info.dayMap;
  122. for (var i in list) {
  123. var obj=list[i]
  124. data1.push(i)
  125. data2.push(obj)
  126. }
  127. if (!this.myChart) {
  128. //this.myChart = echarts.init(document.getElementById('barEcharts'));
  129. this.myChart = echarts.init(document.getElementById('barEcharts'), null, {
  130. height: uni.upx2px(data2.length*80+100)
  131. });
  132. }
  133. this.myChart.resize({
  134. height:uni.upx2px(data2.length*80+100)
  135. })
  136. var option = {
  137. tooltip: {
  138. trigger: 'axis',
  139. axisPointer: {
  140. type: 'shadow'
  141. },
  142. },
  143. grid: {
  144. top: 10,
  145. left: 0,
  146. right: 30,
  147. bottom: 20,
  148. containLabel: true
  149. },
  150. xAxis: {
  151. type: 'value',
  152. data: data1,
  153. },
  154. yAxis: {
  155. type: 'category',
  156. data: data1,
  157. axisLabel: {
  158. rotate: 20,
  159. interval: 0,
  160. textStyle: {
  161. color: "#333"
  162. }
  163. },
  164. },
  165. series: [{
  166. name: '平均用水量',
  167. data: data2,
  168. type: 'bar',
  169. label: {
  170. show: true,
  171. position: 'right',
  172. color: '#5C7BD9'
  173. },
  174. itemStyle: {
  175. color: '#387aea' // 设置所有柱子的颜色为'#4FE773'
  176. }
  177. }
  178. ]
  179. }
  180. console.log(option)
  181. this.myChart.setOption(option);
  182. },
  183. getInfo(){
  184. uni.showLoading({
  185. title: "加载中",
  186. mask: true,
  187. })
  188. API_water.meterHourConsumptionDetails(this.formData).then((response) => {
  189. uni.hideLoading();
  190. this.info=response.data
  191. if(this.myChart){
  192. this.myChart.clear();
  193. }
  194. this.$nextTick(()=>{
  195. this.getBarChartsWater()
  196. })
  197. }).catch(error => {
  198. uni.showToast({
  199. title: error,
  200. icon: "none"
  201. })
  202. })
  203. },
  204. }
  205. }
  206. </script>
  207. <style lang="scss" scoped>
  208. // 标签
  209. .tabs {
  210. height: 96rpx;
  211. line-height: 96rpx;
  212. background-color: #fff;
  213. border-top: 1px solid rgba(241, 241, 241, 1);
  214. display: flex;
  215. justify-content: space-around;
  216. }
  217. .main{
  218. background-color: #fff;
  219. border-radius: 8px;
  220. padding: 32rpx ;
  221. margin: 32rpx;
  222. .tips{
  223. display: flex;
  224. justify-content: space-around;
  225. color: rgba(119,119,119,1);
  226. font-size: 24rpx;
  227. }
  228. .title{
  229. display: flex;
  230. align-items: center;
  231. margin-bottom: 20px;
  232. .icon{
  233. width: 36rpx;
  234. height: 36rpx;
  235. background-color: #b6d4ff;
  236. border: 6px solid #1677ff;
  237. border-radius: 100px;
  238. }
  239. .text{
  240. color: #333333;
  241. font-size: 36rpx;
  242. margin-left: 16rpx;
  243. font-weight: bold;
  244. }
  245. .date{
  246. margin-left: auto;
  247. border: 1px solid #bbbbbb;
  248. border-radius: 4px;
  249. padding: 4px;
  250. font-size: 12px;
  251. text{
  252. margin-right: 8rpx;
  253. }
  254. }
  255. }
  256. // 图标
  257. .chart{
  258. img{
  259. width: 100%;
  260. height: 440rpx;
  261. }
  262. }
  263. }
  264. </style>