'use strict'; /** * 模板模块 * 默认模块名: monitor-data * @return {[object]} [ 返回一个对象 ] */ loader.define({ data: { vm: '' }, loaded: function loaded(require, exports, module) { // 定义F2chart var monVolBar = ''; var monResBar = ''; var monTmpBar = ''; var options = { monVol: [], monRes: [], monTmp: [] }; // 引入vue this.vm = new Vue({ el: getPageRoot(module), data: { shows: { monList: false, total: false, monVol: false, monRes: false, monTmp: false, monResLine: false }, loading: bui.loading(), open: true, uiDialog: '', num: -1, BattGroupId: -1, title: '??', battInfo: { sysstate: 0, sysversion: 1.2, battstate: 0, isOutTime: 1, groupcurr: 0, groupvol: 0, monCount: 0, testTimelong: 0 }, battList: [{ num: 1, BattGroupId: 1, text: '电池组1' }, { num: 2, BattGroupId: 2, text: '电池组2' }], tabs: { active: 0 }, timer: new Timeout(), tbls: { monInfo: { height: '300px', data: [] }, total: { data: [{ type: '电压', high: '', low: '', avg: '' }, { type: '内阻', high: '', low: '', avg: '' }, { type: '温度', high: '', low: '', avg: '' }] } }, options: { page: { curr: 1, // 当前页 size: 25, // 每页的数据量 pageTotal: 1, // 总页数 total: 0 // 数据总量 }, monVol: { // 单体电压 title: new Title(), height: "300px", option: [] }, monRes: { // 单体内阻 title: new Title(), height: "300px", option: { categories: [], data: [] } }, monResLine: { // 单体内阻折线图 title: '', option: [] }, monTmp: { // 单体温度 title: new Title(), height: "300px", option: [] } }, allData: [] }, filters: { stateFilter: function stateFilter(state, isOutTime) { var rs = ''; if (isOutTime == 1) { rs = "未连接"; } else { switch (state) { case -1: rs = '未知'; break; case 0: rs = '浮充'; break; case 1: rs = '放电'; break; case 2: rs = '充电'; break; } } return rs; }, sysstateFilter: function sysstateFilter(sysstate) { var rs = '常规模式'; switch (sysstate) { case 1: rs = '内阻测试'; break; case 2: rs = '编址模式'; break; } return rs; }, formatSeconds: function (_formatSeconds) { function formatSeconds(_x) { return _formatSeconds.apply(this, arguments); } formatSeconds.toString = function () { return _formatSeconds.toString(); }; return formatSeconds; }(function (num) { return formatSeconds(num); }) }, methods: { setAllData: function setAllData(data) { this.allData = data; }, tabsChange: function tabsChange() { var self = this; this.$nextTick(function () { self.updateGrahp(); }); }, openDrawer: function openDrawer() { this.open = true; }, closeDrawer: function closeDrawer() { this.open = false; }, listClick: function listClick(item) { // 设置标题 this.title = item.text; // 关闭Drawer this.open = false; // 初始化分页信息 this.initPage(); // 根据点电池组编号查询电池组信息 this.num = item.num; // 设置电池组id this.BattGroupId = item.BattGroupId; this.startReadBattMonInfo(); }, searchAll: function searchAll() { // 查询电池组的所有信息 if (typeof BattinfService != 'undefined') { BattinfService.searchAll(); } }, startReadBattMonInfo: function startReadBattMonInfo() { // 开始获取电池组信息 var self = this; this.timer.start(function () { self.readBattMonInfo(); }, 4000); }, readBattMonInfo: function readBattMonInfo() { // 读取电池组信息 var num = this.num; if (num == -1) { return; } if (typeof DeviceService != 'undefined') { DeviceService.readBattMonInfo(num); } else { this.setPageContent({ code: 1, data: { sysstate: 0, sysversion: 1.2, battstate: 0, isOutTime: 0, groupcurr: 2.11111, groupvol: 30.444444, monCount: 4, testTimelong: 0, mon_ress: [0.2, 0.3, 1, 2], mon_tmps: [10, 11, 12, 13], mon_vols: [14, 16, 18, 20] } }); this.timer.open(); } }, setList: function setList(data) { var list = []; // 遍历data for (var i = 0; i < data.length; i++) { var _data = data[i]; _data.text = _data.BattGroupName; if (_data.station_install) { list.push(_data); } } // 设置battList的值 this.battList = list; }, setPageContent: function setPageContent(res) { // 设置所有的数据 this.setAllData(res.data); // 设置电池组的总体信息 this.setBattInfo(res.data); // 设置图标配置项 this.setOption(); }, setMonInfoTbl: function setMonInfoTbl(data) { // 判断当前是否更新单体列表 if (this.tabs.active != 0) { return; } var monCount = data.monCount; var list = []; var k = -1; // 遍历单体 for (var i = 0; i < monCount; i++) { var num = i % 3; if (num == 0) { k++; list[k] = {}; } num++; var num_k = 'num' + num; var vol_k = 'vol' + num; var tmp_k = 'tmp' + num; var res_k = 'res' + num; list[k][num_k] = '#' + (i + 1); list[k][vol_k] = data.mon_vols[i]; list[k][res_k] = data.mon_ress[i]; list[k][tmp_k] = data.mon_tmps[i]; } this.tbls.monInfo.data = list; }, setTotal: function setTotal(data) { // 判断当前是否更新统计信息 if (this.tabs.active != 1) { return; } // 单体电压 var vol = this.getMaxMinAvg(data.monCount, data.mon_vols); this.setTotalItem(0, vol, 'V', 2); // 单体内阻 var res = this.getMaxMinAvg(data.monCount, data.mon_ress); this.setTotalItem(1, res, 'mΩ', 2); // 单体温度 var tmp = this.getMaxMinAvg(data.monCount, data.mon_tmps); this.setTotalItem(2, tmp, '℃', 1); }, setTotalItem: function setTotalItem(item, data, unit, fixed) { this.tbls.total.data[item].high = data.max.text + ':' + data.max.val + unit; this.tbls.total.data[item].low = data.min.text + ':' + data.min.val + unit; this.tbls.total.data[item].avg = Number(data.avg.toFixed(fixed)) + unit; }, setOption: function setOption() { this.loading.hide(); var data = this.allData; // 设置单体表格数据 this.setMonInfoTbl(data); // 设置统计信息表格 this.setTotal(data); // 单体个数 var monCount = data.monCount; // 设置分页的总数据量 this.setPageTotal(monCount); // 获取起始和结束电池单体 var startEnd = this.getStartEndIndex(); //console.log(data); // 遍历data的值 var monNum = []; // 单体编号 var monVol = []; // 单体电压 var monRes = []; // 单体内阻 var monTmp = []; // 单体温度 for (var i = startEnd.start; i < startEnd.end; i++) { monNum.push('#' + (i + 1)); monVol.push({ x: '#' + (i + 1), y: data.mon_vols[i] }); monRes.push({ x: '#' + (i + 1), y: data.mon_ress[i] }); monTmp.push({ x: '#' + (i + 1), y: data.mon_tmps[i] }); } // 单体电压 options.monVol = monVol; // 单体内阻 options.monRes = monRes; // 单体温度 options.monTmp = monTmp; // 更新图表 this.updateGrahp(); }, updateGrahp: function updateGrahp() { // 更新单体电压 if (this.tabs.active == 2) { // bui.alert(7788); monVolBar.changeData(options.monVol); } // 更新单体内阻 if (this.tabs.active == 3) { monResBar.changeData(options.monRes); } // 更新单体温度 if (this.tabs.active == 4) { monTmpBar.changeData(options.monTmp); } }, setBattInfo: function setBattInfo(data) { var battInfo = { sysstate: data.sysstate, sysversion: data.sysversion, battstate: data.battstate, isOutTime: data.isOutTime, groupcurr: data.groupcurr, groupvol: data.groupvol, monCount: data.monCount, testTimelong: data.testTimelong }; // 设置电池的信息 this.battInfo = battInfo; }, getMaxMinAvg: function getMaxMinAvg(monCount, data, unit) { // 获取较高,较低单体信息和平均值 // 构造对象 var rs = { min: { text: '#1', val: data[0] }, max: { text: '#1', val: data[0] }, avg: 0 }; var sum = data[0]; // 遍历monCount for (var i = 1; i < monCount; i++) { // 较大值 if (data[i] > rs.max.val) { rs.max.text = "#" + (i + 1); rs.max.val = data[i]; } else if (data[i] == rs.max.val) { rs.max.text += ",#" + (i + 1); } // 较小值 if (data[i] < rs.min.val) { rs.min.text = "#" + (i + 1); rs.min.val = data[i]; } else if (data[i] == rs.min.val) { rs.min.text += ",#" + (i + 1); } sum += data[i]; } rs.avg = sum / monCount; return rs; }, confirmStartRes: function confirmStartRes() { var self = this; var num = this.num; if (num == -1) { this.$message({ message: '请先选择电池组', type: 'warning' }); return; } // 确认框 this.$confirm('启动内阻测试?', '确认信息', { distinguishCancelAndClose: true, confirmButtonText: '确定', cancelButtonText: '取消', callback: function callback(action, instance) { if (action == 'confirm') { self.startBattResTest(num); } } }); }, startBattResTest: function startBattResTest(num) { var self = this; //console.log(num); if (num == -1) { this.$message({ message: '请先选择电池组', type: 'warning' }); return; } // 加载等待 this.loading.show(); if (typeof DeviceService != 'undefined') { DeviceService.startBattResTest(num); } else { this.battInfo.sysstate = 1; // 提示 this.$message({ message: '请使用手机端启动!', type: 'warning' }); setTimeout(function () { self.loading.hide(); }, 4000); } }, confirmStopRes: function confirmStopRes() { var self = this; var num = this.num; if (num == -1) { this.$message({ message: '请先选择电池组', type: 'warning' }); return; } // 确认框 this.$confirm('停止内阻测试?', '确认信息', { distinguishCancelAndClose: true, confirmButtonText: '确定', cancelButtonText: '取消', callback: function callback(action, instance) { if (action == 'confirm') { self.stopBattResTest(num); } } }); }, stopBattResTest: function stopBattResTest(num) { var self = this; //console.log(num); if (num == -1) { this.$message({ message: '请先选择电池组', type: 'warning' }); return; } // 加载等待 this.loading.show(); if (typeof DeviceService != 'undefined') { DeviceService.stopBattResTest(num); } else { this.battInfo.sysstate = 0; // 提示 this.$message({ message: '请使用手机端停止!', type: 'warning' }); setTimeout(function () { self.loading.hide(); }, 4000); } }, confirmRestart: function confirmRestart() { var self = this; var num = this.num; if (num == -1) { this.$message({ message: '请先选择电池组', type: 'warning' }); return; } // 确认框 this.$confirm('重启汇集器?', '确认信息', { distinguishCancelAndClose: true, confirmButtonText: '确定', cancelButtonText: '取消', callback: function callback(action, instance) { if (action == 'confirm') { self.reStartSystem(num); } } }); }, reStartSystem: function reStartSystem(num) { var self = this; //console.log(num); if (num == -1) { this.$message({ message: '请先选择电池组', type: 'warning' }); return; } // 加载等待 this.loading.show(); if (typeof DeviceService != 'undefined') { DeviceService.reStartSystem(num); } else { this.battInfo.sysstate = 0; // 提示 this.$message({ message: '请使用手机端重启!', type: 'warning' }); setTimeout(function () { self.loading.hide(); }, 4000); } }, setHt: function setHt() { var pgHt = this.$refs.tabItemHt.offsetHeight - 1; this.options.monVol.height = pgHt + 'px'; this.options.monRes.height = pgHt + 'px'; this.options.monTmp.height = pgHt + 'px'; this.tbls.monInfo.height = pgHt + 'px'; }, handlePreBtn: function handlePreBtn() { var self = this; if (this.options.page.curr <= 1) { this.$message('当前已经是第一页'); return; } this.options.page.curr--; this.loading.show(); setTimeout(function () { // 设置配置项 self.setOption(); }, 0); }, handleNextBtn: function handleNextBtn() { var self = this; if (this.options.page.curr * this.options.page.size >= this.options.page.total) { this.$message('当前已经是最后一页'); return; } this.options.page.curr++; this.loading.show(); setTimeout(function () { // 设置配置项 self.setOption(); }, 0); }, initPage: function initPage() { // 初始化图表分页信息 // 初始化页数为1 this.options.page.curr = 1; // 设置total this.options.page.total = 0; }, getStartEndIndex: function getStartEndIndex() { // 根据分页信息获取起始和结束点 var page = this.options.page; var start = (page.curr - 1) * page.size; var end = (page.curr - 1) * page.size + page.size; if (end > page.total) { end = page.total; } return { start: start, end: end }; }, setPageTotal: function setPageTotal(total) { // 设置分页的总数据量 this.options.page.total = total; if (total == 0) { this.options.page.pageTotal = 1; } else { this.options.page.pageTotal = Math.ceil(total / this.options.page.size); } }, monHandlerClick: function monHandlerClick(event) { var self = this; var page = this.options.page; var monNum = event.point.index + 1 + (page.curr - 1) * page.size; this.options.monResLine.title = '单体#' + monNum + '内阻折线图'; // 构造查询对象 var searchParams = { BattGroupId: this.BattGroupId, mon_num: monNum }; // 开启等待框 this.loading.show(); if (typeof BattresdataService != "undefined") { BattresdataService.serchByCondition(JSON.stringify(searchParams)); } else { setTimeout(function () { self.loading.hide(); self.setMonResLine([{ mon_res: 10, test_starttime: '2019-12-03 10:09:00' }, { mon_res: 11, test_starttime: '2019-12-03 11:09:00' }, { mon_res: 9, test_starttime: '2019-12-03 12:09:00' }]); self.uiDialog.open(); }, 1000); } }, setMonResLine: function setMonResLine(data) { var monRes = [[]]; var times = []; // 遍历data for (var i = 0; i < data.length; i++) { var _data = data[i]; monRes[0].push(_data.mon_res); times.push(_data.test_starttime); } this.options.monResLine.categories = times; this.options.monResLine.data = monRes; // 设置配置项 this.$refs.monResLine.setOption(this.options.monResLine); } }, created: function created() { var self = this; // 显示左侧弹出框 setTimeout(function () { self.shows.drawer = true; }, 0); // 显示单体列表 setTimeout(function () { self.shows.monList = true; }, 0); // 显示统计信息 setTimeout(function () { self.shows.total = true; }, 0); // 显示单体电压 setTimeout(function () { self.shows.monVol = true; }, 0); // 显示单体内阻 setTimeout(function () { self.shows.monRes = true; }, 0); // 显示单体温度 setTimeout(function () { self.shows.monTmp = true; }, 0); // 显示单体内阻折线 setTimeout(function () { self.shows.monResLine = true; }, 0); }, computed: { getTitle: function getTitle() { return this.title + '-监测数据'; }, getRestart: function getRestart() { var rs = true; // 电池组状态为浮充,系统状态为常规状态 if (this.battInfo.battstate == 0 && this.battInfo.sysstate == 0) { rs = false; } return rs; }, getBattNum: function getBattNum() { var rs = ""; if (this.num != -1) { rs = '#' + this.num; } return rs; }, setPagingPreBtn: function setPagingPreBtn() { var rs = true; if (this.tabs.active == 0 || this.tabs.active == 1 || this.options.page.curr <= 1) { return false; } return rs; }, setPagingNextBtn: function setPagingNextBtn() { var rs = true; if (this.tabs.active == 0 || this.tabs.active == 1 || this.options.page.curr * this.options.page.size >= this.options.page.total) { return false; } return rs; } }, mounted: function mounted() { var self = this; // 页面选项卡 var uiTab = bui.tab({ id: "#uiTab", animate: false, swipe: false }); // 选项卡绑定事件 uiTab.on('to', function (index) { self.tabs.active = index; self.tabsChange(); }); // 创建 Chart 对象 monVolBar = new FGraph(this.$refs.monVolBar); monResBar = new FGraph(this.$refs.monResBar); monTmpBar = new FGraph(this.$refs.monTmpBar); // 自定义居中弹出框 this.uiDialog = bui.dialog({ id: "#dialogCenter", width: 700 }); // 查询所有已经安装的电池组 this.searchAll(); // 设置高度 this.setHt(); // 后台触发事件查询所有的电池组信息 window['BattinfServicesearchAllcalljs'] = function (res) { var data = res.data; self.setList(data); }; // 后台触发返回读取电池组信息 window['DeviceServicereadBattMonInfocalljs'] = function (res) { //console.log(res); // 设置页面信息 self.setPageContent(res); // 开启延时执行 self.timer.open(); }; // 启动内阻测试 window['DeviceServicestartBattResTestcalljs'] = function (res) { //console.log(res); // 关闭等待 self.loading.hide(); // 根据返回结果显示内容 if (res.code == 1) { self.$message({ message: '启动成功!', type: 'success' }); } else { self.$message.error('启动失败!'); } }; // 停止内阻测试 window['DeviceServicestopBattResTestcalljs'] = function (res) { //console.log(res); // 关闭等待 self.loading.hide(); // 根据返回结果显示内容 if (res.code == 1) { self.$message({ message: '停止成功!', type: 'success' }); } else { self.$message.error('停止失败!'); } }; // 停止内阻测试 window['DeviceServicereStartSystemcalljs'] = function (res) { //console.log(res); // 关闭等待 self.loading.hide(); // 根据返回结果显示内容 if (res.code == 1) { self.$message({ message: '重启汇集器成功!', type: 'success' }); } else { self.$message.error('重启汇集器失败!'); } }; // 获取单体内阻信息 window['BattresdataServiceserchByConditioncalljs'] = function (res) { console.log(res); // 关闭等待 self.loading.hide(); // 根据返回结果显示内容 if (res.code == 1) { self.setMonResLine(res.data); } else { self.setMonResLine([]); } // 显示面板 self.uiDialog.open(); }; }, destroyed: function destroyed() { // 注销方法 window.BattinfServicesearchAllcalljs = null; window.DeviceServicereadBattMonInfocalljs = null; window.DeviceServicestartBattResTestcalljs = null; window.DeviceServicestopBattResTestcalljs = null; // 停止计时器 this.timer.stop(); } }); }, destroyed: function destroyed() { this.vm.$destroy(); } });