tabIndex.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. <template>
  2. <div class="detail-tab">
  3. <div class="tab_head">
  4. <zz-tabs :tabs="tabs" :value="value" @change="change"></zz-tabs>
  5. </div>
  6. <div class="box">
  7. <div class="query-box">
  8. <div class="left_search">
  9. <span class="el-mgRight-sm" v-show="value == 'history'"> 上报时间 </span>
  10. <span class="el-mgRight-sm" v-show="value == 'alarm'">告警时间</span>
  11. <span class="el-mgRight-sm" v-show="value == 'valveNote'">操作时间</span>
  12. <span>
  13. <el-date-picker
  14. v-model="dataValue"
  15. type="daterange"
  16. range-separator="至"
  17. start-placeholder="开始日期"
  18. end-placeholder="结束日期"
  19. :value-format="dateType"
  20. :picker-options="endDatePicker"
  21. @change="timeQuery"
  22. :clearable="false"
  23. >
  24. </el-date-picker>
  25. </span>
  26. </div>
  27. <el-tooltip class="item" effect="light" placement="bottom" content="导出">
  28. <i class="zoniot_font zoniot-icon-daochu2 tab_head-right" @click="exportExcel()"></i>
  29. </el-tooltip>
  30. </div>
  31. <div class="box__wrap" v-show="value == 'history'">
  32. <zz-table
  33. :cols="Cols"
  34. :settings="{ showIndex: true, stripe: true }"
  35. height="200"
  36. :data="
  37. historyDataList.slice(
  38. (hispageset.currentPage - 1) * hispageset.pageSize,
  39. hispageset.currentPage * hispageset.pageSize
  40. )
  41. "
  42. :loading="mixins_onQuery"
  43. :pageset="hispageset"
  44. @page-change="hispageChange"
  45. ></zz-table>
  46. <div class="echart_content" v-if="value == 'history'">
  47. <el-echart :option="chartoption"></el-echart>
  48. </div>
  49. </div>
  50. <div class="box__wrap" ref="alarmbox" v-show="value == 'alarm'">
  51. <zz-table
  52. class="fullheight"
  53. :cols="AlertsCols"
  54. :settings="{ showIndex: true, stripe: true }"
  55. :data="mixins_list"
  56. :loading="mixins_onQuery"
  57. :pageset="mixins_pageset"
  58. @page-change="pageChange"
  59. >
  60. </zz-table>
  61. </div>
  62. <div class="box__wrap" ref="valvebox" v-show="value == 'valveNote'">
  63. <zz-table
  64. :cols="valveInfoCols"
  65. class="fullheight"
  66. :settings="{ showIndex: true, stripe: true }"
  67. :data="mixins_list"
  68. :loading="mixins_onQuery"
  69. :pageset="mixins_pageset"
  70. @page-change="pageChange"
  71. >
  72. </zz-table>
  73. </div>
  74. </div>
  75. </div>
  76. </template>
  77. <script>
  78. import list from '@/utils/list';
  79. import { AlertsCols, historyCols, valveInfoCols } from '../baseData';
  80. import { getRowStr } from './basedata';
  81. import { deviceLoader } from '@/utils/basedata.js';
  82. import { chartOption } from './echartoption';
  83. export default {
  84. mixins: [list],
  85. props: ['params'],
  86. components: {},
  87. data() {
  88. return {
  89. deviceLoader,
  90. type: '',
  91. chartoption: {}, //
  92. value: 'history',
  93. dateType: 'yyyyMMdd',
  94. tabs: [
  95. {
  96. value: 'history',
  97. label: '历史数据'
  98. },
  99. {
  100. value: 'alarm',
  101. label: '告警记录'
  102. },
  103. {
  104. value: 'valveNote',
  105. label: '阀控记录'
  106. }
  107. // {
  108. // value: 'replace',
  109. // label: '换表记录'
  110. // }
  111. ],
  112. dataUnit: '',
  113. dataValue: [],
  114. endDatePicker: {
  115. disabledDate: (time) => {
  116. return time.getTime() > new Date().getTime();
  117. }
  118. },
  119. hispageset: {
  120. total: 0,
  121. pageSize: 15,
  122. pageNum: 1,
  123. currentPage: 1,
  124. pageSizes: [15, 30, 60, 120]
  125. },
  126. Cols: [
  127. { label: '上报时间', prop: 'receiveTime' },
  128. { label: '止度', prop: 'receiveTime' },
  129. { label: '阀门状态', prop: 'receiveTime' },
  130. { label: '设备状态', prop: 'receiveTime' }
  131. ],
  132. AlertsCols,
  133. valveInfoCols,
  134. historyCols, //告警列表表头
  135. getRowStr,
  136. historyDataList: []
  137. };
  138. },
  139. created() {
  140. if (!!this.$route.query.type && this.$route.query.type == 2) {
  141. this.tabs[2].label = '闸控记录';
  142. }
  143. this.initDate('YYYYMMDD');
  144. this.mixins_query = {
  145. deviceId: this.params.id || '',
  146. startDate: this.dataValue.length ? `${this.dataValue[0]}` : '',
  147. endDate: this.dataValue.length ? `${this.dataValue[1]}` : ''
  148. };
  149. new Promise((resolve) => {
  150. this.getDeviceMeasuringPoint(resolve);
  151. }).then(() => {
  152. this.change('history');
  153. });
  154. },
  155. methods: {
  156. initDate(type) {
  157. let date = new Date();
  158. this.dataValue = [this.$moment(new Date(date.getFullYear(), date.getMonth(), 1)).format(type), this.$moment().format(type)];
  159. },
  160. change(value) {
  161. this.value = value;
  162. if (value == 'history') {
  163. this.getHistorical();
  164. this.getDiscount();
  165. } else if (value == 'alarm') {
  166. this.getAllHandleAbnormal();
  167. } else if (value == 'valveNote') {
  168. this.getValveData();
  169. }
  170. },
  171. hispageChange(obj) {
  172. if (obj.pageSize) {
  173. this.hispageset.pageSize = obj.pageSize;
  174. }
  175. if (obj.page) {
  176. this.hispageset.currentPage = obj.page;
  177. }
  178. },
  179. // 历史数据
  180. getDiscount() {
  181. this.$http
  182. .post('/sc-energy/device/getQuantity', this.mixins_query)
  183. .then(({ data, status }) => {
  184. if (status === 0) {
  185. let dataoption = { xData: [], yData: [] };
  186. if (data.length > 0) {
  187. data.map((item) => {
  188. if (item.date) {
  189. let itemdata = item.date ? item.date.toString().replace(/(\d{4})(\d{2})(\d{2})/gi, '$1-$2-$3') : '';
  190. itemdata = itemdata ? itemdata.slice(5) : '';
  191. if (itemdata) {
  192. dataoption.xData.push(itemdata);
  193. dataoption.yData.push(item.value || '0');
  194. }
  195. }
  196. });
  197. }
  198. this.chartoption = chartOption('#29B6FF', dataoption, '用水量', '#29B6FF', 't');
  199. }
  200. })
  201. .catch((err) => {
  202. this.chartoption = {};
  203. console.log(err);
  204. });
  205. },
  206. getHistorical() {
  207. this.historyDataList = [];
  208. // 获取历史数据列表
  209. this.mixins_query = {
  210. deviceId: this.params.id || '',
  211. startDate: this.dataValue.length ? `${this.dataValue[0]}` : '',
  212. endDate: this.dataValue.length ? `${this.dataValue[1]}` : ''
  213. };
  214. if (this.params.productId) {
  215. this.$http
  216. .post('/sc-energy/device/getData', this.mixins_query)
  217. .then(({ data, status }) => {
  218. if (status === 0) {
  219. if (data.length) {
  220. let dateTimeCol;
  221. this.historyDataList = [];
  222. for (let [k, v] of data.entries()) {
  223. dateTimeCol = _.map(v);
  224. let timeformat = this.$moment(Number(dateTimeCol[0])).format('YYYY-MM-DD HH:mm:ss');
  225. this.historyDataList.push(Object.assign({ receiveTime: timeformat }, data[k].measureData));
  226. }
  227. this.hispageset.total = data.length;
  228. this.mixins_onQuery = false;
  229. } else {
  230. this.mixins_onQuery = false;
  231. }
  232. } else {
  233. this.mixins_onQuery = false;
  234. }
  235. })
  236. .catch(() => {
  237. this.mixins_onQuery = false;
  238. });
  239. } else {
  240. this.mixins_onQuery = false;
  241. }
  242. },
  243. //告警
  244. getAllHandleAbnormal() {
  245. this.mixins_list = [];
  246. this.mixins_dataUrl = '/sc-energy/alarm/getPage';
  247. this.mixins_post = 'get';
  248. this.mixins_query = {
  249. categoryId: this.params.categoryId || '',
  250. deviceId: this.params.id || '',
  251. startDate: this.dataValue.length ? `${this.dataValue[0]}` : '',
  252. endDate: this.dataValue.length ? `${this.dataValue[1]}` : ''
  253. };
  254. this.mixins_search();
  255. },
  256. // 阀控记录
  257. getValveData() {
  258. this.mixins_list = [];
  259. this.mixins_post = 'get';
  260. this.mixins_dataUrl = '/sc-energy/device/command/page';
  261. this.mixins_query = {
  262. // categoryId: this.params.categoryId || '',
  263. // communityId: this.params.communityId || '',
  264. deviceId: this.params.id || '',
  265. startDate: this.dataValue.length ? `${this.dataValue[0]}` : '',
  266. endDate: this.dataValue.length ? `${this.dataValue[1]}` : ''
  267. };
  268. this.mixins_search();
  269. },
  270. timeQuery() {
  271. (this.mixins_query.startDate = this.dataValue.length ? `${this.dataValue[0]}` : ''),
  272. (this.mixins_query.endDate = this.dataValue.length ? `${this.dataValue[1]}` : '');
  273. this.change(this.value);
  274. },
  275. getDeviceMeasuringPoint(resolve) {
  276. if (this.params && this.params.productId) {
  277. this.$http
  278. .get('/sc-energy/measuring/point/find', { productId: this.params.productId })
  279. .then(({ status, msg, data = [] }) => {
  280. if (status === 0) {
  281. this.pointList = data;
  282. if (data.length) {
  283. this.Cols = [{ label: '上报时间', prop: 'receiveTime', width: 200 }];
  284. data.map((item, index) => {
  285. this.Cols.push({
  286. label: item.measuringName,
  287. prop: item.measuringCode,
  288. format(value) {
  289. if (item.dictList.length) {
  290. let newValue;
  291. item.dictList.map((item, index) => {
  292. if (item.dataValue == value) {
  293. newValue = item.dataName;
  294. }
  295. });
  296. return newValue;
  297. } else {
  298. return value;
  299. }
  300. }
  301. });
  302. });
  303. } else {
  304. this.mixins_onQuery = false;
  305. }
  306. } else {
  307. this.mixins_onQuery = false;
  308. }
  309. resolve && resolve(true);
  310. })
  311. .catch(() => {
  312. this.mixins_onQuery = false;
  313. });
  314. }
  315. },
  316. dataFormat(date) {
  317. return date
  318. .toLocaleString()
  319. .replace(/\/|[\u4e00-\u9fa5]|:|\s+/g, '')
  320. .substr(0, 8);
  321. },
  322. exportExcel(date) {
  323. let downurl = '';
  324. let params = {
  325. deviceId: this.params.id || '',
  326. startDate: this.dataValue.length ? `${this.dataValue[0]}` : '',
  327. endDate: this.dataValue.length ? `${this.dataValue[1]}` : ''
  328. };
  329. if (this.value == 'history') {
  330. params = {
  331. deviceId: this.params.id || '',
  332. startDate: this.dataValue.length ? `${this.dataValue[0]}` : '',
  333. endDate: this.dataValue.length ? `${this.dataValue[1]}` : ''
  334. };
  335. downurl = '/sc-energy/device/getDataExcel';
  336. } else if (this.value == 'alarm') {
  337. params = Object.assign(params, {
  338. categoryId: this.params.categoryId || '',
  339. deviceId: this.params.id || ''
  340. });
  341. downurl = '/sc-energy/alarm/exportExcel';
  342. } else {
  343. downurl = '/sc-energy/device/command/export/excel';
  344. params = {
  345. deviceId: this.params.id || '',
  346. startDate: this.dataValue.length ? `${this.dataValue[0]}` : '',
  347. endDate: this.dataValue.length ? `${this.dataValue[1]}` : ''
  348. };
  349. }
  350. this.__exportExcel(downurl, params);
  351. }
  352. }
  353. };
  354. </script>
  355. <style lang="scss" scoped>
  356. .tab_head-right {
  357. line-height: inherit;
  358. color: #0eaeff;
  359. font-size: 30px;
  360. }
  361. .box__wrap {
  362. /deep/ .fullheight {
  363. height: 100%;
  364. // height: fit-content;
  365. width: 100%;
  366. display: inline-flex;
  367. flex-direction: column;
  368. justify-content: space-between;
  369. .el-table {
  370. overflow-y: auto;
  371. }
  372. }
  373. }
  374. </style>