//Create a new color picker instance（创建色盘）
var colorPicker = new iro.ColorPicker(".colorPicker", {
    width: 280,
    color: "rgb(255, 255, 255)",
    borderWidth: 1,
    borderColor: "#fff"
});
var isControl = false; //能否控制（是否需要在取电状态下控制）
//控制设备
function setDevice(hostID, modalAddress, status, brightness, temperature, fanSpeed, mode, valve) {
    $.ajax({
        url: '/WX/SetDevice/',
        type: "POST",
        dataType: "JSON",
        data: { hostID: hostID, modalAddress: modalAddress, status: status, brightness: brightness, temperature: temperature, fanSpeed: fanSpeed, mode: mode, valve: valve },
        success: function (r) {
            showTip(r.Result);
        }
    });
}
//服务控制
function serviceClick(btn) {
    if ($(btn).attr("modal") != "004000001" && !isControl) { showTip(lang.WXTakePowerFlag); return; }
    var status = 1;
    if ($(btn).hasClass("active") == 1) {
        status = 2;
        $(btn).removeClass("active");
    } else {
        status = 1;
        $(btn).addClass("active");
    }
    setDevice($(btn).attr("hostID"), $(btn).attr("modal"), status, status == 1 ? 100 : 0, 0, 0, 0, 0);
}
//场景控制
function sceneClick(btn) {
    if (!isControl) { showTip(lang.WXTakePowerFlag); return; }
    var takeInverse = false;
    if ($(btn).hasClass("active") == 1) {
        if ($(btn).attr("takeInverse") == 'false') {
            showTip(lang.SceneNotTakeInverseIssue); return;
        } else {
            takeInverse = true;
            $(btn).removeClass("active");
        }
    } else {
        $(btn).addClass("active").siblings().removeClass("active");
    }
    $.ajax({
        url: '/WX/SetScene/',
        type: "POST",
        dataType: "JSON",
        data: { hostID: $(btn).attr("hostID"), sceneID: $(btn).attr("sceneID"), takeInverse: takeInverse },
        success: function (r) {
            showTip(r.Result);
        }
    });
}
//房控控制
function relayClick(btn) {
    if (!isControl) { showTip(lang.WXTakePowerFlag); return; }
    var status = 1;
    if ($(btn).hasClass("active") == 1) {
        status = 2;
        $(btn).removeClass("active");
    } else {
        status = 1;
        $(btn).addClass("active");
    }
    setDevice($(btn).attr("hostID"), $(btn).attr("modal"), status, status == 1 ? 100 : 0, 0, 0, 0, 0);
}
//调光控制
function dimmerClick(btn) {
    $(btn).addClass("active").siblings().removeClass("active");
    $('#brightness').text($(btn).attr("brightness"));
    $('#brightness1').css("top", (100 - $(btn).attr("brightness")) + "%");
    $('#brightness2').val($(btn).attr("brightness"));
}
//颜色变化事件
function onColorChange(c, changes) {
    var obj = $("#color button[class='tab active']")[0];
    if (obj == null) { showTip(lang.NoDeviceControl); return; }
    $("#colorValue").html("<br />" + c.rgbString);
    var s = c.rgbString.replace(/rgb\((\d{1,3})\,\s*(\d{1,3})\,\s*(\d{1,3})\)/, "$1,$2,$3");
    $(obj).attr("brightness1", parseInt((100 * s.split(',')[0]) / 255));
    $(obj).attr("brightness2", parseInt((100 * s.split(',')[1]) / 255));
    $(obj).attr("brightness3", parseInt((100 * s.split(',')[2]) / 255));
    $.ajax({
        url: '/WX/SetTiaoseDevice/',
        type: "POST",
        dataType: "JSON",
        data: { hostID: $(obj).attr("hostID"), modalAddress: $(obj).attr("modal"), modalAddress1: $(obj).attr("modal1"), brightness1: $(obj).attr("brightness1"), modalAddress2: $(obj).attr("modal2"), brightness2: $(obj).attr("brightness2"), modalAddress3: $(obj).attr("modal3"), brightness3: $(obj).attr("brightness3") },
        success: function (r) {
            showTip(r.Result);
        }
    });
}
//调色控制
function colorClick(btn) {
    $(btn).addClass("active").siblings().removeClass("active");
    colorPicker.off('input:end', onColorChange);
    if ($(btn).attr("brightness1") == "0" && $(btn).attr("brightness2") == "0" && $(btn).attr("brightness3") == "0") {
        colorPicker.color.rgbString = "rgb(255,255,255)";
    } else {
        colorPicker.color.rgbString = "rgb("
        + parseInt(parseInt($(btn).attr("brightness1")) * 255 / 100) + ", "
        + parseInt(parseInt($(btn).attr("brightness2")) * 255 / 100) + ", "
        + parseInt(parseInt($(btn).attr("brightness3")) * 255 / 100) + ")";
    }
    colorPicker.on('input:end', onColorChange);
}
//空调控制
function airClick(btn) {
    $(btn).addClass("active").siblings().removeClass("active");
    $('#settingTemp').text($(btn).attr("settingTemp")); //设定温度赋值
    $('#settingTemp1').css("top", (200 - ($(btn).attr("settingTemp") * 6.25)) + "%");
    if ($(btn).attr("status") == 1) {
        $('#power').addClass("active"); //开关选中
        $('#power').html(lang.On);
    } else {
        $('#power').removeClass("active");
        $('#power').html(lang.Off);
    }
    $('#mode button').removeClass("active");
    $($('#mode button')[$(btn).attr("mode") - 1]).addClass("active"); //模式选中
    $('#fanSpeed button').removeClass("active");
    $($('#fanSpeed button')[$(btn).attr("fanSpeed") - 1]).addClass("active"); //风速选中
}
//窗帘控制
function curtainClick(btn) {
    $(btn).addClass("active").siblings().removeClass("active");
    if ($(btn).attr("status") == 1) {
        $('#curtainStatus').addClass("close");
    } else {
        $('#curtainStatus').removeClass("close");
    }
}
//电视控制
function tvClick(btn) {
    $(btn).addClass("active").siblings().removeClass("active");
}
//背景音乐控制
function musicClick(btn) {
    $(btn).addClass("active").siblings().removeClass("active");
    $("#musicVolume").html($(btn).attr("brightness"));
    if (parseInt($(btn).attr("mode")) == 2) {
        $("#musicEqua").css("animation-play-state", "paused");
        $('#musicStatus').attr("mode", 2);
        $('#musicStatus').html("<img src='/Images/weixin2/play.svg' class='play' alt=''/>");
    } else {
        $("#musicEqua").css("animation-play-state", "running");
        $('#musicStatus').attr("mode", 1);
        $('#musicStatus').html("<img src='/Images/weixin2/pause.svg' class='pause' alt=''/>");
    }
}
//脚本初始化
$(function () {
    //获取并绑定数据
    function getWXData(roomNumber, code, takePower) {
        if (takePower == "True") {
            takePower = true;
        } else {
            takePower = false;
        }
        $.ajax({
            url: '/WX/GetWXData/',
            type: "POST",
            dataType: "JSON",
            data: { roomNumber: roomNumber, code: code, takePower: takePower },
            success: function (r) {
                if (!r.IsSuccess) { showTip(r.Result); return; }
                isControl = r.IsControl;
                switch (code) {
                    case "mensuo":
                        $("#kaisuo").removeClass();
                        if (r.Result.WXLockStatus == 1) {
                            $("#kaisuo").addClass("toggle on");
                        } else {
                            $("#kaisuo").addClass("toggle");
                        }
                        $("#kaisuo").attr("hostID", r.Result.HostID);
                        $("#kaisuo").attr("modal", r.Result.WXLockModalAddress);
                        break;
                    case "fuwu":
                        var html = "";
                        $.each(r.Result, function (i, item) {
                            var cls = "middle";
                            if (item.Status == 1) {
                                cls = "middle active";
                            }
                            html += "<button class='" + cls + "' hostID='" + item.HostID + "' modal='" + item.ModalAddress + "' onclick='serviceClick(this);'>" + item.Name + "</button>";
                        });
                        $("#service").html(html);
                        break;
                    case "changjing":
                        var html = "";
                        $.each(r.Result, function (i, item) {
                            var cls = "middle";
                            if (item.Status == 1) {
                                cls = "middle active";
                            }
                            html += "<button class='" + cls + "' hostID='" + item.HostID + "' sceneID='" + item.ID + "' takeInverse='" + item.TakeInverse + "' onclick='sceneClick(this);'>" + item.Name + "</button>";
                        });
                        $("#scene").html(html);
                        break;
                    case "fangkong":
                        var html = "";
                        $.each(r.Result, function (i, item) {
                            var cls = "middle";
                            if (item.Status == 1) {
                                cls = "middle active";
                            }
                            html += "<button class='" + cls + "' hostID='" + item.HostID + "' modal='" + item.ModalAddress + "' onclick='relayClick(this);'>" + item.Name + "</button>";
                        });
                        $("#relay").html(html);
                        break;
                    case "tiaoguang":
                        var html = "";
                        $.each(r.Result, function (i, item) {
                            html += "<button class='tab' hostID='" + item.HostID + "' modal='" + item.ModalAddress + "' status='" + item.Status + "' brightness='" + item.Brightness + "' onclick='dimmerClick(this);'>" + item.Name + "</button>";
                        });
                        $("#dimmer").html(html);
                        //选中第一个调光灯
                        if ($('#dimmer button').length > 0) {
                            $('#dimmer button')[0].click();
                        }
                        break;
                    case "tiaose":
                        var html = "";
                        $.each(r.Result, function (i, item) {
                            html += "<button class='tab' hostID='" + item.HostID + "' status='" + item.Status + "' modal='" + item.ModalAddress + "' brightness='" + item.Brightness +
                            "' modal1='" + item.ModalAddress1 + "' modal2='" + item.ModalAddress2 + "' modal3='" + item.ModalAddress3 +
                            "' brightness1='" + item.Brightness1 + "' brightness2='" + item.Brightness2 + "' brightness3='" + item.Brightness3 +
                            "' onclick='colorClick(this);'>" + item.Name + "</button>";
                        });
                        $("#color").html(html);
                        //选中第一个调色
                        if ($('#color button').length > 0) {
                            $('#color button')[0].click();
                        }
                        break;
                    case "kongtiao":
                        var html = "";
                        $.each(r.Result, function (i, item) {
                            html += "<button class='tab' hostID='" + item.HostID + "' modal='" + item.ModalAddress + "' status='" + item.Status + "' currentTemp='" + item.CurrentTemp + "'' settingTemp='" + item.SettingTemp + "'' fanSpeed='" + item.FanSpeed + "'' mode='" + item.Mode + "'' valve='" + item.Valve + "' onclick='airClick(this);'>" + item.Name + "</button>";
                        });
                        $("#air").html(html);
                        //选中第一个空调
                        if ($('#air button').length > 0) {
                            $('#air button')[0].click();
                        }
                        break;
                    case "chuanglian":
                        var html = "";
                        $.each(r.Result, function (i, item) {
                            html += "<button class='tab' hostID='" + item.HostID + "' modal='" + item.ModalAddress + "' status='" + item.Status + "' onclick='curtainClick(this);'>" + item.Name + "</button>";
                        });
                        $("#curtain").html(html);
                        //选中第一个窗帘
                        if ($('#curtain button').length > 0) {
                            $('#curtain button')[0].click();
                        }
                        break;
                    case "dianshi":
                        var html = "";
                        $.each(r.Result, function (i, item) {
                            html += "<button class='tab' hostID='" + item.HostID + "' modal='" + item.ModalAddress + "' onclick='tvClick(this);'>" + item.Name + "</button>";
                        });
                        $("#tv").html(html);
                        //选中第一个电视
                        if ($('#tv button').length > 0) {
                            $('#tv button')[0].click();
                        }
                        break;
                    case "yinyue":
                        var html = "";
                        $.each(r.Result, function (i, item) {
                            html += "<button class='tab' hostID='" + item.HostID + "' modal='" + item.ModalAddress + "' status='" + item.Status + "' brightness='" + item.Brightness + "'' mode='" + item.Mode + "' onclick='musicClick(this);'>" + item.Name + "</button>";
                        });
                        $("#music").html(html);
                        //选中第一个背景音乐
                        if ($('#music button').length > 0) {
                            $('#music button')[0].click();
                        }
                        break;
                }
            }
        });
    }
    //默认显示选中菜单
    var firstCurrentTabID = $('.tabbar li.active').attr("id");
    getWXData($('#hidRoomNumber').val(), firstCurrentTabID, $('.tabbar li.active').attr("takePower"));
    $("#" + firstCurrentTabID).addClass('show');
    //翻页
    function tabPaging(Event) {
        switch (Event) {
            case "→":
                {
                    $(".tabbar .active").removeClass('active')
                        .parent().next().children().eq(1).addClass('active')
                        .parents('.tabbar').css('left', '-100%')
                        .find('.current').css('left', $(".tabbar .active")[0].offsetLeft + 'px');
                    $(".tabbar .active").click();
                    break;
                }
            case "←":
                {
                    $(".tabbar .active").removeClass('active')
                        .parent().prev().children().first().addClass('active')
                        .parents('.tabbar').css('left', '0%')
                        .find('.current').css('left', $(".tabbar .active")[0].offsetLeft + 'px'); ;
                    $(".tabbar .active").click();
                    break;
                }
        }
    }
    //点击底部菜单
    $('.tabbar li').on('tap click', function (Event) {
        var _thisInnerHTML = this.innerHTML;
        if (_thisInnerHTML == "→" || _thisInnerHTML == "←") {
            tabPaging(_thisInnerHTML);
            Event.preventDefault();
            return false;
        }
        var id = $(this).attr("id");
        getWXData($('#hidRoomNumber').val(), id, $(this).attr("takePower"));
        $("#" + id).addClass("show").siblings().removeClass("show");
        $(this).addClass("active").siblings().removeClass("active").parents('.tabbar').find('.current').css('left', this.offsetLeft + 'px');
        document.title = _thisInnerHTML;
    });
    //微信锁开关
    $('.toggle').on('click', function () {
        if (!isControl) { showTip(lang.WXTakePowerFlag); return; }
        var status = 1;
        if ($(this).hasClass('on')) {
            status = 2;
            $(this).removeClass('on');
        } else {
            status = 1;
            $(this).addClass('on');
        }
        setDevice($(this).attr("hostID"), $(this).attr("modal"), status, status == 1 ? 100 : 0, 0, 0, 0, 0);
    });
    //滑动调光input propertychange
    $('#brightness2').on('change', function () {
        if (!isControl) { showTip(lang.WXTakePowerFlag); return; }
        var obj = $("#dimmer button[class='tab active']")[0];
        if (obj == null) { showTip(lang.NoDeviceControl); return; }
        var brightness = $('#brightness2').val();
        var status = brightness == 0 ? 2 : 1;
        $('#brightness').text(brightness);
        $(obj).attr("status", status);
        $(obj).attr("brightness", brightness);
        $('#brightness1').css("top", (100 - brightness) + "%");
        setDevice($(obj).attr("hostID"), $(obj).attr("modal"), status, brightness, 0, 0, 0, 0);
    })
    //减少调光亮度
    $('#dimmerDown').click(function () {
        if (!isControl) { showTip(lang.WXTakePowerFlag); return; }
        var obj = $("#dimmer button[class='tab active']")[0];
        if (obj == null) { showTip(lang.NoDeviceControl); return; }
        var brightness = $('#brightness').text();
        if (brightness == 0) { return; }
        brightness--;
        var status = brightness == 0 ? 2 : 1;
        $('#brightness').text(brightness);
        $('#brightness2').val(brightness);
        $(obj).attr("status", status);
        $(obj).attr("brightness", brightness);
        $('#brightness1').css("top", (100 - brightness) + "%");
        setDevice($(obj).attr("hostID"), $(obj).attr("modal"), status, brightness, 0, 0, 0, 0);
    });
    //增加调光亮度
    $('#dimmerUp').click(function () {
        if (!isControl) { showTip(lang.WXTakePowerFlag); return; }
        var obj = $("#dimmer button[class='tab active']")[0];
        if (obj == null) { showTip(lang.NoDeviceControl); return; }
        var brightness = $('#brightness').text();
        if (brightness == 100) { return; }
        brightness++;
        $('#brightness').text(brightness);
        $('#brightness2').val(brightness);
        $(obj).attr("status", 1);
        $(obj).attr("brightness", brightness);
        $('#brightness1').css("top", (100 - brightness) + "%");
        setDevice($(obj).attr("hostID"), $(obj).attr("modal"), 1, brightness, 0, 0, 0, 0);
    });
    //减少设定温度
    $('#airDown').click(function () {
        if (!isControl) { showTip(lang.WXTakePowerFlag); return; }
        var obj = $("#air button[class='tab active']")[0];
        if (obj == null) { showTip(lang.NoDeviceControl); return; }
        var settingTemp = $('#settingTemp').text();
        if (settingTemp == 16) { return; }
        settingTemp--;
        $('#settingTemp').text(settingTemp);
        $('#settingTemp1').css("top", (200 - (settingTemp * 6.25)) + "%");
        $(obj).attr("status", 1);
        $(obj).attr("settingTemp", settingTemp);
        setDevice($(obj).attr("hostID"), $(obj).attr("modal"), 1, 100, settingTemp, $(obj).attr("fanSpeed"), $(obj).attr("mode"), $(obj).attr("valve"));
    });
    //增加设定温度
    $('#airUp').click(function () {
        if (!isControl) { showTip(lang.WXTakePowerFlag); return; }
        var obj = $("#air button[class='tab active']")[0];
        if (obj == null) { showTip(lang.NoDeviceControl); return; }
        var settingTemp = $('#settingTemp').text();
        if (settingTemp == 32) { return; }
        settingTemp++;
        $('#settingTemp').text(settingTemp);
        $('#settingTemp1').css("top", (200 - (settingTemp * 6.25)) + "%");
        $(obj).attr("status", 1);
        $(obj).attr("settingTemp", settingTemp);
        setDevice($(obj).attr("hostID"), $(obj).attr("modal"), 1, 100, settingTemp, $(obj).attr("fanSpeed"), $(obj).attr("mode"), $(obj).attr("valve"));
    });
    //空调开关控制
    $('#power').click(function () {
        if (!isControl) { showTip(lang.WXTakePowerFlag); return; }
        var obj = $("#air button[class='tab active']")[0];
        if (obj == null) { showTip(lang.NoDeviceControl); return; }
        var status = 1;
        if ($(this).hasClass("active") == 1) {
            status = 2;
            $(this).removeClass("active");
            $('#power').html(lang.Off);
        } else {
            status = 1;
            $(this).addClass("active");
            $('#power').html(lang.On);
        }
        $(obj).attr("status", status);
        setDevice($(obj).attr("hostID"), $(obj).attr("modal"), status, status == 1 ? 100 : 0, $(obj).attr("settingTemp"), $(obj).attr("fanSpeed"), $(obj).attr("mode"), $(obj).attr("valve"));
    });
    //空调模式控制
    $('#mode button').click(function () {
        if (!isControl) { showTip(lang.WXTakePowerFlag); return; }
        var obj = $("#air button[class='tab active']")[0];
        if (obj == null) { showTip(lang.NoDeviceControl); return; }
        $('#mode button').removeClass("active");
        $(this).addClass("active");
        var mode = $(this).attr("value");
        $(obj).attr("status", 1);
        $(obj).attr("mode", mode);
        setDevice($(obj).attr("hostID"), $(obj).attr("modal"), 1, 100, $(obj).attr("settingTemp"), $(obj).attr("fanSpeed"), mode, $(obj).attr("valve"));
    });
    //空调风速控制
    $('#fanSpeed button').click(function () {
        if (!isControl) { showTip(lang.WXTakePowerFlag); return; }
        var obj = $("#air button[class='tab active']")[0];
        if (obj == null) { showTip(lang.NoDeviceControl); return; }
        $('#fanSpeed button').removeClass("active");
        $(this).addClass("active");
        var fanSpeed = $(this).attr("value");
        $(obj).attr("status", 1);
        $(obj).attr("fanSpeed", fanSpeed);
        setDevice($(obj).attr("hostID"), $(obj).attr("modal"), 1, 100, $(obj).attr("settingTemp"), fanSpeed, $(obj).attr("mode"), $(obj).attr("valve"));
    });
    /*调整H颜色
    $('#color001').change(function () {
    if (!isControl) { showTip(lang.WXTakePowerFlag); return; }
    var obj = $("#color button[class='tab active']")[0];
    if (obj == null) { showTip(lang.NoDeviceControl); return; }
    //每次调色时，将亮度调整为100
    //if (parseInt($('#color004').val()) != 100) {
    //$('#color004').val(100);
    //}
    //获取rgb值
    var rgb = $("#tiaoseSwatch").css('background-color');
    var s = rgb.replace(/rgb\((\d{1,3})\,\s*(\d{1,3})\,\s*(\d{1,3})\)/, "$1+$2+$3")
    $(obj).attr("brightness1", parseInt((100 * s.split('+')[0]) / 255));
    $(obj).attr("brightness2", parseInt((100 * s.split('+')[1]) / 255));
    $(obj).attr("brightness3", parseInt((100 * s.split('+')[2]) / 255));
    $("#tiaoseRGB").html($(obj).attr("brightness1") + "," + $(obj).attr("brightness2") + "," + $(obj).attr("brightness3"));
    setTiaoSe(obj);
    });
    /*调整亮度
    $('#color004').change(function () {
    if (!isControl) { showTip(lang.WXTakePowerFlag); return; }
    var obj = $("#color button[class='tab active']")[0];
    if (obj == null) { showTip(lang.NoDeviceControl); return; }
    var val = parseInt($(this).val());
    //计算各灯带等比例亮度
    $(obj).attr("brightness", parseInt($(obj).attr("brightness") * val / 100));
    $(obj).attr("brightness1", parseInt($(obj).attr("brightness1") * val / 100));
    $(obj).attr("brightness2", parseInt($(obj).attr("brightness2") * val / 100));
    $("#tiaoseRGB").html($(obj).attr("brightness") + "," + $(obj).attr("brightness1") + "," + $(obj).attr("brightness2"));
    setTiaoSe(obj);
    });
    //调整S颜色
    $('#color002').change(function () {
    if (!isControl) { showTip(lang.WXTakePowerFlag); return; }
    var obj = $("#color button[class='tab active']")[0];
    if (obj == null) { showTip(lang.NoDeviceControl); return; }
    var val = parseInt($(this).val());
    $(obj).attr("brightness1", val);
    setTiaoSe(obj);
    });
    //调整L颜色
    $('#color003').change(function () {
    if (!isControl) { showTip(lang.WXTakePowerFlag); return; }
    var obj = $("#color button[class='tab active']")[0];
    if (obj == null) { showTip(lang.NoDeviceControl); return; }
    var val = parseInt($(this).val());
    $(obj).attr("brightness2", val);
    setTiaoSe(obj);
    });*/
    //打开窗帘
    $('#curtainOpen').click(function () {
        if (!isControl) { showTip(lang.WXTakePowerFlag); return; }
        var obj = $("#curtain button[class='tab active']")[0];
        if (obj == null) { showTip(lang.NoDeviceControl); return; }
        $(obj).attr("status", 1);
        $('#curtainStatus').addClass("close");
        setDevice($(obj).attr("hostID"), $(obj).attr("modal"), 1, 100, 0, 0, 0, 0);
    });
    //停止窗帘
    $('#curtainPause').click(function () {
        if (!isControl) { showTip(lang.WXTakePowerFlag); return; }
        var obj = $("#curtain button[class='tab active']")[0];
        if (obj == null) { showTip(lang.NoDeviceControl); return; }
        $(obj).attr("status", 6);
        setDevice($(obj).attr("hostID"), $(obj).attr("modal"), 6, 100, 0, 0, 0, 0);
    });
    //关闭窗帘
    $('#curtainClose').click(function () {
        if (!isControl) { showTip(lang.WXTakePowerFlag); return; }
        var obj = $("#curtain button[class='tab active']")[0];
        if (obj == null) { showTip(lang.NoDeviceControl); return; }
        $(obj).attr("status", 2);
        $('#curtainStatus').removeClass("close");
        setDevice($(obj).attr("hostID"), $(obj).attr("modal"), 2, 0, 0, 0, 0, 0);
    });
    //电视控制
    $('#dianshi button').click(function () {
        if (!isControl) { showTip(lang.WXTakePowerFlag); return; }
        var obj = $("#tv button[class='tab active']")[0];
        if (obj == null) { showTip(lang.NoDeviceControl); return; }
        var _this = this;
        $(_this).addClass("active");
        var mode = $(_this).attr("mode");
        setDevice($(obj).attr("hostID"), $(obj).attr("modal"), 1, 0, 0, 0, mode, 0);
        setTimeout(function () {
            $(_this).removeClass("active");
        }, 1000);
    });
    //音乐控制
    $('#yinyue button').click(function () {
        if (!isControl) { showTip(lang.WXTakePowerFlag); return; }
        var obj = $("#yinyue button[class='tab active']")[0];
        if (obj == null) { showTip(lang.NoDeviceControl); return; }
        var brightness = $(obj).attr("brightness");
        var _this = this;
        $(_this).addClass("active");
        var mode = $(_this).attr("mode");
        switch (mode) {
            case "1": //播放
                mode = 2;
                $("#musicEqua").css("animation-play-state", "paused");
                $(_this).attr("mode", 2);
                $(_this).html("<img src='/Images/weixin2/play.svg' class='play' alt=''/>");
                break;
            case "2": //暂停
                mode = 1;
                $("#musicEqua").css("animation-play-state", "running");
                $(_this).attr("mode", 1);
                $(_this).html("<img src='/Images/weixin2/pause.svg' class='pause' alt=''/>");
                break;
            case "5": //音量加
                if (brightness == 10) { showTip(lang.MaxVolume); return; }
                brightness++;
                break;
            case "6": //音量减
                if (brightness == 0) { showTip(lang.MinVolume); return; }
                brightness--;
                break;
        }
        $(obj).attr("status", 1);
        $(obj).attr("brightness", brightness);
        $("#musicVolume").html(brightness);
        setDevice($(obj).attr("hostID"), $(obj).attr("modal"), 1, brightness, 0, 0, mode, 0);
        setTimeout(function () {
            $(_this).removeClass("active");
        }, 1000);
    });
}); 