var reiniting = false, timeout = 0, outtime = 800; var vm = new Vue({ el: "#app", data: { isNew: true, theme: getTheme(), devCheckedKeys: [], devStrict: false, devHasCD: {}, // filterConnection: false, filterView: false, deleteLoading: false, excelSaveLoading: false, excelFileName: "", excelFilePath: "", excelDateType: "YYYY-MM-DD", dateLabelStart: "开始时间", dateLabelEnd: "结束时间", excelFilesPanel: false, i18n: {}, /*报表文件管理*begin*/ save_loading: false, oldFileName:'',//重命名前文件名称 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*/ addColPanel: false, zx_colName_show: "", zx_colName: "", zx_colValue_show: "", zx_colValue: "", formulaType: "defined", saveFlag: false, cols: [], check_cols: [], check_cols_index: "-1", x_check: [], col_check_node: [], /*添加列*end*/ /*树操作*degin*/ editNodePanel: false, addNodePanel: false, edit_node_type: "", checked_dev_index: 0, check_dev: [], dev_name_text: "", dev_code_text: "", dev_e: "", default_e: defaulte(), 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: 'rgba(16, 67, 102, 1)', th_bgcolor: "", //默认透明 th_color: "", row_line_height: 27, row_chang_color: "two-color", report_bgcolor: "", report_font: "", report_size: "", report_color: "", report_textarea: "", paper_sum: { height: 1, width: 1 }, 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: getTheme()["$font-color"], font_size: "", align: "center", top: 30, right: 10, bottom: 10, left: 10 }, tb_sub: { name: "表格副标题", is_show: "none", font_family: "微软雅黑", font_color: getTheme()["$font-color"], font_size: "", align: "center", top: 10, right: 10, bottom: 10, left: 10 }, tb_detailed_1: { name: "自定义被描述:描述内容", is_show: "none", font_family: "微软雅黑", font_color: getTheme()["$font-color"], font_size: "", align: "center", top: "", right: "", bottom: "", left: "" }, tb_detailed_2: { name: " 表格编号:000", is_show: "none", font_family: "微软雅黑", font_color: getTheme()["$font-color"], font_size: "", align: "center", top: "", right: "", bottom: "", left: "" }, tb_detailed_3: { name: "制表时间:" + new Date().toLocaleDateString(), is_show: "block", font_family: "微软雅黑", font_color: getTheme()["$font-color"], font_size: "", align: "center", top: "", right: "", bottom: "", left: "" }, tb_detailed_4: { name: "制表人:" + (sessionStorage.getItem("name") || ""), is_show: "block", font_family: "微软雅黑", font_color: getTheme()["$font-color"], font_size: "", align: "center", top: "", right: "", bottom: "", left: "" }, tb_width: "600px", tableInit: "########################                                                                                                                                                                                ", table: "########################                                                                                                                                                                                ", /*表格*end*/ /*右侧选项卡*/ sidetabs: "dev", /*向导*/ adding: false, deling: false, 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: {}, stshow: false, station: [], check_station: "", station_info: { label: "", type: "list" }, profession: [], check_profession: "", profession_info: { label: "", type: "list" }, 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: [] }, default_property: { check: [], node: [], expaned: [] }, t_num: 0, check_off: "全选", filter_c: "", filter_q: "", ck_cd: true, ck_cy: true, ck_sx: true, ck_gx: false, ck_dev: false, ck_value: "", cd_tid:[], cd_info_check: { list: [] }, contrasts: [], all_totals: [], checked_contrast_index: [], checked_total_index: [], checked_total_all: false, indeterminate: false, 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: [], /*数据设置*begin*/ dataConfig: false, data_cd: false, data_dev: false, data_point: 2, text_key: "code", old_text: "", new_text: "", digits_fixed: false, input_focus: false, timerNo: "", // 公式 cols_type: "father", cols_parent: "", cols_value: "", formule_name: "", formule_value: "", formule_view: "", protree_to_option: [], //权限 powerPanel: false, checkedGroup: [], allUserGroup: [], curTreeCode: "", devTreeProps: { label: "label" } }, computed: { htmlConfig: function() { return htmlConfig(); }, check_station_name: function() { var vm = this; var node = post.cz.data.filter(function(v) { return v.locationId == vm.check_station; })[0]; if (!node) { node = { name: vm.check_station }; } return node.name; }, excelInputUrl: function() { return post.excelUpload.url || ""; }, fileInputUrl: function() { return post.fileInput.url || ""; }, default_checked_keys: function() { var node = this.default_property.check.concat( this.default_property.expaned ); return node; }, checkedCD: function() { //从设备树形反推选择了哪些测点 }, userInfo: function() { var p = getToken().data.userInfo; return p; }, 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"; }, table_y_name: function() { var val = this.cur_report_style.value; if (val == 0) { return this.sketch.value != "tj" ? this.i18n.js.date : this.i18n.js.sidepoints; } else if (val == 1) { return this.i18n.js.dev; } }, 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(); 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.changeTbtitleName(arr[index]); return arr[index]; }, border_style: function() { var vm = this; var str = vm.fnStyle("border-style", vm.border_type) + vm.fnStyle("border-color", vm.border_bgcolor) + vm.fnStyle("border-width", vm.border_zise, "px") + vm.fnStyle("height", vm.row_line_height, "px"); return str; }, th_style: function() { var vm = this; var str = vm.fnStyle("background-color", vm.th_bgcolor) + vm.fnStyle("color", vm.th_color); return str; }, panel_style: function() { var vm = this; var str = vm.fnStyle("background-color", vm.report_bgcolor) + vm.fnStyle("color", vm.report_color) + vm.fnStyle("font-family", vm.report_font) + vm.fnStyle("font-size", vm.report_size) + this.report_textarea; return str; }, papers: function() { var o = this.paper_size[this.paper_type]; var sum = this.paper_sum.width * this.paper_sum.height; for (var i = 0, arr = []; i < sum; 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); }, reportInterval: function() { var arr = getReportIntreval(); if (this.cur_report_type.value !== "udf") { arr.length = 4; } return arr; }, 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; }, sketchDesabled: function() { if (this.sketch.value == "db" || this.sketch.value == "tj") { this.report_interval = "1"; return true; } return false; }, setDevTreeToObj(tree) { var obj = {}; for (var i = 0; i < tree.length; i++) { var d = tree[i]; if (d.noetype == "dev_type") { if (d.children && d.children.length > 0) { this.setDevTreeToObj(d.children); } } else if (d.noetype == "dev") { } else { } } } }, methods: { devTreeCheckeOn(){ this.devTreeLoop(this.all_dev,function(node,tree){ console.log("devTreeCheckeOn -> node", node) if(node.visible&&!node.checked){ tree.setChecked(node.key,true) } }); }, devTreeCheckeOff(){ this.devTreeLoop(this.all_dev,function(node,tree){ if(node.visible&&node.checked){ tree.setChecked(node.key,false) } }); }, devTreeLoop(list,fn){ var children=[]; var vm=this; list.map(function(v){ var node=vm.$refs.adev_tree.getNode(v); if(typeof fn==='function'){ fn(node,vm.$refs.adev_tree) } if(v.children&&v.children.length>0){ children=children.concat(v.children) } }); if(children.length>0){ this.devTreeLoop(children,fn) } }, changeFilterView() { this.filterView = !this.filterView; this.$set(this.devTreeProps, "label", this.filterView ? "code" : "label"); }, goSec: function() { this.substep = this.substep + 100; this.checked_node = { nodes: [] }; this.changeTbtitleName(this.sketch); }, computedTimeValue(value) { var t = Math.floor(60 * value); var r = ""; if (t > 7 * 1440) { r = Math.floor(t / (7 * 1440)) + "周"; t = t % (7 * 1440); } if (t > 1440) { r += Math.floor(t / 1440) + "天"; t = t % 1440; } if (t > 60) { r += Math.floor(t / 60) + "小时"; t = t % 60; } if (t > 0) { r += t + "分钟"; } return r; }, tableResize: function() { // console.log(666) }, changeCKCD: function() { this.$message.warning( // "更改此项配置需要删除原来测点,重新添加测点才能生效。" this.i18n.js.needRepeat ); }, newExcelReport: function() { this.excelFileName = ""; this.excelFilePath = ""; this.excelDateType = "YYYY-MM-DD"; this.dateLabelStart = this.i18n.excel.startlabel; this.dateLabelEnd = this.i18n.excel.endlabel; this.excelFilesPanel = true; }, addExcelReport: function() { this.excelSaveLoading = true; var param = { path: this.excelFilePath, timeType: this.excelDateType, startTime: this.dateLabelStart, endTime: "", name: this.excelFileName, operateFlag: 0, treePCode: "", sourceType: 3, type: 1 }; if (param.timeType.indexOf("~") !== -1) { param.endTime = this.dateLabelEnd; } 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: this.i18n.js.tip, message: this.i18n.js.bntjwbbzj, type: "warning" }); this.excelSaveLoading = false; return false; } } var vm = this; if ( this.errorMessage(param.name, "请输入报表名称") && this.errorMessage(param.path, "请上传报表模板") && this.errorMessage(param.timeType, "请选择报表时间类型") && this.errorMessage(param.startTime, "请输入报表时间描述") && (param.timeType.indexOf("~") === -1 ? true : this.errorMessage(param.endTime, "请输入报表时间描述")) ) { console.log("验证成功"); } else { setTimeout(function() { vm.excelSaveLoading = false; }, 200); return false; } excelReportSave(param, function(res) { //调用分配权限方法 var file = { treeCode: res.data.obj.treeCode, id: res.data.obj.id }; if (powerDialog()) { vm.showPowerPanel(file); } }); }, errorMessage: function(arg, msg) { if (!arg) { this.$message.error(msg); return false; } return true; }, checkCDIsReal: function() { if (this.sketch.value === "sy") { return false; } var vm = this; //获取树 var tree = this.checked_node.nodes; //递归树,找出所有设备 var fn = function(map) { var child = [], dev = []; map.map(function(v, i, a) { if (v.nodetype == "dev_type") { child = child.concat(v.children); } else if (v.nodetype == "dev") { dev.push(v); } }); return dev.concat(child.length > 0 ? fn(child) : []); }; var devList = fn(tree); //标记是否存在该 var setFeild = function(node, obj) { if (!obj[node.code]) { node.isNotReal = true; node.children.map(function(v, i, a) { v.isNotReal = true; }); } else { obj[node.code] = true; } }; devList.map(function(v, i, a) { var obj = vm.devHasCD[v.code]; for (var i = 0; i < v.children.length; i++) { var node = v.children[i]; if (node.nodetype == "property_type") { node.children.map(function(v, i, a) { setFeild(v, obj); }); } else if (node.nodetype == "property") { setFeild(node, obj); } } }); }, excelInput: function(res) { this.excelFilePath = res; //重新查询报表文件 this.$message.success(this.i18n.js.inputSuccess); //'导入成功' //调用分配权限方法 // var file = { // treeCode: res.data.treeCode, // id: res.data.id // }; // if (powerDialog()) { // vm.showPowerPanel({ // treeCode: d.obj.treeCode, // id: d.obj.id // }); // } }, fnStyle: function(key, value, unit) { if (!unit) { unit = ""; } return value ? key + ":" + value + unit + ";" : ""; }, fileOutput: function() { var code = this.fileSelectedReport.treeCode; if (code) { fileOutput({ treeCode: code }); } else { this.$message.error(this.i18n.js.output); //'请选择要导出的报表' } }, fileInput: function(res) { //重新查询报表文件 getReportTree(); this.$message.success(this.i18n.js.inputSuccess); //'导入成功' //调用分配权限方法 var file = { treeCode: res.data.treeCode, id: res.data.id }; if (powerDialog()) { vm.showPowerPanel({ treeCode: d.obj.treeCode, id: d.obj.id }); } }, totalsChange: function(val) { var chk_count = val.length; this.checked_total_all = chk_count === this.totals.length; this.indeterminate = chk_count > 0 && chk_count < this.totals.length; }, toggleTotals: function(val) { this.checked_total_index = val ? this.totals.reduce(function(o, v, i) { o.push(i); return o; }, []) : []; this.indeterminate = false; }, //权限BeGing userGroupOn: function() { this.checkedGroup = []; for (var i = 0; i < this.allUserGroup.length; i++) { var d = this.allUserGroup[i]; this.checkedGroup.push(d.id); } }, userGroupOff: function() { this.checkedGroup = []; this.checkedGroup.shift(); }, userGroupSubmit: function() { setGroupPower({ usergArr: vm.checkedGroup.join(";"), treeCode: this.curTreeCode.treeCode, id: this.curTreeCode.id }); }, showPowerPanel: function(obj) { this.powerPanel = true; this.curTreeCode = obj; }, //权限End filteColsNode: function(value, data) { return data.nodetype !== "formula"; }, addNewCol: function() { this.zx_colName = this.i18n.js.newNode; this.zx_colValue = ""; this.formulaType = "defined"; this.check_cols = []; }, editCol: function(item) { this.zx_colName = item.name; this.zx_colValue = item.code; this.formulaType = item.formulaType; this.check_cols = item.detail; }, colsDel: function() {}, colsFormulaDel: function(index) { this.check_cols.splice(index, 1); for (var i = 0; i < this.check_cols.length; i++) { this.check_cols[i].key = this.getABC(i); } var len = vm.getABC(i); if (this.zx_colValue.indexOf("+" + len) !== -1) { this.zx_colValue.replace("+" + len, ""); } else if (this.zx_colValue.indexOf(len + "+") !== -1) { this.zx_colValue.replace(len + "+", ""); } else if (this.zx_colValue.indexOf(len) !== -1) { this.zx_colValue.replace(len, ""); } }, colsSave: function() { var obj = { name: vm.zx_colName, label: vm.zx_colName, tid: vm.t_num++, ptid: "", formulaType: vm.formulaType, code: vm.zx_colValue, nodetype: "formula", detail: vm.check_cols }; if (this.check_cols_index == -1) { this.cols.push(obj); this.$refs.x_tree.append(obj); this.check_cols_index = this.cols.length - 1; } else { this.cols[vm.check_cols_index] = obj; vm.$refs.x_tree.append(obj); this.cols.push(""); this.cols.pop(); } }, checkEvent: function(data, node, tree) { var nt = data.nodetype, np, npp; switch (nt) { case "property_value": np = node.parent; npp = np.parent; break; case "property": return false; break; case "dev": return false; break; case "dev_type": return false; break; case "col_defined": return false; break; } var dpp = JSON.parse(JSON.stringify(npp.data)); var dp = JSON.parse(JSON.stringify(np.data)); var d = JSON.parse(JSON.stringify(data)); dp.children = []; dpp.children = []; var vm = this; var obj = { key: vm.getABC(vm.check_cols.length), nodes: [dpp, dp, d], code: "[" + dpp.code + "]" + "_&_" + "[" + dp.code + "]" + "_&_" + "[" + d.code + "]" }; if (!this.zx_colValue) { this.zx_colValue = obj.key; } else { this.zx_colValue += "+" + obj.key; } this.check_cols.push(obj); }, getABC: function(index) { var arr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".split(""), length = arr.length, r = arr[index % length], result = r, l = Math.floor(index / length); for (var i = 0; i < l; i++) { result += r; } return result; }, /* 添加公式列*/ formulaResetName: function() {}, formulaResetFormula: function() {}, formulaTypeChange: function() {}, /*报表文件管理*/ reportReName: function(item) { if (item.rename == false) { return false; } //没有改动的情况下 if (this.oldFileName == item.label) { return false; } var fn = function(node, addobj) { vm.newFile = false; vm.oldFileName="" }; var param = { operateFlag: 1, name: item.label, treeCode: item.treeCode }; if (!param.name) { param.name = new Date().getTime(); } vm.timerNo = setTimeout(function() { auReport(param, param, fn, function() { item.rename = true; }); }, 80); }, reInit: function() { var report = this.fileSelectedReport; if (report.sourceType == 3) { return false; } if (!report) { vm.$notify({ title: this.i18n.js.err, message: this.i18n.js.uncheckReport, type: "error" }); return false; } if (report.type == 0) { this.checkedFiles = this.fileSelectedReport.children; return false; } this.$msgbox({ message: this.i18n.js.mstotr, title: this.i18n.js.tip, type: "info", showCancelButton: true, confirmButtonText: this.i18n.js.ok, cancelButtonText: this.i18n.js.cancel, callback: function(action, instance) { if (action == "confirm") { vm.time_tree = []; getReportDetail( { treeCode: report.treeCode }, function(report_defail) { var data = JSON.parse(report_defail); vm.dev_tree = []; vm.cols_width = []; reiniting = true; for (var k in data.vm) { if (k !== "table") { vm[k] = data.vm[k]; } } vm.initOption(data.vm); //初始化勾选 vm.reportFilesPanel = false; vm.newFile = false; vm.table = data.vm.table; vm.tb_title = data.vm.tb_title; vm.form = data.vm.tb_title; setTimeout(function() { reiniting = false; vm.refreshDevTree(); vm.$nextTick(function() { vm.form = data.vm.tb_title; //解决打开报表第一次修改不成功bug vm.radio_form = "tb_title"; vm.returnBack("", true); }); }, 200); } ); } } }); }, initOption: function(d) { d === undefined && (d = vm); if (d.ck_sx === undefined) { this.setCk_sx(); } }, setCk_sx: function() { this.ck_sx = !!( this.sketch.value == "yx" || this.sketch.value == "dd" || this.sketch.value == "bb" || this.sketch.value == "cr" ); }, goStyle: function() { this.substep = vm.substep + 100; this.setCk_sx(); this.changeTbtitleName(this.sketch); }, getDevKeys: function() { var nodes = this.checked_node.nodes, fn = function(arr) { return arr.reduce(function(o, v, i) { if (v.nodetype == "dev_type" && v.children.length > 0) { Array.prototype.push.apply(o, fn(v.children)); } else if (v.nodetype == "dev") { o.push(v.code); } return o; }, []); }, keys = fn(nodes); getCdInfo({ devTpName: keys.join(";"), type: vm.sketch.cdtype || vm.sketch.value }); }, returnBack: function(event, flag) { var vm = this; this.isNew = false; var num = this.substep % 100; switch (vm.sketch.value) { case "yx": case "dd": case "bb": case "cr": this.getDevKeys(); // this.substep = num+4; break; case "sy": getProceeds(vm.checked_node.nodes[0].devCode); // this.substep = num+4; break; case "tj": this.getDevKeys(); // this.substep = num+4 break; case "db": this.getDevKeys(); // this.substep = num+4; break; } if (!flag) { this.substep = num + 400; this.step = true; } }, 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; if (!report.code) { return false; } this.deleteLoading = true; var text = ""; if (report && report.type == "0" && report.code) { text = this.i18n.js.delreports; } else if (report && report.type == "1" && report.code) { text = this.i18n.js.delreport; } this.$confirm(text, this.i18n.js.tip, { confirmButtonText: this.i18n.js.ok, cancelButtonText: this.i18n.js.cancel, type: "info", callback: function(action, instance) { if (action == "confirm") { deleteReport(report, function(success) { if (success) { var self = vm.$refs.report_tree.getNode(report); var _rt = report.treePCode; var _p = self.parent; vm.$refs.report_tree.remove(report); vm.fileSelectedReport = {}; } vm.deleteLoading = false; }); } else { vm.deleteLoading = false; } } }); }, addFiles: function() { if (timeout !== 0) { return false; } timeout = setTimeout(function() { timeout = 0; }, outtime); if (vm.newFiles == false) { return false; } if (!this.fileRename.trim()) { this.fileRename = this.i18n.js.newfiles + 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; param.sourceType = 1; 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: this.i18n.js.tip, message: this.i18n.js.canttochild, 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: this.i18n.js.tip, message: this.i18n.js.rptunchkd, type: "warning" }); return false; } this.$confirm( this.i18n.js.suretr + '"' + this.fileSelectedReport.label + '" ?', this.i18n.js.tip, { confirmButtonText: this.i18n.js.ok, cancelButtonText: this.i18n.js.cancel, type: "info", callback: function(action, instance) { if (action == "confirm") { var obj = JSON.parse( JSON.stringify({ vm: vm.$data }) ); vm.deleteOtherDevHasCD(); deleteReportFileItem(obj); auReport({ treeCode: vm.fileSelectedReport.treeCode, treePCode: vm.fileSelectedReport.treePCode, name: vm.fileSelectedReport.label, type: 1, fileDetail: JSON.stringify(obj), operateFlag: 1 }); } } } ); }, deleteOtherDevHasCD: function() { for (var k in vm.devHasCD) { for (var key in vm.devHasCD[k]) { if (vm.devHasCD[k][key] !== true) { // delete vm.devHasCD[k][key] } } } }, addFile: function() { if (timeout !== 0) { return false; } timeout = setTimeout(function() { timeout = 0; }, outtime); if (vm.newFile == false) { return false; } if (!this.fileRename.trim()) { this.fileRename = this.i18n.js.newport + new Date().getTime(); } var obj = JSON.parse( JSON.stringify({ vm: vm.$data }) ); vm.deleteOtherDevHasCD(); 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: this.i18n.js.tip, message: this.i18n.js.bntjwbbzj, 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.sourceType != "3" && report.type == "1" && !this.isSave ) { this.reInit(); } // if(report.filetype=='mode'){ // tempInit(); // this.reportFilesPanel=false; // this.outerVisible1=true; // } }, scrollBottom: function() { var vm = this; this.$nextTick(function() { var div = vm.$el.querySelector("#fileScroll"); div.scrollTop = div.scrollHeight; }); }, addNewFiles: function() { this.newFiles = true; this.fileRename = ""; this.scrollBottom(); }, addNewFile: function() { this.newFile = true; this.fileRename = ""; this.scrollBottom(); }, reportRename: function() { this.oldFileName=this.fileSelectedReport.label; if (this.fileSelectedReport) { vm.input_focus = true; 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.formule_view = ""; this.protree_to_option = []; this.addNodePanel = true; }, navBack: function() { var n = vm.substep; if (this.sketch_index < 300) { n = 400 + vm.substep - (vm.substep % 100); } else if (this.sketch_index == 300) { n = 300 + vm.substep - (vm.substep % 100); } else if (this.sketch_index == 400) { n = 300 + vm.substep - (vm.substep % 100); } this.postDev(); getCdInfo({ devTpName: "", type: vm.sketch.cdtype || vm.sketch.value }); this.substep = n; this.step = 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; this.dev_e = data.e; } else { this.$notify({ title: this.i18n.js.tip, message: this.i18n.js.notsame }); } }, editXNode: function(node, data) { this.edit_node_type = data.nodetype; var arr = [data]; if (data.nodetype) { for (var i = 0; i < data.children.length; i++) { var d = data.children[i]; //测点 arr.push(d); if (d.children) { for (var n = 0; n < d.children.length; n++) { arr.push(d.children[n]); } } } } this.check_dev = arr; this.checked_dev_index = 0; this.checked_dev_node.label = data.label; this.checked_dev_node.code = data.code; this.dev_name_text = data.label; this.dev_code_text = data.code; this.dev_e = data.e; this.editNodePanel = true; }, changeLabel: function() { this.checked_dev_node.label = this.dev_name_text; this.checked_dev_node.code = this.dev_code_text; this.checked_dev_node.e = this.dev_e; this.refreshDevTree(); }, 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(this.i18n.js.suredel, this.i18n.js.tip, { confirmButtonText: this.i18n.js.ok, cancelButtonText: this.i18n.js.cancel, 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: this.i18n.js.err, message: this.i18n.js.inputfeild, type: "error" }); return; } if (type !== "father") { if (!code) { vm.$notify({ title: this.i18n.js.err, message: this.i18n.js.inputvalue, 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 fv = this.formule_view; var arr = this.protree_to_option; var index = this.cols_value; var code; if (this.sketch.value == "sy") { code = "[" + arr[index].code + "]"; } else { code = "[" + this.devtree_to_option[vm.cols_parent].code + ";" + arr[index].code + "]"; } if (v) { var last = v[v.length - 1]; if ( last === "+" || last === "-" || last === "*" || last === "/" || last === "(" ) { this.formule_value = v + code; this.formule_view = fv + "[" + arr[index].label + "]"; } else { vm.$notify({ title: this.i18n.js.err, message: this.i18n.js.inputoperator, type: "error" }); } } else { this.formule_value = code; this.formule_view = "[" + arr[index].label + "]"; } }, formulAddNum: function(n) { var v = this.formule_value; var fv = this.formule_view; if (v) { var last = v[v.length - 1]; if ( last === "+" || last === "-" || last === "*" || last === "/" || last === "(" ) { this.formule_value = v + n; this.formule_view = fv + n; } else if (Number(last)) { this.formule_value = v + n; this.formule_view = fv + n; } else { vm.$notify({ title: this.i18n.js.err, message: this.i18n.js.inputoperator, type: "error" }); } } else { this.formule_value = n; this.formule_view = n; } }, formulAddPrth: function(p) { var v = this.formule_value; var fv = this.formule_view; v = !v ? "" : v; fv = !fv ? "" : fv; 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 + "("; this.formule_view = fv + "("; } else { vm.$notify({ title: this.i18n.js.err, message: this.i18n.js.inputoperator, 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: this.i18n.js.err, message: this.i18n.js.inputnum, type: "error" }); } else { this.formule_value = v + ")"; this.formule_view = fv + ")"; } } }, formuleBack: function() { var v = this.formule_value; var fv = this.formule_view; if (v) { var last = v[v.length - 1]; if ( last === "+" || last === "-" || last === "*" || last === "/" || last === "(" || last === ")" ) { this.formule_value = v.substring(0, v.length - 1); this.formule_view = fv.substring(0, fv.length - 1); } else { var vl = this.formule_value.split(/[\+\-\*\/\(\)]/); this.formule_value = v.substring( 0, v.length - vl[vl.length - 1].length ); var ve = this.formule_view.split(/[\+\-\*\/\(\)]/); this.formule_view = fv.substring( 0, fv.length - ve[ve.length - 1].length ); } } }, formulAddOperator: function(o) { var v = this.formule_value; var fv = this.formule_view; if (v) { var last = v[v.length - 1]; if ( last === "+" || last === "-" || last === "*" || last === "/" || last === "(" ) { vm.$notify({ title: this.i18n.js.err, message: this.i18n.js.inputnum, type: "error" }); } else { this.formule_value = v + o; this.formule_view = fv + o; } } else { vm.$notify({ title: this.i18n.js.err, message: this.i18n.js.inputnum, 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); } } }, clearDevCD: function() { var tree = this.$refs.dev_tree; var dev = tree.getCheckedNodes(); for (var i = 0; i < dev.length; i++) { var d = dev[i]; if (d.nodetype === "dev") { d.children.map(function(v) { (function(v) { setTimeout(function() { tree.remove(v); }, 10); })(v); }); } } }, 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() { this.checkCDIsReal(); this.cd_tid=getCheckedNodeTid(this.checked_node.nodes) var fn = function(nodes) { var result = true; for (var i = 0; i < nodes.length; i++) { if (nodes[i].nodetype === "dev_type") { result = fn(nodes[i].children); } else if (nodes[i].nodetype === "dev" && !nodes[i].children.length) { return false; } if (!result) { return false; } } return result; }; if (!fn(this.checked_node.nodes)) { this.$alert(this.i18n.js.nywtjcd, this.i18n.js.tip, { confirmButtonText: this.i18n.js.ok, callback: function(action, instance) {} }); } else { //处理多选问题 // if(this.checked_total_index.length>0){ // if(this.totals.length==this.checked_total_index.length){ // this.checked_total_all=true; // this.indeterminate=false; // }else{ // this.checked_total_all=false; // this.indeterminate=true; // } // }else{ // this.checked_total_all=false; // this.indeterminate=false; // } this.checked_total_all = false; this.indeterminate = false; this.checked_total_index = []; //下一步 vm.substep = vm.substep + 100; } }, statisticFinish: function() { this.checkCDIsReal(); var property = this.$refs.c_tree.getCheckedNodes(); if (property.length == 0) { this.$alert(this.i18n.js.qxztjcd, this.i18n.js.err, { confirmButtonText: this.i18n.js.ok, callback: function() {} }); return false; } //将测点编码存入属性 property.map(function(v, i, a) { if (v.nodetype == "property_value") { var ppty = property.filter(function(p, i, a) { return p.tid == v.ptid; })[0]; v.pCode = ppty.code; } }); //统计*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)); // 判断是返回向导还是新增 if (this.dev_tree.length === 0 || this.isNew) { this.dev_tree = arr; } else { // 记录原来的顺序,改变现有树的顺序 var sx = {}; // 展开dev_tree并记录顺序 this.treeToList(this.dev_tree, sx); // 展开arr合成顺序字段 this.treeToSort(arr, sx); this.dev_tree = arr; } }, treeToList: function(list, obj) { for (var i = 0; i < list.length; i++) { var v = list[i]; obj[v.code] = i; if ( (v.nodetype == "dev" || v.nodetype == "dev_type") && v.children && v.children.length > 0 ) { this.treeToList(v.children, obj); } } }, treeToSort: function(list, obj) { if (list[0].nodetype !== "dev" && list[0].nodetype !== "dev_type") { return false; } for (var i = 0; i < list.length; i++) { var v = list[i]; var temp = v.remark10; v.remark10 = obj[v.code]; if (isNaN(v.remark10)) { v.remark10 = temp; } if (v.children && v.children.length > 0) { this.treeToSort(v.children, obj); } } list.sort(function(a, b) { return a.remark10 - b.remark10; }); }, 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) { parentNodeOp(); } else { if (!this.ck_cd) { pn.ptid = ptid; probj.arr.push(probj[pn.tid]); } } } return probj; }, addPropertyNew: function() { setTimeout(function() { this.adding = true; }); 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 ? this.i18n.js.qxzjcdsb : this.i18n.js.qxztjcd, this.i18n.js.tip, { confirmButtonText: this.i18n.js.ok } ); this.adding = false; return false; } //克隆测点数据,以免对原树造成影响 var JSON_prop = JSON.parse(JSON.stringify(prop_obj)); //去除children增加克隆性能 var fn_removeChildren = function(obj) { for (var i in obj) { obj[i].children = []; } }; fn_removeChildren(JSON_prop.t_); fn_removeChildren(JSON_prop.p_); fn_removeChildren(JSON_prop.s_); var jpo = { t_: JSON_prop.t_, p_: JSON_prop.p_, s_: JSON_prop.s_ }; JSON_prop = JSON.stringify(jpo); //处理测点数据 var fn_devProp = function(arr, result) { var keys = { property_type: "t_", property: "p_", property_value: "s_" }; var arrList = []; if (arr instanceof Array) { arr.map(function(v) { result[keys[v.nodetype]][v.tid] = v; if (v.children && v.children.length > 0) { arrList = arrList.concat(v.children); } }); } if (arrList.length > 0) { fn_devProp(arrList, result); } }; for (var d in dev_obj.d_) { var _d = dev_obj.d_[d]; var _prop = JSON.parse(JSON_prop); var _id = _d.tid.substr(1); var _child = { t_: {}, p_: {}, s_: {} }; fn_devProp(_d.children, _child); //添加测点类型 //策略:当设备还没有添加测点时,通过配置判断,如果添加过测点,就按照子节点是否有测点类型来 var _flag = (_d.children.length == 0 && !this.ck_cd) || (_d.children.length > 0 && _d.children[0].nodetype == "property_type"); if (_flag) { for (var t in _prop.t_) { if (_child.t_[_prop.t_[t].tid + _id] === undefined) { _prop.t_[t].tid += _id; _prop.t_[t].ptid = _d.tid; _d.children.push(_prop.t_[t]); //添加到菜单里 _child.t_[_prop.t_[t].tid] = _prop.t_[t]; //添加到零时类别里 } } } //添加测点, //1.设备children是空的 //2.设备下的children有测点类别,类别是空的 //3.设备下的children有测点类别,类别下有一些测点 for (var p in _prop.p_) { if (_child.p_[_prop.p_[p].tid + _id] === undefined) { _prop.p_[p].tid += _id; if (_flag) { _prop.p_[p].ptid += _id; _child.t_[_prop.p_[p].ptid].children.push(_prop.p_[p]); } else { _prop.p_[p].ptid = _d.tid; _d.children.push(_prop.p_[p]); } _child.p_[_prop.p_[p].tid] = _prop.p_[p]; } } //添加测点属性 //1.测点下children是空的 //2.测点下children已存在一些属性 for (var s in _prop.s_) { if (_child.s_[_prop.s_[s].tid + _id] === undefined) { _prop.s_[s].tid += _id; _prop.s_[s].ptid += _id; _child.p_[_prop.s_[s].ptid].children.push(_prop.s_[s]); } } } }, addProperty: function() { setTimeout(function() { this.adding = true; }); 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 ? this.i18n.js.qxzjcdsb : this.i18n.js.qxztjcd, this.i18n.js.tip, { confirmButtonText: this.i18n.js.ok } ); this.adding = false; 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); } this.adding = false; }, delProperty: function() { var dev_obj = {}, dev = this.$refs.dev_tree.getCheckedNodes(); var prop_obj = {}, property = this.$refs.c_tree.getCheckedNodes(); dev_obj = this.recursion( { recursion: false }, dev ); prop_obj = this.recursion( { key: "tid", recursion: false }, property ); if (dev.length == 0 || property.length == 0) { this.$alert( dev.length == 0 ? this.i18n.js.qxzdeldev : this.i18n.js.qxzdelcd, this.i18n.js.tip, { confirmButtonText: this.i18n.js.ok } ); return false; } for (var k in dev_obj.d_) { var _child = dev_obj.d_[k].children; var _temp = this.recursion( { key: "tid", recursion: true }, _child ); var skey = "s_"; if (this.sketch.value == "sy") { skey = "p_"; } for (var s in prop_obj[skey]) { var code = ""; //判断设备中有无该测点,没有进行下次循环 for (var c in _temp[skey]) { if (c.indexOf(s) === 0) { code = c; break; } } if (code == "") { continue; } //查找属性的父级测点,删除属性节点, var p = this.$refs.dev_tree.getNode(_temp[skey][code]).parent; this.$refs.dev_tree.remove(_temp[skey][code]); //判断该测点是否为空,为空则删除该测点,判断是否有测点类型,如过有 if (p.childNodes.length == 0) { //查找测点的父级,判断测点类型子级是否为空,为空则删除该节点 var d = p.parent; if (p.data.nodetype !== "dev") { this.$refs.dev_tree.remove(p); if ( d.data.nodetype == "property_type" && d.childNodes.length == 0 ) { this.$refs.dev_tree.remove(d); } } } } } }, checkCd: function(data, nlist) { var node = this.$refs.c_tree.getNode(data); if (this.editNodePanel) { node = this.$refs.clone_c_tree.getNode(data); } else { //检查有没有选中多个 if (data.nodetype == "property_value") { // console.log(node) } } var checked = node.checked; //向下遍历 var trvsChildren = function(node, checked) { var _child = node.childNodes; if (!_child[0]) { node.checked = checked; //重置测点选中记录 if (checked) { vm.cd_info_check.dev = node.data.ptid; vm.cd_info_check.list = []; for (var i = 0; i < node.parent.childNodes.length; i++) { //记录最底级测点 var nd = node.parent.childNodes[i]; if (nd.checked == true) { vm.cd_info_check.list.push({ code: nd.data.code, index: i }); } } } return false; } if (checked) { node.checked = true; if ( node.data.nodetype === "property" && node.data.ptid != vm.cd_info_check.dev ) { //勾选最底级测点 for ( var i = 0, flag = true; i < vm.cd_info_check.list.length; i++ ) { var code = vm.cd_info_check.list[i]; if ( node.childNodes[code.index] && node.childNodes[code.index].data.code == code.code ) { flag = false; node.childNodes[code.index].checked = true; } } //如果没有一个被选中默认选中第一个 if (flag) { node.childNodes[0].checked = true; } } else { return trvsChildren(_child[0], true); } } else { node.checked = false; for (var i = 0; i < _child.length; i++) { if (_child[i].checked) { trvsChildren(_child[i], false); } } } }; trvsChildren(node, checked); //向上遍历 var trvsParent = function(node, checked) { var parent = node.parent; if (!parent) { return false; } if (checked) { if (parent.checked) { return false; } parent.checked = true; } else { for (var i = 0, flag = false; i < parent.childNodes.length; i++) { var _p = parent.childNodes[i]; if (_p.checked) { flag = true; } } if (!flag) { parent.checked = false; } } return trvsParent(parent, checked); }; trvsParent(node, checked); }, creatProperty: function() { this.property_tree = []; if (this.sketch.value == "sy") { if (post.syCd.data === undefined) { var node = vm.$refs.adev_tree.getCurrentNode(); if (node) { getProceeds(node.devCode); } return false; } this.all_property = post.syCd.data; var keys = tiemInterval(); for (var i = 0; i < keys.length; i++) { //测点树 var item = this.all_property[keys[i]]; this.property_tree.push(item); //设备树(添加默认点) var d = this.checked_node.nodes[i]; var cl = JSON.parse(JSON.stringify(item)); if (this.sketch.value !== "tj") { for (var j = 0; j < cl.children.length; j++) { cl.children[j].ptid = d.tid; cl.children[j].tid = cl.children[j].tid + "_" + this.t_num++; d.children.push(cl.children[j]); } } } } else { this.all_property = post.cd.data; } if (this.sketch.value == "yx") { this.property_tree.push(this.all_property.yc); } else if (this.sketch.value == "dd") { this.property_tree.push(this.all_property.ym); } else if (this.sketch.value !== "sy") { for (var k in this.all_property) { this.property_tree.push(this.all_property[k]); } } this.clone_property_tree = JSON.parse(JSON.stringify(vm.property_tree)); }, recursion: function(op, arr, obj) { if (obj === undefined) { obj = { c_: {}, d_: {}, t_: {}, p_: {}, s_: {}, __other: {} }; } for (var i = 0, n = []; i < arr.length; i++) { var o = arr[i]; var code = op.key ? arr[i][op.key] : arr[i].code; obj[code] = o; if (o.nodetype === "dev_type") { obj.c_[code] = o; } else if (o.nodetype === "dev") { obj.d_[code] = o; } else if (o.nodetype === "property_type") { obj.t_[code] = o; } else if (o.nodetype === "property") { obj.p_[code] = o; } else if (o.nodetype === "property_value") { obj.s_[code] = o; } else { obj.__other[code] = o; } obj[o.code] = o; if (o.children && o.children.length > 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; }, isUncheck: function(flag) { if (flag) { this.substep = this.substep + 100; return true; } else { this.$alert(this.i18n.js.unseldev, this.i18n.js.tip, { confirmButtonText: this.i18n.js.ok, callback: function() {} }); return false; } }, creatDev: function() { this.devCheckedKeys = []; this.property_tree = []; this.property_tree.shift(); this.checked_node.nodes = []; this.checked_node.nodes.shift(); if (this.sketch.value == "sy") { this.creatDevSy(); } else { this.creatDevTree(); } }, creatDevSy: function() { var node = vm.$refs.adev_tree.getCurrentNode(); if (!this.isUncheck(node)) { return false; } for (var i = 0, _arr = tiemInterval(); 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); }, creatDevTree: function() { var adev = {}; //全部设备中选中的设备 if (vm.$refs.adev_tree) { //新建的时候 adev.dev_list = vm.$refs.adev_tree.getCheckedNodes(false, true); } else { //选择了报表 adev.dev_list = this.checked_node.nodes; } if (!this.isUncheck(adev.dev_list.length > 0)) { return false; } //处理自身数据 var devList = []; var devTypeList = []; var devkeys = []; for (var i = 0, temp = {}; i < adev.dev_list.length; i++) { var d = this.nodeFor(adev.dev_list[i]); if (temp[d.treeCode] !== undefined) { temp[d.treeCode].children.forEach(function(v) { v.ptid = temp[d.treeCode].tid; }); d.children = temp[d.treeCode].children; } temp[d.treeCode] = d; if (d.treePCode == "") { devTypeList.push(d); } else { if (temp[d.treePCode] === undefined) { temp[d.treePCode] = { children: [d] }; } else { d.ptid = temp[d.treePCode].tid; temp[d.treePCode].children.push(d); } } if (d.nodetype === "dev") { devList.push(d); devkeys.push(d.code); } } this.devCheckedKeys = devkeys; if (!this.ck_gx) { for (var k in temp) { if (temp[k].tid === undefined) { Array.prototype.push.apply(devTypeList, temp[k].children); } } } getCdInfo({ devTpName: devkeys.join(";"), type: vm.sketch.cdtype || vm.sketch.value, devList: devList, devTypeList: devTypeList }); getDevCD(devkeys.join(";")); }, pushCd: function(devList, devTypeList, cdlist) { var _type = { yx: "yc", dd: "ym", bb: "yc,ym,yx,mix", tj: "yc,ym,yx,mix", db: "yc,ym,yx,mix", cr: "yc,ym,yx,mix", undefined: "yc,ym,yx,mix" }; devList.forEach(function(v, i) { if (!v.children instanceof Array) { v.children = []; } var _id = v.tid.substr(1); if (vm.sketch.value != "tj") { cdlist.reduce(function(obj, item, index) { if ( // item.isCommon === "1" && _type[vm.sketch.value].indexOf(item.type) !== -1 ) { var _tid = item.tid + _id; var child=[item.children[0]] if(vm.cd_tid&&vm.cd_tid.length>0){ child=item.children.filter(function(v){ return vm.cd_tid.indexOf(v.tid)!==-1 }); } obj.push({ tid: _tid, children: item.children&&item.children.length>0?child.map(function(v){ return objClone(v, function(k, _obj, o) { if (k === "ptid") { o[k] = _tid; } else if (k === "tid") { o[k] = _obj[k] + _id; } else { o[k] = _obj[k]; } }) }):[], code: item.code, isCommon: item.isCommon, label: item.label, nodetype: item.nodetype, pointType: item.pointType, ptid: v.tid, stateText: item.stateText, stateTextList: item.stateTextList, type: item.type }); } return obj; }, v.children); } }); if (this.ck_gx) { this.checked_node.nodes = devList; } else { this.checked_node.nodes = devTypeList; } setTimeout(function() { vm.check_all = false; vm.checkedAll(); }, 50); }, creatDevTree_old: function() { this.check_all = true; var dev = {}; //原先选中的设备 var adev = {}; //全部设备中选中的设备 dev = this.checked_node; adev.dev_list = vm.$refs.adev_tree.getCheckedNodes(false, true); if (!this.isUncheck(dev.nodes.length > 0 || adev.dev_list.length > 0)) { 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 (dev[k].devModelCode) { devmodels.arr.push(k); devmodels[k] = dev[k]; } } getCdInfo({ devTpName: devmodels.arr.join(";"), type: vm.sketch.cdtype || vm.sketch.value }); }, 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); }, simChange: function(data, event, node) { this.check_station = data.id; this.postDev(); this.stshow = false; }, postDev: function() { var vm = this; this.all_dev = []; this.tree_loading = true; var len = configDevSearch().length; var flag; switch (len) { case 0: flag = true; break; case 1: flag = vm.check_station; break; case 2: flag = vm.check_profession && vm.check_station; break; } if (flag) { getDev(vm.check_profession, vm.check_station); } }, filterMspsNode: function(value, data) { console.log(12341234) 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_") !== -1) { if (!this.editNodePanel) { node = this.$refs.c_tree.getNode(data).parent.data; } else { node = this.$refs.clone_c_tree.getNode(data).parent.data; } } // s_ 要放到前面判断应为s_的也含有父级tid p_ if (!this.filter_q) { if (data.tid.indexOf("s_") !== -1) { // ps=node.label.indexOf(vm.filter_c)!==-1 ps = this.filterMulty(node.label, fc); }else if (data.tid.indexOf("p_") !== -1) { // ps=data.label.indexOf(vm.filter_c)!==-1 ps = this.filterMulty(data.label, fc); } } else if (!this.filter_c) { if (data.tid.indexOf("s_") !== -1) { // ps=data.label.indexOf(vm.filter_q)!==-1 ps = this.filterMulty(data.label, fq); } } else { var s_result=false,s_result=false; if (data.tid.indexOf("s_") !== -1) { // 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); }else if (data.tid.indexOf("p_") !== -1) { // ps=data.label.indexOf(vm.filter_c)!==-1 ps = this.filterMulty(data.label, fc); } } return ps; }, filter_all_dev_enter: function() { var val = this.filter_all_dev; this.devStrict = true; if (this.step) { this.$refs.adev_tree.filter(val); } else if (this.editNodePanel) { this.$refs.clone_adev_tree.filter(val); } }, filter_check_dev_enter: function() { var val = this.filter_check_dev; this.$refs.dev_tree.filter(val); }, filter_c_enter: function() { var val = this.filter_c; if (this.step) { this.$refs.c_tree.filter(val); } else if (this.editNodePanel) { this.$refs.clone_c_tree.filter(val); } }, filter_q_enter: function() { var val = this.filter_q; if (this.step) { this.$refs.c_tree.filter(val); } else if (this.editNodePanel) { this.$refs.clone_c_tree.filter(val); } }, 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 (data.nodetype === "dev") { if (this.filter_all_dev_type == "code") { t = this.filterMulty(data.code, str); } else { t = this.filterMulty(data.label, str); //如果不显示,则查找父级,是否符合,如果父级符合也显示 if(!t){ var pNode=node.parent; while (pNode&&pNode.parent&&!t) { t=this.filterMulty(pNode.data.label, str); pNode=pNode.parent; } } } } return t; }, filterMulty: function(data, value) { for (var i = 0, t = false, s = true; i < value.length; i++) { var str = value[i].trim(); if (str === "" || str === undefined || str === null) { continue; } if (data.indexOf(str) !== -1) { t = true; } if (data.indexOf(str) === -1) { s = false; } } return this.filterConnection ? s : 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 = 100; if (t === "dd") { /*电度*/ this.substep = num + 1; } else if (t === "bb") { /*报表*/ this.substep = num + 2; } else if (t === "cr") { /*班报表*/ this.substep = num + 3; } else if (t === "tj") { /*统计*/ this.substep = num + 5; this.reIniCheckNode(); } else if (t === "db") { /*对比*/ this.substep = num + 6; } else if (t === "qx") { /*全线*/ this.substep = num + 7; } else { /*运行和收益*/ this.substep = num; } }, // reportInterval: function () { // var arr = getReportIntreval(); // if (this.cur_report_type.value !== 'udf') { // arr.length = 3; // } // return arr; // }, reportIntervalClear: function() { this.report_interval = ""; }, /*菜单*/ preview: function() { // console.time('json'); var obj = JSON.parse( JSON.stringify({ vm: vm.$data }) ); // console.timeEnd('json'); // console.time('filter'); deleteReportFileItem(obj); delete obj.vm.checked_node; // console.timeEnd('filter'); // console.time('devtreeStorage'); sessionStorage.setItem( "dev_tree", pako.gzip(JSON.stringify(obj.vm.dev_tree), { to: "string" }) ); // console.timeEnd('devtreeStorage'); // console.time('allStorage'); delete obj.vm.dev_tree; // delete obj.all_dev; // delete obj.adev_tree; sessionStorage.setItem( "vm", pako.gzip(JSON.stringify(obj.vm), { to: "string" }) ); // console.timeEnd('allStorage'); }, menuSelect: function(v) { if (v == 4) { this.configure = true; } else if (v == 5) { this.preview(); var urlParam = decodeURIComponent(location.search), arr = [], tstr = ""; if (urlParam.indexOf("theme") !== -1) { arr = urlParam.substr(urlParam.indexOf("theme")).split(/[\=\&]/g); tstr = "?theme=" + arr[1]; } window.open("../page/view.html" + tstr, "_blank"); } else if (v == "1-1") { //初始化参数 if (this.substep != 0) { this.$confirm(this.i18n.js.cleareport, "", { distinguishCancelAndClose: true, confirmButtonText: this.i18n.js.aboult, cancelButtonText: this.i18n.js.newcur, type: "warning", callback: function(action, instance) { if (action == "confirm") { sessionStorage.setItem("reloadFlag", true); location.reload(); vm.substep = 0; } else if (action == "cancel") { vm.substep = vm.substep % 100; } if (action !== "close") { vm.isNew = true; vm.filter_check_dev = ""; vm.filter_c = ""; vm.filter_q = ""; vm.filter_all_dev = ""; vm.filter_all_dev_type = "name"; 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( this.i18n.js.saveept + '"' + vm.openedFile.name + '"?', "", { confirmButtonText: this.i18n.js.saveupd, cancelButtonText: this.i18n.js.openrpt, 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: this.i18n.js.simsun, value: this.i18n.js.simsun, v: "SimSun" }, { name: this.i18n.js.nsimsun, value: this.i18n.js.nsimsun, v: "NSimSun" }, { name: this.i18n.js.fangsong, value: this.i18n.js.fangsong, v: "FangSong" }, { name: this.i18n.js.kaiti, value: this.i18n.js.kaiti, v: "KaiTi" }, { name: this.i18n.js.simhei, value: this.i18n.js.simhei, v: "SimHei" }, { name: this.i18n.js.yahei, value: this.i18n.js.yahei, 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; }, changeTbtitleName: function() { this.$nextTick(function() { var text = this.i18n.js.report; this.tb_title.name = this.sketch.name; if ( this.tb_title.name.toLowerCase().indexOf(text.toLowerCase()) === -1 ) { this.tb_title.name = this.tb_title.name + text; } }); } }, watch: { all_dev: { handler(nv) { if (nv.length === 0) { this.devStrict = false; } else { // setTimeout(() => { // vm.devStrict = true; // }, 300); } } }, checked_contrast_index: function(nv, ov) { //什么原因让数组转成了true呢? if (nv instanceof Array) { } else { this.checked_contrast_index = ov; } }, default_e: function(nv) { var fn = function(nodes) { for (var i = 0; i < nodes.length; i++) { var d = nodes[i]; if (d.nodetype == "dev_type") { fn(d.children); } else if (d.nodetype == "dev") { d.e = nv; } else { continue; } } }; if (nv && !isNaN(nv)) { fn(vm.dev_tree); } }, 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.dev_e = v.e; this.edit_node_type = v.nodetype; }, radio_form: function(nv, no) { vm.form = vm[nv]; }, show_field: function(val) { /*切换树的显示方式*/ this.$set(vm.dev_field, "label", val ? "code" : "label"); }, 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 { console.log(data,vm.time_map) 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); } }, created: function() { var vm = this; var language = i18n(); //中英文 axios .get("../locales/" + language + "/report.json") .then(function(res) { vm.i18n = res.data; init(vm); vm.check_off = vm.i18n.js.fullsel; vm.tb_title.name = vm.i18n.js.tbttle; vm.tb_title.font_family = vm.i18n.js.yahei; vm.tb_sub.name = vm.i18n.js.tbsubtle; vm.tb_sub.font_family = vm.i18n.js.yahei; vm.tb_detailed_1.name = vm.i18n.js.defincontent; vm.tb_detailed_1.font_family = vm.i18n.js.yahei; vm.tb_detailed_2.name = vm.i18n.js.tbcode; vm.tb_detailed_2.font_family = vm.i18n.js.yahei; vm.tb_detailed_3.name = vm.i18n.js.watchmakingTime + ":" + new Date().toLocaleDateString(); vm.tb_detailed_3.font_family = vm.i18n.js.yahei; vm.tb_detailed_4.name = vm.i18n.js.watchmaker + ":" + (sessionStorage.getItem("name") || ""); vm.tb_detailed_4.font_family = vm.i18n.js.yahei; vm.border_type_list = [ { label: vm.i18n.js.solid, value: "solid" }, { label: vm.i18n.js.dotted, value: "dotted" }, { label: vm.i18n.js.dashed, value: "dashed" }, { label: vm.i18n.js.double, value: "double" }, { label: vm.i18n.js.groove, value: "groove" }, { label: vm.i18n.js.ridge, value: "ridge" }, { label: vm.i18n.js.inset, value: "inset" }, { label: vm.i18n.js.outset, value: "outset" } ]; vm.reportFiles[0].label = vm.i18n.js.report; vm.reportModes[0].label = vm.i18n.js.model; vm.reportModes[0].children[0].label = vm.i18n.js.model + "1"; vm.dateLabelStart = vm.i18n.excel.startlabel; vm.dateLabelEnd = vm.i18n.excel.endlabel; }) .catch(function(err) {}); /*对比*/ this.contrasts = getAllContrasts(); /*统计*/ this.all_totals = getALLTotals(); if (sessionStorage.getItem("reloadFlag") == "true") { this.step = true; sessionStorage.setItem("reloadFlag", false); } }, directives: { treefocus: { update: function(el, obj, newnode, oldnode) { var tag = el.getElementsByTagName("input")[0]; tag.focus(); if ( nv == ov && vm.input_focus && newnode.elm.style.display !== "none" ) { var nv = newnode.data.props.value; var ov = oldnode.data.props.value; tag.select(); vm.input_focus = false; } } }, resize: { // 指令的名称 bind(el, binding) { // el为绑定的元素,binding为绑定给指令的对象 var width = "", height = ""; function isReize() { var style = document.defaultView.getComputedStyle(el); if (width !== style.width || height !== style.height) { binding.value(); // 关键 } var o = vm.paper_size[vm.paper_type]; width = style.width; height = style.height; var wsum = 1, hsum = 1; if (vm.paper_orientation == "col") { wsum = Math.ceil(parseFloat(width) / o.col); hsum = Math.ceil(parseFloat(height) / o.row); } else { wsum = Math.ceil(parseFloat(width) / o.row); hsum = Math.ceil(parseFloat(height) / o.col); } vm.paper_sum.width = wsum; vm.paper_sum.height = hsum; } el.__vueSetInterval__ = setInterval(isReize, 300); }, unbind(el) { clearInterval(el.__vueSetInterval__); } } }, mounted: function() { var theme = "", href = ""; if (this.userInfo) { //根据外层框架信息切换主题 theme = this.userInfo.theme ? this.userInfo.theme : ""; } if (theme == "dark-theme") { //深色主题 href = "../css/dark/dark_design.css"; addCSSFile(href); } if (theme == "default-theme") { //浅色主题 href = "../css/light/light_design.css"; addCSSFile(href); } this.radio_form = "tb_title"; } }); 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) { if (!str) { 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]; if (vm.sketch.value === "tj" && t.nodetype == "property_value") { //统计时处理time_map var property = arr[i - 1].filter(function(v, i, a) { return v.tid == t.ptid; })[0]; if (property) { t.pCode = property.code; } } pid[t.ptid] = (pid[t.ptid] === undefined ? 0 : pid[t.ptid]) + (pid[t.tid] === undefined ? 1 : pid[t.tid]); if (pid[t.tid] === undefined) { if (t.nodetype == "dev") { var _dis_ = vm.ck_dev && vm.cur_report_style.value == 0 ? ";display:none;" : ""; } else { var _dis_ = vm.ck_sx && vm.cur_report_style.value == 0 ? ";display:none;" : ""; } _str += "
" + (t.label || t.name) + "
"; ids[i].push(t); } else { var _dis_ = t.nodetype == "dev" && vm.ck_dev ? ";display:none" : ""; _str += "
" + (t.label || t.name) + "
"; if (ids[i + 1] !== undefined) { ids[i] = ids[i].concat(ids[i].splice(0, pid[t.tid])); } } } if (i > 0) { var tr = ""; } else { vm.ck_sx && vm.cur_report_style.value != 0 && collength--; //如果隐藏测点属性 vm.ck_dev && vm.cur_report_style.value != 0 && collength--; //如果隐藏设备 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 = "", 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) { if (t.nodetype == "dev") { var _dis_ = vm.ck_dev && vm.cur_report_style.value != 0 ? ";display:none;" : ""; } else { var _dis_ = vm.ck_sx && vm.cur_report_style.value != 0 ? ";display:none;" : ""; } th = '
' + (t.label || t.name) + "
"; if (pid[t.ptid] == 1) { ids[t.ptid] = []; } var row = (pid[t.ptid] != 1 || i == 0 ? "" : "") + th + getNormalTd(t) + ""; ids[t.ptid].push(row); if (i == 0) { str += row; } } else { var _dis_ = t.nodetype == "dev" && vm.ck_dev ? ";display:none" : ""; th = '
' + (t.label || t.name) + "
"; 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; } //生成某一行td function getNormalTd(node) { var tds = ""; var obj = vm.devHasCD; var isRow = vm.cur_report_style.value == 0; //判断是横向报表还是纵向报表 var reportType = vm.sketch.value; //判断是不是统计报表 // console.log(isRow, reportType); // console.log(vm.dev_map); // console.log(vm.time_map); if (isRow) { if (reportType === "tj") { // console.log("横向统计",node); tds = vm.dev_map.reduce(function(o, v, i) { o += '
' + (obj[v.code] && obj[v.code][node.pCode] ? " " : "\\") + "
"; if (obj[v.code] && obj[v.code][node.pCode]) { obj[v.code][node.pCode] = true; } return o; }, ""); } else { //横向逐时 tds = vm.dev_map.reduce(function(o, v, i) { o += '
' + (v.isNotReal ? "\\" : " ") + "
"; return o; }, ""); } } else { if (reportType === "tj") { tds = vm.time_map.reduce(function(o, v, i) { o += '
' + (obj[node.code] && obj[node.code][v.pCode] ? " " : "\\") + "
"; if (obj[v.code] && obj[v.code][node.pCode]) { obj[v.code][node.pCode] = true; } return o; }, ""); } else { //纵向逐时 tds = new Array(vm.time_map.length + 1).join( '
' + (node.isNotReal ? "\\" : " ") + "
" ); } } return tds; } //生成自己以及后代节点的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 = { // 向导 devHasCD: 1, 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_total_all: 1, indeterminate: 1, devCheckedKeys: 1, checked_contrast_index: 1, totals: 1, ck_cd: 1, ck_dev:1, ck_sx: 1, cd_tid: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, //其他 all_totals: 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; var diff = (Number(vm.ck_sx)||0)+(Number(vm.ck_dev)||0);// 判断是否隐藏间隔信号或者隐藏属性(瞬时值,最大值这一行), for (var i = 0; i < th - diff; 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 + ""; } function addCSSFile(href) { //引入css样式表 var link = document.createElement("link"); link.type = "text/css"; link.rel = "stylesheet"; link.href = href; document.getElementsByTagName("head")[0].appendChild(link); }