Administrator
2023-04-19 40ec16bbb7c9d23df625aa31ae42ac36e901749d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/**
* date: 
* author: neeler
*/
 
//test data start
// var data_getList = Mock.mock('/basicconfig/gates/getCEquipmentList.htm', {code: 0, list: [{id: '33', eqname: '显示器', equipmentno: 'e123213', mclientNo: 'mc12312321', type: '道闸', ip: '1.1.2.1', serviceIP: '2.2.3.3', port: '235', servicePort: '5555', aname: 'zhangsan', password: '', state: false, aspect: 1}]})
// var data_doDel = Mock.mock('/basicconfig/gates/delCEquipmentItem.htm', {code: 0, })
// var data_doUsed = Mock.mock('/basicconfig/gates/cequipmentChangeState.htm', {code: 0, })
//test data end
 
window.I = {
    relationno: $('#relationno').val()
}
 
var ViewModel = function() {
    var self = this;
    self.list = ko.observableArray();
    self.used = function (item) {
        // doUsed(item);
    }
    
    self.del = function(item) {
        delConfirm(item);
    }
}
 
$(function () {
    window.vm = new ViewModel();
    ko.applyBindings(vm);
    if (I.relationno) {
        getList(I.relationno);
    }
    pageInit();
    $('#newceq').click(function(event) {
        var relationno=$('#relationno').val();
        jQuery.post('/basicconfig/gates/getMClient.htm', {relationno:relationno}, function(data, textStatus, xhr) {
            if(data.item!=null){
                window.location.href="gates_cequipmentEdit.jsf?mclientNo="+data.item.mclientNo;
            }else{
               // parent.showErrmsg("没有门禁客户端,请先配置门禁客户端!");
                swal({title:'',text:'没有门禁客户端,请先配置门禁客户端',type:'error',confirmButtonText:'确定'}); 
            }
        }); 
    });
});
 
function pageInit() {
}
 
function getList(mclientNo) {
    $.post("/basicconfig/gates/getCEquipmentList.htm", {mclientNo: mclientNo},
        function (data, textStatus, jqXHR) {
            vm.list.removeAll();
            if (data.code >= 1) {
                //parent.showErrmsg(data.errmsg);
                swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); 
                return;
            }
            if (data.code == 0) {
                if (isList(data.list)) {
                    $.each(data.list, function (index, value) { 
                        value.state = ko.observable(value.state);
                        vm.list.push(value);
                    });
                }
                return;
            }
        },
        "json"
    );
}
 
function delConfirm(item) {
    $("#modalContent").html('确定要删除【' + item.eqname + '】吗?');
    $("#dialog-confirm").removeClass('hide').dialog({
        resizable: false,
        width: '320',
        modal: true,
        title: "<div class='widget-header'><h4 class='smaller'><i class='ace-icon fa fa-exclamation-triangle red'></i>确认信息</h4></div>",
        title_html: true,
        position: { my: "center", at: "center", of: window },
        buttons: [
            {
                html: "<i class='ace-icon fa fa-trash-o bigger-110'></i>&nbsp; 确定",
                "class" : "btn btn-danger btn-minier",
                click: function() {
                    $( this ).dialog( "close" );
                    doDel(item);
                }
            }
            ,
            {
                html: "<i class='ace-icon fa fa-times bigger-110'></i>&nbsp; 取消",
                "class" : "btn btn-minier",
                click: function() {
                    $( this ).dialog( "close" );
                }
            }
        ]
    });
}
 
 
function doDel(item) {
    if (!!I.AjaxDelItem) return;
    I.AjaxDelItem = true;
    $.post('/basicconfig/gates/delCEquipmentItem.htm', {id: item.id}, function(data, textStatus, xhr) {
        I.AjaxDelItem = false;
        if (data.code >= 1) {
           // parent.showErrmsg(data.errmsg);
            swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); 
            return;
        }
        if (data.code == 0) {
            vm.list.remove(item);
            location.replace(location.href);
            return;
        }
    }, 'json');
}
 
function doUsed(item) {
    if (!I.AjaxChangeUsed) {
        var used = !item.state();
        I.AjaxChangeUsed = true;
        $.post('/basicconfig/gates/cequipmentChangeState.htm', {id: item.id, state: used}, function(data, textStatus, xhr) {
            I.AjaxChangeUsed = false;
            if (data.code >= 1) {
                //parent.showErrmsg(data.errmsg);
               swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); 
                return;
            }
            if (data.code == 0) {
                item.state(used);
                return;
            }
        }, 'json');
    }
}