threshold.js 11.3 KB
define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'reservoir/threshold/index' + location.search,
                    add_url: 'reservoir/threshold/add',
                    edit_url: 'reservoir/threshold/edit',
                    del_url: 'reservoir/threshold/del',
                    multi_url: 'reservoir/threshold/multi',
                    import_url: 'reservoir/threshold/import',
                    table: 'reservoir_threshold',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        // {field: 'reservoirequipment.type', title: __('Reservoirequipment.type'), searchList: {"1":__('Type 1'),"2":__('Type 2'),"3":__('Type 3'),"4":__('Type 4'),"5":__('Type 5'),"6":__('Type 6'),"7":__('Type 7')},custom: {"1":'none', "2":'none',"3":'none', "4":'none', "5":'none', "6":'none', "7":'none'}, formatter: Table.api.formatter.status},
                        // {field: 'reservoirequipment.name', title: __('Reservoirequipment.name'), operate: 'LIKE'},
                        {field: 'type_text', title: __('设备类型'), operate: false},
                        {field: 'device_name', title: __('设备名称'), operate: false},
                        {field: 'deviceId', title: __('Deviceid'), operate: 'LIKE'},
                        {field: 'config', title: __('Config')},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'reservoirlist.name', title: '水库名称', operate: 'LIKE'},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            $('input[name="row[types]"]').on('change',function () {
               let types = parseInt($(this).val());
               let deviceId = $('#deviceId');
               let deviceCode2 = $('#device_code2');
               let deviceCode3 = $('#device_code3');
               let deviceCode4 = $('#device_code4');
               let deviceCode5 = $('#device_code5');
               let deviceCode6 = $('#device_code6');
               let deviceCode7 = $('#device_code7');
               let config2 = $('#config2');
               let config = $('#config');
               if (types === 1){
                   deviceId.show();
                   deviceCode2.hide();
                   deviceCode3.hide();
                   deviceCode4.hide();
                   deviceCode5.hide();
                   deviceCode6.hide();
                   deviceCode7.hide();
                   config2.hide();
                   if (config){
                       config.show();
                   }
               }else if(types === 2){
                   deviceId.hide();
                   deviceCode2.show();
                   deviceCode3.hide();
                   deviceCode4.hide();
                   deviceCode5.hide();
                   deviceCode6.hide();
                   deviceCode7.hide();
                   let code2Val = $('#c-device_code2').val();
                   if (code2Val){
                       config2.show();
                   }else{
                       config2.hide();
                   }
                   if (config){
                       config.hide();
                   }
               }else if(types === 3){
                   deviceId.hide();
                   deviceCode2.hide();
                   deviceCode3.show();
                   deviceCode4.hide();
                   deviceCode5.hide();
                   deviceCode6.hide();
                   deviceCode7.hide();
                   let code3Val = $('#c-device_code3').val();
                   if (code3Val){
                       config2.show();
                   }else{
                       config2.hide();
                   }
                   if (config){
                       config.hide();
                   }
               }else if(types === 4){
                   deviceId.hide();
                   deviceCode2.hide();
                   deviceCode3.hide();
                   deviceCode4.show();
                   deviceCode5.hide();
                   deviceCode6.hide();
                   deviceCode7.hide();
                   let code4Val = $('#c-device_code4').val();
                   if (code4Val){
                       config2.show();
                   }else{
                       config2.hide();
                   }
                   if (config){
                       config.hide();
                   }
               }else if(types === 5){
                   deviceId.hide();
                   deviceCode2.hide();
                   deviceCode3.hide();
                   deviceCode4.hide();
                   deviceCode5.show();
                   deviceCode6.hide();
                   deviceCode7.hide();
                   let code5Val = $('#c-device_code5').val();
                   if (code5Val){
                       config2.show();
                   }else{
                       config2.hide();
                   }
                   if (config){
                       config.hide();
                   }
               }else if(types === 6){
                   deviceId.hide();
                   deviceCode2.hide();
                   deviceCode3.hide();
                   deviceCode4.hide();
                   deviceCode5.hide();
                   deviceCode6.show();
                   deviceCode7.hide();
                   let code6Val = $('#c-device_code6').val();
                   if (code6Val){
                       config2.show();
                   }else{
                       config2.hide();
                   }
                   if (config){
                       config.hide();
                   }
               }else if(types === 7){
                   deviceId.hide();
                   deviceCode2.hide();
                   deviceCode3.hide();
                   deviceCode4.hide();
                   deviceCode5.hide();
                   deviceCode6.hide();
                   deviceCode7.show();
                   let code7Val = $('#c-device_code7').val();
                   if (code7Val){
                       config2.show();
                   }else{
                       config2.hide();
                   }
                   if (config){
                       config.hide();
                   }
               }
            });
            $('#c-device_code2').on('change',function () {
                let code2Val = $('#c-device_code2').val();
                let config2 = $('#config2');
                if (code2Val){
                    config2.show();
                }else{
                    config2.hide();
                }
            });
            $('#c-device_code3').on('change',function () {
                let code3Val = $('#c-device_code3').val();
                let config2 = $('#config2');
                if (code3Val){
                    config2.show();
                }else{
                    config2.hide();
                }
            });
            $('#c-device_code4').on('change',function () {
                let code4Val = $('#c-device_code4').val();
                let config2 = $('#config2');
                if (code4Val){
                    config2.show();
                }else{
                    config2.hide();
                }
            });
            $('#c-device_code5').on('change',function () {
                let code5Val = $('#c-device_code5').val();
                let config2 = $('#config2');
                if (code5Val){
                    config2.show();
                }else{
                    config2.hide();
                }
            });
            $('#c-device_code6').on('change',function () {
                let code6Val = $('#c-device_code6').val();
                let config2 = $('#config2');
                if (code6Val){
                    config2.show();
                }else{
                    config2.hide();
                }
            });
            $('#c-device_code7').on('change',function () {
                let code7Val = $('#c-device_code7').val();
                let config2 = $('#config2');
                if (code7Val){
                    config2.show();
                }else{
                    config2.hide();
                }
            });
            $("#c-deviceId").on("change", function(){
                var id = $("#c-deviceId").val();
                if (!id){
                    $('#config').remove();
                    $('#c-reservoir_id').val('');
                    return;
                }
                $.ajax({
                    url:"reservoir/equipment/getType",
                    data:{id:id},
                    dataType:'json',
                    type:'post',
                    success:function(res){
                        $('#config').remove();
                        $('#c-reservoir_id').val(res.reservoir_id);
                        if(res.type != '6'){
                            var str = '<div class="form-group" id="config"><label class="control-label col-xs-12 col-sm-2">预警阈值区间[单位:mm](示例:10,20):</label><div class="col-xs-12 col-sm-8"><input id="c-config-value" class="form-control" name="row[config][value]" type="text" value=""></div></div>';
                            $('#deviceId').after(str);
                        }
                        else{
                            var str = '<div id="config"><div class="form-group"><label class="control-label col-xs-12 col-sm-2">X预警阈值区间[单位:mm]((示例:10,20):</label><div class="col-xs-12 col-sm-8"><input id="c-config-x"class="form-control"name="row[config][x]"type="text"value=""></div></div><div class="form-group"><label class="control-label col-xs-12 col-sm-2">Y预警阈值区间[单位:mm]((示例:10,20):</label><div class="col-xs-12 col-sm-8"><input id="c-config-y"class="form-control"name="row[config][y]"type="text"value=""></div></div><div class="form-group"><label class="control-label col-xs-12 col-sm-2">Z预警阈值区间[单位:mm]((示例:10,20):</label><div class="col-xs-12 col-sm-8"><input id="c-config-z"class="form-control"name="row[config][z]"type="text"value=""></div></div></div>';
                            $('#deviceId').after(str);
                        }
                    }
                })
           });
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});