<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('策略条件列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>策略编号：</label>
<!--                                <input type="text" name="strategyId"/>-->
                                <select name="strategyId">
                                    <option th:each="strategy:${strategyList}" th:selected="${strategyId==strategy.id}" th:value="${strategy.id}" th:text="${strategy.name}"></option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
<!--                <a class="btn btn-success" onclick="addStrategyCondition()$.operate.add()" shiro:hasPermission="zhny:strategycondition:add">-->
                <a class="btn btn-success" onclick="addStrategyCondition()" shiro:hasPermission="zhny:strategycondition:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
<!--                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="zhny:strategycondition:edit">-->
<!--                    <i class="fa fa-edit"></i> 修改-->
<!--                </a>-->
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="zhny:strategycondition:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
<!--                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="zhny:strategycondition:export">-->
<!--                    <i class="fa fa-download"></i> 导出-->
<!--                </a>-->
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('zhny:strategycondition:edit')}]];
        var removeFlag = [[${@permission.hasPermi('zhny:strategycondition:remove')}]];
        var prefix = ctx + "zhny/strategycondition";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "策略条件",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: '',
                    visible: false
                },
                {
                    field: 'strategyId',
                    title: '策略编号',
                    formatter: function(value, row, index) {
                        return  $("select[name='strategyId']").find("[value='"+value+"']").text();
                    }
                },
                {
                    field: '',
                    title: '字段',
                    formatter:function (value,row,index){
                        var text = '';
                        if (row.qufen == 1) {
                            text = checkField(row.condition_field4)
                        }else {
                            text = checkField(
                                row.condition_field1)
                                +
                                checkFieldType(row.condition_field_type1)
                                +
                                checkField(row.condition_field2)
                                +
                                checkFieldType(row.condition_field_type2)
                                +
                                checkField(row.condition_field3)
                        }
                        return text;
                    }
                },
                {
                    field: 'conditionType',
                    title: '条件类型1',
                    formatter:function (value, row, index){
                        if (value == 1) {return '大于'}
                        else if (value == 2) {return '小于'}
                        else if (value == 3) {return '等于'}
                        else if (value == 4) {return '时间'}
                        else if (value == 5) {return '区间'}
                        else if (value == 6) {return '大于等于'}
                        else if (value == 7) {return '小于等于'}
                    }
                },
                {
                    field: 'targetCondition',
                    title: '目标条件1'
                },
                    {
                        field: '',
                        title: '字段2',
                        formatter:function (value,row,index){
                            var text = '';
                            if (row.qufen2 == 1) {
                                text = checkField(row.condition2_field4)
                            }else {
                                text = checkField(
                                    row.condition2_field1)
                                    +
                                    checkFieldType(row.condition2_field_type1)
                                    +
                                    checkField(row.condition2_field2)
                                    +
                                    checkFieldType(row.condition2_field_type2)
                                    +
                                    checkField(row.condition2_field3)
                            }
                            return text;
                        }
                    },
                {
                    field: 'conditionType2',
                    title: '条件类型2',
                    formatter:function (value, row, index){
                        if (value == 1) {return '大于'}
                        else if (value == 2) {return '小于'}
                        else if (value == 3) {return '等于'}
                        else if (value == 4) {return '时间'}
                        else if (value == 5) {return '区间'}
                        else if (value == 6) {return '大于等于'}
                        else if (value == 7) {return '小于等于'}
                    }
                },
                {
                    field: 'targetCondition2',
                    title: '目标条件2'
                },
                    {
                        field: '',
                        title: '字段3',
                        formatter:function (value,row,index){
                            var text = '';
                            if (row.qufen3 == 1) {
                                text = checkField(row.condition3_field4)
                            }else {
                                text = checkField(
                                    row.condition3_field1)
                                    +
                                    checkFieldType(row.condition3_field_type1)
                                    +
                                    checkField(row.condition3_field2)
                                    +
                                    checkFieldType(row.condition3_field_type2)
                                    +
                                    checkField(row.condition3_field3)
                            }
                            return text;
                        }
                    },
                {
                    field: 'conditionType3',
                    title: '条件类型3',
                    formatter:function (value, row, index){
                        if (value == 1) {return '大于'}
                        else if (value == 2) {return '小于'}
                        else if (value == 3) {return '等于'}
                        else if (value == 4) {return '时间'}
                        else if (value == 5) {return '区间'}
                        else if (value == 6) {return '大于等于'}
                        else if (value == 7) {return '小于等于'}
                    }
                },
                {
                    field: 'targetCondition3',
                    title: '目标条件3'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        // actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        // actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        actions.push('<a class="btn btn-primary btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="openCondition(\'' + row.id + '\')"><i class="fa fa-opencart"></i>目标</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        function checkField(val){
            if (val == null || val == '' || val == undefined) {return ''}
            if (val == 1) {
                return '客流';
            }else if (val === 2) {
                return '时间段';
            }else if (val === 3) {
                return '光照度';
            }else if (val === 4) {
                return '温度';
            }else if (val === 5) {
                return '储能当前电量';
            }else if (val === 6) {
                return '当前时间';
            }else if (val === 7) {
                return '光伏发电';
            }else if (val === 8) {
                return '风力发电';
            }else if (val === 9) {
                return '空气质量';
            }
        }

        function checkFieldType(val){
            if (val == null || val == '' || val == undefined) {return ''}
            if (val === 1) {
                return '+';
            }else if (val === 2) {
                return '-';
            }else if (val === 3) {
                return '*';
            }else if (val === 4) {
                return '÷';
            }
        }

        function addStrategyCondition(){
            let strategyId = [[${strategyId}]]
            var url = prefix+'/add/'+strategyId;
            $.modal.open("新增生效条件", url, 800, 600);
        }

        var target_prefix = ctx + "zhny/strategytarget/";
        function openCondition(strategyId){
            $.modal.openTab("策略生效条件", target_prefix+'strategytarget/'+strategyId);
        }
    </script>
</body>
</html>