common.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. /**
  2. * Created by Administrator on 2016/9/7.
  3. */
  4. $(document).on('click','.submitform',function(){
  5. var serialize=$(this).parents('form').serialize();
  6. var action=$(this).parents('form').attr('action');
  7. qls.loading();
  8. $.post(action,serialize,function(data){
  9. qls.close();
  10. if(data.code==1)
  11. {
  12. qls.success(data.msg,data.url);
  13. }
  14. else
  15. {
  16. qls.error(data.msg);
  17. }
  18. },'json');
  19. });
  20. $(document).on('click','.deleteall',function(){
  21. var length= $('input[type="checkbox"].i-checks:checked').length;
  22. var ids='';
  23. for(var i=0;i<length;i++)
  24. {
  25. if(ids!='')ids+=',';
  26. var val=$('input[type="checkbox"].i-checks:checked').eq(i).val();
  27. if(!isNaN(val))ids+=val;
  28. }
  29. qls.waring(function(){
  30. qls.loading();
  31. $.get(jsdeletedata,{id:ids},function(data){
  32. qls.close();
  33. if(data.code==1)
  34. {
  35. swal(data.msg, "您已经永久删除了信息。", "success");
  36. setTimeout(function(){sweetAlert.close();
  37. location.href=data.url;
  38. },2000);
  39. }
  40. else
  41. {
  42. swal(data.msg, "您执行的删除操作失败。", "error");
  43. setTimeout(function(){sweetAlert.close();},2000);
  44. }
  45. },'json');
  46. });
  47. });
  48. function closeDilog(url,fun1,type)
  49. {
  50. $('#modal-dialog .modal-dialog').animate({'margin-top':'-233px'},400,function(){
  51. $('#modal-dialog').remove();
  52. if(qls_location_url!='')
  53. {
  54. location.href=qls_location_url;
  55. }
  56. else if(qls_location_url==''&&type==1)location.reload();
  57. })
  58. }
  59. function selectchange(obj,ids,tabelname,column)
  60. {
  61. var leng=$('#'+ids+' select.form-control.m-b').length;
  62. var level=$(obj).attr('level');
  63. for(var i=0;i<leng;)
  64. {
  65. if($('#'+ids+' select.form-control.m-b').eq(i).attr('level')>level)
  66. {
  67. $('#'+ids+' select.form-control.m-b').eq(i).remove();
  68. continue;
  69. }
  70. i++;
  71. }
  72. var filed=$(obj).attr('field');
  73. $.post(jscascadeUrl,{model:tabelname,column:column,parentId:$(obj).val(),filed:JSON.parse(filed)},function(data){
  74. if(data.data!=null)
  75. {
  76. var htm='<select name="'+ids+'[]" onchange="selectchange(this,\''+ids+'\',\''+tabelname+'\',\''+column+'\')" field=\''+filed+'\' class="form-control m-b" level="'+(parseInt(level)+1)+'"><option value="">--请选择--</option>';
  77. $.each(data.data,function(i,n){
  78. htm+='<option value="'+ n.id+'">'+ n.name+'</option>';
  79. });
  80. htm+='</select>';
  81. if(data.data.length>0)
  82. $(obj).after(htm);
  83. }
  84. },'json');
  85. }
  86. function sendGetAjax(url,datas,fun)
  87. {
  88. qls.loading();
  89. if(datas==null)datas={};
  90. $.get(url,datas,function(data){
  91. qls.close();
  92. if(fun!=null)
  93. {
  94. fun(data);
  95. }
  96. else
  97. {
  98. if(data.code==1)
  99. {
  100. layer.msg(data.msg, {icon: 1, time: 2000});
  101. setTimeout(function(){
  102. location.href=data.url;
  103. },2000);
  104. }
  105. else
  106. {
  107. layer.msg(data.msg, {icon: 2, time: 2000});
  108. }
  109. }
  110. },'json');
  111. }
  112. var qls_location_url='';
  113. var qls={
  114. "success":function(msg,url,fun1,fun2){
  115. qls_location_url=url;
  116. var html='<div class="modal" id="modal-dialog" style="display:block; background:rgba(0,0,0,0.5)"> ' +
  117. '<div class="modal-dialog" style="margin-top: -233px;"> ' +
  118. '<div class="modal-content"> ' +
  119. '<div class="modal-header alert alert-success"> ' +
  120. '<h4 class="modal-title" id="myModalLabel">提示信息 </h4> ' +
  121. '</div> ' +
  122. '<div class="modal-body"> ' +
  123. '<div ><i style="font-size: 45px;color: #3c763d;" class="fa fa-smile-o"></i> <span style="position: relative;top: -11px;padding-left: 10px;font-size: 15px;">'+msg+'</span> </div></div> ' +
  124. '<div class="modal-footer"> ' +
  125. '<button type="button" class="btn btn-primary" onclick="closeDilog('+url+','+fun1+',1)" data-dismiss="modal">确认 ' +
  126. '</button> ' +
  127. '<button type="button" onclick="closeDilog('+url+','+fun2+',1)" class="btn btn-default">取消 </button> ' +
  128. '</div> ' +
  129. '</div> ' +
  130. '</div> ' +
  131. '</div> ';
  132. $('#modal-dialog').remove();
  133. $('body').append(html);
  134. $('#modal-dialog .modal-dialog').animate({'margin-top':'30px'},400,function(){
  135. setTimeout(function(){
  136. $('#modal-dialog .modal-dialog').animate({'margin-top':'-233px'},400,function(){
  137. $('#modal-dialog').remove();
  138. if(qls_location_url!='')
  139. {
  140. location.href=qls_location_url;
  141. }
  142. else if(qls_location_url=='')location.reload();
  143. })
  144. },1300);
  145. });
  146. } ,
  147. "error":function(msg,url,fun1,fun2){
  148. qls_location_url=url!=null?url:'';
  149. var html='<div class="modal" id="modal-dialog" style="display:block; background:rgba(0,0,0,0.5)"> ' +
  150. '<div class="modal-dialog" style="margin-top: -233px;"> ' +
  151. '<div class="modal-content"> ' +
  152. '<div class="modal-header alert alert-danger"> ' +
  153. '<h4 class="modal-title" id="myModalLabel">提示信息 </h4> ' +
  154. '</div> ' +
  155. '<div class="modal-body"> ' +
  156. '<div ><i style="font-size: 45px;color: #a94442;" class="fa fa-smile-o"></i> <span style="position: relative;top: -11px;padding-left: 10px;font-size: 15px;">'+msg+'</span> </div></div> ' +
  157. '<div class="modal-footer"> ' +
  158. '<button type="button" class="btn btn-danger" onclick="closeDilog('+url+','+fun1+',2)" data-dismiss="modal">确认 ' +
  159. '</button> ' +
  160. '<button type="button" onclick="closeDilog('+url+','+fun2+',2)" class="btn btn-default">取消 </button> ' +
  161. '</div> ' +
  162. '</div> ' +
  163. '</div> ' +
  164. '</div> ';
  165. $('#modal-dialog').remove();
  166. $('body').append(html);
  167. $('#modal-dialog .modal-dialog').animate({'margin-top':'30px'},400,function(){
  168. setTimeout(function(){
  169. $('#modal-dialog .modal-dialog').animate({'margin-top':'-233px'},400,function(){
  170. $('#modal-dialog').remove();
  171. if(qls_location_url!='')
  172. {
  173. location.href=qls_location_url;
  174. }
  175. })
  176. },1300);
  177. });
  178. },
  179. "waring":function(func){//警告
  180. swal({
  181. title: "您确定要执行该操作吗?",
  182. text: "数据操作后将无法还原,请谨慎操作!",
  183. type: "warning",
  184. showCancelButton: true,
  185. confirmButtonColor: "#DD6B55",
  186. confirmButtonText: "执行",
  187. closeOnConfirm: false
  188. }, func);
  189. },
  190. "prompt":function(title,fun,type,val){
  191. parent.layer.prompt({
  192. title: title,
  193. value:val!=null?val:'',
  194. formType: type!=null?type:2 //prompt风格,支持1-2
  195. }, fun);
  196. },
  197. "confirm":function(title,fun1,fun2){
  198. var html='<div class="modal" id="modal-dialog" style="display:block; background:rgba(0,0,0,0.5)"></div>';
  199. $('#modal-dialog').remove();
  200. $('body').append(html);
  201. parent.layer.confirm(title, {
  202. btn: ['确认','取消'], //按钮
  203. shade: false //不显示遮罩
  204. }, function(){
  205. if(fun1!=null) fun1();
  206. $('#modal-dialog').remove();
  207. }, function(){
  208. if(fun2!=null)fun2();
  209. $('#modal-dialog').remove();
  210. });
  211. },
  212. "loading":function(){
  213. parent.layer.load(1, {
  214. shade: [0.5,'#fff'] //0.1透明度的白色背景
  215. });
  216. },
  217. "msg":function(title,icon){//icon 1成功 2失败 3疑问 4锁定
  218. parent.layer.msg(title, {icon: icon!=null?icon:1});
  219. },
  220. "open":function(title,html,wh){
  221. if(wh==null)
  222. {
  223. wh=['420px', '240px'];
  224. }
  225. parent.layer.open({
  226. title:title,
  227. type: 1,
  228. area: [wh[0], wh[1]], //宽高
  229. skin: 'layui-layer-demo', //样式类名
  230. closeBtn: true, //不显示关闭按钮
  231. shift: 2,
  232. shadeClose: true, //开启遮罩关闭
  233. content: html
  234. });
  235. },
  236. "poenifrm":function(title,url,wh){
  237. if(wh==null)wh=['80%', '60%'];
  238. layer.open({
  239. type: 2,
  240. title: title,
  241. shadeClose: true,
  242. shade: 0.8,
  243. area:wh ,
  244. content: url //iframe的url
  245. });
  246. },
  247. "close":function(){
  248. layer.closeAll();
  249. parent.layer.closeAll();
  250. },
  251. /**
  252. * 级联
  253. * @param 元素id
  254. * @param tabelname 表名
  255. * @param column 关联键名
  256. * @param parentId 上级id
  257. * @param filed 查询的字段对象{"name":"","id":""}
  258. */
  259. "cascade":function(slecteds,tabelname,column,parentId,filed,val,html,level)//qls.cascade('slecteds','area','parent_id',0,{"name":'area_name',"id":"area_id"},'15,16');
  260. {
  261. if(parentId==='')return false;
  262. var vals=val!=null?val.split(','):[];
  263. var levels=level!=null?level:0;
  264. //if(vals.length<=leves+1)return html;
  265. var htmls=html!=null?html:'';
  266. var str=JSON.stringify(filed);
  267. var htm='<select name="'+slecteds+'[]" onchange="selectchange(this,\''+slecteds+'\',\''+tabelname+'\',\''+column+'\')" field=\''+str+'\' class="form-control m-b" level="'+levels+'"><option value="">--请选择--</option>';
  268. var pid='';
  269. $.post(jscascadeUrl,{model:tabelname,column:column,parentId:parentId,filed:filed},function(data){
  270. if(data.data!=null)
  271. {
  272. $.each(data.data,function(i,n){
  273. var ische='';
  274. if(vals[levels]== n.id)
  275. {
  276. ische='selected=selected';
  277. pid=n.id;
  278. }
  279. htm+='<option '+ische+' value="'+ n.id+'">'+ n.name+'</option>';
  280. });
  281. htm+='</select>';
  282. }
  283. htmls+=htm;
  284. if(vals.length>levels&&pid!='')
  285. {
  286. qls.cascade(slecteds,tabelname,column,pid,filed,val,htmls,levels+1);
  287. }
  288. if(data.data.length>0)
  289. {
  290. $('#'+slecteds).html(htmls);
  291. }
  292. },'json');
  293. }
  294. };
  295. /**
  296. * post 请求
  297. * @param url
  298. * @param data
  299. * @param func
  300. */
  301. function sendajax(url,data,func)
  302. {
  303. qls.loading();
  304. $.post(url,data,function(datas){
  305. qls.close();
  306. if(func!=null)func(datas);
  307. else
  308. {
  309. if(datas.code==1)
  310. {
  311. swal(datas.msg, "你执行的操作已成功,数据已更新。", "success");
  312. setTimeout(function(){
  313. location.href=datas.url;
  314. },2000);
  315. }
  316. else
  317. {
  318. swal(datas.msg, "你执行的操作失败,数据未更新。", "error");
  319. }
  320. }
  321. },'json')
  322. }