
document.write("<script type='text/javascript' src='../static/bootstrap/bootstrap/js/bootstrap.js'></script>");
document.write("<link rel='stylesheet' href='../static/bootstrap/bootstrap/css/bootstrap.css'  media='all'>");
document.write("<script type='text/javascript' src='../static/echarts/echarts.min.js'></script>");
document.write("<script type='text/javascript' src='../public/interface.js'></script>");
document.write("<script type='text/javascript' src='../ElectronicLoadTester/files/public.js'></script>");


document.write("<script type='text/javascript' src='../static/layui/layui.all.js'></script>");



$(function(){




    window.t1 = function() {//layer.msg(obj.cnt.toString())
        if(interface.getFreeTime(0) < 100){
            // layer.msg(interface.getFreeTime(0))
        }
        else if(obj.cnt == 0){//查询控制方式
            get_LOCal();
            if(select_is("#RadioButton_Remote_img") == true){
                obj.cnt++;
            }else{
                $('#Heading_ConnectionStatus_text').html("连接状态:未连接");
            }
        }
        else if(obj.cnt == 1) {//通道选择
            if(ch_select() == "ok"){
                obj.cnt++;
            }
        }
        else if(obj.cnt == 2) {//查询电流
            interface.getSerialComm(0, "MEASure:CURRent?", "measure_current", TaktTimeDelay, OverTimeDelay); //var dat = comm.get_Curr();
            window.measure_current = function (i, dat) {
                chart_data_add(0, dat);obj.cnt++;
                $('#Heading_GetCurrent_text').html(dat + " A");
            }
        }
        else if(obj.cnt == 3) {//查询电压
            interface.getSerialComm(0, "MEASure:VOLTage?", "measure_voltage", TaktTimeDelay, OverTimeDelay); //var dat = comm.get_Volt();
            window.measure_voltage = function (i, dat) {
                chart_data_add(1, dat);obj.cnt++;
                $('#Heading_GetVoltage_text').html(dat + " V");
            }
        }
        else if(obj.cnt == 4) {//查询功率
            interface.getSerialComm(0, "MEAS:POWer?", "measure_Power", TaktTimeDelay, OverTimeDelay); //var dat = comm.get_Power();
            window.measure_Power = function (i, dat) {
                chart_data_add(2, dat);obj.cnt++;
                $('#Heading_GetPower_text').html(dat + " W");
            }
        }
        else if(obj.cnt == 5) {//查询开关状态
            if(get_OnOff() == "ok"){
                obj.cnt++;
            }
        }
        else if(obj.cnt == 6){//查询触发方式
            if(get_Trig_Mode()== "ok"){
                obj.cnt++;
            }
        }
        else if(obj.cnt == 7){//查询触发状态
            if(get_Trigger()== "ok"){
                obj.cnt++;
            }
        }
        else if(obj.cnt == 8){//查询暂停状态
            if(get_PauseState()== "ok"){
                obj.cnt++;
            }
        }
        else if(obj.cnt == 9){//查询短路状态
            if(get_ShortState()== "ok"){
                obj.cnt++;
            }
        }
        else if(obj.cnt == 10){//查询补偿功能状态
            if(get_SENSe()== "ok"){
                obj.cnt++;
            }
        }
        else if(obj.cnt == 11){//查询补偿功能状态
            if(get_ModeState()== "ok"){
                obj.cnt++;
            }
        }
        else if(obj.cnt == 12){
            if(ListTest() > 0){
                obj.cnt++;
            }
        }
        else if(obj.cnt == 13){//查询版本
            interface.getSerialComm(0, "*IDN?", "get_idn", TaktTimeDelay, OverTimeDelay); //var dat = comm.get_IDN();
            window.get_idn = function (i, dat) {
                obj.cnt = 0;
                InstrumentModel = dat;
                $('#Heading_DeviceInformation_text').html("设备信息:" + dat);
                $('#Heading_ConnectionStatus_text').html("连接状态:已连接");
            }
        }
        else{
            obj.cnt = 0;
        }
    }



    //如下为列表测试
    {
        //初始化表头
        {
            var str_html1 = "\
            <table id='TableCell_List_ListTestTable' class='table table-bordered table-condensed'  style='background: white; '>\
                <tr>\
                    <th style='text-align: center; width: 80px'>序号</th>\
                    <th style='text-align: center; width: 170px '>模式</th>\
                    <th style='text-align: center; width: 100px '>设置值</th>\
                    <th style='text-align: center; width: 100px '>定时(ms)</th>\
                    <th style='text-align: center; width: 140px '>检查</th>\
                    <th style='text-align: center; width: 100px '>上限</th>\
                    <th style='text-align: center; width: 100px '>下限</th>\
                    <th style='text-align: center; width: 100px '>结果</th>\
                </tr>\
            </table>";
        $("#TableCell_ListTest").html(str_html1);
        $("#TableCell_ListTest").css("height", "470px");
        $("#TableCell_ListTest").css("overflow", "scroll");
        $("th").css({'padding':'0px', 'vertical-align': 'middle', 'margin': '0 0 0 0'});
        $("td").css({'padding':'0px', 'vertical-align': 'middle', 'margin': '0 0 0 0'});
    }

        //行的增删操作
        {
            function select(str1, str2) {
                if(str1 == str2){return "selected='selected'";}else{return "";}
            }
            function add_row(row, mode, SetValue, SetTime, Check, Max, Min){
                var newRow = "\
                <tr style='background: white'>\
                    <td style=''></td>\
                    <td style=''>\
                        <select class='form-control' style=''>\
                            <option value='恒电流'" + select(mode, "恒电流") + ">恒电流</option>\
                            <option value='恒电压'" + select(mode, "恒电压") + ">恒电压</option>\
                            <option value='恒功率'" + select(mode, "恒功率") + ">恒功率</option>\
                            <option value='恒电阻'" + select(mode, "恒电阻") + ">恒电阻</option>\
                            <option value='开路'" + select(mode, "开路") + ">开路</option>\
                            <option value='短路'" + select(mode, "短路") + ">短路</option>\
                        </select>\
                    </td>\
                    <td style=''><input placeholder='设置值' class='form-control' style='' value='" + SetValue + "'></td>\
                    <td style=''><input placeholder='定时值(ms)' class='form-control' style='' value='" + SetTime + "'></td>\
                    <td style=''>\
                        <select class='form-control' style=''>\
                            <option value='关'" + select(Check, "关") + ">关</option>\
                            <option value='电流'" + select(Check, "电流") + ">电流</option>\
                            <option value='电压'" + select(Check, "电压") + ">电压</option>\
                            <option value='功率'" + select(Check, "功率") + ">功率</option>\
                        </select>\
                    </td>\
                    <td style=''><input placeholder='上限' class='form-control' style='' value='" + Max + "'></td>\
                    <td style=''><input placeholder='下限' class='form-control' style='' value='" + Min + "'></td>\
                    <td style=''></td> \
                </tr>";

                if(row < 0){
                    $("#TableCell_List_ListTestTable tr:last").after(newRow);//追加
                }else{
                    $("#TableCell_List_ListTestTable tr:gt(0):eq(" + row + ")").before(newRow);//指定位置前插入
                }
                tabSelectSetBackground(row + 1);
                $("th").css({'padding':'0px', 'vertical-align': 'middle', 'margin': '0 0 0 0'});
                $("td").css({'padding':'0px', 'vertical-align': 'middle', 'margin': '0 0 0 0'});
            };
            //删除行
            $("#FlowShape_List_Del").click(function () {//删除行
                var state = get_NowRowSelect("TableCell_List_ListTestTable");
                if(state.SelectRow > 0){
                    $("#TableCell_List_ListTestTable tr").eq(state.SelectRow).remove();
                    if(state.SelectRow > 1){tabSelectSetBackground(state.SelectRow);}else{tabSelectSetBackground(1);}
                }else{layer.msg("<h1>请选择删除位置</h1>");}
            });
            //添加行
            $("#FlowShape_List_Add").click(function () {
                var state = get_NowRowSelect("TableCell_List_ListTestTable");
                if(state.RowSum > 16){
                    layer.msg("<h1>不能超过16行</h1>");
                }
                else {
                    add_row(-1, "恒电流", "1.00", "1000", "关", "2.00", "0.50");
                }
            });
            //插入行
            $("#FlowShape_List_Insert").click(function () {
                var state = get_NowRowSelect("TableCell_List_ListTestTable");
                if(state.RowSum > 16){
                    layer.msg("<h1>不能超过16行</h1>");
                }
                else if(state.SelectRow > 0){
                    add_row(state.SelectRow - 1, "恒电流", "1.00", "1000", "关", "2.00", "0.50");
                }else{layer.msg("<h1>请选择插入位置</h1>")}
            });
        }

        //行状态获取及选中颜色设置
        {
            //获得当前选择的行
            function get_NowRowSelect(id){
                var ob  = {RowSum:-1, SelectRow: -1}
                var tbl = document.getElementById(id);
                var trs = tbl.getElementsByTagName("tr");
                ob.RowSum = trs.length;
                for (var i = 0; i < trs.length; i++) {
                    if(trs[i].style.background != "" && trs[i].style.background != "white"){
                        ob.SelectRow = i;
                        break;
                    }
                }
                return ob;
            }
            //选中行颜色
            $(document).on('click', '#TableCell_List_ListTestTable tr', function () {
                tabSelectSetBackground(this);
            });
            function tabSelectSetBackground(a){
                var tbl = document.getElementById("TableCell_List_ListTestTable");
                var trs = tbl.getElementsByTagName("tr");
                for (var i = 1; i < trs.length; i++) {
                    if (trs[i] == a || a == i) {  //判断是不是当前选择的行
                        trs[i].style.background = "#02f5ff";
                    }
                    else {
                        trs[i].style.background = "white";
                    }
                    trs[i].cells[0].innerText = i;
                }
            }
        }

        //表数据的导入与导出
        {
            //导出表中所有输入数据
            $("#FlowShape_List_Export").click(function () {
                var group = $('#TextField_List_Group_input').val();
                var repeat = $('#TextField_List_Repeat_input').val();
                var select = $('#Droplist_List_RunMode_input option:selected').val();
                var str = "{";
                str += "\"select\":\"" + select + "\", \"repeat\":\"" + repeat + "\", \"group\":\"" + group + "\", \"data\":[";
                var dat = get_list_data();
                for(var row=1; row<dat.length; row++){
                    str += "{";
                    for(var col=0; col<dat[row].length; col++){
                        str += "\"" + dat[row][col][0] + "\":";
                        str += "\"" + dat[row][col][1] + "\",";
                    }
                    str = str.substr(0, str.length - 1);//去除多余逗号
                    str += "},";
                }
                str = str.substr(0, str.length - 1);//去除多余逗号
                str += "]}";
                interface.saveFile(str, "ListTest");
            });
            function get_list_data() {
                var dat = [];
                $("#TableCell_List_ListTestTable tr").each(function(row){
                    var row_dat = []
                    $(this).find("input").each(function(col){
                        row_dat.push(["input" + col, $(this).val()]);
                    })
                    $(this).find("select").each(function(col){
                        row_dat.push(["select" + col, $(this).val()]);
                    })
                    dat.push(row_dat);
                })
                return dat;
            }
            //导入数据到表中
            $("#FlowShape_List_Import").click(function () {
                // var str = "{\"select\":\"连续\", \"data\":[{\"input0\":\"1.00\",\"input1\":\"1000\",\"input2\":\"1.50\",\"input3\":\"0.50\",\"select0\":\"恒电流\",\"select1\":\"电压\"},{\"input0\":\"1.20\",\"input1\":\"3000\",\"input2\":\"2.00\",\"input3\":\"1.00\",\"select0\":\"恒电压\",\"select1\":\"电流\"},{\"input0\":\"3.00\",\"input1\":\"2000\",\"input2\":\"5.00\",\"input3\":\"4.50\",\"select0\":\"恒功率\",\"select1\":\"电压\"},{\"input0\":\"5.00\",\"input1\":\"6000\",\"input2\":\"10.00\",\"input3\":\"0.50\",\"select0\":\"恒电阻\",\"select1\":\"电流\"},{\"input0\":\"0.00\",\"input1\":\"3000\",\"input2\":\"1.00\",\"input3\":\"0.00\",\"select0\":\"开路\",\"select1\":\"电流\"},{\"input0\":\"10.00\",\"input1\":\"2000\",\"input2\":\"15.00\",\"input3\":\"1.00\",\"select0\":\"短路\",\"select1\":\"电流\"}]}";
                // var json = JSON.parse(str);
                var json = JSON.parse(interface.readFile());
                if(json != false){
                    var state = get_NowRowSelect("TableCell_List_ListTestTable");
                    $('#TextField_List_Group_input').val(json["group"]);
                    $('#TextField_List_Repeat_input').val(json["repeat"]);
                    $('#Droplist_List_RunMode_input').val(json["select"]);
                    for(var i=1; i<state.RowSum; i++){
                        $("#TableCell_List_ListTestTable tr").eq(1).remove();
                    }
                    for(var row=0; row<json["data"].length; row++){
                        add_row(-1, json["data"][row]["select0"], json["data"][row]["input0"], json["data"][row]["input1"], json["data"][row]["select1"], json["data"][row]["input2"], json["data"][row]["input3"]);
                    }
                }
            });
        }

        var ListTestIndex = 0;
        $('#FlowShape_List_Start').click(function() {//按键-开始
            ListTestIndex = 1;
            $("#TableCell_List_ListTestTable tr").each(function (row) {
                $(this).find("td").eq(7).html("");
            });
        });
        $('#FlowShape_List_Stop').click(function() {//按键-停止
            ListTestIndex = 0;
            // serial_comm(0, "input 0",TaktTimeDelay, WriteTimeDelay, 0);
            interface.setSerialSend(0, "input 0", "", obj.delay1, obj.delay2, obj.overDelay);
        });

        var loading;
        function ListTest(){//列表测试
            var dat = get_list_data();//layer.msg(ListTestIndex.toString())
            if(ListTestIndex == 0){

            }
            else if(ListTestIndex < dat.length){
                loading = layer.load(2, {time: 20000});
                var cmd_str = "";
                var select = dat[ListTestIndex][4][1];//设置列表第一步带载模式。命令中第几步则以SET加上相应数字表示，步数最大不能超过16步。
                if(select == "恒电流")          {cmd_str += "LIST:SET" + PrefixInteger(ListTestIndex,2) + ":MODE 0.0;";}
                else if(select == "恒电压")         {cmd_str += "LIST:SET" + PrefixInteger(ListTestIndex,2) + ":MODE 1.0;";}
                else if(select == "恒功率")         {cmd_str += "LIST:SET" + PrefixInteger(ListTestIndex,2) + ":MODE 3.0;";}
                else if(select == "恒电阻")         {cmd_str += "LIST:SET" + PrefixInteger(ListTestIndex,2) + ":MODE 2.0;";}
                else if(select == "开路")           {cmd_str += "LIST:SET" + PrefixInteger(ListTestIndex,2) + ":MODE 4.0;";}
                else if(select == "短路")           {cmd_str += "LIST:SET" + PrefixInteger(ListTestIndex,2) + ":MODE 5.0;";}

                //设置列表第一步带载定值。命令中第几步则以SET加上相应数字表示，步数最大不能超过16步。
                cmd_str += "LIST:SET" + PrefixInteger(ListTestIndex,2) + ":VALue " + dat[ListTestIndex][0][1] + ";";

                //设置列表第一步带载时间。命令中第几步则以SET加上相应数字表示，步数最大不能超过16步
                cmd_str += "LIST:SET" + PrefixInteger(ListTestIndex,2) + ":DWELl " + dat[ListTestIndex][1][1] + ";";

                //设置列表第一步检查项。命令中第几步则以SET加上相应数字表示，步数最大不能超过16步。
                var select = dat[ListTestIndex][5][1];
                if(select == "电流")         {cmd_str += "LIST:SET" + PrefixInteger(ListTestIndex,2) + ":PROTection 1.0;";}
                else if(select == "电压")         {cmd_str += "LIST:SET" + PrefixInteger(ListTestIndex,2) + ":PROTection 2.0;";}
                else if(select == "功率")         {cmd_str += "LIST:SET" + PrefixInteger(ListTestIndex,2) + ":PROTection 3.0;";}
                else                               {cmd_str += "LIST:SET" + PrefixInteger(ListTestIndex,2) + ":PROTection 0.0;";}

                //设置列表第一步保护上限值。命令中第几步则以SET加上相应数字表示，步数最大不能超过16步。
                cmd_str += "LIST:SET" + PrefixInteger(ListTestIndex,2) + ":UPPer " + dat[ListTestIndex][2][1] + ";";

                //设置列表第一步保护下限值。命令中第几步则以SET加上相应数字表示，步数最大不能超过16步。
                cmd_str += "LIST:SET" + PrefixInteger(ListTestIndex,2) + ":LOWer " + dat[ListTestIndex][3][1] + ";";

                // ListTestIndex++;
                // obj.SetCmd = cmd_str.substr(0, cmd_str.length -1);
                // obj.TaktTiem = 100; obj.OverTime = 500; obj.RxdByteSum = 0;
                // var dat = serial_comm(0, cmd_str,100, 200, 0);
                // if(dat.sta == "ok"){
                //     ListTestIndex++;
                // }else{ListTestIndex = 0; layer.msg("<h1>应答异常</h1>");}

                if(interface.setSerialSend(0, cmd_str, "", 100, 0, 150) == "ok") {
                    ListTestIndex++;
                }
                return 0;
            }
            else if(ListTestIndex == dat.length + 0){//设置列表执行重复次数
                // var dat = serial_comm(0, "LIST:REPeat " + $('#TextField_List_Repeat_input').val(), TaktTimeDelay, WriteTimeDelay, 0);
                if(interface.setSerialSend(0, "LIST:REPeat " + $('#TextField_List_Repeat_input').val(), "", obj.delay1, obj.delay2, obj.overDelay) == "ok") {
                    ListTestIndex++;
                }
                // if(dat.sta == "ok"){
                //     ListTestIndex++;
                // }else{ListTestIndex = 0; layer.msg("<h1>应答异常</h1>")}
                return 0;
            }
            else if(ListTestIndex == dat.length + 1){//设置列表执行步数
                if(interface.setSerialSend(0, "LIST:STEP " + (dat.length - 1), "", obj.delay1, obj.delay2, obj.overDelay) == "ok") {
                    ListTestIndex++;
                }
                // var dat = serial_comm(0, "LIST:STEP " + (dat.length - 1), TaktTimeDelay, WriteTimeDelay, 0);
                // if(dat.sta == "ok"){
                //     ListTestIndex++;
                // }else{ListTestIndex = 0; layer.msg("<h1>应答异常</h1>")}
                return 0;
            }
            else if(ListTestIndex == dat.length + 2){//设置CONT连续，TRIG触发，CONTERR连续有异常停止，CONTERR触发有异常停止
                var str_cmd = "";
                var select = $('#Droplist_List_RunMode_input option:selected').val();
                if(select == "连续")                 {str_cmd = "LIST:MODE CONT";}
                else if(select == "触发")           {str_cmd = "LIST:MODE TRIG";}
                else if(select == "连续+异常停")   {str_cmd = "LIST:MODE CONTERR";}
                else if(select == "触发+异常停")   {str_cmd = "LIST:MODE TRIGERR";}
                else                                 {ListTestIndex = 0;}
                if(interface.setSerialSend(0, str_cmd, "", obj.delay1, obj.delay2, obj.overDelay) == "ok") {
                    ListTestIndex++;
                }
                // var dat = serial_comm(0, str_cmd,TaktTimeDelay, WriteTimeDelay, 0);
                // if(dat.sta == "ok"){
                //     ListTestIndex++;
                // }else{ListTestIndex = 0; layer.msg("<h1>应答异常</h1>")}
                return 0;
            }
            else if(ListTestIndex == dat.length + 3){//选择负载的列表测试模式
                if(interface.setSerialSend(0, "MODE LIST", "", obj.delay1, obj.delay2, obj.overDelay) == "ok") {
                    ListTestIndex++;
                }
                // var dat = serial_comm(0, "MODE LIST",TaktTimeDelay, WriteTimeDelay, 0);
                // if(dat.sta == "ok"){
                //     ListTestIndex++;
                // }else{ListTestIndex = 0; layer.msg("<h1>应答异常</h1>");}
                return 0;
            }
            else if(ListTestIndex == dat.length + 4){//开始测试
                if(interface.setSerialSend(0, "INPut 1", "", obj.delay1, obj.delay2, obj.overDelay) == "ok") {
                    ListTestIndex++;
                }
                layer.close(loading);
                // var dat = serial_comm(0, "INPut 1",TaktTimeDelay, WriteTimeDelay, 0);
                // if(dat.sta == "ok"){
                //     ListTestIndex++;
                //     layer.msg("<h1>完成设置</h1>");
                // }else{ListTestIndex = 0; layer.msg("<h1>应答异常</h1>")}
                return 0;
            }
            else if(ListTestIndex == dat.length + 5){//判断测试是否已经开始
                if(select_is("#PrimaryButton_OnOff_img") == true){
                    ListTestIndex++;
                }
                // return 1;
            }
            else if(ListTestIndex == dat.length + 6){//查询测试结果
                // var dat = serial_comm(0, "LIST:RES?", TaktTimeDelay, OverTimeDelay, 3);//
                // if(dat.sta == "ok" && dat.val.length > 0 && select_is("#PrimaryButton_OnOff_img") == false){
                //     ListTestIndex++;
                //     var len = $("#TableCell_List_ListTestTable").find("tr").length;
                //     var select = $('#Droplist_List_RunMode_input option:selected').val();
                //     for(var row=1; row<len; row++){
                //         if(((parseInt(dat.val)&(1<<(row-1))) > 0)){
                //             $("#TableCell_List_ListTestTable").find("tr").eq(row).find("td").eq(7).html("PASS");
                //         }else{
                //             $("#TableCell_List_ListTestTable").find("tr").eq(row).find("td").eq(7).html("FAIL");
                //             if(select == "连续+异常停" || select == "触发+异常停") {
                //                 break;
                //             }
                //         }
                //     }
                //     layer.msg("返回值: 0x" + dat.val);
                // }
                let dat = {val:""};
                interface.getSerialComm(0, "LIST:RES?", "get_list_res", TaktTimeDelay, OverTimeDelay);
                window.get_list_res = function (i, str) {
                    dat.val = str;
                    if(dat.val.length > 0 && select_is("#PrimaryButton_OnOff_img") == false){
                        ListTestIndex++;
                        var len = $("#TableCell_List_ListTestTable").find("tr").length;
                        var select = $('#Droplist_List_RunMode_input option:selected').val();
                        for(var row=1; row<len; row++){
                            if(((parseInt(dat.val)&(1<<(row-1))) > 0)){
                                $("#TableCell_List_ListTestTable").find("tr").eq(row).find("td").eq(7).html("PASS");
                            }else{
                                $("#TableCell_List_ListTestTable").find("tr").eq(row).find("td").eq(7).html("FAIL");
                                if(select == "连续+异常停" || select == "触发+异常停") {
                                    break;
                                }
                            }
                        }
                        // layer.msg("返回值: 0x" + dat.val);
                    }
                }
            }
            else{
                ListTestIndex = 0;
            }
            return 1;
            //obj.SetCmd = "";
        }
    }






    //如下为图表显示
    {
        var chart_curr = new eEhart("#FlowShape_ChartCurr",        "", [{name: '电流'},{name: '电压'}, {name: '功率'}], 2);
        var chart_power = new eEhart("#FlowShape_ChartVoltPower", "", [{name: '电流'},{name: '电压'}, {name: '功率'}], 2);
        
        function chart_data_add(num, data) {
            var select_ch = $("#Droplist_Channel_input").val();
            if(select_ch == "CH2"){
                chart_curr.add_data(1, num, data);   chart_curr.chart_select = 1;
                chart_power.add_data(1, num, data);  chart_power.chart_select = 1;
            }
            else{
                chart_curr.add_data(0, num, data);   chart_curr.chart_select = 0;
                chart_power.add_data(0, num, data);   chart_power.chart_select = 0;
            }
        }
        $("#Droplist_Channel_input").change(function () {
            chart_curr.chart_select = this.selectedIndex;
            chart_power.chart_select = this.selectedIndex;
        });


        //水平滚动条联动
        function dataZoom(params){
            if(params.dataZoomId.indexOf("1") < 0){
                var end = 100,start = 0;
                if(params.start == undefined){
                    end = params.batch[0].end;
                    start = params.batch[0].start;
                }else{
                    end = params.end;
                    start = params.start;
                }
                chart_curr.option_data[chart_curr.chart_select].dataZoom[0].end = end;
                chart_curr.option_data[chart_curr.chart_select].dataZoom[0].start = start;
                chart_power.option_data[chart_curr.chart_select].dataZoom[0].end = end;
                chart_power.option_data[chart_curr.chart_select].dataZoom[0].start = start;
                chart_curr.echart.setOption(chart_curr.option_data[chart_curr.chart_select]);
                chart_power.echart.setOption(chart_power.option_data[chart_curr.chart_select]);
            }
        }
        chart_curr.echart.on('dataZoom', function (params) {
            dataZoom(params);
        });
        chart_power.echart.on('dataZoom', function (params) {
            dataZoom(params);
        });

        var curr_seriesIndex = 0;
        $("#FlowShape_ChartCurr").append('<div id="div_colpick_show1" style="padding-left: 0px; padding-top: 0px"></div>');
        chart_curr.echart.on('click', function (params) {
            curr_seriesIndex = params.seriesIndex;
            const box = document.querySelector("#div_colpick_show1");
            $(box).colpick({
                onSubmit: (hsb, hex, rgb, el, bySetColor) => {
                    // layer.msg(hex);
                    chart_curr.option_data[chart_curr.chart_select].series[curr_seriesIndex].color = "#" + hex;
                    chart_curr.echart.setOption(chart_curr.option_data[chart_curr.chart_select]);
                    $(box).colpickHide();
                }
            }); // 初始化
            $(box).colpickShow(); // 显示
        });

        var power_seriesIndex = 0;
        $("#FlowShape_ChartVoltPower").append('<div id="div_colpick_show2" style="padding-left: 0px; padding-top: 0px"></div>');
        chart_power.echart.on('click', function (params) {
            power_seriesIndex = params.seriesIndex;
            const box = document.querySelector("#div_colpick_show2");
            $(box).colpick({
                onSubmit: (hsb, hex, rgb, el, bySetColor) => {
                    // layer.msg(hex);
                    chart_power.option_data[chart_power.chart_select].series[power_seriesIndex].color = "#" + hex;
                    chart_power.echart.setOption(chart_power.option_data[chart_power.chart_select]);
                    $(box).colpickHide();
                }
            }); // 初始化
            $(box).colpickShow(); // 显示
        });
    }





    {//input值恢复与定时备份
        var userAgent = myBrowser().indexOf("WOW64");
        
        function SetingRestore() {
            if(userAgent >= 0){
                var select_ch = $("#Droplist_Channel_input").val();
                $("#TextField_SetVoltage_input").val(interface.getIni("ListTest", select_ch + "_TextField_SetVoltage_input",            "5.00"));      $("#TextField_SetVoltage_input").attr("maxlength",5);
                $("#TextField_SetCurrent_input").val(interface.getIni("ListTest", select_ch + "_TextField_SetCurrent_input",            "1.20"));      $("#TextField_SetCurrent_input").attr("maxlength",5);
                $("#TextField_SetPower_input").val(interface.getIni("ListTest", select_ch + "_TextField_SetPower_input",                 "2.00"));      $("#TextField_SetPower_input").attr("maxlength",5);
                $("#TextField_SetResistance_input").val(interface.getIni("ListTest", select_ch + "_TextField_SetResistance_input",      "2.00"));     $("#TextField_SetResistance_input").attr("maxlength",5);
                $("#Droplist_ResistanceUnit_input").val(interface.getIni("ListTest", select_ch + "_Droplist_ResistanceUnit_input",      "Ohm"));
                $("#TextField_List_Group_input").val(interface.getIni("ListTest", select_ch + "_TextField_List_Group_input",             "1"));        $("#TextField_List_Group_input").attr("maxlength",5);
                $("#TextField_List_Repeat_input").val(interface.getIni("ListTest", select_ch + "_TextField_List_Repeat_input",           "1"));        $("#TextField_List_Repeat_input").attr("maxlength",5);
                $("#Droplist_List_RunMode_input").val(interface.getIni("ListTest", select_ch + "_Droplist_List_RunMode_input",           "连续"));

                var state = get_NowRowSelect("TableCell_List_ListTestTable");
                for(var i=1; i<state.RowSum; i++){
                    $("#TableCell_List_ListTestTable tr").eq(1).remove();
                }
                var TableRwoSum = parseInt(interface.getIni("ListTest", select_ch + "_Table_RowSum", "1"));
                for(var row = 1; row < TableRwoSum; row++){
                    add_row(-1,
                        interface.getIni("ListTest", select_ch + "_Table_Row" + row + "_SelectCol0", "恒电流"),
                        interface.getIni("ListTest", select_ch + "_Table_Row" + row + "_InputCol1",  "1.00"),
                        interface.getIni("ListTest", select_ch + "_Table_Row" + row + "_InputCol2",  "1000"),
                        interface.getIni("ListTest", select_ch + "_Table_Row" + row + "_SelectCol3", "电压"),
                        interface.getIni("ListTest", select_ch + "_Table_Row" + row + "_InputCol4",  "1.50"),
                        interface.getIni("ListTest", select_ch + "_Table_Row" + row + "_InputCol5",  "0.50")
                    );
                }

                for(var i=0; i<chart_curr.option_data[0].series.length; i++){
                    chart_curr.option_data[0].series[i].color = interface.getIni("ListTest", "FlowShape_chart_curr_series" + i,  "#0000ff");
                }
                chart_curr.echart.setOption(chart_curr.option_data[0]);

                for(var i=0; i<chart_power.option_data[0].series.length; i++){
                    chart_power.option_data[0].series[i].color = interface.getIni("ListTest", "FlowShape_chart_power_series" + i,  "#0000ff");
                }
                chart_power.echart.setOption(chart_power.option_data[0]);
            }
        }

        $("#Droplist_Channel_input").val(interface.getIni("ListTest", "Droplist_Channel_input", "CH1"));
        SetingRestore();
        $("#Droplist_Channel_input").change(function () {
            SetingRestore();
        });

        chart_curr.option_data[0].legend.selected = JSON.parse(interface.getIni("ListTest", "FlowShape_List_ChartCurr_legend_selected0",  "{}"));   chart_curr.echart.setOption(chart_curr.option_data[0]);
        chart_curr.option_data[1].legend.selected = JSON.parse(interface.getIni("ListTest", "FlowShape_List_ChartCurr_legend_selected1",  "{}"));   chart_curr.echart.setOption(chart_curr.option_data[1]);
        chart_power.option_data[0].legend.selected = JSON.parse(interface.getIni("ListTest", "FlowShape_List_ChartPower_legend_selected0",  "{}")); chart_power.echart.setOption(chart_power.option_data[0]);
        chart_power.option_data[1].legend.selected = JSON.parse(interface.getIni("ListTest", "FlowShape_List_ChartPower_legend_selected1",  "{}")); chart_power.echart.setOption(chart_power.option_data[1]);

        window.tini = function() {
            if(userAgent >= 0){
                var select_ch = $("#Droplist_Channel_input").val();
                interface.setIni("ListTest", select_ch + "_TextField_SetVoltage_input",        $("#TextField_SetVoltage_input").val());
                interface.setIni("ListTest", select_ch + "_TextField_SetCurrent_input",        $("#TextField_SetCurrent_input").val());
                interface.setIni("ListTest", select_ch + "_TextField_SetPower_input",           $("#TextField_SetPower_input").val());
                interface.setIni("ListTest", select_ch + "_TextField_SetResistance_input",     $("#TextField_SetResistance_input").val());
                interface.setIni("ListTest", select_ch + "_Droplist_ResistanceUnit_input",     $("#Droplist_ResistanceUnit_input").val());
                interface.setIni("ListTest", select_ch + "_TextField_List_Group_input",        $("#TextField_List_Group_input").val());
                interface.setIni("ListTest", select_ch + "_TextField_List_Repeat_input",       $("#TextField_List_Repeat_input").val());
                interface.setIni("ListTest", select_ch + "_Droplist_List_RunMode_input",       $("#Droplist_List_RunMode_input").val());
                interface.setIni("ListTest", "Droplist_Channel_input",             $("#Droplist_Channel_input").val());

                var dat = get_list_data();
                var select_ch = $("#Droplist_Channel_input").val();
                if(dat.length > 1){
                    interface.setIni("ListTest", select_ch + "_Table_RowSum",  dat.length);
                    for(var row=1; row<dat.length; row++){
                        interface.setIni("ListTest", select_ch + "_Table_Row" + row + "_SelectCol0",  dat[row][4][1]);
                        interface.setIni("ListTest", select_ch + "_Table_Row" + row + "_InputCol1",   dat[row][0][1]);
                        interface.setIni("ListTest", select_ch + "_Table_Row" + row + "_InputCol2",   dat[row][1][1]);
                        interface.setIni("ListTest", select_ch + "_Table_Row" + row + "_SelectCol3",  dat[row][5][1]);
                        interface.setIni("ListTest", select_ch + "_Table_Row" + row + "_InputCol4",   dat[row][2][1]);
                        interface.setIni("ListTest", select_ch + "_Table_Row" + row + "_InputCol5",   dat[row][3][1]);
                    }
                }
                interface.setIni("ListTest", "FlowShape_List_ChartCurr_legend_selected0",  JSON.stringify(chart_curr.echart.getOption().legend[0].selected));
                interface.setIni("ListTest", "FlowShape_List_ChartCurr_legend_selected1",  JSON.stringify(chart_curr.echart.getOption().legend[0].selected));
                interface.setIni("ListTest", "FlowShape_List_ChartPower_legend_selected0", JSON.stringify(chart_power.echart.getOption().legend[0].selected));
                interface.setIni("ListTest", "FlowShape_List_ChartPower_legend_selected1", JSON.stringify(chart_power.echart.getOption().legend[0].selected));

                var opt = chart_curr.echart.getOption().series;
                for(var i=0; i<opt.length; i++){
                    interface.setIni("ListTest", "FlowShape_chart_curr_series" + i,  opt[i].color);
                }
                var opt = chart_power.echart.getOption().series;
                for(var i=0; i<opt.length; i++){
                    interface.setIni("ListTest", "FlowShape_chart_power_series" + i,  opt[i].color);
                }
            }
        }
    }

    function ChartClick(){
        // 多窗口模式，层叠置顶
        layer.open({
            type: 2,
            "title": " ",
            shade: false,
            area: ['90%', '90%'],
            maxmin: false,
            content: '../ElectronicLoadTester/files/list_mode/echart.html',
            zIndex: layer.zIndex, //重点1
            success: function(layero){
                layer.setTop(layero); //重点2
            }
        });
    }
    //$("#FlowShape_ChartCurr").dblclick(function () {ChartClick();});
    //$("#FlowShape_ChartVoltPower").dblclick(function () {ChartClick();});

    interface.setTime([["t1", 30], ["tini", 10000]]);



});





























