yongshuifenxi.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  1. <template>
  2. <div>
  3. <el-row>
  4. <el-col :span="24" class="first-row">
  5. <div class="tag">用水分析</div>
  6. </el-col>
  7. </el-row>
  8. <el-row>
  9. <el-col :span="24" class="second-row">
  10. <el-form :inline="true" class="demo-form-inline">
  11. <el-form-item label="楼栋号:" class="shuibiaoId">
  12. <el-select v-model="drom_options.value" placeholder="请选择" class="my-select"
  13. @change="selectGetBuild(drom_options.value)">
  14. <el-option v-for="item in drom_options.builds" :key="item.value" :label="item.label"
  15. :value="item.value">
  16. </el-option>
  17. </el-select>
  18. </el-form-item>
  19. <el-form-item label="宿舍号:" class="shuibiaoId left-margin">
  20. <el-input placeholder="请输入宿舍号" v-model="room_value" @input="roomInputChange($event)"
  21. maxlength="6" @blur="updateData" @keyup.enter.native="enterBlur($event)" clearable
  22. :disabled="room_select_disabled">
  23. </el-input>
  24. </el-form-item>
  25. </el-form>
  26. <div class="water-total">用水总量:{{yongshuizongliang}}吨</div>
  27. <div class="show-detail" @click="show_detail">查看详情</div>
  28. </el-col>
  29. </el-row>
  30. <hr style="background-color: #CCCCCC;height: 1px;border: 0;">
  31. <el-row>
  32. <el-col :span="24" class="third-row">
  33. <div style="margin-top: 20px">
  34. <div class="pages">
  35. <div class="tip">用水统计图</div>
  36. <div class="right-tip">
  37. <div class="dmy-btn" :class="{my_active:show_active == '日'}" @click="change_riqi('日')">日
  38. </div>
  39. <div class="dmy-btn" :class="{my_active:show_active == '月'}" @click="change_riqi('月')">月
  40. </div>
  41. <div class="dmy-btn" :class="{my_active:show_active == '年'}" @click="change_riqi('年')">年
  42. </div>
  43. </div>
  44. </div>
  45. <!--为echarts准备一个具备大小的容器dom-->
  46. <div id="main" style="width: 100%; height: 500px"></div>
  47. </div>
  48. </el-col>
  49. </el-row>
  50. <el-row>
  51. <el-col :span="24" class="forth-row">
  52. <!-- 详情对话框 -->
  53. <el-dialog title="用水详情" :visible.sync="detail_dialogFormVisible" width="800px" top="0vh"
  54. class="my-dialog" :close-on-click-modal="false" :close-on-press-escape="false">
  55. <hr
  56. style="width: 100%; position: absolute; top: 60px; left: 0px;background-color: #CCCCCC;height: 1px;border: 0;">
  57. <el-form :inline="true" class="demo-form-inline">
  58. <el-form-item label="姓名:" class="shuibiaoId">
  59. <el-input v-model="detail_userName" placeholder="请输入姓名" clearable></el-input>
  60. </el-form-item>
  61. <el-form-item>
  62. <el-button type="primary" @click="onSearch">查找</el-button>
  63. </el-form-item>
  64. </el-form>
  65. <el-table ref="multipleTable" :data="detail_tableData" tooltip-effect="dark" style="width: 100%"
  66. highlight-current-row>
  67. <el-table-column align="center" label="学号">
  68. <template slot-scope="scope">{{ scope.row.stu_number }}</template>
  69. </el-table-column>
  70. <el-table-column align="center" prop="user_name" label="姓名" show-overflow-tooltip>
  71. </el-table-column>
  72. <el-table-column align="center" prop="use_amount" label="用水量" :formatter="formatDun"
  73. show-overflow-tooltip>
  74. </el-table-column>
  75. </el-table>
  76. <div slot="footer" class="dialog-footer">
  77. <div class="dialog-pages">
  78. <el-pagination layout="prev, pager, next"
  79. :current-page.sync="control_table.detail_current_page" :hide-on-single-page="true"
  80. :page-size="control_table.detail_page_rows" @current-change="handleCurrentChange"
  81. :total="control_table.detail_total_rows"></el-pagination>
  82. </div>
  83. </div>
  84. </el-dialog>
  85. </el-col>
  86. </el-row>
  87. </div>
  88. </template>
  89. <script>
  90. export default {
  91. data() {
  92. return {
  93. show_active: '', // 切换年、月、日
  94. charts: "", // 折线图
  95. room_select_disabled: true, // 控制宿舍号是否可以编辑
  96. drom_value: 0, // 楼栋号编码
  97. drom: '', // 楼栋号
  98. room_value: '', // 待搜索的宿舍号
  99. yongshuizongliang: 0.0.toFixed(2), // 用水总量
  100. // 楼栋号下拉列表
  101. drom_options: { // 下拉列表的数据绑定
  102. builds: [{
  103. value: 0,
  104. label: '全部'
  105. }],
  106. value: 0,
  107. label: ''
  108. },
  109. // 详情对话框相关参数
  110. detail_dialogFormVisible: false, // 控制详情对话框显示、隐藏
  111. detail_userName: '', // 姓名用于查询
  112. detail_tableData: [],
  113. control_table: {
  114. detail_current_page: 1,
  115. detail_page_rows: 8,
  116. detail_total_rows: 0
  117. }
  118. }
  119. },
  120. created() {
  121. // 填充楼栋号
  122. this.getBuildsFillSelect()
  123. // 获取用水总量
  124. this.get_total_yongshuizongliang()
  125. // 共用部分,更新图
  126. this.updateData()
  127. },
  128. methods: {
  129. formatDun(row, column, cellValue, index) {
  130. // row: 行数据
  131. // column: 列属性
  132. // cellValue: 单元格数据值
  133. // index: 行索引,注意:2.3.9版本以后才有。
  134. return cellValue.toFixed(2)
  135. },
  136. /**
  137. * 改变页码
  138. * @param {Object} val
  139. */
  140. handleCurrentChange(val) {
  141. this.control_table.detail_current_page = val
  142. this.show_detail()
  143. },
  144. /**
  145. * 显示面积图
  146. */
  147. show_mianjitu(params_dt, params_data) {
  148. var date = [];
  149. var data = [];
  150. for (var i = 0; i < params_dt.length; i++) {
  151. date.push(params_dt[i].replace(/-/g, '/'));
  152. data.push(parseFloat(params_data[i]).toFixed(2));
  153. }
  154. // console.log(data);
  155. var option = {
  156. tooltip: {
  157. trigger: 'axis',
  158. position: function(pt) {
  159. return [pt[0], '10%'];
  160. }
  161. },
  162. xAxis: {
  163. type: 'category',
  164. boundaryGap: false,
  165. data: date
  166. },
  167. yAxis: {
  168. type: 'value',
  169. boundaryGap: [0, '100%']
  170. },
  171. dataZoom: [{
  172. type: 'inside',
  173. start: 0,
  174. end: 100
  175. }, {
  176. start: 0,
  177. end: 100
  178. }],
  179. series: [{
  180. name: '用水量',
  181. type: 'line',
  182. smooth: true,
  183. symbol: 'none',
  184. areaStyle: {},
  185. data: data
  186. }]
  187. };
  188. this.$nextTick(function() {
  189. this.charts = this.$echarts.init(document.getElementById('main'));
  190. this.charts.setOption(option);
  191. });
  192. },
  193. /**
  194. * 获取用水总量
  195. */
  196. get_total_yongshuizongliang() {
  197. let params = {}
  198. if (this.drom) {
  199. params.build = this.drom
  200. }
  201. if (this.room_value) {
  202. dom: this.room_value
  203. }
  204. var _this = this
  205. this.$axios.get('/jxch-smartmp/HotWaters/waterwaterTotal.action', {
  206. params: params
  207. })
  208. .then(res => {
  209. // console.log(res.data);
  210. if (typeof(res.data.size) != 'undefined' && res.data.size != '' && JSON.stringify(res
  211. .data) != '{}') {
  212. this.yongshuizongliang = parseFloat(res.data.size).toFixed(2)
  213. } else {
  214. _this.$message.success('【获取用水总量】暂无数据!');
  215. }
  216. })
  217. .catch(err => {
  218. // console.log(err);
  219. _this.$message.error('【获取用水总量】请求异常: ' + err);
  220. })
  221. },
  222. /**
  223. * 更新宿舍号输入框
  224. * @param {Object} e
  225. */
  226. roomInputChange(e) {
  227. // console.log(e);
  228. this.$forceUpdate()
  229. },
  230. /**
  231. * 获取楼栋号,填充下拉列表
  232. */
  233. getBuildsFillSelect() {
  234. // 获取楼栋号,填充下拉列表
  235. var _this = this
  236. this.$axios.get('/jxch-smartmp/HotWaters/watergetBuilds.action')
  237. .then(res => {
  238. // console.log(res.data);
  239. if (typeof(res.data.builds) != 'undefined' && res.data.builds != '' && JSON.stringify(res
  240. .data) != '{}') {
  241. this.drom_options.builds = [{
  242. value: 0,
  243. label: '全部'
  244. }]
  245. for (var i = 0; i < res.data.builds.length; i++) {
  246. let tmp = {
  247. value: i + 1,
  248. label: res.data.builds[i]
  249. }
  250. this.drom_options.builds.push(tmp)
  251. }
  252. } else {
  253. _this.$message.success('【楼栋号】暂无数据!');
  254. }
  255. })
  256. .catch(err => {
  257. // console.log(err);
  258. _this.$message.error('【楼栋号】请求异常: ' + err);
  259. })
  260. },
  261. /**
  262. * 切换年、月、日,查询相关数据
  263. * @param {Object} riqi
  264. */
  265. change_riqi(riqi) {
  266. this.show_active = riqi
  267. // 获取查询年、月、日的数据的参数
  268. var _this = this
  269. var params = {}
  270. if (typeof(this.drom) != 'undefined' && this.drom != '' && this.drom) {
  271. params.build = this.drom
  272. }
  273. if (typeof(this.room_value) != 'undefined' && this.room_value != '' && this.room_value) {
  274. params.dom = this.room_value
  275. }
  276. // 日用水量
  277. if (riqi == '日') {
  278. // 查询日的数据
  279. this.$axios.get('/jxch-smartmp/HotWaters/waterdayTong.action', {
  280. params: params
  281. })
  282. .then(res => {
  283. // console.log(res.data);
  284. if (typeof(res.data.day) != 'undefined' && res.data.day != '' && JSON.stringify(res
  285. .data) != '{}') {
  286. // 显示面积图
  287. this.show_mianjitu(res.data.day, res.data.use_size)
  288. } else {
  289. _this.$message.success('【日用水】暂无数据!');
  290. }
  291. })
  292. .catch(err => {
  293. // console.log(err);
  294. _this.$message.error('【日用水】请求异常: ' + err);
  295. })
  296. } else if (riqi == '月') { // 月用水量
  297. // 查询月的数据
  298. this.$axios.get('/jxch-smartmp/HotWaters/watermonthTong.action', {
  299. params: params
  300. })
  301. .then(res => {
  302. // console.log(res.data);
  303. if (typeof(res.data.month) != 'undefined' && res.data.month != '' && JSON.stringify(res
  304. .data) != '{}') {
  305. // 显示面积图
  306. this.show_mianjitu(res.data.month, res.data.use_size)
  307. } else {
  308. _this.$message.success('【月用水】暂无数据!');
  309. }
  310. })
  311. .catch(err => {
  312. // console.log(err);
  313. _this.$message.error('【月用水】请求异常: ' + err);
  314. })
  315. } else if (riqi == '年') { // 年用水量
  316. // 查询年的数据
  317. this.$axios.get('/jxch-smartmp/HotWaters/wateryearTong.action', {
  318. params: params
  319. })
  320. .then(res => {
  321. // console.log(res.data);
  322. if (typeof(res.data.year) != 'undefined' && res.data.year != '' && JSON.stringify(res
  323. .data) != '{}') {
  324. // 显示面积图
  325. this.show_mianjitu(res.data.year, res.data.use_size)
  326. } else {
  327. _this.$message.success('【年用水】暂无数据!');
  328. }
  329. })
  330. .catch(err => {
  331. // console.log(err);
  332. _this.$message.error('【年用水】请求异常: ' + err);
  333. })
  334. }
  335. },
  336. /**
  337. * 选择楼栋号
  338. */
  339. selectGetBuild(vId) {
  340. // console.log(vId);
  341. this.drom_value = vId
  342. if (this.drom_value != 0) {
  343. this.room_select_disabled = false
  344. } else {
  345. this.room_select_disabled = true
  346. this.room_value = ''
  347. }
  348. let obj = {};
  349. obj = this.drom_options.builds.find((item) => {
  350. return item.value === vId; //筛选出匹配数据
  351. });
  352. // console.log(obj);
  353. this.drom_options.value = obj.value
  354. this.drom_options.label = obj.label
  355. if (this.drom_options.label != '全部') {
  356. // 获取楼栋号
  357. this.drom = this.drom_options.label
  358. } else {
  359. this.drom = ''
  360. }
  361. // 共用部分
  362. this.updateData()
  363. // 获取用水总量
  364. this.get_total_yongshuizongliang()
  365. },
  366. /**
  367. * 失去焦点更新数据
  368. * @param {Object} event
  369. */
  370. updateData(event) {
  371. if (this.show_active == '') {
  372. this.show_active = '日'
  373. }
  374. // 查询对应的数据
  375. this.change_riqi(this.show_active)
  376. },
  377. /**
  378. * 回车失去焦点
  379. * @param {Object} event
  380. */
  381. enterBlur(event) {
  382. event.target.blur()
  383. },
  384. /**
  385. * 打开详情对话框
  386. * @param {Object} e
  387. */
  388. show_detail() {
  389. // this.detail_tableData = [];
  390. this.detail_dialogFormVisible = true;
  391. let params = {
  392. page: this.control_table.detail_current_page,
  393. rows: this.control_table.detail_page_rows
  394. }
  395. if (this.room_value != '' && typeof(this.room_value) != 'undefined') {
  396. params.dom = this.room_value
  397. }
  398. if (this.drom != '' && typeof(this.drom) != 'undefined') {
  399. params.build = this.drom
  400. }
  401. if (this.detail_userName != '' && typeof(this.detail_userName) != 'undefined') {
  402. params.username = this.detail_userName
  403. }
  404. var _this = this;
  405. // 显示详细列表
  406. this.$axios.get('/jxch-smartmp/HotWaters/waterdetailWater.action', {
  407. params: params
  408. })
  409. .then(res => {
  410. // console.log(res.data);
  411. if (typeof(res.data.rows) != 'undefined' && res.data.rows != '' && JSON.stringify(res
  412. .data) != '{}') {
  413. _this.detail_tableData = res.data.rows
  414. _this.control_table.detail_total_rows = res.data.total
  415. } else {
  416. _this.$message.success('【用水详情】暂无数据!');
  417. }
  418. })
  419. .catch(err => {
  420. // console.log(err);
  421. _this.$message.error('【用水详情】请求异常: ' + err);
  422. })
  423. },
  424. /**
  425. * 详情页面查找
  426. */
  427. onSearch() {
  428. this.control_table.detail_current_page = 1
  429. this.show_detail()
  430. }
  431. }
  432. }
  433. </script>
  434. <style scoped>
  435. @import url("yongshuifenxi.css");
  436. </style>