tabIndex.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  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. AlertsCols,
  128. valveInfoCols,
  129. historyCols, //告警列表表头
  130. getRowStr,
  131. historyDataList: []
  132. };
  133. },
  134. created() {
  135. if (!!this.$route.query.type && this.$route.query.type == 2) {
  136. this.tabs[2].label = '闸控记录';
  137. }
  138. this.initDate('YYYYMMDD');
  139. this.mixins_query = {
  140. deviceId: this.params.id || '',
  141. startDate: this.dataValue.length ? `${this.dataValue[0]}` : '',
  142. endDate: this.dataValue.length ? `${this.dataValue[1]}` : ''
  143. };
  144. new Promise((resolve) => {
  145. this.getDeviceMeasuringPoint(resolve);
  146. }).then(() => {
  147. this.change('history');
  148. });
  149. },
  150. methods: {
  151. initDate(type) {
  152. let date = new Date();
  153. this.dataValue = [this.$moment(new Date(date.getFullYear(), date.getMonth(), 1)).format(type), this.$moment().format(type)];
  154. },
  155. change(value) {
  156. this.value = value;
  157. if (value == 'history') {
  158. this.getHistorical();
  159. this.getDiscount();
  160. } else if (value == 'alarm') {
  161. this.getAllHandleAbnormal();
  162. } else if (value == 'valveNote') {
  163. this.getValveData();
  164. }
  165. },
  166. hispageChange(obj) {
  167. if (obj.pageSize) {
  168. this.hispageset.pageSize = obj.pageSize;
  169. }
  170. if (obj.page) {
  171. this.hispageset.currentPage = obj.page;
  172. }
  173. },
  174. // 历史数据
  175. getDiscount() {
  176. this.$http
  177. .post('/sc-energy/device/getQuantity', this.mixins_query)
  178. .then(({ data, status }) => {
  179. if (status === 0) {
  180. let dataoption = { xData: [], yData: [] };
  181. if (data.length > 0) {
  182. data.map((item) => {
  183. if (item.date) {
  184. let itemdata = item.date ? item.date.toString().replace(/(\d{4})(\d{2})(\d{2})/gi, '$1-$2-$3') : '';
  185. itemdata = itemdata ? itemdata.slice(5) : '';
  186. if (itemdata) {
  187. dataoption.xData.push(itemdata);
  188. dataoption.yData.push(item.value || '0');
  189. }
  190. }
  191. });
  192. }
  193. this.chartoption = chartOption('#29B6FF', dataoption, '用水量', '#29B6FF', 't');
  194. }
  195. })
  196. .catch((err) => {
  197. this.chartoption = {};
  198. console.log(err);
  199. });
  200. },
  201. getHistorical() {
  202. this.historyDataList = [];
  203. // 获取历史数据列表
  204. this.mixins_query = {
  205. deviceId: this.params.id || '',
  206. startDate: this.dataValue.length ? `${this.dataValue[0]}` : '',
  207. endDate: this.dataValue.length ? `${this.dataValue[1]}` : ''
  208. };
  209. if (this.params.productId) {
  210. this.$http
  211. .post('/sc-energy/device/getData', this.mixins_query)
  212. .then(({ data, status }) => {
  213. if (status === 0) {
  214. if (data.length) {
  215. let dateTimeCol;
  216. this.historyDataList = [];
  217. for (let [k, v] of data.entries()) {
  218. dateTimeCol = _.map(v);
  219. let timeformat = this.$moment(Number(dateTimeCol[0])).format('YYYY-MM-DD HH:mm:ss');
  220. this.historyDataList.push(Object.assign({ receiveTime: timeformat }, data[k].measureData));
  221. }
  222. this.hispageset.total = data.length;
  223. this.mixins_onQuery = false;
  224. } else {
  225. this.mixins_onQuery = false;
  226. }
  227. } else {
  228. this.mixins_onQuery = false;
  229. }
  230. })
  231. .catch(() => {
  232. this.mixins_onQuery = false;
  233. });
  234. } else {
  235. this.mixins_onQuery = false;
  236. }
  237. },
  238. //告警
  239. getAllHandleAbnormal() {
  240. this.mixins_list = [];
  241. this.mixins_dataUrl = '/sc-energy/alarm/getPage';
  242. this.mixins_post = 'get';
  243. this.mixins_query = {
  244. categoryId: this.params.categoryId || '',
  245. deviceId: this.params.id || '',
  246. startDate: this.dataValue.length ? `${this.dataValue[0]}` : '',
  247. endDate: this.dataValue.length ? `${this.dataValue[1]}` : ''
  248. };
  249. this.mixins_search();
  250. },
  251. // 阀控记录
  252. getValveData() {
  253. this.mixins_list = [];
  254. this.mixins_post = 'get';
  255. this.mixins_dataUrl = '/sc-energy/device/command/page';
  256. this.mixins_query = {
  257. categoryId: this.params.categoryId || '',
  258. communityId: this.params.communityId || '',
  259. startDate: this.dataValue.length ? `${this.dataValue[0]}` : '',
  260. endDate: this.dataValue.length ? `${this.dataValue[1]}` : ''
  261. };
  262. this.mixins_search();
  263. },
  264. timeQuery() {
  265. (this.mixins_query.startDate = this.dataValue.length ? `${this.dataValue[0]}` : ''),
  266. (this.mixins_query.endDate = this.dataValue.length ? `${this.dataValue[1]}` : '');
  267. this.change(this.value);
  268. },
  269. getDeviceMeasuringPoint(resolve) {
  270. if (this.params && this.params.productId) {
  271. this.$http
  272. .get('/sc-energy/measuring/point/find', { productId: this.params.productId })
  273. .then(({ status, msg, data = [] }) => {
  274. if (status === 0) {
  275. this.pointList = data;
  276. this.Cols.push({ label: '时间', prop: 'receiveTime', width: 200 });
  277. if (data.length) {
  278. data.map((item, index) => {
  279. this.Cols.push({
  280. label: item.measuringName,
  281. prop: item.measuringCode,
  282. format(value) {
  283. if (item.dictList.length) {
  284. let newValue;
  285. item.dictList.map((item, index) => {
  286. if (item.dataValue == value) {
  287. newValue = item.dataName;
  288. }
  289. });
  290. return newValue;
  291. } else {
  292. return value;
  293. }
  294. }
  295. });
  296. });
  297. } else {
  298. this.mixins_onQuery = false;
  299. }
  300. } else {
  301. this.mixins_onQuery = false;
  302. }
  303. resolve && resolve(true);
  304. })
  305. .catch(() => {
  306. this.mixins_onQuery = false;
  307. });
  308. }
  309. },
  310. dataFormat(date) {
  311. return date
  312. .toLocaleString()
  313. .replace(/\/|[\u4e00-\u9fa5]|:|\s+/g, '')
  314. .substr(0, 8);
  315. },
  316. exportExcel(date) {
  317. let downurl = '';
  318. let params = {
  319. deviceId: this.params.id || '',
  320. startDate: this.dataValue.length ? `${this.dataValue[0]}000000` : '',
  321. endDate: this.dataValue.length ? `${this.dataValue[1]}235959` : ''
  322. };
  323. if (this.value == 'history') {
  324. params = {
  325. deviceId: this.params.id || '',
  326. startDate: this.dataValue.length ? `${this.dataValue[0]}` : '',
  327. endDate: this.dataValue.length ? `${this.dataValue[1]}` : ''
  328. };
  329. downurl = '/sc-energy/device/getDataExcel';
  330. } else if (this.value == 'alarm') {
  331. params = Object.assign(params, {
  332. categoryId: this.params.categoryId || '',
  333. deviceId: this.params.id || ''
  334. });
  335. downurl = '/sc-energy/alarm/exportExcel';
  336. } else if (this.value == 'replace') {
  337. return;
  338. params = {
  339. deviceNo: this.params.deviceNo || '',
  340. replaceMethod: this.params.replaceMethod || '',
  341. startDate: this.dataValue.length ? `${this.dataValue[0]}000000` : '',
  342. endDate: this.dataValue.length ? `${this.dataValue[1]}235959` : ''
  343. };
  344. downurl = '/zoniot-rmcp-web/device/meter/replace/export/excel';
  345. } else {
  346. downurl = '/sc-energy/device/command/export/excel';
  347. params = {
  348. categoryId: this.params.categoryId,
  349. startDate: this.dataValue.length ? `${this.dataValue[0]}000000` : '',
  350. endDate: this.dataValue.length ? `${this.dataValue[1]}235959` : '',
  351. type: '' //操作类型
  352. };
  353. }
  354. this.__exportExcel(downurl, params);
  355. }
  356. }
  357. };
  358. </script>
  359. <style lang="scss" scoped>
  360. .tab_head-right {
  361. line-height: inherit;
  362. color: #0eaeff;
  363. font-size: 30px;
  364. }
  365. .box__wrap {
  366. /deep/ .fullheight {
  367. height: 100%;
  368. // height: fit-content;
  369. width: 100%;
  370. display: inline-flex;
  371. flex-direction: column;
  372. justify-content: space-between;
  373. .el-table {
  374. overflow-y: auto;
  375. }
  376. }
  377. }
  378. </style>