depositSwitch.html 4.36 KB
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8"/>
    <title>Yoho!Buy运营平台</title>
    <script src="/ufoPlatform/js/include.js"></script>
</head>
<body class="easyui-layout">

<div region="north" style="height:1500px;">
    <script>
        document.write(addHead('订单管理', '寄存开关'));
    </script>

    <div style="padding:20px;">
        <label style="font-size: 15px">现货寄存开关:</label>
        <input class="easyui-switchbutton" onText="开启" offText="关闭" name="inStockDepositSwitch" id="inStockDepositSwitch">
    </div>

    <div style="padding:20px;">
        <label style="font-size: 15px">闪购寄存开关:</label>
        <input class="easyui-switchbutton" onText="开启" offText="关闭" name="quickDeliverDepositSwitch" id="quickDeliverDepositSwitch">
    </div>

    <div style="padding:20px;">
        <label style="font-size: 15px">极速寄存开关:</label>
        <input class="easyui-switchbutton" onText="开启" offText="关闭" name="fastDeliverDepositSwitch" id="fastDeliverDepositSwitch">
    </div>
</div>

<script>
    $(function() {

        //展示开关当前状态
        getDepositSwitchStatus();

        //现货寄存开关
        $("#inStockDepositSwitch").switchbutton({
            width: 120,
            height: 40,
            onChange: function(switchStatus){
                updateDepositSwitch("IN_STOCK", switchStatus);
            }
        });

        //闪购寄存开关
        $("#quickDeliverDepositSwitch").switchbutton({
            width: 120,
            height: 40,
            onChange: function(switchStatus){
                updateDepositSwitch("QUICK_DELIVER", switchStatus);
            }
        });

        //极速寄存开关
        $("#fastDeliverDepositSwitch").switchbutton({
            width: 120,
            height: 40,
            onChange: function(switchStatus){
                updateDepositSwitch("FAST_DELIVER", switchStatus);
            }
        });

    });

    //获取当前开关状态
    function getDepositSwitchStatus(){
        const inStockDepositSwitchBtn = $("#inStockDepositSwitch");
        const quickDeliverDepositSwitchBtn = $("#quickDeliverDepositSwitch");
        const fastDeliverDepositSwitchBtn = $("#fastDeliverDepositSwitch");
        $.ajax({
            type: "POST",
            url: contextPath + '/storageDeposit/getDepositSwitchStatus',
            async: false,
            cache: false,
            dataType: 'json',
            success: function (result) {
                if(result.code != 200) {
                    window.self.$.messager.show({
                        title : "提示",
                        msg : "获取当前开关状态失败"
                    });
                }
                const inStockSwitchStatus = result.data.IN_STOCK;
                if(inStockSwitchStatus == true){
                    inStockDepositSwitchBtn.switchbutton("check");
                }else {
                    inStockDepositSwitchBtn.switchbutton("uncheck");
                }
                const quickDeliverSwitchStatus = result.data.QUICK_DELIVER;
                if(quickDeliverSwitchStatus == true){
                    quickDeliverDepositSwitchBtn.switchbutton("check");
                }else {
                    quickDeliverDepositSwitchBtn.switchbutton("uncheck");
                }
                const fastDeliverSwitchStatus = result.data.FAST_DELIVER;
                if(fastDeliverSwitchStatus == true){
                    fastDeliverDepositSwitchBtn.switchbutton("check");
                }else {
                    fastDeliverDepositSwitchBtn.switchbutton("uncheck");
                }
            }
        });
    }

    //更改开关状态
    function updateDepositSwitch(switchType, switchStatus){
        $.ajax({
            type: "POST",
            url: contextPath + '/storageDeposit/updateDepositSwitch?switchType='+switchType+'&switchStatus='+switchStatus,
            async: false,
            cache: false,
            dataType: 'json',
            success: function (result) {
                const operateType = switchStatus == true ? "开启" : "关闭";
                if(result.code == 200) {
                    window.self.$.messager.show({
                        title : "提示",
                        msg : operateType + "成功"
                    });
                }
            }
        });
    }

</script>
</body>
</html>