widget.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  1. <template>
  2. <div
  3. v-way="wayFun('mainDiv')"
  4. style="width: 100%; height: 100%; padding: 8px"
  5. >
  6. <el-row>
  7. <el-form
  8. ref="ruleForm"
  9. :model="ruleForm"
  10. :rules="rules"
  11. style="
  12. display: flex;
  13. flex-wrap: wrap;
  14. justify-content: flex-start;
  15. align-items: flex-start;
  16. "
  17. >
  18. <el-form-item
  19. label="类型:"
  20. style="width: 205px; display: inline-block; margin-bottom: 6px"
  21. >
  22. <el-select
  23. v-model="categoryName"
  24. filterable
  25. style="display: inline-block; width: 140px"
  26. size="small"
  27. placeholder="请选择类型"
  28. @change="selectChange"
  29. >
  30. <el-option key="1" label="水厂" value="1" />
  31. <el-option key="2" label="管网" value="2" />
  32. </el-select>
  33. </el-form-item>
  34. <el-form-item
  35. label="设备名称:"
  36. prop="site"
  37. style="width: 360px; display: inline-block; margin-bottom: 6px"
  38. >
  39. <el-select
  40. ref="site"
  41. v-model="ruleForm.site"
  42. style="display: inline-block; width: 240px"
  43. size="small"
  44. placeholder="请选择"
  45. @change="bindTsNameChange"
  46. >
  47. <el-option
  48. v-for="item in isSeletcSite"
  49. :key="item.id"
  50. :label="item.name"
  51. :value="item.id"
  52. />
  53. </el-select>
  54. </el-form-item>
  55. <el-form-item
  56. label="指标名称:"
  57. prop="type"
  58. style="width: 240px; display: inline-block; margin-bottom: 6px"
  59. >
  60. <el-select
  61. v-model="ruleForm.indexName"
  62. collapse-tags
  63. style="display: inline-block; width: 140px"
  64. size="small"
  65. placeholder="请选择"
  66. disabled
  67. >
  68. <el-option
  69. v-for="item in indexNames"
  70. :key="item.variableCode"
  71. :label="item.displayName"
  72. :value="item.variableCode"
  73. />
  74. </el-select>
  75. </el-form-item>
  76. <el-form-item
  77. label="统计日期:"
  78. prop="times"
  79. style="display: inline-block; width: 440px; margin-bottom: 6px"
  80. >
  81. <el-date-picker
  82. v-model="ruleForm.times"
  83. size="small"
  84. type="daterange"
  85. align="right"
  86. unlink-panels
  87. range-separator="至"
  88. start-placeholder="开始日期"
  89. end-placeholder="结束日期"
  90. format="yyyy-MM-dd"
  91. value-format="yyyy-MM-dd"
  92. />
  93. </el-form-item>
  94. <el-form-item
  95. style="display: inline-block; width: 300px; margin-bottom: 6px"
  96. >
  97. <el-button
  98. size="small"
  99. type="primary"
  100. @click="monitorHisToryQuery('ruleForm')"
  101. >查询</el-button>
  102. <el-button
  103. size="small"
  104. type="primary"
  105. @click="statisticsScadaExport('ruleForm')"
  106. >导出</el-button>
  107. </el-form-item>
  108. </el-form>
  109. </el-row>
  110. <div style="height: calc(100% - 35px)">
  111. <el-table
  112. id="siteMonitor"
  113. v-loading="loading"
  114. class="mapTable"
  115. :data="dayUseWaterData"
  116. :total="tableTotal"
  117. :summary-method="getSummaries"
  118. show-summary
  119. border
  120. style="width: 100%; height:calc(100% - 80px); margin-top: 20px"
  121. >
  122. <el-table-column type="index" align="center" width="50" label="序号" />
  123. <el-table-column
  124. prop="deviceName"
  125. align="center"
  126. label="设备名称"
  127. sortable="custom"
  128. show-overflow-tooltip
  129. />
  130. <el-table-column
  131. prop="codeName"
  132. align="center"
  133. label="统计指标名称"
  134. sortable="custom"
  135. show-overflow-tooltip
  136. />
  137. <el-table-column
  138. prop="endTime"
  139. align="center"
  140. label="监测时间"
  141. sortable="custom"
  142. show-overflow-tooltip
  143. >
  144. <template slot-scope="scope">
  145. {{ scope.row.endTime.split(" ")[0] }}
  146. </template>
  147. </el-table-column>
  148. <el-table-column
  149. prop="difference"
  150. align="center"
  151. sortable="custom"
  152. :label="'日用量(m³)'"
  153. />
  154. </el-table>
  155. <el-row style="margin-top: 0px">
  156. <el-col :span="24">
  157. <el-pagination
  158. ref="pagination"
  159. small
  160. layout="total, sizes, prev, pager, next, jumper"
  161. :pager-count="5"
  162. :current-page="pageInfo.current"
  163. :page-sizes="[10,40, 80, 120, 200]"
  164. style="margin-top: 4px"
  165. :page-size="pageInfo.size"
  166. :total="tableTotal"
  167. @size-change="handleSizeChange"
  168. @current-change="handleCurrentChange"
  169. />
  170. </el-col>
  171. </el-row>
  172. </div>
  173. </div>
  174. </template>
  175. <script>
  176. import elementResizeDetectorMaker from 'element-resize-detector'
  177. import TableItem from '@/components/Table'
  178. import Echarts from 'echarts'
  179. import ExportBtn from '@/views/zhpt/wxreportforms/components/ExportBtn'
  180. import {
  181. queryDevice,
  182. queryIndexConfiguration,
  183. statisticsScadaPage,
  184. statisticsScadaExport
  185. } from '@/api/scadaApi'
  186. import { getSysCommonCode } from '@/api/dataCenter'
  187. export default {
  188. name: 'AnalysisResult',
  189. components: { TableItem, Echarts, ExportBtn },
  190. directives: {
  191. way(el, bind) {
  192. if (typeof bind.value === 'function') bind.value(el)
  193. }
  194. },
  195. data() {
  196. return {
  197. dayUseWaterData: [], // 表格数据
  198. tabsItem: [],
  199. activeName: '',
  200. monitorLable: '',
  201. tableLoading: false,
  202. nameUnit: '',
  203. total: 0,
  204. loading: false,
  205. pageInfo: { current: 1, size: 40 }, // 分页数据
  206. ruleForm: {
  207. site: '',
  208. indexName: '',
  209. times: []
  210. },
  211. rules: {
  212. site: [{ required: true, message: '', trigger: 'change' }],
  213. times: [{ required: true, message: '', trigger: 'change' }]
  214. },
  215. sites: [], // 测站名称
  216. types: [], // 指标类型
  217. indexNames: null, // 指标名称
  218. elements: {},
  219. tableTotal: 0, // 表格数据总条数
  220. categoryName: '1', // 默认选择水厂
  221. categoryNames: [],
  222. isSeletcSite: [],
  223. linkageEchart: null,
  224. deviceTypeCode: [],
  225. num: ''
  226. }
  227. },
  228. watch: {
  229. 'ruleForm.indexName': {
  230. handler(newValue, oldVal) {
  231. this.monitorHisToryQuery('ruleForm')
  232. }
  233. }
  234. },
  235. created() {},
  236. mounted() {
  237. const date = new Date()
  238. const year = date.getFullYear()
  239. const month = date.getMonth() + 1
  240. const day = date.getDate()
  241. this.ruleForm.times = [
  242. year + '-' + month + '-1',
  243. year + '-' + month + '-' + day
  244. ]
  245. // this.elements["mainDiv"].parentElement.style.height = "100%";
  246. // this.elements["mainDiv"].parentElement.parentElement.style.height =
  247. // "calc(100% - 56px)";
  248. // this.elements[
  249. // "mainDiv"
  250. // ].parentElement.parentElement.parentElement.style.height = "100%";
  251. // this.showUnitIndex = {};
  252. getSysCommonCode({ pCid: '53400' }).then((res) => {
  253. const deviceTypes = res.result[0].codeList
  254. this.deviceTypeCode = deviceTypes.map((item) => {
  255. if (item.cname.indexOf('压力') == -1) return item.ccode
  256. })
  257. this.queryDevice() // 绑定测站名称
  258. })
  259. },
  260. methods: {
  261. /**
  262. * 合计
  263. *
  264. */
  265. getSummaries(param) {
  266. const { columns, data } = param
  267. const sums = []
  268. columns.forEach((column, index) => {
  269. if (index === 0) {
  270. sums[index] = '合计'
  271. return
  272. }
  273. const values = data.map((item) => Number(item[column.property]))
  274. if (!values.every((value) => isNaN(value))) {
  275. sums[index] = this.num
  276. }
  277. })
  278. return sums
  279. },
  280. /**
  281. * 根据设备类型查询设备
  282. */
  283. queryDevice() {
  284. queryDevice({ type: this.categoryName, size: 10000 }).then((res) => {
  285. const device = res.result.records
  286. this.isSeletcSite = device.filter(
  287. (item) => this.deviceTypeCode.indexOf(item.deviceType) != -1
  288. )
  289. if (this.isSeletcSite.length > 0) {
  290. this.ruleForm.site = this.isSeletcSite[0].id
  291. this.bindTsNameChange()
  292. }
  293. })
  294. },
  295. /**
  296. * 根据设备ID查询设备指标
  297. */
  298. queryIndexType() {
  299. queryIndexConfiguration({
  300. deviceId: this.ruleForm.site,
  301. size: 10000
  302. }).then((res) => {
  303. const arr = this.process(res.result.records)
  304. this.types = arr
  305. this.indexNames = arr.filter(
  306. (item) =>
  307. item.variableCode.indexOf('.JLJ') != -1 ||
  308. item.variableCode.indexOf('.LJL') != -1
  309. )
  310. if (this.indexNames.length > 0) { this.ruleForm.indexName = this.indexNames[0].variableCode }
  311. })
  312. },
  313. queryIndexConfiguration() {
  314. queryIndexConfiguration({
  315. deviceId: this.ruleForm.site,
  316. type: this.ruleForm.type,
  317. size: 10000
  318. }).then((res) => {
  319. this.indexNames = res.result.records
  320. var index = (this.targetIndex = {})
  321. res.result.records.map((e) => {
  322. index[e.variableCode] = e
  323. })
  324. })
  325. },
  326. process(arr) {
  327. // 缓存用于记录
  328. const cache = []
  329. for (const t of arr) {
  330. // 检查缓存中是否已经存在
  331. if (cache.find((c) => c.type === t.type)) {
  332. // 已经存在说明以前记录过,现在这个就是多余的,直接忽略
  333. continue
  334. }
  335. // 不存在就说明以前没遇到过,把它记录下来
  336. cache.push(t)
  337. }
  338. // 记录结果就是过滤后的结果
  339. return cache
  340. },
  341. // 设备名称发生改变时触发
  342. bindTsNameChange() {
  343. this.tabsItem = []
  344. this.types = []
  345. this.indexNames = []
  346. this.targetIndex = {}
  347. this.ruleForm.type = ''
  348. this.ruleForm.indexName = ''
  349. this.queryIndexType()
  350. },
  351. // 获得表格数据
  352. getData(data) {
  353. this.dayUseWaterData = []
  354. this.loading = true
  355. statisticsScadaPage(data)
  356. .then((res) => {
  357. if (res.code == 1) {
  358. this.dayUseWaterData = res.result.records
  359. this.tableTotal = res.result.total
  360. } else this.$message.error(res.message)
  361. this.loading = false
  362. })
  363. .catch((err) => {
  364. console.log(err)
  365. })
  366. const indexName1 = this.ruleForm.indexName.replace(/\#/g, '%23')
  367. const data1 = {
  368. code: indexName1 + '', // 指标名称
  369. startTime: this.ruleForm.times[0] + ' 00:00:00',
  370. endTime: this.ruleForm.times[1] + ' 23:59:59',
  371. size: this.pageInfo.size,
  372. current: this.pageInfo.current,
  373. totalAll: 1
  374. }
  375. statisticsScadaPage(data1)
  376. .then((res) => {
  377. if (res.code == 1) {
  378. this.num = res.result.difference
  379. }
  380. })
  381. .catch((err) => {
  382. console.log(err)
  383. })
  384. },
  385. // 点击查询,获取表格数据
  386. monitorHisToryQuery(formName) {
  387. this.$refs[formName].validate(async(valid) => {
  388. if (valid) {
  389. const indexName = this.ruleForm.indexName.replace(/\#/g, '%23')
  390. const data = {
  391. code: indexName + '', // 指标名称
  392. startTime: this.ruleForm.times[0] + ' 00:00:00',
  393. endTime: this.ruleForm.times[1] + ' 23:59:59',
  394. size: this.pageInfo.size,
  395. current: this.pageInfo.current
  396. }
  397. this.getData(data)
  398. } else {
  399. return false
  400. }
  401. })
  402. },
  403. // 每页显示条数改变时触发事件
  404. handleSizeChange(val) {
  405. this.pageInfo.size = val
  406. this.monitorHisToryQuery('ruleForm')
  407. },
  408. // 翻页时触发事件
  409. handleCurrentChange(val) {
  410. this.pageInfo.current = val
  411. this.monitorHisToryQuery('ruleForm')
  412. },
  413. wayFun: function(flag) {
  414. return (el) => {
  415. this.elements[flag] = el
  416. }
  417. },
  418. statisticsScadaExport(formName) {
  419. this.$refs[formName].validate(async(valid) => {
  420. if (valid) {
  421. const indexName = this.ruleForm.indexName.replace(/\#/g, '%23')
  422. const data = {
  423. code: indexName + '', // 指标名称
  424. startTime: this.ruleForm.times[0] + ' 00:00:00',
  425. endTime: this.ruleForm.times[1] + ' 23:59:59'
  426. }
  427. statisticsScadaExport(data).then((res) => {
  428. const blob = URL.createObjectURL(
  429. new Blob([res], {
  430. type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
  431. })
  432. )
  433. const a = document.createElement('a')
  434. a.href = blob
  435. a.download = '日用量报表.xlsx'
  436. a.click()
  437. })
  438. } else {
  439. return false
  440. }
  441. })
  442. },
  443. selectChange(val) {
  444. this.categoryName = val
  445. this.tabsItem = []
  446. this.isSeletcSite = []
  447. this.types = []
  448. this.indexNames = []
  449. this.targetIndex = {}
  450. for (const i in this.ruleForm) {
  451. if (i != 'times') {
  452. this.ruleForm[i] = ''
  453. }
  454. }
  455. this.queryDevice()
  456. }
  457. }
  458. }
  459. </script>
  460. <style scoped="less">
  461. .el-table__footer-wrapper {
  462. margin-bottom: 32px;
  463. }
  464. </style>