var reiniting = false, timeout = 0, outtime = 800; var vm = new Vue({ el: '#app', data: { i18n: { title1: "报表管理", title4: "其他配置", title5: "预览", t1_1: "新建报表", t1_2: "打开报表", t1_3: "保存报表", t2_1: "图片", }, /*报表文件管理*begin*/ save_loading: false, openedFile: {}, reportFilesPanel: false, reportFiles: [{ label: '报表', code: 'root', expand: false, filetype: 'report', children: [] }], reportModes: [{ label: '模板', code: 'mode', filetype: 'mode', type: 'files', children: [{ label: '模板1', code: 'mode_1', filetype: 'mode', type: 'file', children: [] }] }], fileName: '', fileSelected: '', checkedFiles: [], showFileRename: false, fileRename: '', isSave: true, newFile: false, newFiles: false, isMode: false, fileSelected: '', fileSelectedReport: {}, reportFilesTips_nofile: false, reportFilesTips_file: false, reportFilesTips_files: false, /*报表文件管理*end*/ /*树操作*degin*/ editNodePanel: false, addNodePanel: false, edit_node_type: '', checked_dev_index: '', check_dev: [], dev_name_text: '', dev_code_text: '', clone_all_dev: [], edit_is_add: false, delete_box: false, show_field: false, dev_field: { label: 'label' }, deleteFlag: true, /*配置*begin*/ configure: false, activeName: 'first', border_type: '', border_type_list: [{ label: '实线', value: 'solid' }, { label: '点线', value: 'dotted' }, { label: '虚线', value: 'dashed' }, { label: '双线', value: 'double' }, { label: '3D凹槽线边框(需要边框线较大才有明显的效果)', value: 'groove' }, { label: '3D垄状线边框(需要边框线较大才有明显的效果)', value: 'ridge' }, { label: '3D凹形', value: 'inset' }, { label: '3D凸形', value: 'outset' }, ], border_bgcolor: '', border_zise: '', th_bgcolor: '', th_color: '', row_line_height: '', row_chang_color: 'no-color', report_bgcolor: '', report_font: '', report_size: '', report_color: '', report_textarea: '', paper_type: 'A4', paper_orientation: 'col', paper_size: { A4: { col: 1086, row: 756 }, A3: { col: 1548, row: 1084 } }, /*配置*end*/ /*表格*begin*/ form: {}, cols_width: [], radio_form: '', tb_title: { name: '表格标题', is_show: 'block', font_family: '微软雅黑', font_color: '#0096D7', font_size: '', align: 'center', top: 30, right: 10, bottom: 10, left: 10 }, tb_sub: { name: '表格副标题', is_show: 'none', font_family: '微软雅黑', font_color: '#0096D7', font_size: '', align: 'center', top: 10, right: 10, bottom: 10, left: 10 }, tb_detailed_1: { name: ' 自定义被描述:描述内容', is_show: 'none', font_family: '微软雅黑', font_color: '#0096D7', font_size: 'center', align: '', top: '', right: '', bottom: '', left: '' }, tb_detailed_2: { name: ' 表格编号:000', is_show: 'none', font_family: '微软雅黑', font_color: '#0096D7', font_size: '', align: 'center', top: '', right: '', bottom: '', left: '' }, tb_detailed_3: { name: ' 制表时间:' + new Date().toLocaleDateString(), is_show: 'block', font_family: '微软雅黑', font_color: '#0096D7', font_size: '', align: 'center', top: '', right: '', bottom: '', left: '' }, tb_detailed_4: { name: ' 制表人:' + (sessionStorage.getItem('name') || ''), is_show: 'block', font_family: '微软雅黑', font_color: '#0096D7', font_size: '', align: 'center', top: '', right: '', bottom: '', left: '' }, tb_width: '600px', table: '########################                                                                                                                                                                                ', /*表格*end*/ /*右侧选项卡*/ sidetabs: 'dev', /*向导*/ step: false, substep: 0, report_types: [], filter_check_dev: '', cur_report_type: {}, sketch_index: 0, report_s_month: 1, report_s_day: 1, report_s_hours: 0, report_interval: 1, report_style: [], cur_report_style: {}, station: [], profession: [], check_station: '', check_profession: '', all_dev: [], check_all: true, all_property: {}, property_tree: [], clone_property_tree: [], filter_all_dev: '', filter_all_dev_type: 'name', tree_loading: false, checked_node: { nodes: [] }, t_num: 0, check_off: '全选', filter_c: '', filter_q: '', ck_cd: '', ck_value: '', cd_info_check: { list: [], }, contrasts: [], all_totals: [], checked_contrast_index: [], checked_total_index: [], dev_tree: (function (n) { for (var i = 0, arr = []; i < n; i++) { arr.push({ label: '###', tid: i }); } return arr; })(8), time_tree: [], dev_map: [], dev_head: [], time_map: [], table_y_name: '时间', /*数据设置*begin*/ dataConfig: false, data_cd: false, data_dev: false, data_point: 2, text_key: 'code', old_text: '', new_text: '', digits_fixed: false, // 公式 cols_type: 'father', cols_parent: '', cols_value: '', formule_name: '', formule_value: '', protree_to_option: [], }, computed: { totals: function () { var vm = this; if (!vm.all_totals) { return [] } var obj = JSON.parse(JSON.stringify(vm.all_totals)); if (this.sketch.value == 'sy' || this.sketch.value == 'dd') { return [obj[obj.length - 1]]; } else { return obj; } }, devtree_to_option: function () { var arr = this.dev_tree; var parent = arr, i = 0, child = [], result = []; while (parent[i]) { if (parent[i].nodetype === "dev") { result.push(parent[i]) } else { if (parent[i].children && parent[i].children.length > 0) { Array.prototype.push.apply(child, parent[i].children); } } i++; if (parent[i] === undefined) { parent = child; child = []; i = 0; } } return result; }, adev_check: function () { var arr = this.cur_report_type.type; var index = this.sketch_index; this.postDev(); return arr[index].value != 'sy'; }, checked_dev_node: function () { return vm.check_dev[vm.checked_dev_index]; }, checked_total: function () { var arr = this.totals; var index = this.checked_total_index; for (var i = 0, n = []; i < index.length; i++) { n.push(arr[index[i]]); } return n; }, checked_contrast: function () { var arr = this.contrasts; var index = this.checked_contrast_index; for (var i = 0, n = []; i < index.length; i++) { n.push(arr[index[i]]); } return n; }, sketch: function () { var arr = this.cur_report_type.type; var index = this.sketch_index; var _temp_ = getReportStyle(); var text = "报表"; this.report_style = []; if (arr[index].value === 'sy') { this.cur_report_style = _temp_[0]; this.report_style.push(_temp_[0]); } else { this.report_style = _temp_; } this.tb_title.name = arr[index].name; if (this.tb_title.name.indexOf(text) === -1) { this.tb_title.name = this.tb_title.name + text; } return arr[index]; }, border_style: function () { return 'border-style:' + this.border_type + ';border-color:' + this.border_bgcolor + ';border-width:' + this.border_zise + 'px;height:' + this.row_line_height + 'px'; }, th_style: function () { return 'background-color:' + this.th_bgcolor + ';color:' + this.th_color; }, panel_style: function () { return 'background-color:' + this.report_bgcolor + ';color:' + this.report_color + ';font-family:' + this.report_font + ';font-size:' + this.report_size + ';' + this.report_textarea }, papers: function () { var o = this.paper_size[this.paper_type]; for (var i = 0, arr = []; i < 100; i++) { var str = ""; if (this.paper_orientation == 'col') { str = "width:" + o.col + 'px;height:' + o.row + 'px;'; } else { str = "height:" + o.col + 'px;width:' + o.row + 'px;'; } arr.push(str); } return arr; }, tb_title_style: function () { var obj = this.tb_title; return 'margin:auto;width:100%;' + setStyle(obj); }, tb_sub_style: function () { var obj = this.tb_sub; return 'margin:auto;width:width:100%;' + setStyle(obj); }, tb_detailed_1_style: function () { var obj = this.tb_detailed_1; return setStyle(obj); }, tb_detailed_2_style: function () { var obj = this.tb_detailed_2; return setStyle(obj); }, tb_detailed_3_style: function () { var obj = this.tb_detailed_3; return setStyle(obj); }, tb_detailed_4_style: function () { var obj = this.tb_detailed_4; return setStyle(obj); } }, methods: { selectDesabled: function () { if (this.sketch.value == 'sy') { this.report_s_month = 1; this.report_s_day = 1; this.report_s_hours = 0; this.report_interval = 1; return true; } return false; }, preview: function () { var obj = JSON.parse(JSON.stringify({ vm: vm.$data })); deleteReportFileItem(obj); delete obj.vm.checked_node; sessionStorage.setItem('dev_tree', pako.gzip(JSON.stringify(obj.vm.dev_tree), {to: "string"})); delete obj.vm.dev_tree; sessionStorage.setItem('vm', pako.gzip(JSON.stringify(obj.vm), {to: "string"})); }, /*报表文件管理*/ reportReName: function (item) { if (item.rename == false) { return false; } var fn = function (node, addobj) { vm.newFile = false; } var param = { operateFlag: 1, name: item.label, treeCode: item.treeCode, } auReport(param, param, fn); }, reInit: function () { var report = this.fileSelectedReport; if (!report) { vm.$notify({ title: '错误', message: '未选中报表。', type: 'error' }); return false; } if (report.type == 0) { this.checkedFiles = this.fileSelectedReport.children; return false; } this.$msgbox({ message: '确定打开该报表?', title: '提示', type: 'info', showCancelButton: true, confirmButtonText: '确定', cancelButtonText: '取消', callback: function (action, instance) { if (action == "confirm") { getReportDetail({ treeCode: report.treeCode }, function (report_defail) { var data = JSON.parse(report_defail); vm.dev_tree = []; reiniting = true; for (var k in data.vm) { if (k !== 'table') { vm[k] = data.vm[k]; } } vm.reportFilesPanel = false; vm.newFile = false; vm.table = data.vm.table; setTimeout(function () { reiniting = false; vm.refreshDevTree(); }, 200); }); } } }) }, update_checkedFiles: function () { this.checkedFiles.push(''); this.checkedFiles.pop(); }, fileClick: function (data, node, nodes) { this.checkedFiles = node.parent.data.children || node.parent.data; this.fileSelectedReport = data; this.update_checkedFiles(); }, reportDelete: function () { var report = this.fileSelectedReport; var text = ''; if (report && report.type == '0') { text = "确定删除该文件夹以及该文件夹下所有报表?"; } else if (report && report.type == '1') { text = "确定删除该报表?"; } this.$confirm(text, '提示', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'info', callback: function (action, instance) { if (action == 'confirm') { deleteReport(report, function (success) { if (success) { vm.$refs.report_tree.remove(report); vm.fileSelectedReport = {}; } }); } } }) }, addFiles: function () { if (timeout !== 0) { return false; } timeout = setTimeout(function () { timeout = 0 }, outtime); if (vm.newFiles == false) { return false; } if (!this.fileRename) { this.fileRename = '新建文件夹_' + (new Date().getTime()); } var param = { treePCode: '', name: '', type: 0, operateFlag: this.newFiles == false ? 1 : 0 }; var label = this.fileRename; var path = []; var node = {}; param.name = label; if (this.checkedFiles[0]) { path = this.checkedFiles[0].path.split('/'); param.treePCode = this.checkedFiles[0].treePCode; } else { if (this.fileSelectedReport && this.fileSelectedReport.type == 0) { param.treePCode = this.fileSelectedReport.treeCode; } else if (this.fileSelectedReport && this.fileSelectedReport.type == 1) { vm.$notify({ title: '提示', message: '不能添加为报表的子级', type: 'warning' }); return false; } } if (path.length < 2) { path = label; } else { path[path.length - 1] = label; path = path.join('/'); } node = { "label": label, "code": 'files' + (vm.t_num++), "type": 0, "path": path, "treePCode": param.treePCode || '', "children": [] } var fn = function (node, addobj) { node.treeCode = addobj.treeCode; vm.checkedFiles.push(node); vm.fileRename = ''; vm.newFiles = false; } this.save_loading = true; auReport(param, node, fn) }, updateFile: function () { if (timeout !== 0) { return false; } timeout = setTimeout(function () { timeout = 0 }, outtime); if (this.newFile || this.newFiles) { return false; } if ((!this.fileSelectedReport.treeCode) || this.fileSelectedReport.type != 1) { vm.$notify({ title: '提示', message: '没有选中的报表', type: 'warning' }); return false; } this.$confirm('确定到报表 "' + this.fileSelectedReport.label + '" ?', '提示', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'info', callback: function (action, instance) { if (action == 'confirm') { var obj = JSON.parse(JSON.stringify({ vm: vm.$data })); deleteReportFileItem(obj) auReport({ treeCode: vm.fileSelectedReport.treeCode, treePCode: vm.fileSelectedReport.treePCode, name: vm.fileSelectedReport.label, type: 1, fileDetail: JSON.stringify(obj), operateFlag: 1 }); } } }) }, addFile: function () { if (timeout !== 0) { return false; } timeout = setTimeout(function () { timeout = 0 }, outtime); if (vm.newFile == false) { return false; } if (!this.fileRename) { this.fileRename = '新建报表_' + (new Date().getTime()); } var obj = JSON.parse(JSON.stringify({ vm: vm.$data })); deleteReportFileItem(obj); var param = { treePCode: '', name: '', type: 1, fileDetail: JSON.stringify(obj), operateFlag: vm.newFile ? 0 : 1 } var path = []; var label = this.fileRename; param.name = label; if (this.checkedFiles[0]) { path = this.checkedFiles[0].path.split('/'); param.treePCode = this.checkedFiles[0].treePCode; } else { if (this.fileSelectedReport && this.fileSelectedReport.type == 0) { param.treePCode = this.fileSelectedReport.treeCode; } else if (this.fileSelectedReport && this.fileSelectedReport.type == 1) { vm.$notify({ title: '提示', message: '不能添加为报表的子级', type: 'warning' }); return false; } } if (path.length < 2) { path = label; } else { path[path.length - 1] = label; path = path.join('/'); } var node = { "label": label, "code": 'file' + (vm.t_num++), "type": 1, "treePCode": param.treePCode || "", "path": path } var fn = function (node, addobj) { node.treeCode = addobj.treeCode; vm.checkedFiles.push(node); vm.fileRename = ''; vm.newFile = false; }; this.save_loading = true; auReport(param, node, fn) }, reportPanelDblClick: function (report) { if (report.type == '0') { if (!report.children) { report.children = []; } this.checkedFiles = report.children; this.update_checkedFiles(); } else if (report.type == '1' && (!this.isSave)) { this.reInit(); } // if(report.filetype=='mode'){ // tempInit(); // this.reportFilesPanel=false; // this.outerVisible1=true; // } }, addNewFiles: function () { this.newFiles = true; this.fileRename = '' }, addNewFile: function () { this.newFile = true; this.fileRename = '' }, reportRename: function () { if (this.fileSelectedReport) { vm.$set(this.fileSelectedReport, 'rename', true); } }, reportPanelClick: function (report) { this.$refs.report_tree.setCurrentKey(report.code); this.fileSelectedReport = report; if (!this.isSave) { this.fileName = report.path; } }, /*树*/ addFormula: function () { this.cols_type = 'father'; this.cols_parent = ''; this.cols_value = ''; this.formule_name = ''; this.formule_value = ''; this.protree_to_option = []; this.addNodePanel = true; }, changeAllXNode: function () { var key = this.text_key; var oldtxt = this.old_text; var newtxt = this.new_text; if (!oldtxt || !newtxt) { return false; } this.changeNodeCode(vm.dev_tree, key, oldtxt, newtxt); this.refreshDevTree(); }, changeNodeCode: function (arr, key, ot, nt) { for (var i = 0; i < arr.length; i++) { var d = arr[i]; if (d[key] && d[key].indexOf(ot) !== -1) { d[key] = d[key].replace(ot, nt); } if (d.children && d.children.length > 0) { this.changeNodeCode(d.children, key, ot, nt); } } }, change_input_text: function (data) { if (data.nodetype == this.checked_dev_node.nodetype) { this.dev_name_text = data.label; this.dev_code_text = data.code; } else { this.$notify({ title: "提示", message: "不是相同中类的节点" }); } }, editXNode: function (node, data) { this.edit_node_type = data.devType; var arr = [data]; if (data.devType) { for (var i = 0; i < data.children.length; i++) { var d = data.children[i]; //测点 arr.push(d); for (var n = 0; n < d.children.length; n++) { arr.push(d.children[n]); } } } this.check_dev = arr; this.editNodePanel = true; }, changeLabel: function () { this.checked_dev_node.label = this.dev_name_text; this.checked_dev_node.code = this.dev_code_text; }, addXNode: function () { var data = []; if (vm && vm.dev_tree) { data = JSON.stringify(vm.dev_tree); } this.x_check = JSON.parse(data); this.addColPanel = true; if (this.$refs.col_tree) { this.$refs.col_tree.filter(); } }, refreshDevTree: function () { this.dev_tree.push(''); this.dev_tree.pop(); }, transposition: function () { this.cur_report_style = this.cur_report_style.value == this.report_style[0].value ? this.report_style[1] : this.report_style[0]; this.refreshDevTree(); }, allowDrag: function () { return true }, allowDrop: function (nodeing, node, type) { // type:inner/prev/next this.$refs.x_tree.setCurrentNode(node); var key = node.key; var t = true; switch (0) { case nodeing.key.indexOf('p_f'): if (type != 'inner') { t = key.indexOf('p_') == 0; } else { t = key.indexOf('d_f') == 0; } break; case nodeing.key.indexOf('c_'): t = key.indexOf('c_') == 0; break; case nodeing.key.indexOf('d_'): if (type != 'inner') { t = key.indexOf('d_') == 0; } else { t = key.indexOf('c_') == 0; } break; case nodeing.key.indexOf('t_'): if (type != 'inner') { t = key.indexOf('t_') == 0; } else { t = key.indexOf('d_') == 0; } break; case nodeing.key.indexOf('p_'): if (type != 'inner') { t = key.indexOf('p_') == 0; } else { t = key.indexOf('t_') == 0; } break; case nodeing.key.indexOf('s_'): if (type != 'inner') { t = key.indexOf('s_') == 0; } else { t = key.indexOf('p_') == 0; } break; } return t; }, nodeDrop: function (n, o, s) { this.refreshDevTree(); var ptid = ''; if (s == 'inner') { ptid = o.data.tid; } else { ptid = o.data.ptid; } this.$set(n.data, 'ptid', ptid); }, expendDev: function (event, dev) { //展开到设备这一级 if (dev === undefined) { dev = this.$refs.x_tree.store.root.childNodes; } for (var i = 0; i < dev.length; i++) { if (dev[i].data.nodetype == 'dev') { dev[i].expanded = false; } else { dev[i].expanded = true; if (dev[i].childNodes.length > 0) { this.expendDev(event, dev[i].childNodes); } } } }, changePtid: function () { }, deleteNode: function (node, data) { var c = this.$createElement; if (data.devType === false) { this.delete_box = true; } else { this.$confirm('确定删除该节点?', '提示', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning', callback: function (action, instance) { if (action == 'confirm') { vm.$refs.x_tree.remove(node); vm.refreshDevTree(); } } }); } }, filterXNode: function (value, data) { if (!value) return true; return data.label.indexOf(value) !== -1; }, /*配置*/ makeFormule: function () { var type = this.cols_type; var name = this.formule_name; var code = this.formule_value; if (!name) { vm.$notify({ title: '错误', message: '请输入列名!', type: 'error' }); return; } if (type !== "father") { if (!code) { vm.$notify({ title: '错误', message: '请输入列值!', type: 'error' }); return; } } this.dev_tree.push({ label: name, name: name, nodetype: type == "father" ? 'fml_type' : type == "code" ? 'fml' : 'fml_string', code: code, tid: type !== "father" ? ('p_f' + vm.t_num++) : ('d_f' + vm.t_num++), }); this.addNodePanel = false; }, formulAddCode: function () { var v = this.formule_value; var code; if (this.sketch.value == 'sy') { code = '[' + this.cols_value + ']'; } else { code = '[' + this.devtree_to_option[vm.cols_parent].code + ';' + this.cols_value + ']'; } if (v) { var last = v[v.length - 1]; if (last === '+' || last === '-' || last === '*' || last === '/' || last === '(') { this.formule_value = v + code; } else { vm.$notify({ title: '错误', message: '请先输入运算符!', type: 'error' }); } } else { this.formule_value = code; } }, formulAddNum: function (n) { var v = this.formule_value; if (v) { var last = v[v.length - 1]; if (last === '+' || last === '-' || last === '*' || last === '/' || last === '(') { this.formule_value = v + n; } else if (Number(last)) { this.formule_value = v + n; } else { vm.$notify({ title: '错误', message: '请先输入运算符!', type: 'error' }); } } else { this.formule_value = n; } }, formulAddPrth: function (p) { var v = this.formule_value; v = !v ? '' : v; if (p === '(') { if ((!v) || v[v.length - 1] === '+' || v[v.length - 1] === '-' || v[v.length - 1] === '*' || v[v.length - 1] === '/' || v[v.length - 1] === '(') { this.formule_value = v + '('; } else { vm.$notify({ title: '错误', message: '请先输入运算符!', type: 'error' }); } } else { if ((!v) || v[v.length - 1] === '+' || v[v.length - 1] === '-' || v[v.length - 1] === '*' || v[v.length - 1] === '/' || v[v.length - 1] === '(') { vm.$notify({ title: '错误', message: '请先输入代码或数字!', type: 'error' }); } else { this.formule_value = v + ')'; } } }, formuleBack: function () { var v = this.formule_value; if (v) { var last = v[v.length - 1]; if (last === '+' || last === '-' || last === '*' || last === '/' || last === '(' || last === ')') { this.formule_value = v.substring(0, v.length - 1); } else { var arr = this.formule_value.split(/[\+\-\*\/\(\)]/); this.formule_value = v.substring(0, v.length - arr[arr.length - 1].length); } } }, formulAddOperator: function (o) { var v = this.formule_value; if (v) { var last = v[v.length - 1]; if (last === '+' || last === '-' || last === '*' || last === '/' || last === '(') { vm.$notify({ title: '错误', message: '请先输入代码或数字!', type: 'error' }); } else { this.formule_value = v + o; } } else { vm.$notify({ title: '错误', message: '请先输入代码或数字!', type: 'error' }); } }, /*向导*/ reInitSDate: function () { this.report_s_month = 1; this.report_s_day = 1; this.report_s_hours = 0; this.report_interval = 1; }, reIniCheckNode: function () { this.checked_node = { nodes: [] } }, expendChecked: function (event) { var dev = this.$refs.dev_tree.store.root.childNodes; this.expendDev(event, dev); }, checkedchecked: function (node) { var n = this.$refs.dev_tree.getNode(node); this.checkedAll(n.childNodes, n.checked); }, checkedAll: function (dev, checked) { //选中到设备这一级 if (dev === undefined) { dev = this.$refs.dev_tree.store.root.childNodes; } if (checked === undefined) { checked = !this.check_all; } for (var i = 0; i < dev.length; i++) { if (dev[i].data.devType !== undefined && dev[i].visible) { dev[i].checked = checked; } if (dev[i].childNodes.length > 0) { this.checkedAll(dev[i].childNodes, checked); } } }, checkedDel: function () { var dev = this.$refs.dev_tree.getCheckedNodes(); for (var i = 0; i < dev.length; i++) { this.$refs.dev_tree.remove(dev[i]); delete this.checked_node[dev[i].treeCode]; } }, noneChild: function () { var t = true; for (var k in this.checked_node) { if (k !== 'nodes' && this.checked_node[k].devType && (this.checked_node[k].children == undefined || this.checked_node[k].children.length == 0)) { this.$confirm('您有设备未添加测点,是否继续下一步?', '提示', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning', callback: function (action, instance) { if (action == 'confirm') { vm.substep = Math.roundFixed(++vm.substep); } else if (action == 'cancel') { return false; } } }); t = false; break; } } if (t) { vm.substep = Math.roundFixed(++vm.substep); } }, statisticFinish: function () { var property = this.$refs.c_tree.getCheckedNodes(); if (property.length == 0) { this.$alert('请选择要添加的测点', '错误', { confirmButtonText: '确定', callback: function () {} }); return false; } //统计*y轴树 var obj = this.propertyDataOp(property, vm.t_num++, ''); this.time_tree = obj.arr; //统计*x轴树 this.createXTree(); this.step = false; this.openedFile = {}; }, totalFinish: function () { this.createYTree(); for (var i = 0; i < this.checked_total.length; i++) { var item = this.checked_total[i]; this.time_tree.push({ label: item.label, code: item.value, tid: 'l_' + this.t_num++ }) } this.createXTree(); this.step = false; this.openedFile = {}; }, contrastFinish: function () { //对比*y轴树 for (var i = 0, arr = []; i < this.checked_contrast.length; i++) { var c = this.checked_contrast[i]; arr.push({ label: c.label, code: c.value, tid: '_c' + vm.t_num++ }); } this.time_tree = arr; //对比*x轴树 this.createXTree(); this.step = false; this.openedFile = {}; }, createXTree: function () { var arr = JSON.parse(JSON.stringify(vm.checked_node.nodes)); this.dev_tree = arr; }, createYTree: function () { //时间格式this.cur_report_type,this.sketch //时间间隔this.report_interval //开始时间this.report_s_month,this.report_s_day,this.report_s_hours var strat, type = this.cur_report_type.value, ban = this.sketch.value; if (type == 'day' || type == 'udf') { strat = this.report_s_hours; } else if (type == 'year') { strat = this.report_s_month; } else { strat = this.report_s_day; } strat = isNaN(strat * 1) ? 1 : strat * 1 this.time_tree = getTimeList(type, strat, vm.report_interval, ban); }, propertyDataOp: function (property, num, ptid) { //处理测点数据方法 var probj = { arr: [] }; for (var i = 0; i < property.length; i++) { var pn = objClone(property[i]); pn.children = []; pn.tid = pn.tid + '_' + num; pn.ptid = pn.ptid + '_' + num; if (probj[pn.tid] === undefined) { probj[pn.tid] = pn; } else { pn.children = probj[pn.tid].children; probj[pn.tid] = pn; } var parentNodeOp = function () { if (probj[pn.ptid] === undefined) { probj[pn.ptid] = { tid: pn.ptid, children: [pn] } } else { probj[pn.ptid].children.push(pn); } } if (pn.tid.indexOf('p') == 0) { if (this.ck_cd) { pn.ptid = ptid; probj.arr.push(probj[pn.tid]) } else { parentNodeOp(); } } else if (pn.tid.indexOf('s') == 0) { var _pid = pn.ptid.replace('_' + num, '') if (_pid === undefined || _pid === '' || _pid === 'undefined') { pn.ptid = ptid; probj.arr.push(probj[pn.tid]) } else { parentNodeOp(); } } else { if (!this.ck_cd) { pn.ptid = ptid; probj.arr.push(probj[pn.tid]) } } } return probj; }, addProperty: function () { var dev = this.$refs.dev_tree.getCheckedNodes(); var property = this.$refs.c_tree.getCheckedNodes(); var dev_obj = this.recursion({ recursion: false }, dev); var prop_obj = this.recursion({ key: 'tid', recursion: false }, property); if (dev.length == 0 || property.length == 0) { this.$alert(dev.length == 0 ? '请选择要添加测点的设备' : '请选择要添加的测点', '提示', { confirmButtonText: '确定', }); return false; } //处理设备数据 var JSON_prop = JSON.stringify(prop_obj); //记录不同的测点属性 for (var d in dev_obj.d_) { var num = this.t_num++; var _prop = JSON.parse(JSON_prop); var _child = this.recursion({ key: 'tid', recursion: true }, dev_obj.d_[d].children); //记录不同的测点类型 var t_obj = {}, unt_obj = {}, n_node = []; for (var t in _prop.t_) { var tcode = ""; for (var ct in _child.t_) { if (ct.indexOf(t) === 0) { tcode = ct; } } if (tcode === '') { t_obj[_prop.t_[t].tid] = _prop.t_[t]; n_node.push(_prop.t_[t]); } else { unt_obj[t] = _child.t_[tcode]; } } //记录不同的测点 var p_obj = {}, unp_obj = {}; for (var p in _prop.p_) { var pcode = ""; for (var cp in _child.p_) { if (cp.indexOf(p) === 0) { pcode = cp; } } if (pcode === '') { if (unt_obj[_prop.p_[p].ptid] === undefined) { p_obj[_prop.p_[p].tid] = _prop.p_[p]; n_node.push(_prop.p_[p]); } else { var obj = _prop.p_[p]; var ptid = _prop.p_[p].ptid; obj.tid = obj.tid + '_' + num; obj.ptid = unt_obj[ptid].tid; unt_obj[ptid].children.push(obj); } } else { unp_obj[p] = _child.p_[pcode]; } } //记录不同的测点属性 var s_obj = {}; for (var s in _prop.s_) { var scode = ""; for (var cs in _child.s_) { if (cs.indexOf(s) === 0) { scode = cs; } } if (scode === '') { if (unp_obj[_prop.s_[s].ptid] === undefined) { s_obj[_prop.s_[s].tid] = _prop.s_[s]; n_node.push(_prop.s_[s]); } else { var obj = _prop.s_[s]; var ptid = _prop.s_[s].ptid; obj.tid = obj.tid + '_' + num; obj.ptid = unp_obj[ptid].tid; unp_obj[ptid].children.push(obj); } } } var _obj = this.propertyDataOp(n_node, num, dev_obj.d_[d].tid); //属相对象 dev_obj.d_[d].children = dev_obj.d_[d].children.concat(_obj.arr); } // for(var i=0;i 0) { n = n.concat(o.children); } } if (n.length == 0 || !op.recursion) { return obj; } else { return this.recursion(op, n, obj); } }, nodeFor: function (obj) { var o = objClone(obj); if (o.children && o.children.length > 0) { o.tid = 'c_' + this.t_num++; } else { o.tid = 'd_' + this.t_num++; } o.children = []; return o; }, creatDevTree: function () { if (this.sketch.value == 'sy') { var node = vm.$refs.adev_tree.getCurrentNode(); this.checked_node.nodes = []; for (var i = 0, _arr = ['峰', '平', '谷', '尖']; i < _arr.length; i++) { var _id = node.devCode + ';' + vm.t_num + ';'; var _o = { label: _arr[i], code: _id, nodetype: 'dev', devCode: node.devCode, devType: true, children: [], tid: 'd_' + vm.t_num++ } this.checked_node[_id] = _o; this.checked_node.nodes.push(_o); } getProceeds(node.devCode); if (node) { this.substep = Math.roundFixed(++this.substep); } else { this.$alert('您未选中任何设备!', '提示', { confirmButtonText: '确定', callback: function () {} }); } return false; } this.check_all = true; var dev = {}; //原先选中的设备 var adev = {}; //全部设备中选中的设备 dev = this.checked_node; adev.dev_list = vm.$refs.adev_tree.getCheckedNodes(false, true); if (dev.nodes.length > 0 || adev.dev_list.length > 0) { this.substep = Math.roundFixed(++this.substep); } else { this.$alert('您未选中任何设备!', '提示', { confirmButtonText: '确定', callback: function () {} }); return false; } //同步对象和节点 if (dev.nodes.length > 0 && (dev.nodes[0] !== dev[dev.nodes[0].treeCode])) { var _temp = dev.nodes; dev = { nodes: _temp }; var _temp_arr = _temp; while (_temp_arr.length > 0) { for (var i = 0, _arr = []; i < _temp_arr.length; i++) { var d = _temp_arr[i]; dev[d.treeCode] = d; if (d.children && d.children.length > 0) { var ntpye = d.children[0].nodetype; if (ntpye !== 'property_type' && ntpye !== 'property') { _arr = _arr.concat(d.children); } } } _temp_arr = _arr; } } //过滤数据 for (var i = 0, gl = {}; i < adev.dev_list.length; i++) { var d = adev.dev_list[i]; if (dev[d.treeCode] === undefined) { var obj_d = this.nodeFor(d); dev[d.treeCode] = obj_d; gl[obj_d.treeCode] = obj_d; } } //处理自己的层级关系 var arr = []; for (var k in gl) { var d = gl[k]; if ((!d.treePCode) || gl[d.treePCode] === undefined) { arr.push(d); } else { d.ptid = gl[d.treePCode].tid; gl[d.treePCode].children.push(d); } } //生成nodes for (var i = 0; i < arr.length; i++) { var d = arr[i]; if (dev[d.treePCode] === undefined) { d.ptid = ""; dev.nodes.push(d); } else { d.ptid = dev[d.treePCode].tid; dev[d.treePCode].children.push(d); } } //生成devModel var devmodels = { arr: [] }; for (var k in dev) { if (k == 'nodes') { continue; } if (devmodels[dev[k].devModelCode] !== undefined) { devmodels.arr.push(dev[k].devModelCode); devmodels[dev[k].devModelCode] = dev[k].devModelCode; } } getCdInfo({ devTpName: devmodels.arr.join(';') }) }, checkSelectedStatus: function (nodes) { var node_on = 0, node_off = 0; for (var i = 0, len = nodes.childNodes.length; i < len; i++) { var node = nodes.childNodes[i]; if (node.checked || node.indeterminate) { node_on++; } else { node_off++; } } if (node_on == len) { nodes.checked = true; nodes.indeterminate = false; } else if (node_off == len) { nodes.checked = false; nodes.indeterminate = false; } else { nodes.checked = true; nodes.indeterminate = true; } }, checkVisible: function (data, checked) { var node = this.$refs.adev_tree.getNode(data); var ac = false, auc = false; var checkedStatus = node.checked; var _arr = node.childNodes; while (_arr.length > 0) { for (var i = 0, _temp = []; i < _arr.length; i++) { var n = _arr[i]; if (n.visible) { this.$refs.adev_tree.setChecked(n.data, checkedStatus); } if (n.childNodes.length > 0) { _temp = _temp.concat(n.childNodes); } if (n.checked) { ac = true; } else { auc = true; } } _arr = _temp; if (ac && auc) { n.parent.indeterminate = true; } } this.checkSelectedStatus(node.parent); // } }, postDev: function () { var vm = this; this.all_dev = []; this.tree_loading = true; if (this && this.check_profession) { getDev(vm.check_profession, vm.check_station); } }, filterMspsNode: function (value, data) { if (!this.filter_c && !this.filter_q) return true; var ps = false, node; var fc = this.filter_c.split(/\s+/g); var fq = this.filter_q.split(/\s+/g); if (data.tid.indexOf('s') == 0) { if (!this.editNodePanel) { node = this.$refs.c_tree.getNode(data).parent.data; } else { node = this.$refs.clone_c_tree.getNode(data).parent.data; } }; if (!this.filter_q) { if (data.tid.indexOf('p') == 0) { // ps=data.label.indexOf(vm.filter_c)!==-1 ps = this.filterMulty(data.label, fc); } else if (data.tid.indexOf('s') == 0) { // ps=node.label.indexOf(vm.filter_c)!==-1 ps = this.filterMulty(node.label, fc); } } else if (!this.filter_c) { if (data.tid.indexOf('s') == 0) { // ps=data.label.indexOf(vm.filter_q)!==-1 ps = this.filterMulty(data.label, fq); } } else { if (data.tid.indexOf('p') == 0) { // ps=data.label.indexOf(vm.filter_c)!==-1 ps = this.filterMulty(data.label, fc); } else if (data.tid.indexOf('s') == 0) { // ps=data.label.indexOf(vm.filter_q)!==-1&&node.label.indexOf(vm.filter_c)!==-1 ps = this.filterMulty(data.label, fq) && this.filterMulty(node.label, fc); } } return ps; }, filterCheckNode: function (value, data) { if (!value || data.nodetype === 'dev_type') return true; var str = value.split(/\s+/g); var d = data; if (d.nodetype !== 'dev') { do { var n = this.$refs.dev_tree.getNode(d).parent; d = n ? n.data : d; } while (n && d.nodetype !== 'dev'); } return this.filterMulty(d.label, str); }, filterDevNode: function (value, data) { if (!value) return true; var str = value.split(/\s+/g); if (this.step) { var node = this.$refs.adev_tree.getNode(data); } else { var node = this.$refs.clone_adev_tree.getNode(data); } var t = false; if (this.filter_all_dev_type == 'code') { t = this.filterMulty(data.code, str); } else { t = this.filterMulty(data.label, str); } return t; }, filterMulty: function (data, value) { for (var i = 0, t = false; i < value.length; i++) { if (value[i] === '' || value[i] === undefined || value[i] === null) { continue; } if (data.indexOf(value[i]) !== -1) { t = true; } } return t; }, setTableType: function (type) { this.cur_report_type = type; this.sketch = type.type[0]; if (this.sketch_index === '' || this.sketch_index === undefined || this.sketch_index > (this.cur_report_type.type.length - 1)) { this.sketch_index = 0; } this.reInitSDate(); }, changeReportType: function () { var t = this.sketch.value; var num = Math.floor(vm.substep); if (t === 'yx') { /*运行*/ this.substep = num; } else if (t === 'dd') { /*电度*/ this.substep = num + 0.01; } else if (t === 'bb') { /*报表*/ this.substep = num + 0.02; } else if (t === 'cr') { /*班报表*/ this.substep = num + 0.03; } else if (t === 'tj') { /*统计*/ this.substep = num + 0.05; this.reIniCheckNode(); } else if (t === 'db') { /*对比*/ this.substep = num + 0.06; } else if (t === 'qx') { /*全线*/ this.substep = num + 0.07; } }, reportInterval: function (str, fn) { var arr = getReportIntreval(); if (this.cur_report_type.value !== 'udf') { arr.length = 3; } fn(arr); }, reportIntervalClear: function () { this.report_interval = ''; }, /*菜单*/ menuSelect: function (v) { if (v == 4) { this.configure = true; } else if (v == 6) { } else if (v == '1-1') { //初始化参数 vm.filter_check_dev = ''; vm.filter_c = ''; vm.filter_q = ''; vm.filter_all_dev = ''; vm.filter_all_dev_type = 'name'; if (this.substep != 0) { this.$confirm('是否清除现有报表向导数据?', '', { confirmButtonText: '是,从空白新建', cancelButtonText: '否,从现有新建', type: 'warning', callback: function (action, instance) { if (action !== 'cancel') { vm.cur_report_type = vm.report_types[0]; vm.sketch = vm.report_types[0].type[0]; vm.cur_report_style = vm.report_style[0]; vm.sketch_index = 0; vm.report_s_month = 1; vm.report_s_day = 1; vm.report_s_hours = 0; vm.report_interval = 1; vm.check_station = vm.station[0].id; vm.check_profession = vm.profession[0].id; vm.postDev(); vm.ck_cd = ''; vm.checked_node = { nodes: [] }; vm.checked_total_index = []; vm.checked_contrast_index = []; vm.cd_info_check = { list: [] }; vm.cols_width = []; } vm.substep = 0; vm.step = true; } }); } else { this.substep = 0; this.step = true; } } else if (v == '1-2') { this.reportFilesPanel = true; this.isSave = false; } else if (v == '1-3') { var obj = JSON.parse(JSON.stringify({ vm: vm.$data })); deleteReportFileItem(obj); if (!vm.openedFile.treeCode) { vm.reportFilesPanel = true; vm.isSave = true; } else { this.$confirm('确定保存到报表"' + vm.openedFile.name + '"?', '', { confirmButtonText: '保存修改', cancelButtonText: '打开报表库', type: 'warning', callback: function (action, instance) { if (action == 'cancel') { vm.reportFilesPanel = true; vm.isSave = true; } else { vm.openedFile.fileDetail = JSON.stringify(obj); auReport(vm.openedFile); } } }); } } else if (v == '1-4') { // this.newFile=true; } }, /*右侧选项卡*/ tabClick: function () { }, /*属性*begin*/ querySearchFont: function (str, fn) { fn([{ name: '宋体', value: '宋体', v: 'SimSun' }, { name: '新宋体', value: '新宋体', v: 'SimSun' }, { name: '仿宋', value: '仿宋', v: 'SimSun' }, { name: '楷体', value: '楷体', v: 'SimSun' }, { name: '黑体', value: '黑体', v: 'SimSun' }, { name: '微软雅黑', value: '微软雅黑', v: 'Microsoft YaHei' }, { name: 'Arial', value: 'Arial', v: 'Arial' }, { name: 'Arial Black', value: 'Arial Black', v: 'Arial Black' }, { name: 'Times New Roman', value: 'Times New Roman', v: 'Times New Roman' }, { name: 'Courier New', value: 'Courier New', v: 'Courier New' }, { name: 'Tahoma', value: 'Tahoma', v: 'Tahoma' }, { name: 'Verdana', value: 'Verdana', v: 'Verdana' } ]); }, querySearchSize: function (str, fn) { fn([{ value: '12px' }, { value: '14px' }, { value: '22px' }, { value: '30px' }, { value: '46px' }, ]); }, handleComplete: function () {}, handleIconClick5: function () { this.state5 = ''; }, handleIconClick6: function () { this.state6 = ''; }, changeStyle: function (obj) { this.sidetabs = 'table'; this.radio_form = obj; } }, watch: { cols_parent: function (nv) { var arr = this.devtree_to_option; this.protree_to_option = []; Array.prototype.push.apply(vm.protree_to_option, arr[nv].children); }, checked_dev_index: function (nv) { var v = this.check_dev[nv]; if (!v) { return false; } this.dev_name_text = v.label; this.dev_code_text = v.code; this.edit_node_type = v.nodetype; // if(!v.tid){return false;} // if(v.tid.indexOf('c_')==0){ // }else if(v.tid.indexOf('d_')==0){ // }else if(v.tid.indexOf('t_')==0){ // }else if(v.tid.indexOf('p_')==0){ // }else if(v.tid.indexOf('s_')==0){ // } }, radio_form: function (nv, no) { vm.form = vm[nv]; }, show_field: function (val) { /*切换树的显示方式*/ this.$set(vm.dev_field, 'label', val ? 'code' : 'label'); }, filter_all_dev: function (val) { if (this.step) { this.$refs.adev_tree.filter(val); } else if (this.editNodePanel) { this.$refs.clone_adev_tree.filter(val); } }, filter_check_dev: function (val) { this.$refs.dev_tree.filter(val); }, filter_c: function (val) { if (this.step) { this.$refs.c_tree.filter(val); } else if (this.editNodePanel) { this.$refs.clone_c_tree.filter(val); } }, filter_q: function (val) { if (this.step) { this.$refs.c_tree.filter(val); } else if (this.editNodePanel) { this.$refs.clone_c_tree.filter(val); } }, dev_tree: function (nv, ov) { if (reiniting) { return false; } //同步弹窗的树 var newValue = JSON.stringify(nv); //生成表头数据 var data = dataOp(JSON.parse(newValue), 'x_tree'); this.dev_map = getLastNode(JSON.parse(newValue)); var style = this.border_style + ";" + this.th_style; var width_td = ''; if (this.time_map.length > 0) { var tree = dataOp(JSON.parse(JSON.stringify(vm.time_tree)), 'y_tree'); var head, body; if (this.cur_report_style.value == 0) { width_td = widthTd(tree.length, vm.dev_map.length); //横向 head = creatTHRow(data, tree.length, style).str; body = creatTHCol(tree, new Array(vm.dev_map.length + 1).join('
 
'), style); } else { width_td = widthTd(data.length, vm.time_map.length); //纵向 head = creatTHRow(tree, data.length, style).str; body = creatTHCol(data, new Array(vm.time_map.length + 1).join('
 
'), style); } this.table = '' + width_td + head + '' + '' + body + ''; } for (var i = 0, sum = 0; i < vm.cols_width.length; i++) { sum += vm.cols_width[i] * 1; } vm.tb_width = sum + 'px'; setTimeout(function () { document.getElementById('table').style.width = vm.tb_width; }, 20); }, time_tree: function (nv, ov) { if (reiniting) { return false; } var newValue = JSON.stringify(nv); //生成表头数据 var data = dataOp(JSON.parse(newValue), 'y_tree'); this.time_map = getLastNode(JSON.parse(newValue)); var style = this.border_style + ";" + this.th_style; var width_td = ''; if (this.dev_map.length > 0) { var tree = dataOp(JSON.parse(JSON.stringify(vm.dev_tree)), 'x_tree'); var tds = new Array(vm.time_map.length + 1).join('
 
'); var head, body; if (this.cur_report_style.value != 0) { width_td = widthTd(tree.length, vm.time_map.length); //纵向 head = creatTHRow(data, tree.length, style).str; body = creatTHCol(tree, new Array(vm.time_map.length + 1).join('
 
'), style); } else { width_td = widthTd(data.length, vm.dev_map.length); //横向 head = creatTHRow(tree, data.length, style).str; body = creatTHCol(data, new Array(vm.dev_map.length + 1).join('
 
'), style); } this.table = '' + width_td + head + '' + '' + body + ''; } for (var i = 0, sum = 0; i < vm.cols_width.length; i++) { sum += vm.cols_width[i] * 1; } vm.tb_width = sum + 'px'; setTimeout(function () { document.getElementById('table').style.width = vm.tb_width; }, 20); }, cur_report_style: function (nv, ov) { if (nv.value == 0) { this.table_y_name = '时间'; } else if (nv.value == 1) { this.table_y_name = '设备'; } }, }, created: function () { var vm = this; /*对比*/ this.contrasts = getAllContrasts(); /*统计*/ this.all_totals = getALLTotals(); init(vm); }, directives: { treefocus: { update: function (el, { value }, newnode, oldnode) { if ((nv == ov) && vm.input_focus && newnode.elm.style.display !== 'none') { var nv = newnode.data.props.value; var ov = oldnode.data.props.value; var tag = el.getElementsByTagName('input')[0]; tag.focus(); tag.select(); vm.input_focus = false; } } } } }); function setStyle(form) { var style = 'padding:' + form.top + 'px ' + form.right + 'px ' + form.bottom + 'px ' + form.left + 'px ' + ';font-family:' + form.font_family + ';color:' + form.font_color + ';font-size:' + form.font_size + ';text-align:' + form.align + ';display:' + form.is_show; return style; } /** * @desc 去除自定义列 */ function filterDefined(obj, code) { var o = [], index; for (var i = 0; i < obj.length; i++) { var ob = obj[i]; if ((ob.code + '').indexOf('definedId') === -1) { o.push(ob); if (ob.children && ob.children.length > 0) { var _obj = filterDefined(ob.children, code) o[o.length - 1].children = _obj.node; if (index === undefined) { index = _obj.index; } } } else { if (ob.code === code) { index = vm.formulas.length; vm.formulas_index = index; } vm.formulas.push(ob); vm.formulas['ind' + ob.code] = vm.formulas.length - 1; } } return { node: o, index: index }; } //自动关闭提示 function showTimeout(key, times) { setTimeout(function () { vm[key] = false; }, times * 1000) } //递归同步树公式数据 function formulaTreeData(tree, formula) { for (var i = 0; i < tree.length; i++) { var len = formula['ind' + tree[i].code]; if (len !== undefined) { tree[i].label = formula[len].label; tree[i].formula = formula[len].formula; } if (tree[i].children && tree[i].children.length > 0) { formulaTreeData(tree[i].children, formula); } } } //返回公式类型 function getFormulaType(str = '') { str += ''; var len = str.indexOf('(') if (len === -1) { return 'string'; } else { var s = str.substr(0, len); return !s ? 'defined' : s } } //拆解树形数据 function dataOp(arr, tree, result) { if (result === undefined) { result = []; } var temp = []; result[result.length] = temp; for (var i = 0, t = []; i < arr.length; i++) { var node = vm.$refs[tree].getNode(arr[i]); if (node && node.visible === false) { continue; } temp.push(arr[i]); var child = arr[i].children; if (child instanceof Array && child.length > 0) { t = t.concat(child); } } if (t.length > 0) { return dataOp(t, tree, result); } else { return result; } } //生成横向表头 function creatTHRow(arr, collength, style) { var pid = {}, ids = [], str = "", len = arr.length; for (var i = len - 1; i >= 0; i--) { ids[i] = []; var a = arr[i], _str = ''; for (var k = 0; k < a.length; k++) { var t = a[k]; pid[t.ptid] = (pid[t.ptid] === undefined ? 0 : pid[t.ptid]) + (pid[t.tid] === undefined ? 1 : pid[t.tid]); if (pid[t.tid] === undefined) { _str += "
" + t.label + "
"; ids[i].push(t); } else { _str += "
" + t.label + "
"; if (ids[i + 1] !== undefined) { ids[i] = ids[i].concat(ids[i].splice(0, pid[t.tid])); } } } if (i > 0) { var tr = ""; } else { var tr = '
' + vm.table_y_name + '
'; } str = tr + _str + "" + str; } return { str: str, arr: ids[0] }; } //生成纵向表头 function creatTHCol(arr, n, style) { var pid = {}, ids = {}, str = '', tr = n + '', len = arr.length; for (var i = len - 1; i >= 0; i--) { var a = arr[i]; for (var k = 0; k < a.length; k++) { var t = a[k]; if (!t.ptid) { t.ptid = 'root' } if (pid[t.ptid] === undefined) { pid[t.ptid] = 0; } pid[t.ptid] += pid[t.tid] === undefined ? 1 : pid[t.tid]; var th = ''; if (pid[t.tid] === undefined) { th = '
' + t.label + '
'; if (pid[t.ptid] == 1) { ids[t.ptid] = []; } var row = (pid[t.ptid] != 1 || i == 0 ? '' : '') + th + tr; ids[t.ptid].push(row); if (i == 0) { str += row; } } else { th = '
' + t.label + '
'; if (i == 0) { ids[t.tid][0] = '' + th + ids[t.tid][0]; str += ids[t.tid].join(''); } else { if (ids[t.ptid] === undefined) { ids[t.ptid] = []; ids[t.tid][0] = th + ids[t.tid][0]; } else { ids[t.tid][0] = '' + th + ids[t.tid][0]; } ids[t.ptid] = ids[t.ptid].concat(ids[t.tid]); } } } } return str; } //生成自己以及后代节点的tidh和ptid function changeTid(ptid, obj, num, arr) { var o = obj instanceof Array ? obj : [obj]; if (ptid === undefined) { ptid = 'root' } if (arr === undefined) { arr = {} } for (var i = 0; i < o.length; i++) { var t = o[i], id = 't_' + num++; if (arr[t.code] === undefined) { arr[t.code] = [t]; } else { arr[t.code].push(t); } if (t.tid === undefined) { t.tid = id; t.ptid = ptid; } if (t.children instanceof Array && t.children.length > 0) { return changeTid(id, t.children, num, arr); } } return num; } /*获取最末级节点数据*/ function getLastNode(nodes) { var arr = []; for (var i = 0, len = nodes.length; i < len; i++) { var curNode = nodes[i]; if (curNode.children instanceof Array && curNode.children.length > 0) { arr = arr.concat(getLastNode(curNode.children)); } else { arr.push(curNode); } } return arr; } Math.roundFixed = function (num, n) { if (!n) { n = 2; } var cs = Math.pow(10, n); return Math.round(num * cs) / cs; } /** * @desc 对象浅克隆 * @param {object:要复制的对象} obj * @param {function:复制时处理的逻辑,缺省全部复制} fn */ function objClone(obj, fn) { var o = {}; for (var k in obj) { if (typeof fn == 'function') { fn(k, obj, o); } else { o[k] = obj[k]; } } return o; } /** * @desc 初始化时处理tree数据 * @param {*} arr */ function filterTree(arr) { if (!(arr instanceof Array)) { return arr; } for (var i = 0, obj = []; i < arr.length; i++) { arr[i] = Object.assign({}, arr[i]); if (arr[i].children && arr[i].children.length > 0) { obj = obj.concat(arr[i].children); } } if (obj.length > 0) { return filterTree(obj); } } function deleteReportFileItem(obj) { var saveKey = { // 向导 substep: 1, cur_report_type: 1, cur_report_style: 1, sketch_index: 1, report_s_month: 1, report_s_day: 1, report_s_hours: 1, report_interval: 1, check_station: 1, check_profession: 1, checked_node: 1, checked_total_index: 1, checked_contrast_index: 1, totals: 1, contrasts: 1, // 页面 table: 1, row_chang_color: 1, dev_tree: 1, time_tree: 1, dev_map: 1, time_map: 1, tb_title: 1, tb_sub: 1, tb_width: 1, tb_detailed_1: 1, tb_detailed_2: 1, tb_detailed_3: 1, tb_detailed_4: 1, // 数据配置 data_point: 1, digits_fixed: 1, //其他配置 report_bgcolor: 1, report_font: 1, report_size: 1, report_color: 1, report_textarea: 1, row_line_height: 1, row_chang_color: 1, border_type: 1, border_bgcolor: 1, border_zise: 1, th_bgcolor: 1, th_color: 1, //其他 cols_width: 1, t_num: 1 } for (var k in obj.vm) { if (saveKey[k] === undefined) { delete obj.vm[k]; } } } function widthTd(th, td) { var ths = ''; var tds = ''; vm.cols_width.length = th + td; for (var i = 0; i < th; i++) { vm.cols_width[i] = !vm.cols_width[i] ? 70 : vm.cols_width[i]; ths += ''; } for (var j = 0; j < td; j++) { var n = i + j; vm.cols_width[n] = !vm.cols_width[n] ? 70 : vm.cols_width[n]; tds += ''; } return '' + ths + tds + ''; }