Administrator
2023-04-19 eeb08a586132f489c10e12551c6479b13c9def5e
提交 | 用户 | 时间
58d006 1 window.I = {}
A 2 var basic=getpath();
3 var modelview=function() {
4     var self=this;
5     self.filter=ko.observable();
6     self.mts=ko.observableArray();
7     self.mt=ko.observable({
8         id:ko.observable(0),
9         title:ko.observable(),
10         note:ko.observable()
11     });
12     self.delmt=function(item){
13         jQuery.post(basic+'/admin/bmenucon/mtpdel.htm', {id: item.id()}, function(data, textStatus, xhr) {
14             if(data.code==1)
15             {
16                 alert(data.errmsg);
17             }else{
18                 self.mts.remove(item);
19             }
20         },'json');
21     };
22     self.editmt=function(item){    
23         $('#modal1').modal('show');
24         self.mt(item);
25     };
26 }
27 jQuery(document).ready(function($) {
28     window.mtype=$('#mtype').val();
29     var md=window.md=new modelview();
30     ko.applyBindings(md);
31     getmts(0,15,null,1,0);
32
33
34     $('#ctbtn').click(function(){
35         md.mt().id(0);
36         md.mt().title("");
37         md.mt().note("");
38         $("#modal1").modal('show');
39     });
40     var fm1=jQuery('#fm1');
41     fm1.validate({
42         rules:{
43             title:{
44                 required:true
45             }
46         },
47         messages:{
48             title:{
49                 required:'请输入题目'
50             }
51         },
52         errorPlacement:function(err,element)
53                         {
54                             err.appendTo($('#errmsg'));
55                         }
56     });
57     $('#tjbtn').click(function(){
58         // if(window.op==1)
59         //     return;
60         // window.op=1;
61         $('#errmsg').text("");
62         if(!fm1.valid())
63             return;
64         var btn=$(this).button('loading');
65         var tt=md.mt();
66         var obj=ko.mapping.toJS(tt);
67         jQuery.post(basic+'/admin/bmenucon/mtpsave.htm', obj, function(data, textStatus, xhr) {
68             // window.op=0;
69             btn.button('reset');
70             
71             if(data==null)
72                 return;
73             if(data.code==1)
74             {
75                 alert(data.errmsg);
76                 return;
77             }
78             if(tt.id()==0)
79             {
80                 $('#modal1').modal('hide');
81                 getmts(0,15,md.filter(),1,data.nid);
82             }
83         },'json');
84     });
85
86     $("#searcha").click(function(){
87         getmts(0,15,md.filter(),1,0);
88     });
89 });
90 function getmts(page,pagesize,filter,pages,tid)
91 {
92     jQuery.post(basic+'/admin/bmenucon/mtps.htm', {page:page,pagesize:pagesize,filter:filter,pages:pages,tid:tid}, function(data, textStatus, xhr) {
93         if(data==null)
94             return;
95         if(data.page!=null)
96             page=data.page;
97         if(data.items!=null)
98         {
99             window.md.mts.removeAll();
100             jQuery.each(data.items, function(index, val) {
101                 window.md.mts.push(ko.mapping.fromJS(val));
102             });
103         }
104         if(data.pages!=null)
105         {
106             $('#pagdiv').unbind('page').empty();
107             if(data.pages>1)
108             {
109                 $('#pagdiv').bootpag({total:data.pages,maxVisible:10,page:page+1}).on('page',function(event,num){
110                       getmts(num-1,pagesize,filter,0,0);
111                 });
112             }
113         }
114     },'json');    
115 }