ajax.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. $(document).ready(function(){
  2. var examGroupId=$('input[name=exam_group_id]').val();
  3. var page=1;
  4. $('#viewNoUploadPaperStudentAll').click(function(){
  5. page=1;
  6. loadStudent(examGroupId,page,0);
  7. });
  8. $('#studentType').change(function(){
  9. page=1;
  10. loadStudent(examGroupId,page,1);
  11. });
  12. $('#classes').change(function(){
  13. page=1;
  14. loadStudent(examGroupId,page,1);
  15. });
  16. $('.student_list_page')
  17. .on('click','.gotoPage',function(){
  18. page=parseInt($(this).html())
  19. loadStudent(examGroupId,page,1);
  20. })
  21. .on('click','.previous',function(){
  22. page=parseInt($(this).attr('pageNum'))
  23. loadStudent(examGroupId,page,1);
  24. })
  25. .on('click','.next',function(){
  26. page=parseInt($(this).attr('pageNum'))
  27. loadStudent(examGroupId,page,1);
  28. })
  29. $('.student-list')
  30. .on('click','.delStudent',function(){
  31. studentsIds=[];
  32. studentId=$(this).closest('tr').find('input').val();
  33. examId=$(this).attr('exam_id');
  34. studentsIds.push(studentId);
  35. obj=$(this).closest('tr');
  36. layer.msg('确定删除选中的学生吗?', {
  37. time: 0,
  38. btn: ['确定', '取消'],
  39. yes: function(index){
  40. layer.close(index);
  41. var data={
  42. "studentsIds":studentsIds,
  43. "examId":examId,
  44. "examGroupId":examGroupId,
  45. };
  46. jQuery.post(
  47. "/index.php/print/delExamStudent",data,function(data){
  48. var m =JSON.parse(data);
  49. if(m.status==1)
  50. {
  51. var icon = 6;
  52. layer.alert("删除成功", {icon: icon}, function(){
  53. obj.find('.status').html('缺考');
  54. obj.find('td:last').html('');
  55. layer.closeAll()
  56. });
  57. }else{
  58. var icon = 5;
  59. layer.alert("删除失败", {icon: icon}, function(){
  60. layer.closeAll()
  61. });
  62. }
  63. });
  64. }
  65. });
  66. })
  67. $('.delBatchStudent').click(function(){
  68. var studentsIds=[];
  69. layer.msg('确定删除选中的学生吗?', {
  70. time: 0,
  71. btn: ['确定', '取消'],
  72. yes: function(index){
  73. layer.close(index);
  74. if (!$("input[class='myselect']").is(':checked'))
  75. {
  76. layer.msg('请至少选择一个学生!');return false;
  77. }
  78. jQuery("input[class='myselect']").each(function()
  79. {
  80. if(jQuery(this).is(":checked") && typeof(jQuery(this).val())!= "undefined")
  81. {
  82. studentsIds.push(jQuery(this).val());
  83. }
  84. });
  85. var data={
  86. "studentsIds":studentsIds,
  87. "examGroupId":examGroupId,
  88. };
  89. jQuery.post(
  90. "/index.php/print/delExamStudent",data,function(data){
  91. var m =JSON.parse(data);
  92. if(m.status==1)
  93. {
  94. var icon = 6;
  95. layer.alert("删除成功", {icon: icon}, function(){
  96. loadStudent(examGroupId,page,1);
  97. layer.closeAll()
  98. });
  99. }else{
  100. var icon = 5;
  101. layer.alert("删除失败", {icon: icon}, function(){
  102. layer.closeAll()
  103. });
  104. }
  105. });
  106. }
  107. });
  108. return false;
  109. });
  110. $('.downLoadBatchStudent').click(function(){
  111. layer.msg('确定下载全部未上传学生吗?', {
  112. time: 0,
  113. btn: ['确定', '取消'],
  114. yes: function(index){
  115. layer.close(index);
  116. window.location.href="/index.php/print/downloadSelectStudent?examGroupId="+examGroupId
  117. }
  118. });
  119. return false;
  120. });
  121. $('.delAllStudent').click(function(){
  122. layer.msg('确定删除全部未上传学生吗?', {
  123. time: 0,
  124. btn: ['确定', '取消'],
  125. yes: function(index){
  126. layer.close(index);
  127. var data={
  128. "examGroupId":examGroupId,
  129. };
  130. jQuery.post(
  131. "/index.php/print/delAllNotUploadStudent",data,function(data){
  132. var m =JSON.parse(data);
  133. if(m.status==1)
  134. {
  135. var icon = 6;
  136. layer.alert("删除成功", {icon: icon}, function(){
  137. loadStudent(examGroupId,page,1);
  138. layer.closeAll()
  139. });
  140. }else{
  141. var icon = 5;
  142. layer.alert("删除失败", {icon: icon}, function(){
  143. layer.closeAll()
  144. });
  145. }
  146. });
  147. }
  148. });
  149. return false;
  150. });
  151. function loadStudent(examGroupId,page,select){
  152. var classId=$('#classes').val(),
  153. studentType=$('#studentType').val();
  154. if(select==0){
  155. classId=0;
  156. }
  157. $.ajax({
  158. url:'/index.php/print/ajaxLoadNoUploadStudent',
  159. type:'POST',
  160. dataType:'json',
  161. data:{exam_group_id:examGroupId,page:page,class_id:classId,is_del:studentType},
  162. success:function(res){
  163. if(res.status==1){
  164. var data=res.data,
  165. listHtml='',
  166. pageHtml='',
  167. classHtml='';
  168. if(select==0){
  169. classHtml+='<option value="0">全部</option>';
  170. $.each(data['classes'],function(index,value){
  171. classHtml+='<option value="'+index+'">'+value+'</option>';
  172. });
  173. $('#classes').html(classHtml);
  174. }
  175. if(data['list'].length>0){
  176. $.each(data['list'],function(index,value){
  177. listHtml+='<tr>';
  178. listHtml+='<td><input type="checkbox" value="'+value['student_id']+'" class="myselect" name="student[]"><input type="hidden" name="examId" class="examId" value="'+value['exam_id']+'"></td>';
  179. listHtml+='<td>'+(index+1+(page-1)*data['pageLimit'])+'</td>';
  180. listHtml+='<td class="studentName">'+value['student_name']+'</td>';
  181. listHtml+='<td class="studentCard">'+value['student_card']+'</td>';
  182. listHtml+='<td class="schoolStudentCard">'+value['school_student_card']+'</td>';
  183. listHtml+='<td class="className">'+value['class_name']+'</td>';
  184. listHtml+='<td class="status">'+value['status']+'</td>';
  185. if(value['status']=='未上传'){
  186. listHtml+='<td ><a href="#" exam_id="'+value['exam_id']+'" class="delStudent">删除</td>';
  187. }else{
  188. listHtml+='<td></td>';
  189. }
  190. listHtml+='</tr>';
  191. });
  192. }else{
  193. listHtml+='<tr>';
  194. listHtml+='<td colspan="8">暂无数据</td>';
  195. listHtml+='</tr>';
  196. }
  197. //分页
  198. if(data['totalPage']>1){
  199. pageHtml+='<ul class="yiiPager">';
  200. var startPage=page-2;
  201. var endPage=page+2;
  202. if(startPage<1){
  203. startPage=1;
  204. }
  205. if(endPage>data['totalPage']){
  206. endPage=data['totalPage']
  207. }
  208. if(page>1){
  209. pageHtml+='<li class="previous" pageNum="'+(page-1)+'"><a href="#" >上一页</a></li>';
  210. }
  211. for(var i=startPage;i<=endPage;i++){
  212. if(page==i){
  213. pageHtml+='<li class="page selected"><a href="#" >'+i+'</a></li>';
  214. }else{
  215. pageHtml+='<li class="page"><a href="#" class="gotoPage">'+i+'</a></li>';
  216. }
  217. }
  218. if(page<data['totalPage']){
  219. pageHtml+='<li class="next" pageNum="'+(page+1)+'"><a href="#" >下一页</a></li>';
  220. }
  221. pageHtml+='<li >共:'+data['total']+'条</li>';
  222. pageHtml+='</ul>';
  223. }
  224. $('.student_list_page').html(pageHtml);
  225. $('.student-list').find('tbody').html(listHtml)
  226. $('#fieldModalStudent').show();
  227. $(".selectAll").prop("checked",false);
  228. }
  229. }
  230. });
  231. }
  232. $('.student-list-close').click(function(){
  233. $("#classes").find("option:contains('0')").attr("selected",true);
  234. $('#fieldModalStudent').hide();
  235. });
  236. // 全选\反选
  237. $(".selectAll").on('click',function(event){
  238. if ($(this).prop("checked")) {
  239. var s_obj = $(".myselect");
  240. var s_len = s_obj.length;
  241. for (var i=0;i<s_len;i++) {
  242. if (!s_obj[i].disabled) {
  243. s_obj[i].checked=true;
  244. }
  245. }
  246. } else {
  247. $(".myselect").prop("checked",false);
  248. }
  249. });
  250. $('#transfer').click(function(){
  251. $.ajax({
  252. url:'/index.php/print/getUploadedStudent',
  253. type:'POST',
  254. dataType:'json',
  255. data:{examGroupId:examGroupId},
  256. success:function(res){
  257. if(res.success==1){
  258. if(res.data.uploaded.length>0){
  259. uploaded=res.data.uploaded;
  260. html='';
  261. for(var i=0;i<uploaded.length;i++){
  262. html+='<option value="'+uploaded[i]['student_id']+'">'+uploaded[i]['student_name']+' '+uploaded[i]['student_card']+'</option>';
  263. }
  264. $('#uploadedStudent').html(html);
  265. $('#uploadedStudent').select2();
  266. }
  267. if(res.data.noUploaded.length>0){
  268. noUploaded=res.data.noUploaded;
  269. html='';
  270. for(var i=0;i<noUploaded.length;i++){
  271. html+='<option value="'+noUploaded[i]['student_id']+'">'+noUploaded[i]['student_name']+' '+noUploaded[i]['student_card']+'</option>';
  272. }
  273. $('#noUploadedStudent').html(html);
  274. $('#noUploadedStudent').select2();
  275. }
  276. }else{
  277. if(res.message!=undefined){
  278. layer.msg(res.message);
  279. }else{
  280. layer.msg('加载考试学生数据失败');
  281. }
  282. }
  283. }
  284. })
  285. $('#transferWindow').show();
  286. });
  287. $('.transfer-close,.transfer-cancel-btn').click(function(){
  288. $('#transferWindow').hide();
  289. });
  290. $('.transferSubmit').click(function(){
  291. var uploadStudent=$('#uploadedStudent').val(),
  292. noUploadStudent=$('#noUploadedStudent').val();
  293. layer.msg('成绩转移中,请稍候。。。。。。',{time:0});
  294. $.ajax({
  295. url:'/index.php/print/ajaxTransferStudentRs',
  296. type:'POST',
  297. dataType:'json',
  298. data:{examGroupId:examGroupId,uploadStudentId:uploadStudent,noUploadStudentId:noUploadStudent},
  299. success:function(res){
  300. if(res.success==1){
  301. layer.msg('转移成功',{
  302. icon: 1
  303. }, function(){
  304. layer.closeAll();
  305. $('#transferWindow').hide();
  306. });
  307. }else{
  308. if(res.message!=undefined){
  309. layer.msg(res.message);
  310. }else{
  311. layer.msg('转移失败');
  312. }
  313. }
  314. }
  315. });
  316. });
  317. //删除未上传班级学生
  318. $('.delClassStudent').click(function(){
  319. //加载班级
  320. examGroupId=$('input[name=exam_group_id]').val();
  321. $.ajax({
  322. url:'/index.php/print/loadExamClass',
  323. type:'POST',
  324. dataType:'json',
  325. data:{examGroupId:examGroupId},
  326. success:function (res) {
  327. if(res.status==1){
  328. if(res.uploaded.length>0){
  329. html=' <input type="checkbox" class="select_upload_class" value="">全选';
  330. $.each(res.uploaded,function(i,n){
  331. html += "<span class='show_classes'><input type='checkbox' class='uploaded student_paper_class' name='paper_class[]' value='"+n.exam_id+"'>" + n.class_name + " </span>";
  332. });
  333. $('.show_uploaded').html(html);
  334. }else{
  335. $('.show_uploaded').html('无');
  336. }
  337. if(res.no_uploaded.length>0){
  338. html2=' <input type="checkbox" class="select_noupload_class" value="">全选';
  339. $.each(res.no_uploaded,function(i,n){
  340. html2 += "<span class='show_classes'><input type='checkbox' class='no_uploaded student_paper_class' name='paper_class[]' value='"+n.exam_id+"'>" + n.class_name + " </span>";
  341. });
  342. $('.show_nouploaded').html(html2);
  343. }else{
  344. $('.show_nouploaded').html('无');
  345. }
  346. layer.open({
  347. type: 1,
  348. title: '删除未上传',
  349. btn: ['确定', '取消'],
  350. area: ['420px', '340px'], //宽高
  351. btnAlign: 'c',
  352. content: $('#studentUploadClass'),
  353. yes: function (index, layero) {
  354. var examIds=[];
  355. $(".student_paper_class").each(function(m,n){
  356. if ($(this).prop('checked')) {
  357. examIds.push($(this).val())
  358. }
  359. });
  360. if (examIds.length==0) {
  361. layer.msg('请至少选择一个班级!');return false;
  362. }
  363. layer.msg('确定删除选中班级内未上传的学生吗?', {
  364. time: 0,
  365. btn: ['确定', '取消'],
  366. yes: function(index){
  367. indexNo=layer.msg('正在删除,请稍候......',{time:0})
  368. //提交
  369. $.ajax({
  370. type: 'post',
  371. url: "/index.php/print/delStudentPaperRelation",
  372. data: {'examIds': examIds},
  373. dataType: 'json',
  374. success: function (data) {
  375. layer.close(indexNo)
  376. if (data.status) {
  377. var icon = 6;
  378. layer.alert("删除成功", {icon: icon}, function(){
  379. loadStudent(examGroupId,page,1);
  380. layer.closeAll()
  381. });
  382. } else {
  383. var icon = 5;
  384. layer.alert("删除失败", {icon: icon}, function(){
  385. layer.closeAll()
  386. });
  387. }
  388. }
  389. })
  390. }
  391. });
  392. }
  393. });
  394. }
  395. }
  396. });
  397. return false;
  398. });
  399. // 全选\反选
  400. $('#studentUploadClass')
  401. .on('click','.select_upload_class',function(){
  402. if ($(this).prop("checked")) {
  403. $(".uploaded").prop("checked",true);
  404. } else {
  405. $(".uploaded").prop("checked",false);
  406. }
  407. })
  408. .on('click','.select_noupload_class',function(){
  409. if ($(this).prop("checked")) {
  410. $(".no_uploaded").prop("checked",true);
  411. } else {
  412. $(".no_uploaded").prop("checked",false);
  413. }
  414. })
  415. })