hjg
2023-11-18 bb48edb3d9faaaeab0088151c86fc24137acdb08
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
/**
* date: 2016-12-20
* author: neeler
*/
 
//test data start
// var data_getSysConfig = Mock.mock('/system/getSysConfig.htm', {code: 0, errmsg: '获取失败!', item: {isSendSMSCode: true, isVisitorCheck: true}})
// var data_setSysConfig = Mock.mock('/system/setSysConfig.htm', {code: 0, errmsg: '设置失败!', value: true})
//test data end
 
window.I = {
    save: $('#save')
}
 
var ViewModel = function() {
    var self = this;
    self.sklimit=ko.observable();
    self.mustloading=ko.observable();
    self.ingotpounds=ko.observable();
    self.qtpounds=ko.observable();
    self.fbout=ko.observable();
}
 
$(function () {
    window.vm = new ViewModel();
    ko.applyBindings(vm);
    getSysConfig();
    pageInit();
 
    // $('.confi').blur(function(event) {
    //     var $this=$(this);
    //     var name=$this.attr("name");
    //     var value=$this.val();
    //     setSysConfig(name,value);
    // });
});
 
function pageInit() {
    I.save.click(function (e) { 
        e.preventDefault();
        setAllSysConfig();
    });
}
 
function getSysConfig() {
    $.post('/system/configs.htm', null, function(data, textStatus, xhr) {
        jQuery.each(data, function(index, val) {
            if(val.name=='sklimit'){
                vm.sklimit(val.value);
            }else if(val.name=='mustloading'){
                vm.mustloading(val.value);
            }else if(val.name=='ingotpounds'){
                vm.ingotpounds(val.value);
            }else if(val.name=='qtpounds'){
                vm.qtpounds(val.value);
            }else if(val.name=='fbout'){
                vm.fbout(val.value);
            }
        });
    }, 'json');
}
 
function setSysConfig(name, value) {
    $.post('/system/setSysConfig.htm', {name: name, value: value}, function(data, textStatus, xhr) {
        if (data.code >= 1) {
            //showErrmsg(data.errmsg);
            swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); 
            return;
        }
        if (data.code == 0) {
            if(name=='sklimit'){
                vm.sklimit(value);
            }else if(name=='mustloading'){
                vm.mustloading(value);
            }else if(name=='ingotpounds'){
                vm.ingotpounds(value);
            }else if(name=='qtpounds'){
                vm.qtpounds(value);
            }else if(name=='fbout'){
                vm.fbout(value);
            }
            showErrmsg("配置"+name+"已经设置成功");
            return;
        }
    }, 'json');
}
 
function setAllSysConfig() {
    $.post("/system/setallSysConfig.htm", {
        sklimit: vm.sklimit(),
        mustloading: vm.mustloading(),
        ingotpounds: vm.ingotpounds(),
        qtpounds: vm.qtpounds(),
        fbout: vm.fbout()
    },
        function (data, textStatus, jqXHR) {
            if (data.code >= 1) {
                showErrmsg(data.errmsg);
                return;
            }
            if (data.code == 0) {
                showErrmsg('保存成功!');
                return;
            }
        },
        "json"
    );
}