Administrator
2022-09-14 58d006e05dcf2a20d0ec5367dd03d66a61db6849
提交 | 用户 | 时间
58d006 1 /**
A 2 * date: 2016-12-20
3 * author: neeler
4 */
5
6 //test data start
7 // var data_getSysConfig = Mock.mock('/system/getSysConfig.htm', {code: 0, errmsg: '获取失败!', item: {isSendSMSCode: true, isVisitorCheck: true}})
8 // var data_setSysConfig = Mock.mock('/system/setSysConfig.htm', {code: 0, errmsg: '设置失败!', value: true})
9 //test data end
10
11 window.I = {
12     save: $('#save')
13 }
14
15 var ViewModel = function() {
16     var self = this;
17     self.sklimit=ko.observable();
18     self.mustloading=ko.observable();
19     self.ingotpounds=ko.observable();
20     self.qtpounds=ko.observable();
21     self.fbout=ko.observable();
22 }
23
24 $(function () {
25     window.vm = new ViewModel();
26     ko.applyBindings(vm);
27     getSysConfig();
28     pageInit();
29
30     // $('.confi').blur(function(event) {
31     //     var $this=$(this);
32     //     var name=$this.attr("name");
33     //     var value=$this.val();
34     //     setSysConfig(name,value);
35     // });
36 });
37
38 function pageInit() {
39     I.save.click(function (e) { 
40         e.preventDefault();
41         setAllSysConfig();
42     });
43 }
44
45 function getSysConfig() {
46     $.post('/system/configs.htm', null, function(data, textStatus, xhr) {
47         jQuery.each(data, function(index, val) {
48             if(val.name=='sklimit'){
49                 vm.sklimit(val.value);
50             }else if(val.name=='mustloading'){
51                 vm.mustloading(val.value);
52             }else if(val.name=='ingotpounds'){
53                 vm.ingotpounds(val.value);
54             }else if(val.name=='qtpounds'){
55                 vm.qtpounds(val.value);
56             }else if(val.name=='fbout'){
57                 vm.fbout(val.value);
58             }
59         });
60     }, 'json');
61 }
62
63 function setSysConfig(name, value) {
64     $.post('/system/setSysConfig.htm', {name: name, value: value}, function(data, textStatus, xhr) {
65         if (data.code >= 1) {
66             //showErrmsg(data.errmsg);
67             swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); 
68             return;
69         }
70         if (data.code == 0) {
71             if(name=='sklimit'){
72                 vm.sklimit(value);
73             }else if(name=='mustloading'){
74                 vm.mustloading(value);
75             }else if(name=='ingotpounds'){
76                 vm.ingotpounds(value);
77             }else if(name=='qtpounds'){
78                 vm.qtpounds(value);
79             }else if(name=='fbout'){
80                 vm.fbout(value);
81             }
82             showErrmsg("配置"+name+"已经设置成功");
83             return;
84         }
85     }, 'json');
86 }
87
88 function setAllSysConfig() {
89     $.post("/system/setallSysConfig.htm", {
90         sklimit: vm.sklimit(),
91         mustloading: vm.mustloading(),
92         ingotpounds: vm.ingotpounds(),
93         qtpounds: vm.qtpounds(),
94         fbout: vm.fbout()
95     },
96         function (data, textStatus, jqXHR) {
97             if (data.code >= 1) {
98                 showErrmsg(data.errmsg);
99                 return;
100             }
101             if (data.code == 0) {
102                 showErrmsg('保存成功!');
103                 return;
104             }
105         },
106         "json"
107     );
108 }