select-class.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. $(".select-class").click(function () {
  2. teacherId=$('input[name=teacherId]').val();
  3. grade=$('.select-grade').val();
  4. gradetext=$('.select-grade option:selected').text();
  5. if(teacherId==0){
  6. layer.msg('请选择阅卷员');
  7. return false;
  8. }
  9. if(grade==0){
  10. layer.msg('请选择年级');
  11. return false;
  12. }
  13. //已选择班级
  14. selectClassData=[];
  15. selectClassEle=$(".selected-box").find('li');
  16. if(selectClassEle.length>0){
  17. selectClassEle.each(function(index,ele){
  18. selectClassData.push($(ele).attr('value'))
  19. })
  20. }
  21. $('#global_check_all').prop('checked',false);
  22. $('#global_check_arts').prop('checked',false);
  23. $('#global_check_science').prop('checked',false);
  24. layer.msg('正在加载班级,请稍候......',{time:0});
  25. $.ajax({
  26. url:'/index.php/third/ajaxGetClassByTeacherGrade',
  27. type:'POST',
  28. dataType:'json',
  29. data:{teacherId:teacherId,grade:grade,selectClassData:selectClassData},
  30. success:function(res){
  31. layer.closeAll();
  32. if(res.status==1){
  33. var selectedBoxHtml='';
  34. classData=res.data;
  35. for(var i=0;i<classData.length;i++){
  36. if(classData[i]['selected']==1){
  37. selectedBoxHtml+="<li class='ellipsis active' classId='"+classData[i]['class_id']+"' artsScience='"+classData[i]['arts_science']+"' title='"+classData[i]['class_name']+"'>"+handleLongName(classData[i]['class_name'],10)+"</li>";
  38. }else{
  39. selectedBoxHtml+="<li class='ellipsis' classId='"+classData[i]['class_id']+"' artsScience='"+classData[i]['arts_science']+"' title='"+classData[i]['class_name']+"'>"+handleLongName(classData[i]['class_name'],10)+"</li>";
  40. }
  41. }
  42. $('#gradeTxt').html(gradetext);
  43. $('.area_1').html(selectedBoxHtml);
  44. $('#fieldModal').show();
  45. }
  46. }
  47. });
  48. return false;
  49. });
  50. // 切换年级
  51. $('.select-grade').change(function(){
  52. $('.selected-box').html('');
  53. grade=$(this).val();
  54. isthird=$(this).attr('isthird');
  55. if(isthird==0){
  56. if(grade!=3){
  57. if(subjects[grade]!=undefined){
  58. $('input[name=subjectId]').val(subjects[grade]['subject_id']);
  59. $('input[name=textbookId]').val(subjects[grade]['textbook_id']);
  60. $('.show_text_book').html(subjects[grade]['subject_name']+' 教材版本'+subjects[grade]['text_book_name']);
  61. }
  62. }else{
  63. if(subjects[3]!=undefined){
  64. $('input[name=subjectId]').val(subjects[3]['subject_id']);
  65. $('input[name=textbookId]').val(subjects[3]['textbook_id']);
  66. $('.show_text_book').html(subjects[3]['subject_name']+' 教材版本'+subjects[3]['text_book_name']);
  67. }else{
  68. $('.show_text_book').html(' 高三通用');
  69. $('input[name=subjectId]').val(6);
  70. $('input[name=textbookId]').val(28);
  71. }
  72. }
  73. }
  74. });
  75. $('.add-class-close,.cancel-btn').click(function () {
  76. $('#fieldModal').hide();
  77. });
  78. $('.area_1')
  79. .on('click','li',function(){
  80. if($(this).hasClass('active')){
  81. $(this).removeClass('active');
  82. }else{
  83. $(this).addClass('active');
  84. }
  85. })
  86. $('#global_check_all').change(function(){
  87. var hasChecked = $(this).prop('checked');
  88. if(!hasChecked){
  89. $('#global_check_arts').prop('checked',false);
  90. $('#global_check_science').prop('checked',false);
  91. }
  92. var allChecks = $('#class_area').find('li');
  93. allChecks.each(function (index,el) {
  94. if(hasChecked){
  95. if($(el).hasClass('active'))return;
  96. $(el).addClass('active');
  97. }else{
  98. if($(el).hasClass('active')){
  99. $(el).removeClass('active')
  100. }
  101. }
  102. });
  103. });
  104. $('#global_check_arts').change(function(){
  105. var hasChecked = $(this).prop('checked');
  106. var allChecks = $('#class_area').find('li');
  107. if(!hasChecked){
  108. $('#global_check_all').prop('checked',false);
  109. }
  110. allChecks.each(function (index,el) {
  111. if(hasChecked){
  112. if($(el).attr('artsScience')=="1" && !$(el).hasClass('active')){
  113. $(el).addClass('active');
  114. }
  115. }else{
  116. if($(el).attr('artsScience')=="1" && $(el).hasClass('active')){
  117. $(el).removeClass('active');
  118. }
  119. }
  120. });
  121. });
  122. $('#global_check_science').change(function(){
  123. var hasChecked = $(this).prop('checked');
  124. if(!hasChecked){
  125. $('#global_check_all').prop('checked',false);
  126. }
  127. var allChecks = $('#class_area').find('li');
  128. allChecks.each(function (index,el) {
  129. if(hasChecked){
  130. if($(el).attr('artsScience')=="2" && !$(el).hasClass('active')){
  131. $(el).addClass('active');
  132. }
  133. }else{
  134. $('#global_check_all').prop('checked',false);
  135. if($(el).attr('artsScience')=="2" && $(el).hasClass('active')){
  136. $(el).removeClass('active');
  137. }
  138. }
  139. });
  140. });
  141. //确定选择班级
  142. $('.setting_sumbit').click(function(){
  143. var allChecks = $('#class_area').find('li');
  144. var selectedBoxHtml='';
  145. allChecks.each(function (index,el) {
  146. if($(el).hasClass('active')){
  147. selectedBoxHtml+='<li value="'+$(el).attr('classId')+'">'+$(el).attr('title')+'<img src="/images/icon-delete.png" alt=""></li>';
  148. }
  149. });
  150. $('.selected-box').html(selectedBoxHtml);
  151. $('#fieldModal').hide();
  152. });
  153. $(".selected-box").on("click", "li", function() {
  154. $(this).remove();
  155. })
  156. function handleLongName(str,length) {
  157. var str_len = str.length;
  158. if(str_len > length){
  159. return str.substring(0,length) + '...';
  160. }else {
  161. return str;
  162. }
  163. }